Blame SOURCES/mellon_create_metadata.sh

198568
#!/usr/bin/env bash
198568
set -e
198568
198568
PROG="$(basename "$0")"
198568
198568
printUsage() {
198568
    echo "Usage: $PROG ENTITY-ID ENDPOINT-URL"
198568
    echo ""
198568
    echo "Example:"
198568
    echo "  $PROG urn:someservice https://sp.example.org/mellon"
198568
    echo ""
198568
}
198568
198568
if [ "$#" -lt 2 ]; then
198568
    printUsage
198568
    exit 1
198568
fi
198568
198568
ENTITYID="$1"
198568
if [ -z "$ENTITYID" ]; then
198568
    echo "$PROG: An entity ID is required." >&2
198568
    exit 1
198568
fi
198568
198568
BASEURL="$2"
198568
if [ -z "$BASEURL" ]; then
198568
    echo "$PROG: The URL to the MellonEndpointPath is required." >&2
198568
    exit 1
198568
fi
198568
198568
if ! echo "$BASEURL" | grep -q '^https\?://'; then
198568
    echo "$PROG: The URL must start with \"http://\" or \"https://\"." >&2
198568
    exit 1
198568
fi
198568
198568
HOST="$(echo "$BASEURL" | sed 's#^[a-z]*://\([^/]*\).*#\1#')"
198568
BASEURL="$(echo "$BASEURL" | sed 's#/$##')"
198568
198568
OUTFILE="$(echo "$ENTITYID" | sed 's/[^A-Za-z.]/_/g' | sed 's/__*/_/g')"
198568
echo "Output files:"
198568
echo "Private key:                              $OUTFILE.key"
198568
echo "Certificate:                              $OUTFILE.cert"
198568
echo "Metadata:                                 $OUTFILE.xml"
198568
echo "Host:                                     $HOST"
198568
echo
198568
echo "Endpoints:"
198568
echo "SingleLogoutService (SOAP):               $BASEURL/logout"
198568
echo "SingleLogoutService (HTTP-Redirect):      $BASEURL/logout"
198568
echo "AssertionConsumerService (HTTP-POST):     $BASEURL/postResponse"
198568
echo "AssertionConsumerService (HTTP-Artifact): $BASEURL/artifactResponse"
198568
echo "AssertionConsumerService (PAOS):          $BASEURL/paosResponse"
198568
echo
198568
198568
# No files should not be readable by the rest of the world.
198568
umask 0077
198568
198568
TEMPLATEFILE="$(mktemp -t mellon_create_sp.XXXXXXXXXX)"
198568
198568
cat >"$TEMPLATEFILE" <
198568
RANDFILE           = /dev/urandom
198568
[req]
198568
default_bits       = 2048
198568
default_keyfile    = privkey.pem
198568
distinguished_name = req_distinguished_name
198568
prompt             = no
198568
policy             = policy_anything
198568
[req_distinguished_name]
198568
commonName         = $HOST
198568
EOF
198568
198568
openssl req -utf8 -batch -config "$TEMPLATEFILE" -new -x509 -days 3652 -nodes -out "$OUTFILE.cert" -keyout "$OUTFILE.key" 2>/dev/null
198568
198568
rm -f "$TEMPLATEFILE"
198568
198568
CERT="$(grep -v '^-----' "$OUTFILE.cert")"
198568
198568
cat >"$OUTFILE.xml" <
198568
198568
198568
 entityID="$ENTITYID"
198568
 xmlns="urn:oasis:names:tc:SAML:2.0:metadata">
198568
 
198568
   AuthnRequestsSigned="true"
198568
   WantAssertionsSigned="true"
198568
   protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
198568
   <KeyDescriptor use="signing">
198568
     <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
198568
       <ds:X509Data>
198568
         <ds:X509Certificate>$CERT</ds:X509Certificate>
198568
       </ds:X509Data>
198568
     </ds:KeyInfo>
198568
   </KeyDescriptor>
198568
   <KeyDescriptor use="encryption">
198568
     <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
198568
       <ds:X509Data>
198568
         <ds:X509Certificate>$CERT</ds:X509Certificate>
198568
       </ds:X509Data>
198568
     </ds:KeyInfo>
198568
   </KeyDescriptor>
198568
   
198568
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"
198568
     Location="$BASEURL/logout" />
198568
   
198568
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
198568
     Location="$BASEURL/logout" />
198568
   <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
198568
   
198568
     index="0"
198568
     isDefault="true"
198568
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
198568
     Location="$BASEURL/postResponse" />
198568
   
198568
     index="1"
198568
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact"
198568
     Location="$BASEURL/artifactResponse" />
198568
   
198568
     index="2"
198568
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS"
198568
     Location="$BASEURL/paosResponse" />
198568
 </SPSSODescriptor>
198568
</EntityDescriptor>
198568
EOF
198568
198568
umask 0777
198568
chmod go+r "$OUTFILE.xml"
198568
chmod go+r "$OUTFILE.cert"