Exemplo n.º 1
0
        private static XElement MakeDgwsStsReq(IdCard sc, string issuer)
        {
            var xassertion = new XDocument();

            using (var wr = xassertion.CreateWriter())
            {
                sc.Xassertion.WriteTo(wr);
            }

            var xrst = new XElement(NameSpaces.xwst + "RequestSecurityToken",
                                    new XAttribute("Context", "www.sosi.dk"),
                                    new XElement(NameSpaces.xwst + "TokenType", "urn:oasis:names:tc:SAML:2.0:assertion"),
                                    new XElement(NameSpaces.xwst + "RequestType", "http://schemas.xmlsoap.org/ws/2005/02/security/trust/Issue"),
                                    new XElement(NameSpaces.xwst + "Claims", xassertion.Root),
                                    new XElement(NameSpaces.xwst + "Issuer",
                                                 new XElement(NameSpaces.xwsa04 + "Address", issuer)
                                                 )
                                    );

            return(new XElement(NameSpaces.xsoap + "Envelope",
                                new XElement(NameSpaces.xsoap + "Header",
                                             new XElement(NameSpaces.xwsse + "Security",
                                                          new XElement(NameSpaces.xwsu + "Timestamp",
                                                                       new XElement(NameSpaces.xwsu + "Created", DateTime.Now.ToString("u").Replace(' ', 'T'))
                                                                       )
                                                          )
                                             ),
                                new XElement(NameSpaces.xsoap + "Body", xrst)
                                ));
        }
Exemplo n.º 2
0
        protected IdCard(IdCard toCopy,
                         string issuer,
                         string certHash,
                         string alternativeIdentifier,
                         AuthenticationLevel authenticationLevel)
        {
            AlternativeIdentifier = alternativeIdentifier;
            AuthenticationLevel   = authenticationLevel;
            CertHash    = certHash;
            CreatedDate = DateTime.Now;//toCopy.CreatedDate;//?
            ExpiryDate  = toCopy.ExpiryDate;
            Issuer      = issuer;
            Password    = toCopy.Password;
            Username    = toCopy.Username;
            Version     = toCopy.Version;

            IdCardId = Guid.NewGuid().ToString("D");
        }
Exemplo n.º 3
0
        public static IdCard SignIn(IdCard sc, string issuer, string endpointAdr)
        {
            var ss = WebPost(MakeDgwsStsReq(sc, issuer), endpointAdr);

            var fault = ss.Element(NameSpaces.xsoap + "Body")?.Element(NameSpaces.xsoap + "Fault");

            if (fault != null)
            {
                throw new FaultException(new FaultReason(fault.Element("faultstring")?.Value), new FaultCode(fault.Element("faultcode")?.Value), null);
            }

            if (!new SealSignedXml(ss).CheckAssertionSignature())
            {
                throw new FaultException(new FaultReason("Signature error"), new FaultCode("STS"), null);
            }

            var builder = new IdCardModelBuilder();

            return(builder.BuildModel(ss.Descendants(NameSpaces.xsaml + "Assertion").First()));
        }
Exemplo n.º 4
0
 public SystemIdCard(IdCard toCopy, string issuer, string certHash, string alternativeIdentifier, SystemInfo systemInfo, AuthenticationLevel authLevel) : base(toCopy, issuer, certHash, alternativeIdentifier, authLevel)
 {
     SystemInfo = systemInfo;
 }