2014-04-09 3 views
2

공급 업체 서비스에 대해 작동하는 SAML 토큰 소유자 키가있는 일련 화 된 SOAP 요청 메시지가 있습니다. 비슷한 요청을하기 위해 C#에서 데모 프로그램을 만들고 싶습니다. 이렇게하려면 자체 SAML 토큰을 만드는 클라이언트를 작성하고 싶습니다.클라이언트 요청에서 SAML 토큰 뒤에 서명이 필요합니다.

자체 서명 된 인증서에서 SAML2 토큰을 성공적으로 생성했으며이를 ChannelFactoryOperations.CreateChannelWithIssuedToken 접근 방식 (.Net 4.0)을 사용하여 요청에 연결할 수 있습니다. 모든 것이 잘 작동하지만 어설 션 후에 서명을 배치하고 SAML 토큰을 서명 KeyIdentifier로 사용하여 타임 스탬프에 서명하는 데 필요한 C#을 이해할 수 없습니다. 나는 내가 무엇을 요구하고 있는지조차 모르지만 토큰 자체가 쉬운 부분이어야하는 것은 서명과 같은 것처럼 보인다. 그러나 요청에서 SAML을 가져 오는 유일한 방법은 BearerKey 유형을 선언하는 것입니다. 그러나 BearerKey는 어설 션 후에 서명을 생략 한 것처럼 보입니다. SymmetricKey가 필요하지만 토큰에 "키가 없습니다." 어설 션 후에이 같은 서명 요소를 어떻게 만들 수 있습니까? 여기

enter image description here

URI = "#_ 1"WS 보안 타임 스탬프를 참조하여 상술되어있다 (도시 생략).

답변

3

