「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-[[戻る>SAML]]

* 目次 [#b2a7541f]
#contents

*概要 [#ifcd76fe]
汎用認証サイトにSAML2.0を実装するため作成中。

*詳細 [#pacd686c]

**シーケンス [#jd2a8b15]


***リクエスト [#k6798a26]
-GET
 https://idp.example.org/SAML2/SSO/Redirect?SAMLRequest=request&RelayState=token

-SAMLRequest=request
 <samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
   xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="identifier_1" Version="2.0"
   IssueInstant="2004-12-05T09:21:59Z" AssertionConsumerServiceIndex="1">
 
   <saml:Issuer>
     https://sp.example.com/SAML2
   </saml:Issuer>
 
   <samlp:NameIDPolicy AllowCreate="true"
     Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/>
 </samlp:AuthnRequest>

-RelayState=token
--SAMLでは、[[OAuth]] / [[OpenID Connect]]と違って、Resource Serverをサポートしない。
--SAMLでは、SP上のリソースを取得するので、そのリソース入手先のuriを指定する。


***レスポンス [#q5b1d1c4]

-HTTP Redirect Bindingの場合

-HTTP POST Bindingの場合
--(1)
 <form method="post" action="https://sp.example.com/SAML2/SSO/POST" ...>
   <input type="hidden" name="SAMLResponse" value="response" />
   <input type="hidden" name="RelayState" value="token" />
   ...
   <input type="submit" value="Submit" />
 </form>
--(2)
 POST /SAML2/SSO/POST HTTP/1.1
 Host: sp.example.com
 Content-Type: application/x-www-form-urlencoded
 Content-Length: nnnn
 SAMLResponse=response&RelayState=token

***アサーション [#hd8b18d8]
 <samlp:Response
   xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
   xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
   ID="identifier_2" InResponseTo="identifier_1" Version="2.0"
   IssueInstant="2004-12-05T09:22:05Z" Destination="https://sp.example.com/SAML2/SSO/POST">
 
   <saml:Issuer>
     https://idp.example.org/SAML2
   </saml:Issuer>
 
   <samlp:Status>
     <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
   </samlp:Status>
 
   <saml:Assertion
     xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
     ID="identifier_3" Version="2.0" IssueInstant="2004-12-05T09:22:05Z">
 
     <saml:Issuer>
       https://idp.example.org/SAML2
     </saml:Issuer>
 
     <!-- a POSTed assertion MUST be signed -->
     <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
       ...
     </ds:Signature>
 
     <saml:Subject>
       <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">
         3f7b3dcf-1674-4ecd-92c8-1544f346baf8
       </saml:NameID>
       <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
         <saml:SubjectConfirmationData InResponseTo="identifier_1"
           Recipient="https://sp.example.com/SAML2/SSO/POST" NotOnOrAfter="2004-12-05T09:27:05Z"/>
       </saml:SubjectConfirmation>
     </saml:Subject>
 
     <saml:Conditions
       NotBefore="2004-12-05T09:17:05Z" NotOnOrAfter="2004-12-05T09:27:05Z">
       <saml:AudienceRestriction>
           <saml:Audience>
             https://sp.example.com/SAML2
           </saml:Audience>
         </saml:AudienceRestriction>
     </saml:Conditions>
 
     <saml:AuthnStatement
       AuthnInstant="2004-12-05T09:22:00Z" SessionIndex="identifier_3">
         <saml:AuthnContext>
           <saml:AuthnContextClassRef>
             urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
           </saml:AuthnContextClassRef>
         </saml:AuthnContext>
     </saml:AuthnStatement>
   </saml:Assertion>
 </samlp:Response>

**署名・検証のポイント [#f681a495]
-Signature の値を事前にIdpから渡された公開鍵を使ってDigest に復号

-XML署名の対象となっているXMLのnodeに対し

--指定のアルゴリズムで正規化
---Signatureを取り除く
---...

--およびハッシュ化して Digest を作成

-2つの Digest の値が同一である事を検証

***ネストした複数のXML署名が Verify できない [#k3724cb3]
-SAMLはAssertion 側と Response 側どちらでの Signature の存在を仕様上は認めている。
-そのためIdP(またはその設定)によっては両方にXML署名が存在する場合がある。
-ネストしている場合の正規化では、外側のSignatureを取り除き、内部は残しておく。

-System.Security.Cryptography.SignedXmlクラスの実装に問題がある。~
(ネストした Signature を扱うと Verify できないバグがある)

※ 外側だけ検証すればイイ気がする。

***Whitespace を保持したままのXML署名が Verify できない [#n4ce6eeb]
XmlDocuement を利用する際に PreserveWhitespace を単に true にする。

*エンコード・デコード [#n9b349a2]
下記の

*参考 [#q968ebd8]
-SAML認証に関する自分なりのまとめ - なんとな~くしあわせ?の日記~
https://nantonaku-shiawase.hatenablog.com/entry/2016/07/13/081053

-SAML2.0でのシングルサインオン実装と戦うあなたに(.NET編) - Qiita~
https://qiita.com/ea54595/items/e932644477a45070690b

-SAML Token - samltool.io~
https://samltool.io/

**Microsoft Docs [#r40356b9]
-How to: Sign XML Documents with Digital Signatures~
https://docs.microsoft.com/en-us/dotnet/standard/security/how-to-sign-xml-documents-with-digital-signatures

-SignedXml Class (System.Security.Cryptography.Xml)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.xml.signedxml

**Sustainsys/Saml2 [#ve79906f]

-Sustainsys/Saml2: Saml2 Authentication services for ASP.NET~
https://github.com/Sustainsys/Saml2
>https://github.com/Sustainsys/Saml2/blob/master/Sustainsys.Saml2/XmlHelpers.cs#L368

-NuGet Gallery | Sustainsys.Saml~
https://www.nuget.org/packages/Sustainsys.Saml2/

**OneLogin [#m5a97de5]

***developers.onelogin.com [#p5927708]

-C# & ASP.NET SAML Authentication Examples~
C Sharp ASP SAML Single Sign-On (SSO) Tutorial~
https://developers.onelogin.com/saml/c-and-aspnet

-onelogin/dotnet-saml: SAML toolkit for .NET~
https://github.com/onelogin/dotnet-saml

***SAMLTool.com [#ne63aadb]
-SAML Testing Tools | Online SAML Debugger | Examples~
https://www.samltool.com/index.php

-ONLINE TOOLS~
https://www.samltool.com/online_tools.php

--X.509 CERTS~
https://www.samltool.com/sign_authn.php
---Obtain Self-Signed Certs~
https://www.samltool.com/self_signed_certs.php
---Calculate Fingerprint~
https://www.samltool.com/fingerprint.php
---Format X.509 Certificate~
https://www.samltool.com/format_x509cert.php
---Format Private Key~
https://www.samltool.com/format_privatekey.php

--CODE/DECODE~
---Base64~
https://www.samltool.com/base64.php
---Gzip~
https://www.samltool.com/gzip.php
---URL Encode/Decode~
https://www.samltool.com/url.php
---Deflate + Base64 Encode~
https://www.samltool.com/encode.php
---Base 64 Decode + Inflate~
https://www.samltool.com/decode.php

--ENCRYPT / DECRYPT
---Encrypt XML~
https://www.samltool.com/encrypt.php
---Decrypt XML~
https://www.samltool.com/decrypt.php

--SIGN~
---AuthNRequest~
https://www.samltool.com/sign_authn.php
---Response~
https://www.samltool.com/sign_response.php
---Logout Request~
https://www.samltool.com/sign_logout_req.php
---Logout Response~
https://www.samltool.com/sign_logout_res.php
---Metadata~
https://www.samltool.com/sign_metadata.php

--VALIDATE~
---XML Against XSD Schema~
https://www.samltool.com/validate_xml.php
---SAML AuthN Request~
https://www.samltool.com/validate_authn_req.php
---SAML Response~
https://www.samltool.com/validate_response.php
---SAML Logout Request~
https://www.samltool.com/validate_logout_req.php
---SAML Logout Response~
https://www.samltool.com/validate_logout_res.php

--ATTRIBUTE EXTRACTOR~

--XML PRETTY PRINT~

--BUILD METADATA~

--EXAMPLES~

--EXTERNAL SAML TOOLS~


**[[SAMLの仕様を読む。]] [#t67577ba]

----
Tags: [[:IT国際標準]], [[:認証基盤]], [[:クレームベース認証]], [[:SAML]]

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS