Blame SOURCES/mellon_create_metadata.sh

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