SWAMID-649 Update cert login.quicksearch.se
[swamid-metadata.git] / Makefile
1
2 KEY  := /opt/swamid-credentials/swamid-signer.key
3 CERT := /opt/swamid-credentials/swamid-signer.crt
4 PASS := $(shell test -f /opt/swamid-credentials/swamid-signer-pass.txt && cat /opt/swamid-credentials/swamid-signer-pass.txt)
5 DEST := /opt/published-metadata
6 SRCDIRS=swamid-2.0
7
8 DAYS:=15
9 DATE=$(shell perl scripts/expiration_date.pl $(DAYS))
10 NOW=$(shell perl scripts/now_date.pl)
11 RPI=false
12 CONTACTS=false
13 TOU=true
14 ORG=true
15 TRANSFORM=xslt/normalize.xsl
16 ID=$(shell perl scripts/unique_id.pl)
17 XSLTDEFS := --stringparam org $(ORG) --stringparam ID $(ID) --stringparam tou $(TOU) --stringparam rpi $(RPI) --stringparam defaultContact $(CONTACTS) --stringparam date $(DATE) --stringparam now $(NOW)
18 SIGNER := xmlsec1 --sign --privkey-pem $(KEY),$(CERT) --pwd $(PASS) --id-attr:ID urn:oasis:names:tc:SAML:2.0:metadata:EntitiesDescriptor
19 BASEURL := http://md.swamid.se/md
20 SIGN := xslt/sign.xsl
21 SITE := site/md.swamid.se
22 TOU  := swamid-tou-en.txt swamid-tou-sv.txt
23
24 -include $(SWAMID_MK_CONFIG)
25
26 all: clean dependencies test sign clean web
27
28 MXML=$(shell echo *.mxml)
29 SWAMIDXML=$(patsubst swamid-2.0/%.xml,.time/%.time,$(wildcard swamid-2.0/*.xml))
30 TIMEFILES=$(patsubst %.time,.xml/swamid-2.0/%.time,$(wildcard .time/*.time))
31
32 sign: swamid upstream
33
34 %.sig: %.mxml
35         xsltproc $(XSLTDEFS) --stringparam target "$(BASEURL)/$*.xml" --xinclude $(TRANSFORM) $< > $*.n
36         xsltproc $(XSLTDEFS) --xinclude $(SIGN) $*.n > $*.tbs
37         $(SIGNER) --output $@ $*.tbs
38         xmllint --xinclude --nowarning --noout --path schema --schema  schema.xsd $@
39         rm -f $*.tbs $*.n
40
41 %.pub: %.sig
42         mkdir -p $(DEST) && xmllint --nowarning --noout --path schema --schema schema.xsd $< && mv $< $(DEST)/$*.xml
43
44 #dependencies: swamid-externals-sp-2.0.xml swamid-interfederations-idp-2.0.xml swamid-interfederations-sp-2.0.xml
45 dependencies:  swamid-interfederations-idp-2.0.xml swamid-interfederations-sp-2.0.xml
46
47 # kalmar obsolete
48 #upstream: edugain kalmar
49 upstream: edugain
50
51 kalmar:
52         env SWAMID_MK_CONFIG=$(SWAMID_MK_CONFIG) $(MAKE) RPI=false CONTACTS=false swamid-kalmar-1.0.pub swamid-kalmar-testing-1.0.pub
53
54 edugain:
55         env SWAMID_MK_CONFIG=$(SWAMID_MK_CONFIG) $(MAKE) RPI=true CONTACTS=true swamid-edugain-testing-1.0.pub swamid-edugain-1.0.pub
56
57 #aggregate: swamid-externals swamid-interfederations
58 aggregate: swamid-interfederations
59
60 swamid-externals: swamid-externals1 swamid-externals2
61
62 swamid-externals1:
63         scripts/aggregate.sh swamid-externals-1.0
64
65 swamid-externals2:
66         scripts/aggregate.sh swamid-externals-2.0
67
68 # kalmar obsolete
69 #swamid-interfederations: swamid-interfederations1 swamid-interfederations2
70 swamid-interfederations: swamid-interfederations2
71
72 swamid-interfederations1:
73         scripts/aggregate.sh swamid-interfederations-1.0
74
75 swamid-interfederations2:
76         scripts/aggregate.sh swamid-interfederations-2.0
77         @# Blocked by SWAMID-OPS 2021-04-21
78         @sed -i '/services.sheerid.com-Shibboleth-UK/d' swamid-interfederations-2.0.mxml
79         @# Blocked by SWAMID-OPS 2021-12-10 SWAMID-550
80         @sed -i '/verify-a.myunidays.com-shibboleth/d' swamid-interfederations-2.0.mxml
81         @sed -i '/verify-l.myunidays.com-shibboleth/d' swamid-interfederations-2.0.mxml
82         @sed -i '/mecenat.com-sp/d' swamid-interfederations-2.0.mxml
83         @sed -i '/connect.mecenat.com-shibboleth/d' swamid-interfederations-2.0.mxml
84         @sed -i '/verify.studentbeans.com-shibboleth/d' swamid-interfederations-2.0.mxml
85         @sed -i '/federation.proxi.id-samlbridge-module.php-saml-sp-metadata.php-cyclone-saml-bridge/d' swamid-interfederations-2.0.mxml
86
87 swamid: swamid-2.0.pub swamid-no-interfederation-combined.pub swamid-discovery.pub swamid-idp.pub swamid-idp-transitive.pub swamid-sp-transitive.pub swamid-registered.pub swamid-testing-1.0.pub swamid-testing-idp-1.0.pub
88
89 web: $(SITE) $(TOU)
90         rsync -avz $(TOU) $(SITE)/ $(DEST)
91
92 swamid-interfederations-idp-2.0.xml: swamid-interfederations-2.0.mxml
93         @xsltproc --xinclude xslt/extract-idp.xslt swamid-interfederations-2.0.mxml > swamid-interfederations-idp-2.0.xml
94         @# Empty PrivacyStatementURL 2020-12-09
95         @#sed -i '/sso.irc.ugent.be-auth-realms-irc/d' swamid-interfederations-idp-2.0.xml
96         @# Empty ds:KeyName 2021-03-26
97         @#sed -i '/idp.kre.hu-simplesaml-saml2-idp-metadata/d' swamid-interfederations-idp-2.0.xml
98         @#sed -i '/idp.kre.hu-simplesaml-saml2-idp-metadata/d' swamid-interfederations-2.0.mxml
99
100 swamid-interfederations-sp-2.0.xml: swamid-interfederations-2.0.mxml
101         @xsltproc --xinclude xslt/extract-sp.xslt swamid-interfederations-2.0.mxml > swamid-interfederations-sp-2.0.xml
102
103 swamid-externals-sp-2.0.xml: swamid-externals-2.0.mxml
104         @xsltproc --xinclude xslt/extract-non-idp.xslt swamid-externals-2.0.mxml > swamid-externals-sp-2.0.xml
105
106 syntaxtest: clean dependencies schematest
107
108 pedantic: clean dependencies schematest testRefedsRnS testGeantCoCo testEduGAINchecks
109
110 schematest:
111         @fail=false ; for x in $(MXML); do test=`xmllint --xinclude --nowarning --noout --path schema --schema schema.xsd $$x 2>&1`; rc=$$?; echo $$test | sed 's/fails to validate/\e[1;31m&\e[0m/;s/validates/\e[1;32m&\e[0m/'; if [ $$rc -gt 0 ]; then fail=true ; fi; done ; if $$fail ; then exit 1 ; fi
112
113 clean:
114         @rm -f *.xml *.tbs *.n *.sig
115
116 tidy:
117         @for x in `find $(SRCDIRS) -name \*.xml`; do xsltproc --stringparam regDate $(NOW) xslt/add-rpi.xsl $$x > $$x.c && mv $$x.c $$x; done
118         @for x in `find $(SRCDIRS) -name \*.xml`; do xsltproc xslt/clean-entitydescriptor.xsl $$x > $$x.c && mv $$x.c $$x; done
119
120 testMetadataUsage:
121         @echo "Checking for files in swamid-2.0 that isn't used"
122         @for file in swamid-2.0/* ; do if ! grep -q $$file *.mxml; then echo "  $$file is not referenced in any mxml file"; fi; done | sed 's/.*/\e[1;31m&\e[0m/'
123
124 testRefedsRnS:
125         @echo "Checking for refeds R&S compatibillity for entities exported to eduGAIN"
126         @for x in `cat swamid-edugain-*.mxml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}' | xargs grep -l SPSSODescriptor` ; do \
127         got_refeds_RnS=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/Extensions/EntityAttributes/Attribute[@Name='http://macedir.org/entity-category']/AttributeValue" - 2>/dev/null | grep 'http://refeds.org/category/research-and-scholarship'` ; \
128         if [ -n "$$got_refeds_RnS" ] ; then \
129         http_post=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/AssertionConsumerService" - 2>/dev/null | grep 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'` ; \
130         if [ -z "$$http_post" ] ; then echo "  $$x: Missing HTTP-POST binding." | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; \
131         mdui_DisplayName=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/DisplayName" - 2>/dev/null | grep 'DisplayName'` ; \
132         if [ -z "$$mdui_DisplayName" ] ; then echo "  $$x: Missing mdui:DisplayName." | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; \
133         mdui_InformationURL=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/InformationURL" - 2>/dev/null | grep 'InformationURL'` ; \
134         if [ -z "$$mdui_InformationURL" ] ; then echo "  $$x: Missing mdui:InformationURL." | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; \
135         tech_contact=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/ContactPerson[@contactType='technical']" - 2>/dev/null | grep 'EmailAddress'` ; \
136         if [ -z "$$tech_contact" ] ; then echo "  $$x: Missing ContactPerson contactType='technical'." | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; \
137         fi ; \
138         done
139
140 testGeantCoCo:
141         @echo "Checking for Geant CoCo compliance"
142         @touch sp-with-coco-errors
143         @for x in `cat swamid-edugain-sp-1.0.mxml swamid-edugain-testing-1.0.mxml swamid-sp-2.0.mxml swamid-testing-sp-1.0.mxml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}' | xargs grep -l SPSSODescriptor | sort -u` ; do \
144                 got_geant_CoCo=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/Extensions/EntityAttributes/Attribute[@Name='http://macedir.org/entity-category']/AttributeValue" - 2>/dev/null | grep 'http://www.geant.net/uri/dataprotection-code-of-conduct/v1'` ; \
145                 if [ -n "$$got_geant_CoCo" ] ; then \
146                     ( \
147                         mdui_check=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo" - 2>/dev/null` ; \
148                         if [ -z "$$mdui_check" ] ; then \
149                                 echo "    Missing MDUI"'' ; \
150                         else \
151                                 mdui_DisplayName=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/DisplayName" - 2>/dev/null | grep 'DisplayName'` ; \
152                                 if [ -z "$$mdui_DisplayName" ] ; then echo "    Missing mdui:DisplayName"'' ; fi ; \
153                                 mdui_Descr=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/DisplayName" - 2>/dev/null | grep 'DisplayName'` ; \
154                                 if [ -z "$$mdui_Descr" ] ; then echo "    Missing mdui:Description"'' ; fi ; \
155                                 for y in `cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo" - | grep -v "UIInfo" | awk '{print $$1}' | cut -c2- | sort -u` ; do \
156                                         mdui_Test=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/$$y" - 2>/dev/null | grep $$y | grep 'xml:lang="en"'` ; \
157                                         if [ -z "$$mdui_Test" ] ; then echo "    Missing xml:lang=\"en\" on mdui:$$y"'' ; fi ; \
158                                         done ; \
159                                 mdui_PrivacyStatementURL=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/Extensions/UIInfo/PrivacyStatementURL" - 2>/dev/null | grep 'PrivacyStatementURL' | sed 's/&amp;/\&/g'` ; \
160                                 if [ -z "$$mdui_PrivacyStatementURL" ] ; then \
161                                         echo "    Missing PrivacyStatementURL"'' ; \
162                                 else \
163                                         if ! echo "$$mdui_PrivacyStatementURL" | grep -q 'xml:lang="en"' ; then \
164                                                 echo "    Missing PrivacyStatementURL in english"'' ; \
165                                         fi ; \
166                                         echo "$$mdui_PrivacyStatementURL" | sed 's/></>\n</g' | sed 's/.*\ \(xml:lang=.*\)>\(.*\)<.*/\1 \2/' | while read lang url ; do \
167                                                 if grep -qx "$$x" sp-with-coco-errors ; then \
168                                                         echo "  Known bad link to CoCo in PrivacyStatementURL: $$x" 1>&2 ; \
169                                                 else \
170                                                         if ! grep -q "$$url $$lang $$mdui_PrivacyStatementURL" sp-with-once-ok-coco-link ; then \
171                                                                 curl -A 'Mozilla' -s -L -m 5 "$$url" < /dev/null | grep "https*://www.geant.net/uri/dataprotection-code-of-conduct/v1" > /dev/null && echo "$$url $$lang $$mdui_PrivacyStatementURL" >> sp-with-once-ok-coco-link || echo "    Missing link to geant.net/code-of-conduct/v1 in PrivacyStatementURL $$lang ($$url)" ; \
172                                                         fi ; \
173                                                 fi ; \
174                                         done ; \
175                                 fi ; \
176                         fi ; \
177                         requestedAttribute=`cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/SPSSODescriptor/AttributeConsumingService/RequestedAttribute" - 2>/dev/null | grep 'RequestedAttribute'` ; \
178                         if [ -z "$$requestedAttribute" ] ; then echo "    Missing RequestedAttribute"'' ; fi ; \
179                     ) | sed "1s;..*;  \e[1\;31m$$x\e[0m\n&;" | grep . && echo " " ; \
180                 fi ; \
181         done | grep . && tty -s && exit 1 || exit 0
182
183 testEduGAINchecks:
184         @echo "Checking for attributes not allowed in entities exported to eduGAIN"
185         @for x in `cat swamid-edugain-*.mxml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}' | xargs grep -l SPSSODescriptor` ; do \
186                 if ( grep -q "AssertionConsumerService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" $$x ); then \
187                         echo "  $$x: AssertionConsumerService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" not allowed";  \
188                 fi ;  \
189         done
190         @for x in `cat swamid-edugain-idp-1.0.mxml swamid-edugain-sp-1.0.mxml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}'` ; do \
191                 sed 's;\(</*\)[a-z0-9]*:;\1;g' $$x | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Organization/OrganizationName' - 2>/dev/null | grep -vq "^$$" || echo "  $$x missing OrganizationName" | sed 's/.*/\e[1;31m&\e[0m/' ; \
192                 sed 's;\(</*\)[a-z0-9]*:;\1;g' $$x | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Organization/OrganizationDisplayName' - 2>/dev/null | grep -vq "^$$" || echo "  $$x missing OrganizationDisplayName" | sed 's/.*/\e[1;31m&\e[0m/' ; \
193                 sed 's;\(</*\)[a-z0-9]*:;\1;g' $$x | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Organization/OrganizationURL' - 2>/dev/null | grep -vq "^$$" || echo "  $$x missing OrganizationURL" | sed 's/.*/\e[1;31m&\e[0m/' ; \
194         done
195
196
197 testMDUI:
198         @echo "Checking for bad lang codes"
199         @# Lang = ISO_639-1
200         @for x in swamid-2.0/*.xml ; do bad_langs=`cat $$x | sed -n 's/.*xml:lang="\([^"]*\)".*/\1/p' | sort -u | grep -vxE 'cs|da|de|en|fi|fr|it|sv|no|nn|nb|is'` ; if [ -n "$$bad_langs" ] ; then echo "  $$x: `echo $$bad_langs`" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || exit 0
201         @echo "Checking for uniq IdP MDUI DisplayName"
202         @for lang in `cat swamid-2.0/*.xml | sed -n 's/.*xml:lang="\([^"]*\)".*/\1/p' | sort -u` ; do for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l IDPSSODescriptor` ; do cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/IDPSSODescriptor/Extensions/UIInfo/DisplayName[@xml:lang='$$lang']" - 2>/dev/null | sed 's/^[       ]*//;s/[        ]*$$//' | tr -d '\n' | sed 's;<[^>]*>\([^<]*\)</[^>]*>;\1\n;g' | sed "s;^;  $$x $$lang ;" | sed 's/.*/\e[1;31m&\e[0m/' ; done | sort -k 3 | uniq -d -f 2 ; done | grep . && exit 1 || true
203         @echo "Checking for invalid IPHint"
204         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed -n 's;.*<[a-z0-9:]*IPHint>\(.*\)</[a-z0-9:]*IPHint>;\1;p' | grep -q -vE '^$$|^[0-9./a-fA-F:]*$$' ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done
205         @echo "Checking for invalid geodata (syntax is geo:xx.yy,zz.vv)"
206         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed -n 's;.*<[a-z0-9:]*GeolocationHint>\(.*\)</[a-z0-9:]*GeolocationHint>;\1;p' | grep -q -vE '^$$|^geo:[0-9][0-9][0-9.]*,[0-9][0-9][0-9.]*$$' ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done
207         @echo "Check for IdP:s with Logos over http"
208         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed -n '/IDPSSODescriptor/,/\/IDPSSODescriptor/p' | grep -q 'Logo .*http://' ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || exit 0
209
210 testIdPinSP:
211         @echo "Check that SP:s does not define IDPSSODescriptor"
212         @for spfile in `cat swamid-sp-2.0.mxml swamid-externals-sp-2.0.xml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}'` ; do grep -q IDPSSODescriptor $$spfile && echo "  $$spfile" | sed 's/.*/\e[1;31m&\e[0m/' ; done | grep . && exit 1 || exit 0
213
214 testMDUIreach:
215         @echo "Check that MDUI URLs are reachable"
216         @cat swamid-idp-2.0.mxml swamid-sp-2.0.mxml swamid-externals-sp-2.0.xml | grep -v "\.mxml$$" | grep "xi:include" | awk -F\" '{print $$2}' | \
217         xargs -n1 -P 10 scripts/verify-uiinfo-urls.sh
218
219 testOrgData:
220         @echo "Checking for uniq IdP OrganizationDisplayName"
221         @for lang in `cat swamid-2.0/*.xml | sed -n 's/.*xml:lang="\(..\)".*/\1/p' | sort -u` ; do for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l IDPSSODescriptor` ; do cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/Organization/OrganizationDisplayName[@xml:lang='$$lang']" - 2>/dev/null | sed 's/^[    ]*//;s/[        ]*$$//' | tr -d '\n' | sed 's;<[^>]*>\([^<]*\)</[^>]*>;\1\n;g' | sed "s;^;$$x $$lang ;" | sed 's/.*/\ \ \e[1;31m&\e[0m/' ; done | sort -k 3 | uniq -d -f 2 ; done | grep . && exit 1 || true
222
223 testEntCat:
224         @echo "Checking for multiple EntityAttributes in EntityDescriptor/Extensions"
225         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l EntityAttributes` ; do if [ `grep EntityAttributes $$x | wc -l ` -gt 2 ]; then echo "Multiple EntityAttributes in $$x" | sed 's/.*/\e[1;31m&\e[0m/'; fi ; done | grep . && exit 1 || true
226         @echo "Checking for entity-categories in SPSSODescriptors that should be moved to EntityDescriptor/Extensions"
227         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath /EntityDescriptor/SPSSODescriptor/Extensions/EntityAttributes - 2>/dev/null | grep -q entity-category ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
228         @echo "Checking for entity-categories in IDPSSODescriptor that should be moved to EntityDescriptor/Extensions"
229         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath /EntityDescriptor/IDPSSODescriptor/Extensions/EntityAttributes - 2>/dev/null | grep -q entity-category ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
230         @echo "Checking for MDUI in EntityDescriptor/Extensions"
231         @for x in `find $(SRCDIRS) -name \*.xml`; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath /EntityDescriptor/Extensions/UIInfo - 2>/dev/null | grep -q . ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
232         @echo "Checking for entitycategories for IdPs that should be entity-category-support"
233         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l IDPSSODescriptor` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute[attribute::Name="http://macedir.org/entity-category"]/AttributeValue/text()' - 2>/dev/null | grep -q http://refeds.org/category/research-and-scholarship ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
234         @echo "Checking for wrong Name in EntityAttributes/Attribute"
235         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l "Attribute "` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute' - 2>/dev/null | grep "Attribute " | sed 's/.* Name="//' | sed -e 's/ NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"//' -e 's/">//' | egrep -v "http://macedir.org/entity-category|http://macedir.org/entity-category-support|urn:oasis:names:tc:SAML:attribute:assurance-certification|urn:oasis:names:tc:SAML:profiles:subject-id:req|http://www.swamid.se/assurance-requirement" ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
236         @echo "Checking for wrong AttributeValue in EntityAttributes/Attribute http://macedir.org/entity-category"
237         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l "http://macedir.org/entity-category"` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute[attribute::Name="http://macedir.org/entity-category"]' - 2>/dev/null | grep "AttributeValue" | egrep -v ">http://refeds.org/category/research-and-scholarship<|>http://www.geant.net/uri/dataprotection-code-of-conduct/v1<|>http://www.swamid.se/category/research-and-education<|>http://www.swamid.se/category/hei-service<|>http://www.swamid.se/category/nren-service<|>http://www.swamid.se/category/sfs-1993-1153<|>http://www.swamid.se/category/eu-adequate-protection<|>http://refeds.org/category/hide-from-discovery<|>http://id.elegnamnden.se/st/1.0/sigservice<|>http://id.elegnamnden.se/ec/1.0/loa3-pnr<|>http://id.elegnamnden.se/ec/1.0/eidas-naturalperson<|>https://refeds.org/category/anonymous<|>https://myacademicid.org/entity-categories/esi<|>https://refeds.org/category/personalized<|>https://refeds.org/category/pseudonymous<" ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
238         @echo "Checking for wrong AttributeValue in EntityAttributes/Attribute http://macedir.org/entity-category-support"
239         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l "http://macedir.org/entity-category-support"` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute[attribute::Name="http://macedir.org/entity-category-support"]' - 2>/dev/null | grep "AttributeValue" | egrep -v ">http://refeds.org/category/research-and-scholarship<|>http://www.geant.net/uri/dataprotection-code-of-conduct/v1<" ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
240         @echo "Checking for wrong AttributeValue in EntityAttributes/Attribute http://www.swamid.se/assurance-requirement"
241         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l "http://www.swamid.se/assurance-requirement"` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute[attribute::Name="http://www.swamid.se/assurance-requirement"]' - 2>/dev/null | grep "AttributeValue" | egrep -v ">http://www.swamid.se/policy/assurance/al1<|>http://www.swamid.se/policy/assurance/al2<" ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
242         @echo "Checking for wrong AttributeValue in EntityAttributes/Attribute urn:oasis:names:tc:SAML:attribute:assurance-certification"
243         @for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l "urn:oasis:names:tc:SAML:attribute:assurance-certification"` ; do if cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath '/EntityDescriptor/Extensions/EntityAttributes/Attribute[attribute::Name="urn:oasis:names:tc:SAML:attribute:assurance-certification"]' - 2>/dev/null | grep "AttributeValue" | egrep -v ">https://refeds.org/sirtfi<|>http://www.swamid.se/policy/assurance/al1<|>http://www.swamid.se/policy/assurance/al2<|>http://www.swamid.se/policy/authentication/swamid-al2-mfa<|>http://www.swamid.se/policy/authentication/swamid-al2-mfa-hi<" ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || true
244
245 testValidContact:
246         @echo "Checking for valid Contact Information"
247         @for x in swamid-2.0/*.xml ; do if ( cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/ContactPerson" - 2>/dev/null | grep 'EmailAddress' | grep -qv ">mailto:") ; then echo "\e[1;31m Missing mailto in ContactPerson in file $$x \e[0m" ; fi ; done | grep . && exit 1 || true
248         @echo "Checking for empty ContactPerson tags"
249         @if grep -H -E '<(Company|SurName|EmailAddress|TelephoneNumber)/>' swamid-2.0/*.xml | sed 's/^/  /' | grep . ; then exit 1 ; else exit 0 ; fi
250
251 testSimpleSign:
252         @echo "Check for new SP:s with SimpleSign (breaks ADFS IdP:s with Shib SP 2.5+)"
253         @for x in `grep -v "#" sp-with-simplesign`; do if [ ! -r swamid-2.0/$$x ] ; then echo $$x saknas; fi ; done | grep . && exit 1 || exit 0
254         @for x in `find $(SRCDIRS) -name \*.xml`; do if ! grep -qx `basename $$x` sp-with-simplesign && grep -q HTTP-POST-SimpleSign $$x ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done | grep . && exit 1 || exit 0
255
256 testALlevel:
257         @echo "Check for IdP:s with AL2 without AL1"
258         @for x in `find $(SRCDIRS) -name \*.xml`; do if grep -q http://www.swamid.se/policy/assurance/al2 $$x && ! grep -q http://www.swamid.se/policy/assurance/al1 $$x ; then echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ; fi ; done
259
260 testBadStrings:
261         @echo "Check for bad strings in metadata"
262         @for x in `find $(SRCDIRS) -name \*.xml`; do grep -E 'ServiceName xml:lang="[^"]*"/>' $$x | sed 's/^/  /' ; done | grep . && exit 1 || exit 0
263
264 testRoleDescriptor:
265         @echo "Check for RoleDescriptor that should be removed"
266         @for x in `find $(SRCDIRS) -name \*.xml`; do \
267                 grep -EH 'RoleDescriptor.*xsi:type="fed:(ApplicationServiceType|SecurityTokenServiceType)"' $$x | \
268                  sed -e 's/^/  /' -e 's/xmlns.*xsi:type="fed:/xsi:type="fed:/' -e 's/ protocol.*>/>/' -e 's/.*/\e[1;31m&\e[0m/' ; \
269         done | grep . && exit 1 || exit 0
270
271 testAttributeInIdP:
272         @echo "Check for Attribute inside IDPSSODescriptor"
273         @for x in `find $(SRCDIRS) -name \*.xml`; do \
274                 if  cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/IDPSSODescriptor" - 2>/dev/null | grep -q "    <Attribute Name" ; then \
275                         echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ;\
276                 fi;\
277         done | grep . && exit 1 || exit 0
278
279 testRegistrationAuthority:
280         @echo "Check for registrationAuthority="http://www.swamid.se/" in EntityDescriptor/Extensions"
281         @for x in `find $(SRCDIRS) -name \*.xml`; do \
282                 if ! cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/Extensions" - 2>/dev/null | grep -qE 'registrationAuthority="http://www.swamid.se/"|registrationAuthority="http://www.swamid.se/loop"' ; then \
283                         echo "  $$x" | sed 's/.*/\e[1;31m&\e[0m/' ;\
284                 fi;\
285         done | grep . && exit 1 || exit 0
286
287 #test: syntaxtest testMDUI testOrgData testEntCat testSimpleSign testALlevel testEduGAINchecks testRefedsRnS testGeantCoCo testMetadataUsage testBadStrings testIdPinSP testRoleDescriptor testAttributeInIdP testValidContact testRegistrationAuthority
288 test: syntaxtest testMDUI testEntCat testALlevel testEduGAINchecks testRefedsRnS testGeantCoCo testMetadataUsage testBadStrings testIdPinSP testRoleDescriptor testAttributeInIdP testValidContact testRegistrationAuthority
289
290 test2: $(SWAMIDXML) schematest testEntCat testALlevel testEduGAINchecks testRefedsRnS testGeantCoCo testMetadataUsage testBadStrings testIdPinSP testRoleDescriptor testAttributeInIdP testValidContact testRegistrationAuthority
291 #test2: $(SWAMIDXML) 
292
293 .time/%.time: swamid-2.0/%.xml
294         @# make schematest
295         @xmllint --xinclude --nowarning --noout --path schema --schema schema.xsd $< 2>&1
296
297         @# make tidy
298         @xsltproc --stringparam regDate $(NOW) xslt/add-rpi.xsl $< > $<.c && mv $<.c $<
299         @xsltproc xslt/clean-entitydescriptor.xsl $< > $<.c && mv $<.c $<
300
301         @# make testMDUI
302         @echo "Checking for bad lang codes"
303         @# Lang = ISO_639-1
304         @cat $< | sed -n 's/.*xml:lang="\([^"]*\)".*/\1/p' | sort -u | grep -vxE 'cs|da|de|en|fi|fr|it|sv|no|nn|nb|is' | sed 's/.*/\e[1;31mBad lang code : &\e[0m/' | grep . && exit 1 || true
305         @if [ `grep EntityAttributes $< | wc -l ` -gt 2 ]; then echo "Multiple EntityAttributes" | sed 's/.*/\e[1;31m&\e[0m/' ; exit 1; fi
306         @if ( grep -q IDPSSODescriptor $< ) ; then \
307                 echo "Do IdP checks" ;  \
308                 echo ">Checking for uniq IdP MDUI DisplayName"; \
309                 for lang in `cat $< | sed -n 's/.*xml:lang="\(..\)".*/\1/p' | sort -u` ; do \
310                         mdui_displayname=`cat $< | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/IDPSSODescriptor/Extensions/UIInfo/DisplayName[@xml:lang='$$lang']" - 2>/dev/null | sed 's/^[         ]*//;s/[        ]*$$//' | tr -d '\n' | sed 's;<[^>]*>\([^<]*\)</[^>]*>;\1\n;g'`;\
311                          organizationdisplayname=`cat $< | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/Organization/OrganizationDisplayName[@xml:lang='$$lang']" - 2>/dev/null | sed 's/^[     ]*//;s/[        ]*$$//' | tr -d '\n' | sed 's;<[^>]*>\([^<]*\)</[^>]*>;\1\n;g'` ;\
312                         for x in `find $(SRCDIRS) -name \*.xml | xargs grep -l IDPSSODescriptor | egrep -v $<` ; do cat $$x | sed 's;\(</*\)[a-z0-9]*:;\1;g' | sed 's/xmlns="[^"]*"//' | xmllint --xpath "/EntityDescriptor/IDPSSODescriptor/Extensions/UIInfo/DisplayName[@xml:lang='$$lang']" - 2>/dev/null | tr -d '\n' | sed 's;<[^>]*>\([^<]*\)</[^>]*>;\1\n;g' | egrep "^$$mdui_displayname$$" | sed "s;^;Duplicate DisplayName in $$x for lang =  $$lang\n;" | sed 's/.*/\e[1;31m&\e[0m/' ; done | grep . && exit 1 || true;\
313                 done; \
314                 echo ">Checking for invalid IPHint"; \
315                 cat $< | sed -n 's;.*<[a-z0-9:]*IPHint>\(.*\)</[a-z0-9:]*IPHint>;\1;p' | grep -vE '^$$|^[0-9./a-fA-F:]*$$' | sed 's/.*/\e[1;31m&\e[0m/'; \
316                 echo ">Checking for invalid geodata (syntax is geo:xx.yy,zz.vv)";\
317                 cat $< | sed -n 's;.*<[a-z0-9:]*GeolocationHint>\(.*\)</[a-z0-9:]*GeolocationHint>;\1;p' | grep -vE '^$$|^geo:[0-9][0-9][0-9.]*,[0-9][0-9][0-9.]*$$' | sed 's/.*/\e[1;31m&\e[0m/' ; \
318                 echo ">Check for IdP:s with Logos over http";\
319                 cat $< | grep 'Logo .*http://' | sed 's/.*>\(.*\)<.*/\e[1;31m\1\e[0m/' | grep . && exit 1 || exit 0 ; \
320         fi
321
322         @echo $< done
323         @touch -r $< $@
324
325 deeptest: test testMDUIreach
326
327 commit2: test2
328         @git diff --color || true
329         @echo ; echo -n "Run 'git commit -a'? [Y/n/skip] " ; read x ; case $$x in "Y"|"y"|"") git commit -a ;; s|skip) ;; *) exit 1 ;; esac
330         @git status -u
331         @echo "Checking for not committed files in swamid-2.0/" ; if git status --porcelain --ignored | awk '{print $$2}' | grep "^swamid-2.0/" | sed 's/^/  /' | grep . ; then echo "Not committed files in swamid-2.0/, aborting" ; exit 1 ; fi
332         @echo ; echo -n "Run 'git push'? [Y/n] " ; read x ; case $$x in "Y"|"y"|"") ;; *) exit 1 ;; esac
333         @git push
334
335 commit: tidy test
336         @git diff --color || true
337         @echo ; echo -n "Run 'git commit -a'? [Y/n/skip] " ; read x ; case $$x in "Y"|"y"|"") git commit -a ;; s|skip) ;; *) exit 1 ;; esac
338         @git status -u
339         @echo "Checking for not committed files in swamid-2.0/" ; if git status --porcelain --ignored | awk '{print $$2}' | grep "^swamid-2.0/" | sed 's/^/  /' | grep . ; then echo "Not committed files in swamid-2.0/, aborting" ; exit 1 ; fi
340         @echo ; echo -n "Run 'git push'? [Y/n] " ; read x ; case $$x in "Y"|"y"|"") ;; *) exit 1 ;; esac
341         @git push