การติดตั้ง Shibboleth Single Sign-On
ตอนที่ 7 - Relying Party

12. Relying Party

เพื่อทำให้ SP กับ IdP มองเห็นและเชื่อถือ (Trust) ซึ่งกันและกันเราจำเป็นต้องกำหนดค่า Replying Party เข้าไปในไฟล์ดังต่อไปนี้

12.1 แก้ไขไฟล์ idp-metadata.xml

ให้แก้ไขไฟล์ idp-metadata.xml (เวลาแก้ไขต้องแก้ทั้งที่ SP และ IdP) ตามจุดต่างๆที่สำคัญดังต่อไปนี้
ซอร์สโค้ด 4 ไฟล์ idp-metadata.xml (หลังจากเพิ่ม AllEntities, Name และ Key ของ SP)
1
<EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" 
2
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
3
        xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
4
        xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" 
5
        Name="AllEntities">
6

7
<EntityDescriptor entityID="urn:federation:idp"
8
                  xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
9
                  xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
10
                  xmlns:shibmd="urn:mace:shibboleth:metadata:1.0"
11
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="idp">
12

13
        <IDPSSODescriptor protocolSupportEnumeration="urn:mace:shibboleth:1.0 urn:oasis:names:tc:SAML:1.1:protocol urn:oasis:names:tc:SAML:2.0:protocol">
14

15
        <Extensions>
16
            <shibmd:Scope regexp="false">0.1</shibmd:Scope>
17
        </Extensions>
18

19
        <KeyDescriptor>
20
            <ds:KeyInfo>
21
                <ds:X509Data>
22
                    <ds:X509Certificate>
23

24
MIIDFDCCAfygAwIBAgIVAKtK9tKVS9hXWYJvVAQ9SKBMRLPBMA0GCSqGSIb3DQEB
25
BQUAMBQxEjAQBgNVBAMTCTEyNy4wLjAuMTAiGA8yNTUyMDIyMDAyNDUyNloYDzI1
26
NzIwMjIwMDI0NTI2WjAUMRIwEAYDVQQDEwkxMjcuMC4wLjEwggEiMA0GCSqGSIb3
27
DQEBAQUAA4IBDwAwggEKAoIBAQCKmzl6fppsmvxgjziHZCrxRKYDLhKd91oKBABW
28
4ujIBcUg59HJv3K83z3GIOGn9vNXzVcHlrpFVPlW+VXto9QDzmiqAGC5YKRbFnep
29
fFObGkQQCivclfveyN6K2xN6/Bf1AXlMLg3g/EgQGY5puToobfLpOlEciCSP7Xkh
30
lyw2iGibCOdNsYcc6TEAV/MKoAeM7J9FparB/uF03Vi6qh03BfqEfANuwJP9QyHQ
31
Ezz21yG2blMNcSyvRGiegmvgGkNCBkYeLd2DPy/xBWMRGQTWyxEUtCa8x27A5Bbn
32
5aI+Qj2TYHW8AED5714juPFhHGfvwryOUMYH18Mu+E1qwxI7AgMBAAGjWTBXMDYG
33
A1UdEQQvMC2CCTEyNy4wLjAuMYYgaHR0cHM6Ly8xMjcuMC4wLjEvaWRwL3NoaWJi
34
b2xldGgwHQYDVR0OBBYEFNyV6IhIGfjvLQonwprvNXXJbwsWMA0GCSqGSIb3DQEB
35
BQUAA4IBAQBMSEbEgpmqaZLkfVQYJgykaPcYmpKd+T9J/D5o7ON72wDIbLoJJgWv
36
rjF3VZmSxK9SVhMLmRurGK1G/B2zqc8GT/Fn3y87U7KV5wCqd58AKXtC7dJlJW2T
37
DNmp4q3mF400zQi0x2HCtkCKnudvancNHydMTuH7FJGayL9EZ9yNnIpvIgH95nW1
38
vYaswXPl5ROtogzvsYm9QHGcoqVRwFem2HIc1Bh5mVQ+tGJIMLpg+fltDs+8pcVk
39
dF75Xhn082M7nS+740K3Mom86jnAKHzv1XQ+KcNGMXLP87Lkd56vHwouwiHa1OqN
40
iuqNTFctYwHCuJU3FzxjkK4HFEvTW/IQ
41

42
                    </ds:X509Certificate>
43
                </ds:X509Data>
44
            </ds:KeyInfo>
45
        </KeyDescriptor>
46
        
