internal static void AdditionalChecks(IX509AttributeCertificate attrCert, PkixParameters pkixParams) { foreach (string text in pkixParams.GetProhibitedACAttributes()) { if (attrCert.GetAttributes(text) != null) { throw new PkixCertPathValidatorException("Attribute certificate contains prohibited attribute: " + text + "."); } } foreach (string text2 in pkixParams.GetNecessaryACAttributes()) { if (attrCert.GetAttributes(text2) == null) { throw new PkixCertPathValidatorException("Attribute certificate does not contain necessary attribute: " + text2 + "."); } } }
internal static void AdditionalChecks(IX509AttributeCertificate attrCert, PkixParameters pkixParams) { global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)pkixParams.GetProhibitedACAttributes()).GetEnumerator(); try { while (enumerator.MoveNext()) { string text = (string)enumerator.get_Current(); if (attrCert.GetAttributes(text) != null) { throw new PkixCertPathValidatorException("Attribute certificate contains prohibited attribute: " + text + "."); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } enumerator = ((global::System.Collections.IEnumerable)pkixParams.GetNecessaryACAttributes()).GetEnumerator(); try { while (enumerator.MoveNext()) { string text2 = (string)enumerator.get_Current(); if (attrCert.GetAttributes(text2) == null) { throw new PkixCertPathValidatorException("Attribute certificate does not contain necessary attribute: " + text2 + "."); } } } finally { global::System.IDisposable disposable2 = enumerator as global::System.IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } }
internal static void AdditionalChecks( IX509AttributeCertificate attrCert, PkixParameters pkixParams) { // 1 foreach (string oid in pkixParams.GetProhibitedACAttributes()) { if (attrCert.GetAttributes(oid) != null) { throw new PkixCertPathValidatorException( "Attribute certificate contains prohibited attribute: " + oid + "."); } } foreach (string oid in pkixParams.GetNecessaryACAttributes()) { if (attrCert.GetAttributes(oid) == null) { throw new PkixCertPathValidatorException( "Attribute certificate does not contain necessary attribute: " + oid + "."); } } }
private void doTestGenerateWithCert() { X509CertificateParser fact = new X509CertificateParser(); X509Certificate iCert = fact.ReadCertificate(signCert); // // a sample key pair. // RsaKeyParameters pubKey = new RsaKeyParameters( false, new BigInteger("b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16), new BigInteger("11", 16)); // // set up the keys // // PrivateKey privKey; // PublicKey pubKey; // // KeyFactory kFact = KeyFactory.getInstance("RSA"); // // privKey = kFact.generatePrivate(RSA_PRIVATE_KEY_SPEC); // pubKey = kFact.generatePublic(pubKeySpec); AsymmetricKeyParameter privKey = RSA_PRIVATE_KEY_SPEC; X509V2AttributeCertificateGenerator gen = new X509V2AttributeCertificateGenerator(); // the actual attributes GeneralName roleName = new GeneralName(GeneralName.Rfc822Name, "DAU123456789"); // roleSyntax OID: 2.5.24.72 X509Attribute attributes = new X509Attribute("2.5.24.72", new DerSequence(roleName)); gen.AddAttribute(attributes); gen.SetHolder(new AttributeCertificateHolder(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"); IX509AttributeCertificate aCert = gen.Generate(privKey); aCert.CheckValidity(); aCert.Verify(pubKey); AttributeCertificateHolder holder = aCert.Holder; if (holder.GetEntityNames() != null) { Fail("entity names set when none expected"); } if (!holder.SerialNumber.Equals(iCert.SerialNumber)) { Fail("holder serial number doesn't Match"); } if (!holder.GetIssuer()[0].Equivalent(iCert.IssuerDN)) { Fail("holder issuer doesn't Match"); } if (!holder.Match(iCert)) { Fail("generated holder not matching holder certificate"); } X509Attribute[] attrs = aCert.GetAttributes("2.5.24.72"); if (attrs == null) { Fail("attributes related to 2.5.24.72 not found"); } X509Attribute attr = attrs[0]; if (!attr.Oid.Equals("2.5.24.72")) { Fail("attribute oid mismatch"); } Asn1Encodable[] values = attr.GetValues(); GeneralName role = GeneralNames.GetInstance(values[0]).GetNames()[0]; if (role.TagNo != GeneralName.Rfc822Name) { Fail("wrong general name type found in role"); } if (!((IAsn1String)role.Name).GetString().Equals("DAU123456789")) { Fail("wrong general name value found in role"); } X509Certificate sCert = fact.ReadCertificate(holderCertWithBaseCertificateID); if (holder.Match(sCert)) { Fail("generated holder matching wrong certificate"); } equalityAndHashCodeTest(aCert, aCert.GetEncoded()); }