Blame SOURCES/mellon_create_metadata.sh

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