47
        <ArtifactResolutionService Binding="urn:oasis:names:tc:SAML:1.0:bindings:SOAP-binding"
48
                                   Location="https://127.0.0.1:8443/idp/profile/SAML1/SOAP/ArtifactResolution" 
49
                                   index="1"/>
50

51
        <ArtifactResolutionService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"
52
                                   Location="https://127.0.0.1:8443/idp/profile/SAML2/SOAP/ArtifactResolution" 
53
                                   index="2"/>
54
                                   
55
        <NameIDFormat>urn:mace:shibboleth:1.0:nameIdentifier</NameIDFormat>
56
        <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
57

58
        <SingleSignOnService Binding="urn:mace:shibboleth:1.0:profiles:AuthnRequest" 
59
                             Location="https://127.0.0.1:8443/idp/profile/Shibboleth/SSO" />
60
        
61
        <SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
62
                             Location="https://127.0.0.1:8443/idp/profile/SAML2/POST/SSO" />
63

64
        <SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign" 
65
                             Location="https://127.0.0.1:8443/idp/profile/SAML2/POST-SimpleSign/SSO" />
66
        
67
        <SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" 
68
                             Location="https://127.0.0.1:8443/idp/profile/SAML2/Redirect/SSO" />
69
        </IDPSSODescriptor>
70

71
        <AttributeAuthorityDescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:1.1:protocol urn:oasis:names:tc:SAML:2.0:protocol">
72

73
        <Extensions>
74
            <shibmd:Scope regexp="false">0.1</shibmd:Scope>
75
        </Extensions>
76

77
        <KeyDescriptor>
78
            <ds:KeyInfo>
79
                <ds:X509Data>
80
                    <ds:X509Certificate>
81

82
MIIDFDCCAfygAwIBAgIVAKtK9tKVS9hXWYJvVAQ9SKBMRLPBMA0GCSqGSIb3DQEB
83
BQUAMBQxEjAQBgNVBAMTCTEyNy4wLjAuMTAiGA8yNTUyMDIyMDAyNDUyNloYDzI1
84
NzIwMjIwMDI0NTI2WjAUMRIwEAYDVQQDEwkxMjcuMC4wLjEwggEiMA0GCSqGSIb3
85
DQEBAQUAA4IBDwAwggEKAoIBAQCKmzl6fppsmvxgjziHZCrxRKYDLhKd91oKBABW
86
4ujIBcUg59HJv3K83z3GIOGn9vNXzVcHlrpFVPlW+VXto9QDzmiqAGC5YKRbFnep
87
fFObGkQQCivclfveyN6K2xN6/Bf1AXlMLg3g/EgQGY5puToobfLpOlEciCSP7Xkh
88
lyw2iGibCOdNsYcc6TEAV/MKoAeM7J9FparB/uF03Vi6qh03BfqEfANuwJP9QyHQ
89
Ezz21yG2blMNcSyvRGiegmvgGkNCBkYeLd2DPy/xBWMRGQTWyxEUtCa8x27A5Bbn
90
5aI+Qj2TYHW8AED5714juPFhHGfvwryOUMYH18Mu+E1qwxI7AgMBAAGjWTBXMDYG
91
A1UdEQQvMC2CCTEyNy4wLjAuMYYgaHR0cHM6Ly8xMjcuMC4wLjEvaWRwL3NoaWJi
92
b2xldGgwHQYDVR0OBBYEFNyV6IhIGfjvLQonwprvNXXJbwsWMA0GCSqGSIb3DQEB
93
BQUAA4IBAQBMSEbEgpmqaZLkfVQYJgykaPcYmpKd+T9J/D5o7ON72wDIbLoJJgWv
94
rjF3VZmSxK9SVhMLmRurGK1G/B2zqc8GT/Fn3y87U7KV5wCqd58AKXtC7dJlJW2T
95
DNmp4q3mF400zQi0x2HCtkCKnudvancNHydMTuH7FJGayL9EZ9yNnIpvIgH95nW1
96
vYaswXPl5ROtogzvsYm9QHGcoqVRwFem2HIc1Bh5mVQ+tGJIMLpg+fltDs+8pcVk
97
dF75Xhn082M7nS+740K3Mom86jnAKHzv1XQ+KcNGMXLP87Lkd56vHwouwiHa1OqN
98
iuqNTFctYwHCuJU3FzxjkK4HFEvTW/IQ
99

100
                    </ds:X509Certificate>
101
                </ds:X509Data>
102
            </ds:KeyInfo>
103
        </KeyDescriptor>
104

