質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

Q&A

解決済

1回答

6416閲覧

SAMLリクエストについて

metalrabit1987

総合スコア8

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

0グッド

0クリップ

投稿2016/10/10 03:58

編集2016/10/12 06:41

###前提・実現したいこと
ADFSに対してSAMLリクエストを投げ、SAMLレスポンスを受け取りたいです。

###発生している問題・エラーメッセージ
ADFSに対してSAMLリクエストを投げた後、ADFS側で下記のエラーが発生しています。

System.Xml.XmlException: 名前の先頭に '.' (16 進数値 0x00) を使用することはできません。 行 1、位置 2。 場所 System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 場所 System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) 場所 System.Xml.XmlTextReaderImpl.ParseElement() 場所 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 場所 Microsoft.IdentityServer.Protocols.Saml.XmlNamespaceReader.Read() 場所 System.Xml.XmlReader.MoveToContent() 場所 System.Xml.XmlReader.IsStartElement(String localname, String ns) 場所 Microsoft.IdentityServer.Protocols.Saml.SamlProtocolSerializer.ReadSamlMessage(XmlReader reader, NamespaceContext context) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpSamlBindingSerializer.ReadProtocolMessage(String encodedSamlMessage) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpSamlBindingSerializer.CreateFromNameValueCollection(Uri baseUrl, NameValueCollection collection) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpRedirectSamlBindingSerializer.ReadMessage(Uri requestUrl, NameValueCollection form) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.HttpSamlMessageFactory.CreateMessage(WrappedHttpListenerRequest httpRequest) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.SamlContextFactory.CreateProtocolContextFromRequest(WrappedHttpListenerRequest request, ProtocolContext& protocolContext) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.SamlProtocolHandler.CreateProtocolContext(WrappedHttpListenerRequest request) 場所 Microsoft.IdentityServer.Web.PassiveProtocolListener.GetProtocolHandler(WrappedHttpListenerRequest request, ProtocolContext& protocolContext, PassiveProtocolHandler& protocolHandler) 場所 Microsoft.IdentityServer.Web.PassiveProtocolListener.OnGetContext(WrappedHttpListenerContext context)

###該当のソースコード

C#

1 protected void Page_Load(object sender, EventArgs e) 2 { 3 #region Deflateエンコード 4 byte[] deflateEncodedSamlRequestBytes = null; 5 6 XmlDocument samlRequestXmlDoc = new XmlDocument(); 7 samlRequestXmlDoc.Load(@"C:\samlrequest.xml"); 8 9 byte[] samlRequestBytes = Encoding.Unicode.GetBytes(samlRequestXmlDoc.InnerXml); 10 using (MemoryStream samlRequestMemoryStream = new MemoryStream()) 11 { 12 using (DeflateStream samlRequestCompressedStream = new DeflateStream(samlRequestMemoryStream, CompressionMode.Compress, true)) 13 { 14 // エンコード 15 samlRequestCompressedStream.Write(samlRequestBytes, 0, samlRequestBytes.Length); 16 } 17 18 deflateEncodedSamlRequestBytes = samlRequestMemoryStream.ToArray(); 19 } 20 #endregion Deflateエンコード 21 22 // Base64エンコード 23 string base64EncodedSamlRequestString = Convert.ToBase64String(deflateEncodedSamlRequestBytes); 24 25 // URLエンコード 26 string urlEncodedSamlRequestString = HttpUtility.UrlEncode(base64EncodedSamlRequestString); 27 28 //--- AuthnRequestをキャッシュさせないために必要。 29 Response.Cache.SetCacheability(HttpCacheability.NoCache); 30 Response.Cache.SetNoStore(); 31 32 // SAMLリクエスト 33 Response.Redirect(string.Format("https://adfs-test.xxx.co.jp/adfs/ls?SAMLRequest={0}", urlEncodedSamlRequestString)); 34 }

※「samlrequest.xml」の内容は下記の通りです。

XML

1<?xml version="1.0" encoding="UTF-8"?><samlp:AuthnRequest AssertionConsumerServiceURL="https://firebrick.xx.xx.co.jp/SamlAuthTest/SamlAssertionConsumerService.aspx" ID="szqd0c3d0u3vpz5jwna4p24iso42opc4" IssueInstant="2013-04-01T00:00:00Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://firebrick.xx.xx.co.jp/SamlAuthTest</saml:Issuer><samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" /></samlp:AuthnRequest>

※Deflateエンコード→Base64エンコード→URLエンコードの順にエンコードしているのは、下記のページの「2. 認証要求メッセージをIdPに送る」を参考にしました。
【サイボウズエンジニアのブログ】SAML認証ができるまで

###補足情報(言語/FW/ツール等のバージョンなど)
言語:C#
FW:.NET Framework 4.5.1
開発環境:Visual Studio 2015

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

すみません。凡ミスでした。

C#

1byte[] samlRequestBytes = Encoding.Unicode.GetBytes(samlRequestXmlDoc.InnerXml);

ではなく、

C#

1byte[] samlRequestBytes = Encoding.UTF8.GetBytes(samlRequestXmlDoc.InnerXml);

とすることで解消しました。

投稿2016/10/10 05:34

metalrabit1987

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問