Inheritance: Asn1Encodable, IAsn1Choice
Ejemplo n.º 1
0
		public override void PerformTest()
		{
			Target[] targets = new Target[2];
			Target targetName = new Target(Target.Choice.Name, new GeneralName(GeneralName.DnsName, "www.test.com"));
			Target targetGroup = new Target(Target.Choice.Group, new GeneralName(GeneralName.DirectoryName, "o=Test, ou=Test"));
			targets[0] = targetName;
			targets[1] = targetGroup;
			Targets targetss = new Targets(targets);
			TargetInformation targetInformation1 = new TargetInformation(targetss);
			// use an Target array
			TargetInformation targetInformation2 = new TargetInformation(targets);
			// targetInformation1 and targetInformation2 must have same
			// encoding.
			if (!targetInformation1.Equals(targetInformation2))
			{
				Fail("targetInformation1 and targetInformation2 should have the same encoding.");
			}
			TargetInformation targetInformation3 = TargetInformation.GetInstance(targetInformation1.ToAsn1Object());
			TargetInformation targetInformation4 = TargetInformation.GetInstance(targetInformation2.ToAsn1Object());
			if (!targetInformation3.Equals(targetInformation4))
			{
				Fail("targetInformation3 and targetInformation4 should have the same encoding.");
			}
		}
Ejemplo n.º 2
0
		private IX509AttributeCertificate CreateAttrCert()
		{
//			CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");
//			X509Certificate iCert = (X509Certificate) fact
//				.generateCertificate(new ByteArrayInputStream(holderCert));
			X509Certificate iCert = new X509CertificateParser().ReadCertificate(holderCert);

			//
			// a sample key pair.
			//
			// RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(
			// new BigInteger(
			// "b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7",
			// 16), new BigInteger("11", 16));

			//
			// set up the keys
			//
//			KeyFactory kFact = KeyFactory.getInstance("RSA", "BC");
//			PrivateKey privKey = kFact.generatePrivate(RsaPrivateKeySpec);
			AsymmetricKeyParameter privKey = RsaPrivateKeySpec;

			X509V2AttributeCertificateGenerator gen = new X509V2AttributeCertificateGenerator();

			// the actual attributes
			GeneralName roleName = new GeneralName(GeneralName.Rfc822Name, "*****@*****.**");
			Asn1EncodableVector roleSyntax = new Asn1EncodableVector(roleName);

			// roleSyntax OID: 2.5.24.72
			X509Attribute attributes = new X509Attribute("2.5.24.72",
				new DerSequence(roleSyntax));

			gen.AddAttribute(attributes);
			gen.SetHolder(new AttributeCertificateHolder(PrincipalUtilities.GetSubjectX509Principal(iCert)));
			gen.SetIssuer(new AttributeCertificateIssuer(new X509Name("cn=test")));
			gen.SetNotBefore(DateTime.UtcNow.AddSeconds(-50));
			gen.SetNotAfter(DateTime.UtcNow.AddSeconds(50));
			gen.SetSerialNumber(BigInteger.One);
			gen.SetSignatureAlgorithm("SHA1WithRSAEncryption");

			Target targetName = new Target(
				Target.Choice.Name,
				new GeneralName(GeneralName.DnsName, "www.test.com"));

			Target targetGroup = new Target(
				Target.Choice.Group,
				new GeneralName(GeneralName.DirectoryName, "o=Test, ou=Test"));

			Target[] targets = new Target[]{ targetName, targetGroup };

			TargetInformation targetInformation = new TargetInformation(targets);
			gen.AddExtension(X509Extensions.TargetInformation.Id, true, targetInformation);

			return gen.Generate(privKey);
		}
Ejemplo n.º 3
0
		/**
		 * According to RFC 3281 only one targets element must be produced. If
		 * multiple targets are given they must be merged in
		 * into one targets element.
		 *
		 * @param targets An array with {@link Targets}.
		 */
		public TargetInformation(
			Target[] targets)
			: this(new Targets(targets))
		{
		}
Ejemplo n.º 4
0
		/**
		 * Returns the targets in an <code>ArrayList</code>.
		 * <p>
		 * The ArrayList is cloned before it is returned.</p>
		 * 
		 * @return Returns the targets.
		 */
		public virtual Target[] GetTargets()
		{
			Target[] result = new Target[targets.Count];

			for (int i = 0; i < targets.Count; ++i)
			{
				result[i] = Target.GetInstance(targets[i]);
			}

			return result;
		}
Ejemplo n.º 5
0
		/**
		 * Constructor from given targets.
		 * <p>
		 * The ArrayList is copied.</p>
		 * 
		 * @param targets An <code>ArrayList</code> of {@link Target}s.
		 * @see Target
		 * @throws ArgumentException if the ArrayList contains not only Targets.
		 */
		public Targets(
			Target[] targets)
		{
			this.targets = new DerSequence(targets);
		}