105
        <AttributeService Binding="urn:oasis:names:tc:SAML:1.0:bindings:SOAP-binding" 
106
                          Location="https://127.0.0.1:8443/idp/profile/SAML1/SOAP/AttributeQuery" />
107
        
108
        <AttributeService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"
109
                          Location="https://127.0.0.1:8443/idp/profile/SAML2/SOAP/AttributeQuery" />
110
        
111
        <NameIDFormat>urn:mace:shibboleth:1.0:nameIdentifier</NameIDFormat>
112
        <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>
113
        
114
        </AttributeAuthorityDescriptor>
115
        
116
</EntityDescriptor>    
117

118

119
        <EntityDescriptor entityID="urn:federation:sp"
120
                      xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
121
                      xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
122
                      xmlns:shibmd="urn:mace:shibboleth:metadata:1.0"
123
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="sp">
124

125
        <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
126
            
127
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML2/POST" index="1"
128
                Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"/>
129
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML2/POST-SimpleSign" index="2"
130
                Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign"/>
131
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML2/Artifact" index="3"
132
                Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact"/>
133
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML2/ECP" index="4"
134
                Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS"/>
135
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML/POST" index="5"
136
                Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post"/>
137
            <AssertionConsumerService Location="https://127.0.0.1/Shibboleth.sso/SAML/Artifact" index="6"
138
                Binding="urn:oasis:names:tc:SAML:1.0:profiles:artifact-01"/>
139

140
            <KeyDescriptor>
141
                <ds:KeyInfo>
142
                    <ds:X509Data>
143
                        <ds:X509Certificate>
144

145
MIIC5TCCAc2gAwIBAgIJALQaQraNQmi6MA0GCSqGSIb3DQEBBQUAMBUxEzARBgNV
146
BAMTCm5hdHRoYXBvbmcwHhcNMDkwMjE5MTkzMjAwWhcNMTkwMjE3MTkzMjAwWjAV
147
MRMwEQYDVQQDEwpuYXR0aGFwb25nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
148
CgKCAQEAvQR+TOeqe4qnhlaO46BB6Dxw77cB05bL/okT5rUApC5IqCX585VE9RQ6
149
hWHA8C3nuzYRR2Z7OTfdx1877JI0INVfJBqNVyXGsWbVk9OMeDvLxCPmcp9ol41p
150
svy7BAggrQCXprZdkcEp1w2hx8Kn/CgO9aNVRmnBXX7z8PhlaKUT4PSTdA7hQz37
151
oPuMDx4h0RYJ3XcMWyvby2oAc3u0rWVJi7mDax1pvQdJBUvpx65WbL3bb3rcp8XM
152
AgfVxFfljRRQeLSUCT52JOy6FT+YU6AvoOe2Y/cectttaHINBHswbS2mshWrBG8E
153
Bdq0vLISPVoVzpx99sIoepiXL5o66wIDAQABozgwNjAVBgNVHREEDjAMggpuYXR0
154
aGFwb25nMB0GA1UdDgQWBBTnbJ/jyU35OOYmRdO0VG4wTf3zjzANBgkqhkiG9w0B
155
AQUFAAOCAQEAmj9Q4uecgofj8PEGrMJ5/YRwDSxERE/Du9MxQC3nRoFdhmPzDgez
156
3j9qQTqpi27DpTJBhiqH/Gp0OHTe+3cAWosAD4EuLiMZlG4WmPUtcctGAJzXh4W8
157
fUVcQozozUu1sjeAMgz+mM4MWARkGBq9IMuMbh1CFi1E4WfNFnpCNVZC0vWRoODb
158
ihi/c3Dw8MUvlDiijOzc+yi1Q0kwbr8V8nNjYWySHueJykwS9vAL0lowPI7Y1FHu
159
3b5SWKNgAqea5h1+FqeeEajelRX5ia1d5JeOfNPXEoLmhAd+Frr/oN13GGD08rmb
160
F9c2to4NIx47LgMqQQSrAUwXkSeMA/I9pQ==
161

162
                        </ds:X509Certificate>
163
                    </ds:X509Data>
164
                </ds:KeyInfo>
165
            </KeyDescriptor>
166

167
        </SPSSODescriptor>
168
        </EntityDescriptor>
169

