「[[マイクロソフト系技術情報 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~ [[OAuth]] / [[OpenID Connect]]のredirect_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 にする。 *参考 [#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 Developers [#m5a97de5] -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 **[[SAMLの仕様を読む。]] [#t67577ba] ---- Tags: [[:IT国際標準]], [[:認証基盤]], [[:クレームベース認証]], [[:SAML]]