안녕하세요 사람들은 마침내이 모든 것을 알아 냈습니다. 이 코드는 자체 서명 된 인증서를로드하고 SAML 토큰을 생성 한 다음 SAML 토큰을 사용하여 메시지를 보증합니다. 문제는 "토큰에 키가 없습니다"라는 오류입니다. 이것은 issuerToken과 키를 생성하고 이것을 토큰 생성자에 전달함으로써 해결되었습니다. 아래를 참조하십시오. 온라인에서 찾은 가장 유용한 정보는 여기 위대한 게시물이라고 생각합니다. http://devproconnections.com/development/generating-saml-tokens-wif-part-2

 X509Certificate2 cert = new X509Certificate2("C:\\Users\\foobar\\desktop\\test.pfx", "test", X509KeyStorageFlags.MachineKeySet); 
     RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider; 
     RsaSecurityKey rsaKey = new RsaSecurityKey(rsa); 
     RsaKeyIdentifierClause rsaClause = new RsaKeyIdentifierClause(rsa); 
     SecurityKeyIdentifier signingSki = new SecurityKeyIdentifier(new SecurityKeyIdentifierClause[] { rsaClause }); 
     SigningCredentials signingCredentials = new SigningCredentials(rsaKey, SecurityAlgorithms.RsaSha1Signature, SecurityAlgorithms.Sha1Digest, signingSki); 
     Saml2NameIdentifier saml2NameIdentifier = new Saml2NameIdentifier("C=US,O=hi mom,CN=test", new System.Uri("urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName")); 
     Saml2Assertion saml2Assertion2 = new Saml2Assertion(saml2NameIdentifier); 
     saml2Assertion2.SigningCredentials = signingCredentials; 
     Saml2Subject saml2Subject = new Saml2Subject(); 
     saml2NameIdentifier = new Saml2NameIdentifier("[email protected]", new System.Uri("urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName")); 
     saml2Subject.NameId = saml2NameIdentifier; 
     Saml2SubjectConfirmationData subjectConfirmationData = new Saml2SubjectConfirmationData(); 
     Saml2SubjectConfirmation subjectConfirmation = new Saml2SubjectConfirmation(new Uri("urn:oasis:names:tc:SAML:2.0:cm:holder-of-key")); 
     subjectConfirmation.SubjectConfirmationData = subjectConfirmationData; 
     subjectConfirmationData.KeyIdentifiers.Add(signingSki); 
     saml2Subject.SubjectConfirmations.Add(subjectConfirmation); 
     saml2Assertion2.Subject = saml2Subject; 
     Saml2AuthenticationContext saml2AuthCtxt = new Saml2AuthenticationContext(new Uri("urn:oasis:names:tc:SAML:2.0:ac:classes:X509")); 
     Saml2AuthenticationStatement saml2AuthStatement = new Saml2AuthenticationStatement(saml2AuthCtxt); 
     saml2AuthStatement.SessionIndex = "123456"; 
     saml2Assertion2.Statements.Add(saml2AuthStatement); 
     Saml2AttributeStatement saml2AttStatement = new Saml2AttributeStatement(); 
     Saml2Attribute saml2Attribute = new Saml2Attribute("urn:oasis:names:tc:xspa:1.0:subject:subject-id", "foo bar test"); 
     saml2AttStatement.Attributes.Add(saml2Attribute); 
     saml2Attribute = new Saml2Attribute("urn:oasis:names:tc:xspa:1.0:subject:organization", "urn:oid:"+senderOid); 
     saml2AttStatement.Attributes.Add(saml2Attribute); 
     saml2Attribute = new Saml2Attribute("urn:oasis:names:tc:xspa:1.0:subject:organization-id", "urn:oid:" + senderOid); 
     saml2AttStatement.Attributes.Add(saml2Attribute); 
     saml2Attribute = new Saml2Attribute("urn:nhin:names:saml:homeCommunityId", "urn:oid:" + senderOid); 
     saml2AttStatement.Attributes.Add(saml2Attribute); 
     saml2Attribute = new Saml2Attribute("urn:oasis:names:tc:xacml:2.0:subject:role"); 
     saml2AttStatement.Attributes.Add(saml2Attribute); 
     saml2Assertion2.Statements.Add(saml2AttStatement); 
     List<SecurityKey> keyList = new List<SecurityKey>(); 
     keyList.Add(rsaKey); 
     ReadOnlyCollection<SecurityKey> keys = new ReadOnlyCollection<SecurityKey>(keyList); 
     X509SecurityToken issuerToken = new X509SecurityToken(cert); 
     Saml2SecurityToken token2 = new Saml2SecurityToken(saml2Assertion2,keys,issuerToken); 
     XcpdRespondingGatewaySyncService.RespondingGatewaySyncClient myClient = new XcpdRespondingGatewaySyncService.RespondingGatewaySyncClient("IRespondingGatewaySync2"); 
     CustomBinding customBinding = myClient.Endpoint.Binding as CustomBinding; 
     SecurityBindingElement element = customBinding.Elements.Find<SecurityBindingElement>(); 
     IssuedSecurityTokenParameters tokenParameters = element.EndpointSupportingTokenParameters.Signed[0].Clone() as IssuedSecurityTokenParameters; 
     tokenParameters.TokenType = System.IdentityModel.Tokens.SecurityTokenTypes.Saml; 
     tokenParameters.RequireDerivedKeys = false; 
     tokenParameters.KeyType = SecurityKeyType.SymmetricKey; 
     element.EndpointSupportingTokenParameters.Signed.Clear(); 
     element.EndpointSupportingTokenParameters.Endorsing.Add(tokenParameters); 
     myClient.ChannelFactory.Credentials.SupportInteractive = false; 
     myClient.ChannelFactory.ConfigureChannelFactory(); 
     XcpdRespondingGatewaySyncService.IRespondingGatewaySync myChannel = ChannelFactoryOperations.CreateChannelWithIssuedToken(myClient.ChannelFactory, token2); 
+0

덕분에 다른 사람에게 도움이되었습니다. –

관련 문제