170
</EntitiesDescriptor>
บรรทัดที่ 1 – 5                                ครอบ EntityDescriptor ทั้ง 2 ตัวด้วย EntitiesDescriptor และกำหนด Name=”AllEntities”
บรรทัดที่ 11                                    ตั้งชื่อ IdP ด้วย Name=”idp”
บรรทัดที่ 119 – 123                        เพิ่ม EntityDescriptor ของ SP เข้ามา ตั้ง entityID=”urn:federation:sp” ให้ตรงกับ SP และกำหนด Name=”sp”
บรรทัดที่ 125                                  ใส่แท็ก SPSSODescriptor บอกให้รู้ว่า Entity นี้คือ SP และจะใช้โปรโตคอล SAML2 ในการทำ Single Sign-On
บรรทัดที่ 127 – 138                        ไปก็อปปี AssertionConsumerService มาจากไฟล์ shibboleth2.xml และกำหนด Location ให้ถูกต้อง
บรรทัดที่ 145 – 160                        ก็อปปี X509 Certificate มาจากไฟล์ c:\sso\shibboleth-sp\etc\shibboleth\sp-cert.pem
บันทึกไฟล์ idp-metadata.xml ไว้และทำให้เป็นไฟล์เดียวกันทั้งที่ IdP และที่ SP

12.2 แก้ไขไฟล์ relying-party.xml

เปิดไฟล์ relying-party.xml ที่ตำแหน่ง c:\sso\shibboleth-idp\conf แล้วแก้ไขดังนี้
ซอร์สโค้ด 5 บางส่วนของไฟล์ relying-party.xml ที่ IdP (เพิ่ม RelyingParty เข้าไป)
1
<?xml version="1.0" encoding="UTF-8"?>
2

3
<!--
4
    This file is an EXAMPLE configuration file.
5

6
    This file specifies relying party dependent configurations for the IdP, for example, whether SAML assertions to a 
7
    particular relying party should be signed.  It also includes metadata provider and credential definitions used 
8
    when answering requests to a relying party.
9
-->
10

11
<RelyingPartyGroup xmlns="urn:mace:shibboleth:2.0:relying-party"
12
                   xmlns:saml="urn:mace:shibboleth:2.0:relying-party:saml"
13
                   xmlns:metadata="urn:mace:shibboleth:2.0:metadata"
14
                   xmlns:resource="urn:mace:shibboleth:2.0:resource"
15
                   xmlns:security="urn:mace:shibboleth:2.0:security"
16
                   xmlns:samlsec="urn:mace:shibboleth:2.0:security:saml"
17
                   xmlns:samlmd="urn:oasis:names:tc:SAML:2.0:metadata"
18
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19
                   xsi:schemaLocation="urn:mace:shibboleth:2.0:relying-party classpath:/schema/shibboleth-2.0-relying-party.xsd
20
                                       urn:mace:shibboleth:2.0:relying-party:saml classpath:/schema/shibboleth-2.0-relying-party-saml.xsd
21
                                       urn:mace:shibboleth:2.0:metadata classpath:/schema/shibboleth-2.0-metadata.xsd
22
                                       urn:mace:shibboleth:2.0:resource classpath:/schema/shibboleth-2.0-resource.xsd
23
                                       urn:mace:shibboleth:2.0:security classpath:/schema/shibboleth-2.0-security.xsd
24
                                       urn:mace:shibboleth:2.0:security:saml classpath:/schema/shibboleth-2.0-security-policy-saml.xsd
25
                                       urn:oasis:names:tc:SAML:2.0:metadata classpath:/schema/saml-schema-metadata-2.0.xsd">
26
                                       
27
        <!-- ========================================== -->
28
        <!--      Relying Party Configurations          -->
29
        <!-- ========================================== -->
30
        <AnonymousRelyingParty provider="https://127.0.0.1/idp/shibboleth" />
31
        
32
        <DefaultRelyingParty provider="https://127.0.0.1/idp/shibboleth"
33
                         defaultSigningCredentialRef="IdPCredential">
34
        <!-- 
35
            Each attribute in these profiles configuration is set to its default value,
36
            that is, the values that would be in effect if those attributes were not present.
37
            We list them here so that people are aware of them (since they seem reluctant to 
38
            read the documentation).
39
        -->
40
        <ProfileConfiguration xsi:type="saml:ShibbolethSSOProfile" 
41
                              includeAttributeStatement="false"
42
                              assertionLifetime="300000"
43
                              signResponses="conditional"
44
                              signAssertions="never" />
45
                              
46
        <ProfileConfiguration xsi:type="saml:SAML1AttributeQueryProfile"
47
                              assertionLifetime="300000"
48
                              signResponses="conditional"
49
                              signAssertions="never" />
50
        
51
        <ProfileConfiguration xsi:type="saml:SAML1ArtifactResolutionProfile"
