Example #1
0
        /*[Test]
         * public void GatewaySecureBrowserLoginTest()
         * {
         *  DoLogin(Global.MocesCprGyldig);
         *
         *  using (var stsClient = new Seal2SamlStsClient("GWFetchCard"))
         *  using (var scope = new OperationContextScope((IContextChannel) stsClient.Channel.Channel))
         *  {
         *      OperationContext.Current.OutgoingMessageHeaders.Add(new SealCardMessageHeader(SealCard.Create(_assertion)));
         *      var d = stsClient.ExchangeAssertionViaGW("http://sundhed.dk/") as GenericXmlSecurityToken;
         *      var elm = d.TokenXml;
         *  }
         * }*/


        public void DoLogin(X509Certificate2 cert)
        {
            var gwClient = new GW.SosiGWFacadeClient();
            var sec      = MakeSecurity(MakeAssertionForSTS());
            var dig      = gwClient.requestIdCardDigestForSigning(sec, "whatever");

            var csp  = (RSACryptoServiceProvider)cert.PrivateKey;
            var sha1 = new SHA1Managed();
            var hash = sha1.ComputeHash(dig.DigestValue);
            var rb   = new GW.signIdCardRequestBody
            {
                SignatureValue = csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA1")),
                KeyInfo        = new GW.KeyInfo
                {
                    Item = new GW.X509Data {
                        Item = cert.Export(X509ContentType.Cert)
                    }
                }
            };

            var res = gwClient.signIdCard(sec, rb);

            if (res != GW.signIdCardResponse.ok)
            {
                throw new Exception("Gateway logon error");
            }
            _header    = MakeHeader();
            _assertion = SealCard.Create(sec.Assertion).GetAssertion <Assertion>(typeof(GW.AssertionType).Name);
        }
Example #2
0
 private static Security MakeSecurity(Assertion assertion)
 {
     return(new Security
     {
         id = Guid.NewGuid().ToString("D"),
         Timestamp = new Timestamp {
             Created = DateTimeEx.UtcNowRound - TimeSpan.FromMinutes(5)
         },
         Assertion = assertion
     });
 }