Example #1
0
		protected IdentityCard ProcessImport (string filename, string password)
		{
			string xml = new IdentityCardEncryption ().Decrypt (
				new StreamReader (filename).ReadToEnd (), password);
			IdentityCard card = new IdentityCard ();
			card.Load (XmlReader.Create (new StringReader (xml)));
			return card;
		}
Example #2
0
        protected IdentityCard ProcessImport(string filename, string password)
        {
            string xml = new IdentityCardEncryption().Decrypt(
                new StreamReader(filename).ReadToEnd(), password);
            IdentityCard card = new IdentityCard();

            card.Load(XmlReader.Create(new StringReader(xml)));
            return(card);
        }
Example #3
0
		public void Load ()
		{
			IdentityCard ic = new IdentityCard ();
			ic.Load (XmlReader.Create ("Test/resources/rupert.xml"));
			Assert.AreEqual (DateTimeKind.Utc, ic.TimeIssued.Kind, "#1");
			Assert.AreEqual (11, ic.TimeIssued.Hour, "#2");
			Assert.AreEqual (23, ic.TimeExpires.Hour, "#3");
			new IdentityCard ().Load (XmlReader.Create (
				"Test/resources/managed.xml"));
		}
Example #4
0
        public virtual void Import(string filename)
        {
            string password = ReceivePassword();

            if (password == null)
            {
                return;
            }
            IdentityCard card = ProcessImport(filename, password);

            IdentityStore.GetDefaultStore().StoreCard(card, password);
        }
Example #5
0
        GenericXmlSecurityToken GetToken(
            XmlElement target, XmlElement issuer,
            Collection <XmlElement> parameters,
            Uri policyNoticeLink, int policyNoticeVersion)
        {
            Collection <ClaimTypeRequirement> reqs  = new Collection <ClaimTypeRequirement> ();
            Collection <XmlElement>           alist = new Collection <XmlElement> ();

            foreach (XmlElement el in parameters)
            {
                if (el.LocalName == "Claims" && el.NamespaceURI == Constants.WstNamespace)
                {
                    foreach (XmlElement c in el.ChildNodes)
                    {
                        reqs.Add(new ClaimTypeRequirement(c.GetAttribute("Uri"), c.GetAttribute("Optional") == "true"));
                    }
                }
                else
                {
                    alist.Add(el);
                }
            }

            CardSelectionContext ctx = new CardSelectionContext(
                EndpointAddress.ReadFrom(XmlDictionaryReader.CreateDictionaryReader(new XmlNodeReader(target))),
                EndpointAddress.ReadFrom(XmlDictionaryReader.CreateDictionaryReader(new XmlNodeReader(issuer))),
                reqs,
                alist,
                policyNoticeLink,
                policyNoticeVersion);

            IdentityCard card = SelectCardToSend(ctx);

            if (card.Issuer != null)
            {
                // process WS-Trust RST
                return(RequestTrustedToken(ctx, card));
            }
            else
            {
                return(RequestSelfIssuedToken(ctx, card));
            }
        }
Example #6
0
		void SaveRoundtrip (string file)
		{
			IdentityCard ic = new IdentityCard ();
			ic.Load (XmlReader.Create (file));
			MemoryStream ms = new MemoryStream ();
			XmlWriterSettings xws = new XmlWriterSettings ();
			xws.OmitXmlDeclaration = true;
			using (XmlWriter xw = XmlWriter.Create (ms, xws)) {
				ic.Save (xw);
			}
			XmlDocument doc = new XmlDocument ();
			doc.Load (file);
			if (doc.FirstChild is XmlDeclaration)
				doc.RemoveChild (doc.FirstChild);
			string expected = doc.OuterXml;
			doc.Load (new MemoryStream (ms.ToArray ()));
			string actual = doc.OuterXml;
			Assert.AreEqual (expected, actual, file);
		}
Example #7
0
        public virtual GenericXmlSecurityToken RequestSelfIssuedToken(CardSelectionContext ctx, IdentityCard card)
        {
            Uri issuerUri           = card.Issuer ?? new Uri(SelfIdentityIssuerUrl);
            X509Certificate2 cert   = new X509Certificate2(SelfIdentityIssuerCertificate);
            EndpointAddress  issuer = new EndpointAddress(issuerUri, new X509CertificateEndpointIdentity(cert));

            return(RequestToken(issuer, ctx));
        }
Example #8
0
        public virtual GenericXmlSecurityToken RequestTrustedToken(CardSelectionContext ctx, IdentityCard card)
        {
            X509Certificate2 cert   = new X509Certificate2(card.Certificate);
            EndpointAddress  issuer = new EndpointAddress(card.Issuer, new X509CertificateEndpointIdentity(cert));

            return(RequestToken(issuer, ctx));
        }
Example #9
0
 public override void StoreCard(IdentityCard card, string password)
 {
     // FIXME: store card both as public-only and encrypted state
 }
Example #10
0
 public abstract void StoreCard(IdentityCard card, string password);
Example #11
0
		public virtual GenericXmlSecurityToken RequestSelfIssuedToken (CardSelectionContext ctx, IdentityCard card)
		{
			Uri issuerUri = card.Issuer ?? new Uri (SelfIdentityIssuerUrl);
			X509Certificate2 cert = new X509Certificate2 (SelfIdentityIssuerCertificate);
			EndpointAddress issuer = new EndpointAddress (issuerUri, new X509CertificateEndpointIdentity (cert));
			return RequestToken (issuer, ctx);
		}
Example #12
0
		public virtual GenericXmlSecurityToken RequestTrustedToken (CardSelectionContext ctx, IdentityCard card)
		{
			X509Certificate2 cert = new X509Certificate2 (card.Certificate);
			EndpointAddress issuer = new EndpointAddress (card.Issuer, new X509CertificateEndpointIdentity (cert));
			return RequestToken (issuer, ctx);
		}
Example #13
0
		public override void StoreCard (IdentityCard card, string password)
		{
			// FIXME: store card both as public-only and encrypted state
		}
Example #14
0
		public abstract void StoreCard (IdentityCard card, string password);