52
                              signResponses="conditional"
53
                              signAssertions="never" />
54
        
55
        <ProfileConfiguration xsi:type="saml:SAML2SSOProfile" 
56
                              includeAttributeStatement="true"
57
                              assertionLifetime="300000"
58
                              assertionProxyCount="0" 
59
                              signResponses="conditional"
60
                              signAssertions="never" 
61
                              encryptAssertions="conditional"
62
                              encryptNameIds="conditional" />
63
        
64
        <ProfileConfiguration xsi:type="saml:SAML2AttributeQueryProfile" 
65
                              assertionLifetime="300000"
66
                              assertionProxyCount="0" 
67
                              signResponses="conditional"
68
                              signAssertions="never"
69
                              encryptAssertions="conditional"
70
                              encryptNameIds="conditional" />
71
        
72
        <ProfileConfiguration xsi:type="saml:SAML2ArtifactResolutionProfile" 
73
                              signResponses="conditional"
74
                              signAssertions="never"
75
                              encryptAssertions="conditional"
76
                              encryptNameIds="conditional"/>
77
        
78
        </DefaultRelyingParty>
79
        
80
        <RelyingParty id="AllEntities" provider="https://127.0.0.1:8443/idp/shibboleth"
81
        defaultAuthenticationMethod="urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" 
82
        defaultSigningCredentialRef="IdPCredential">
83
        <ProfileConfiguration xsi:type="saml:ShibbolethSSOProfile"/>
84
        <ProfileConfiguration xsi:type="saml:SAML1AttributeQueryProfile" 
85
            signResponses="conditional" 
86
            signAssertions="conditional"/>
87
        <ProfileConfiguration xsi:type="saml:SAML2SSOProfile"/>
88
        <ProfileConfiguration xsi:type="saml:SAML2AttributeQueryProfile"       
89
            signResponses="conditional" 
90
            signAssertions="conditional"/>
91
        </RelyingParty>
92
        
สังเกตว่าแก้ไขโดยเพิ่ม <RelyingParty> เข้าไปที่บรรทัด 80 – 91 บันทึกไฟล์ relying-party.xml ไว้

12.3 แก้ไขไฟล์ shibboleth2.xml

ให้แก้ไขไฟล์ shibboleth2.xml ที่ SP โดยเอาคอมเมนต์ที่ RelyingParty ออกและเขียนเพิ่มเข้าไปดังนี้

รูปภาพ 48 ใส่ Name=”idp” และ keyName=”127.0.0.1” และ signing=”true”
บันทึกไฟล์ shibboleth2.xml ไว้แล้วดำเนินการที่ขั้นต่อไป

12.4 แก้ไขไฟล์ handler.xml เปิดใช้ LoginHandler

เพื่อเปิดใช้หน้าล็อกอินของ IdP เราจำเป็นต้องเลือกวิธีการล็อกอินเป็นแบบ UsernamePassword โดยไปแก้ไขไฟล์ handler.xml ที่ตำแหน่ง c:\sso\shibboleth-idp\conf ดังนี้

รูปภาพ 49 เปิดคอมเมนต์ของ UsernamePassword ที่แท็ก LoginHandler ของไฟล์ handler.xml
บันทึกไฟล์ handler.xml ไว้แล้วดำเนินการที่ขั้นตอนถัดไป

12.5 ทดสอบ Relying Party

ให้รีสตาทร์ทั้ง Shibboleth 2.0 Daemon, Apache Web Server และ Tomcat ใหม่อีกครั้ง และเบราซ์ไปที่ http://localhost/secure ควรจะปรากฏภาพดังนี้

รูปภาพ 50 Apache Web Server ส่งต่อไปที่ https://127.0.0.1:8443/idp/Authn/UserPasword

แม้ว่าจะปรากฏหน้าต่างล็อกอินของ IdP แล้วแต่ปัจจุบันเรายังไม่สามารถล็อกอินได้เนื่องจาก การล็อกอินจะต้องไปตรวจสอบกับระบบ LDAP (Lightweight Directory Access Protocol) ซึ่งเราจำเป็นต้องติดตั้ง LDAP และเชื่อมต่อเข้ากับระบบ IdP ในขั้นตอนถัดไป

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

การติดตั้ง Shibboleth Single Sign-On
ตอนที่ 12 - การทำ SLO (Single Log-out)

ตัวอย่างการเข้ารหัส AES ด้วย Java และถอดรหัสด้วย C#.NET

การรักษาความปลอดภัยแบบ OWASP