Blame SOURCES/mellon_create_metadata.sh

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