Set exec bit.
[shibboleth/cpp-sp.git] / configs / metagen.sh
1 #! /bin/sh
2
3 while getopts a:c:e:h:n:o:s:t: c
4      do
5          case $c in
6            c)         CERT=$OPTARG;;
7            e)         ENTITYID=$OPTARG;;
8            h)         HOSTS[${#HOSTS[*]}]=$OPTARG;;
9            n)         NAKEDHOSTS[${#NAKEDHOSTS[*]}]=$OPTARG;;
10            o)         ORGNAME=$OPTARG;;
11            a)         ADMIN[${#ADMIN[*]}]=$OPTARG;;
12            s)         SUP[${#SUP[*]}]=$OPTARG;;
13            t)         TECH[${#TECH[*]}]=$OPTARG;;
14            \?)        echo metagen -c certificate -h host1 [-h host2 ...] [-e entityID]
15                       exit 1;;
16          esac
17      done
18
19 if [ ${#HOSTS[*]} -eq 0 -a ${#NAKEDHOSTS[*]} -eq 0 ] ; then
20     echo metagen -c certificate -h host1 [-h host2 ...] [-e entityID]
21     exit 1
22 fi
23
24 if [ -z $CERT ] ; then
25     CERT=sp-cert.pem
26 fi
27
28 if  [ ! -s $CERT ] ; then
29     echo Certificate file $CERT does not exist! 
30     exit 2
31 fi
32
33 if [ -z $ENTITYID ] ; then
34     ENTITYID=https://${HOSTS[0]}/shibboleth
35 fi
36
37 cat <<EOF
38 <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="${ENTITYID}">
39   <md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol urn:oasis:names:tc:SAML:1.1:protocol urn:oasis:names:tc:SAML:1.0:protocol">
40     <md:Extensions>
41 EOF
42
43 count=1
44 for h in ${HOSTS[@]}
45 do
46   cat << EOF
47       <DiscoveryResponse xmlns="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="https://$h/Shibboleth.sso/DS" index="$count"/>
48 EOF
49   let "count++"
50 done
51
52 for h in ${NAKEDHOSTS[@]}
53 do
54   cat << EOF
55       <DiscoveryResponse xmlns="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="http://$h/Shibboleth.sso/DS" index="$count"/>
56 EOF
57   let "count++"
58 done
59
60 cat << EOF
61     </md:Extensions>
62     <md:KeyDescriptor>
63       <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
64         <ds:X509Data>
65           <ds:X509Certificate>
66 EOF
67
68 grep -v ^- $CERT
69
70 cat <<EOF
71           </ds:X509Certificate>
72         </ds:X509Data>
73       </ds:KeyInfo>
74     </md:KeyDescriptor>
75     <!--
76 EOF
77
78 for h in ${HOSTS[@]}
79 do
80   cat <<EOF
81     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="https://$h/Shibboleth.sso/SLO/SOAP"/>
82     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://$h/Shibboleth.sso/SLO/Redirect"/>
83     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://$h/Shibboleth.sso/SLO/POST"/>
84     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="https://$h/Shibboleth.sso/SLO/Artifact"/>
85 EOF
86 done
87
88 for h in ${NAKEDHOSTS[@]}
89 do
90   cat <<EOF
91     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="http://$h/Shibboleth.sso/SLO/SOAP"/>
92     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://$h/Shibboleth.sso/SLO/Redirect"/>
93     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://$h/Shibboleth.sso/SLO/POST"/>
94     <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="http://$h/Shibboleth.sso/SLO/Artifact"/>
95 EOF
96 done
97
98 for h in ${HOSTS[@]}
99 do
100   cat <<EOF
101     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="https://$h/Shibboleth.sso/NIM/SOAP"/>
102     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://$h/Shibboleth.sso/NIM/Redirect"/>
103     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://$h/Shibboleth.sso/NIM/POST"/>
104     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="https://$h/Shibboleth.sso/NIM/Artifact"/>
105 EOF
106 done
107
108 for h in ${NAKEDHOSTS[@]}
109 do
110   cat <<EOF
111     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" Location="http://$h/Shibboleth.sso/NIM/SOAP"/>
112     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://$h/Shibboleth.sso/NIM/Redirect"/>
113     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://$h/Shibboleth.sso/NIM/POST"/>
114     <md:ManageNameIDService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="http://$h/Shibboleth.sso/NIM/Artifact"/>
115 EOF
116 done
117
118 cat <<EOF
119     -->
120 EOF
121
122 count=0
123 for h in ${HOSTS[@]}
124 do
125   cat <<EOF
126     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://$h/Shibboleth.sso/SAML2/POST" index="$((count+1))"/>
127     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign" Location="https://$h/Shibboleth.sso/SAML2/POST-SimpleSign" index="$((count+2))"/>
128     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="https://$h/Shibboleth.sso/SAML2/Artifact" index="$((count+3))"/>
129     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="https://$h/Shibboleth.sso/SAML2/ECP" index="$((count+4))"/>
130     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post" Location="https://$h/Shibboleth.sso/SAML/POST" index="$((count+5))"/>
131     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01" Location="https://$h/Shibboleth.sso/SAML/Artifact" index="$((count+6))"/>
132 EOF
133   let "count+=6"
134 done
135
136 for h in ${NAKEDHOSTS[@]}
137 do
138   cat <<EOF
139     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://$h/Shibboleth.sso/SAML2/POST" index="$((count+1))"/>
140     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign" Location="http://$h/Shibboleth.sso/SAML2/POST-SimpleSign" index="$((count+2))"/>
141     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="http://$h/Shibboleth.sso/SAML2/Artifact" index="$((count+3))"/>
142     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="http://$h/Shibboleth.sso/SAML2/ECP" index="$((count+4))"/>
143     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post" Location="http://$h/Shibboleth.sso/SAML/POST" index="$((count+5))"/>
144     <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01" Location="http://$h/Shibboleth.sso/SAML/Artifact" index="$((count+6))"/>
145 EOF
146   let "count+=6"
147 done
148
149 cat <<EOF 
150   </md:SPSSODescriptor>
151 EOF
152
153 if [ -n "$ORGNAME" ] ; then
154   cat <<EOF
155   <md:Organization>
156     <md:OrganizationName xml:lang="en">$ORGNAME</md:OrganizationName>
157     <md:OrganizationDisplayName xml:lang="en">$ORGNAME</md:OrganizationDisplayName>
158     <md:OrganizationURL xml:lang="en">$ENTITYID</md:OrganizationURL>
159   </md:Organization>
160 EOF
161 fi
162
163 for c in ${ADMIN[@]}
164 do
165   c=(${c//\// })
166   cat <<EOF
167   <md:ContactPerson contactType="administrative">
168     <md:GivenName>${c[0]}</md:GivenName>
169     <md:SurName>${c[1]}</md:SurName>
170     <md:EmailAddress>${c[2]}</md:EmailAddress>
171   </md:ContactPerson>
172 EOF
173 done
174
175 for c in ${SUP[@]}
176 do
177   c=(${c//\// })
178   cat <<EOF
179   <md:ContactPerson contactType="support">
180     <md:GivenName>${c[0]}</md:GivenName>
181     <md:SurName>${c[1]}</md:SurName>
182     <md:EmailAddress>${c[2]}</md:EmailAddress>
183   </md:ContactPerson>
184 EOF
185 done
186
187 for c in ${TECH[@]}
188 do
189   c=(${c//\// })
190   cat <<EOF
191   <md:ContactPerson contactType="technical">
192     <md:GivenName>${c[0]}</md:GivenName>
193     <md:SurName>${c[1]}</md:SurName>
194     <md:EmailAddress>${c[2]}</md:EmailAddress>
195   </md:ContactPerson>
196 EOF
197 done
198
199 cat <<EOF 
200 </md:EntityDescriptor>
201 EOF