概要 †
IdP:SimpleSAMLphp, SP:SimpleSAMLphpで、SAML連携を行います。
以下で構築したIdP, SPをベースとします。
上記の手順で作成した場合、http/https共に有効な状態です。
IdP,SPがhttpはセキュリティ上あり得ないので、メタデータの取得はhttpsアクセスで取得してください。
また、SAMLメッセージの確認には、FirefoxのSAML tracerが便利です。
WebSSO, IdP:Redirect, SP:POST, 起点:SP †
- IdP側のメタデータを取得
[IdPサイト]-[Federation]-[SAML 2.0 IdPメタデータ]-[Show metadata]
下部にあるSimpleSAMLphp用のphpコード(メタデータ)をコピーする
- SP側に、IdPのメタデータを設定
- vi metadata/saml20-idp-remote.php
ファイル末尾に、上記でコピーしたIdPのメタデータを張り付ける
- vi config/authsources.php
- デプロイ
1
2
|
| git commit -a -m "Connected IdP"
git push azure master
|
- SP側のメタデータを取得
[SPサイト]-[Federation]-[SAML 2.0 SPメタデータ]-[Show metadata]
IdP側と同様に、SimpleSAMLphp用のphpコード(メタデータ)をコピーする
- IdP側に、SPのメタデータを設定
- vi metadata/saml20-sp-remote.php
ファイル末尾に、上記でコピーしたIdPのメタデータを張り付ける
- デプロイ
1
2
|
| git commit -a -m "Connected SP"
git push azure master
|
設定確認 †
- IdP側のFederationページ(adminでログイン済み)
信頼されたSPとして登録されていること
- SP側のFederationページ(adminでログイン済み)
信頼されたIdPとして登録されていること
動作確認 †
- SP側のAutenticationページ
[Test configured authentication sources]-[default-sp]
- 認証のためにIdPへリダイレクト
- 認証後にSPへリダイレクト
SAMLメッセージ †
- Client - IdP(GET)
- Client - SP(POST)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
| <samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_dd25fc96ee930c31d737c37e856bed1c7462ca0bde"
Version="2.0"
IssueInstant="2017-06-04T21:10:04Z"
Destination="https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp"
InResponseTo="_4e12db0bcaaa1f023f4a17fc3a0ff5e270e184e873"
>
<saml:Issuer>https://idp003152.azurewebsites.net/simplesaml/saml2/idp/metadata.php</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_dd25fc96ee930c31d737c37e856bed1c7462ca0bde">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>91Ko1IwaaOOcyKsaanIHDOwhYTixDORqoHc8agHBXQs=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>nc9WBFPsRrMxs5u7mPtfaP4w6ZTN8U3VeLtBq・・・</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIDKTCCAhGgAwIBAgIJAIpi・・・</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
ID="_65797c0743748d572725f34aa42c15e32ef888cd47"
Version="2.0"
IssueInstant="2017-06-04T21:10:04Z"
>
<saml:Issuer>https://idp003152.azurewebsites.net/simplesaml/saml2/idp/metadata.php</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_65797c0743748d572725f34aa42c15e32ef888cd47">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>VpKJd4uyE3w+JOE3dG8nP7vNM9b7GPF7fSCan0sLs1Y=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>nc9WBFPsRrMxs5u7mPtfaP4w6ZTN8U3VeLtBq・・・</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIDKTCCAhGgAwIBAgIJAIpi・・・</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml:Subject>
<saml:NameID SPNameQualifier="https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/metadata.php/default-sp"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
>_e24b67f4b184004764c198e4a493b611234e4d4671</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2017-06-04T21:15:04Z"
Recipient="https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp"
InResponseTo="_4e12db0bcaaa1f023f4a17fc3a0ff5e270e184e873"
/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2017-06-04T21:09:34Z"
NotOnOrAfter="2017-06-04T21:15:04Z"
>
<saml:AudienceRestriction>
<saml:Audience>https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/metadata.php/default-sp</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2017-06-04T21:10:04Z"
SessionNotOnOrAfter="2017-06-05T05:10:04Z"
SessionIndex="_7ccf5b3a7ef8eeaeaa5da7259a0924bf9851bd5015"
>
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.1"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml:AttributeValue xsi:type="xs:string">member</saml:AttributeValue>
<saml:AttributeValue xsi:type="xs:string">student</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>
|
NameIDを一意な値にする †
デフォルト設定の場合、ログイン毎にNameIDが変わります(transient)。
IdPのデフォルト値を設定する場合はIdP側を、SP側から要求フォーマットをtransient以外に指定する場合はSP側の設定を変更します。
- vi metadata/saml20-idp-hosted.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| -
|
|
|
!
-
|
|
!
|
'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
'authproc' => array(
10 => array(
'class' => 'saml:TransientNameID',
),
20 => array(
'class' => 'saml:PersistentNameID',
'attribute' => 'uid',
),
30 => array(
'class' => 'saml:AttributeNameID',
'attribute' => 'mail',
'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
),
),
|
- vi config/authsources.php
1
|
| 'NameIDPolicy' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
|
- 結果
NameId Formatがpersistentになっており、何度ログイン/ログアウトを繰り返しても、NameIdは変わらない
IdPをPOSTバインディングにする †
デフォルト設定の場合、IdPはRedirectバインディングです。
これをPOSTバインディングにするには、IdP側の設定を変更します。
- vi metadata/saml20-idp-hosted.php
1
2
| -
!
| 'SingleSignOnServiceBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
|
- デプロイ
- IdPのメタデータが更新されるため、再取得しSP側に設定
- 結果
リクエスト,レスポンスともにPOST
表示名を変更する †
- vi metadata/saml20-idp-hosted.php
1
2
3
4
5
6
7
8
9
10
11
12
| -
|
!
|
'name' => array(
'en' => 'idp en',
'ja' => 'idp ja',
),
'OrganizationName' => 'ON',
'OrganizationDisplayName' => 'ON',
'OrganizationURL' => array(
'en' => 'http://example.com'
),
|
- vi config/authsources.php
1
2
3
4
5
6
7
8
9
10
11
12
| -
|
!
|
'name' => array(
'en' => 'sp1 en',
'ja' => 'sp1 ja',
),
'OrganizationName' => 'ON',
'OrganizationDisplayName' => 'ON',
'OrganizationURL' => array(
'en' => 'http://example.com'
),
|
- どちらを変更してもメタデータが更新されるため、再取得し設定する必要がある
認証要求に署名をつける †
デフォルト設定の場合、認証要求は署名されません。
SPの設定によらず署名を期待する場合はIdP側を、IdPの設定によらず署名する場合はSP側の設定を変更します。
- vi metadata/saml20-idp-hosted.php
1
2
3
4
| -
!
|
'redirect.sign' => TRUE,
'redirect.validate' => TRUE,
|
- vi config/authsources.php
1
2
3
4
| -
!
|
'redirect.sign' => TRUE,
'redirect.validate' => TRUE,
|
- どちらを変更してもメタデータが更新されるため、再取得し設定する必要がある
- SAMLメッセージ
Client - IdP(POST)
NameIDを暗号化する †
デフォルト設定の場合、認証応答に含まれるNameIDは平文です。
これを暗号化する場合、IdP, SPの設定が必要です。
- vi metadata/saml20-idp-hosted.php
1
|
| 'nameid.encryption' => TRUE,
|
- vi config/authsources.php
1
|
| 'nameid.encryption' => TRUE,
|
- SAMLメッセージ
Client - SP(POST)
saml:Subject下がsaml:NameIDではなく、saml:EncryptedIDとなっている
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
| <samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_3c4fa0b2eb51145455228944c4713ea20af016102a"
Version="2.0"
IssueInstant="2017-06-05T11:33:12Z"
Destination="https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp"
InResponseTo="_c7815ab4768c3b1ffdeb9e657980a7c3c567e3e289"
>
<saml:Issuer>https://idp003152.azurewebsites.net/simplesaml/saml2/idp/metadata.php</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_3c4fa0b2eb51145455228944c4713ea20af016102a">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>aXhTa9Py/k2Pbm3OImtSGI3swzuonhiXCW/m5GwRQG0=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>iQT4G42HDSpNKKdfkgarPHsd・・・</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIDKTCCAhGgAwIBAgIJA・・・</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
ID="_9b28b2030cdc73e281d451251e9016bb094fc5a68f"
Version="2.0"
IssueInstant="2017-06-05T11:33:12Z"
>
<saml:Issuer>https://idp003152.azurewebsites.net/simplesaml/saml2/idp/metadata.php</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_9b28b2030cdc73e281d451251e9016bb094fc5a68f">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>QfFg2MCjjN0ua9GGpm1pnzitTlaxIyEepsCWq//hIXI=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>rSLyTrP5FjyQ2ytdne4NifSItP5・・・</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>MIIDKTCCAhGgAwIBAgIJAIpi/+0・・・</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<saml:Subject>
<saml:EncryptedID>
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
Type="http://www.w3.org/2001/04/xmlenc#Element"
>
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
<xenc:EncryptedKey>
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" />
<xenc:CipherData>
<xenc:CipherValue>IRzn6Yox5HqSUl9Yhdqh・・・</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedKey>
</dsig:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>WRxkO0kcEkscGEsyBokadvWlPbIDrm・・・</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</saml:EncryptedID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2017-06-05T11:38:12Z"
Recipient="https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/saml2-acs.php/default-sp"
InResponseTo="_c7815ab4768c3b1ffdeb9e657980a7c3c567e3e289"
/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2017-06-05T11:32:42Z"
NotOnOrAfter="2017-06-05T11:38:12Z"
>
<saml:AudienceRestriction>
<saml:Audience>https://sp1-042810.azurewebsites.net/simplesaml/module.php/saml/sp/metadata.php/default-sp</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2017-06-05T11:33:12Z"
SessionNotOnOrAfter="2017-06-05T19:33:12Z"
SessionIndex="_8280e0771f785a7d23fa117ce27ae5c5d471bfe4fa"
>
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="uid"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="eduPersonAffiliation"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml:AttributeValue xsi:type="xs:string">member</saml:AttributeValue>
<saml:AttributeValue xsi:type="xs:string">student</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="mail"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml:AttributeValue xsi:type="xs:string">[email protected]</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>
|
アサーションを暗号化する †
デフォルト設定の場合、認証応答に含まれるアサーションは平文です。
これを暗号化する場合、IdP, SPの設定が必要です。
- vi metadata/saml20-idp-hosted.php
1
|
| 'assertion.encryption' => TRUE,
|
- vi config/authsources.php
1
|
| 'assertion.encryption' => TRUE,
|
- SAMLメッセージ
Client - SP(POST)
samlp:Response下がsaml:Assertionではなく、saml:EncryptedAssertionとなっている
検証時の環境 †
- IdP
- Azure App Service
- PHP 5.6
- SimpleSAMLphp 1.14.14
- SP
- Azure App Service
- PHP 5.6
- SimpleSAMLphp 1.14.14
- 作業端末
参考 †