public override void PerformTest() { DistributionPointName name = new DistributionPointName( new GeneralNames(new GeneralName(new X509Name("cn=test")))); ReasonFlags reasonFlags = new ReasonFlags(ReasonFlags.CACompromise); checkPoint(6, name, true, true, reasonFlags, true, true); checkPoint(2, name, false, false, reasonFlags, false, false); checkPoint(0, null, false, false, null, false, false); try { IssuingDistributionPoint.GetInstance(new object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
private void checkPoint( int size, DistributionPointName distributionPoint, bool onlyContainsUserCerts, bool onlyContainsCACerts, ReasonFlags onlySomeReasons, bool indirectCRL, bool onlyContainsAttributeCerts) { IssuingDistributionPoint point = new IssuingDistributionPoint(distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); Asn1Sequence seq = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(point.GetEncoded())); if (seq.Count != size) { Fail("size mismatch"); } point = IssuingDistributionPoint.GetInstance(seq); checkValues(point, distributionPoint, onlyContainsUserCerts, onlyContainsCACerts, onlySomeReasons, indirectCRL, onlyContainsAttributeCerts); }
/** * Returns a string representation of this CRL. * * @return a string representation of this CRL. */ public override string ToString() { StringBuilder buf = new StringBuilder(); string nl = Platform.NewLine; buf.Append(" Version: ").Append(this.Version).Append(nl); buf.Append(" IssuerDN: ").Append(this.IssuerDN).Append(nl); buf.Append(" This update: ").Append(this.ThisUpdate).Append(nl); buf.Append(" Next update: ").Append(this.NextUpdate).Append(nl); buf.Append(" Signature Algorithm: ").Append(this.SigAlgName).Append(nl); byte[] sig = this.GetSignature(); buf.Append(" Signature: "); buf.Append(AsHexString(sig, 0, 20)).Append(nl); for (int i = 20; i < sig.Length; i += 20) { int count = System.Math.Min(20, sig.Length - i); buf.Append(" "); buf.Append(AsHexString(sig, i, count)).Append(nl); } X509Extensions extensions = c.TbsCertList.Extensions; if (extensions != null) { IEnumerator e = extensions.ExtensionOids.GetEnumerator(); if (e.MoveNext()) { buf.Append(" Extensions: ").Append(nl); } do { DerObjectIdentifier oid = (DerObjectIdentifier)e.Current; X509Extension ext = extensions.GetExtension(oid); if (ext.Value != null) { Asn1Object asn1Value = X509ExtensionUtilities.FromExtensionValue(ext.Value); buf.Append(" critical(").Append(ext.IsCritical).Append(") "); try { if (oid.Equals(X509Extensions.CrlNumber)) { buf.Append(new CrlNumber(DerInteger.GetInstance(asn1Value).PositiveValue)).Append(nl); } else if (oid.Equals(X509Extensions.DeltaCrlIndicator)) { buf.Append( "Base CRL: " + new CrlNumber(DerInteger.GetInstance( asn1Value).PositiveValue)) .Append(nl); } else if (oid.Equals(X509Extensions.IssuingDistributionPoint)) { buf.Append(IssuingDistributionPoint.GetInstance((Asn1Sequence)asn1Value)).Append(nl); } else if (oid.Equals(X509Extensions.CrlDistributionPoints)) { buf.Append(CrlDistPoint.GetInstance((Asn1Sequence)asn1Value)).Append(nl); } else if (oid.Equals(X509Extensions.FreshestCrl)) { buf.Append(CrlDistPoint.GetInstance((Asn1Sequence)asn1Value)).Append(nl); } else { buf.Append(oid.Id); buf.Append(" value = ").Append( Asn1Dump.DumpAsString(asn1Value)) .Append(nl); } } catch (Exception) { buf.Append(oid.Id); buf.Append(" value = ").Append("*****").Append(nl); } } else { buf.Append(nl); } }while (e.MoveNext()); } ISet certSet = GetRevokedCertificates(); if (certSet != null) { foreach (X509CrlEntry entry in certSet) { buf.Append(entry); buf.Append(nl); } } return(buf.ToString()); }
private void TbsV2CertListGenerate() { V2TbsCertListGenerator gen = new V2TbsCertListGenerator(); gen.SetIssuer(new X509Name("CN=AU,O=Bouncy Castle")); gen.AddCrlEntry(new DerInteger(1), new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 1)), ReasonFlags.AACompromise); gen.SetNextUpdate(new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 2))); gen.SetThisUpdate(new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 0, 500))); gen.SetSignature(new AlgorithmIdentifier(PkcsObjectIdentifiers.Sha1WithRsaEncryption, DerNull.Instance)); // // extensions // IList order = new ArrayList(); IDictionary extensions = new Hashtable(); SubjectPublicKeyInfo info = new SubjectPublicKeyInfo( new AlgorithmIdentifier( OiwObjectIdentifiers.ElGamalAlgorithm, new ElGamalParameter(BigInteger.One, BigInteger.Two)), new DerInteger(3)); order.Add(X509Extensions.AuthorityKeyIdentifier); order.Add(X509Extensions.IssuerAlternativeName); order.Add(X509Extensions.CrlNumber); order.Add(X509Extensions.IssuingDistributionPoint); extensions.Add(X509Extensions.AuthorityKeyIdentifier, new X509Extension(true, new DerOctetString(CreateAuthorityKeyId(info, new X509Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2)))); extensions.Add(X509Extensions.IssuerAlternativeName, new X509Extension(false, new DerOctetString(GeneralNames.GetInstance(new DerSequence(new GeneralName(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 3"))))))); extensions.Add(X509Extensions.CrlNumber, new X509Extension(false, new DerOctetString(new DerInteger(1)))); extensions.Add(X509Extensions.IssuingDistributionPoint, new X509Extension(true, new DerOctetString(IssuingDistributionPoint.GetInstance(DerSequence.Empty)))); X509Extensions ex = new X509Extensions(order, extensions); gen.SetExtensions(ex); TbsCertificateList tbs = gen.GenerateTbsCertList(); if (!Arrays.AreEqual(tbs.GetEncoded(), v2CertList)) { Fail("failed v2 cert list generation"); } // // read back test // Asn1InputStream aIn = new Asn1InputStream(v2CertList); Asn1Object o = aIn.ReadObject(); if (!Arrays.AreEqual(o.GetEncoded(), v2CertList)) { Fail("failed v2 cert list read back test"); } }
public override string ToString() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown StringBuilder val = new StringBuilder(); string newLine = Platform.NewLine; val.Append(" Version: ").Append(Version).Append(newLine); val.Append(" IssuerDN: ").Append((object)IssuerDN).Append(newLine); val.Append(" This update: ").Append((object)ThisUpdate).Append(newLine); val.Append(" Next update: ").Append((object)NextUpdate).Append(newLine); val.Append(" Signature Algorithm: ").Append(SigAlgName).Append(newLine); byte[] signature = GetSignature(); val.Append(" Signature: "); val.Append(Hex.ToHexString(signature, 0, 20)).Append(newLine); for (int i = 20; i < signature.Length; i += 20) { int length = Math.Min(20, signature.Length - i); val.Append(" "); val.Append(Hex.ToHexString(signature, i, length)).Append(newLine); } X509Extensions extensions = c.TbsCertList.Extensions; if (extensions != null) { global::System.Collections.IEnumerator enumerator = extensions.ExtensionOids.GetEnumerator(); if (enumerator.MoveNext()) { val.Append(" Extensions: ").Append(newLine); } do { DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)enumerator.get_Current(); X509Extension extension = extensions.GetExtension(derObjectIdentifier); if (extension.Value != null) { Asn1Object asn1Object = X509ExtensionUtilities.FromExtensionValue(extension.Value); val.Append(" critical(").Append(extension.IsCritical).Append(") "); try { if (derObjectIdentifier.Equals(X509Extensions.CrlNumber)) { val.Append((object)new CrlNumber(DerInteger.GetInstance(asn1Object).PositiveValue)).Append(newLine); continue; } if (derObjectIdentifier.Equals(X509Extensions.DeltaCrlIndicator)) { val.Append(string.Concat((object)"Base CRL: ", (object)new CrlNumber(DerInteger.GetInstance(asn1Object).PositiveValue))).Append(newLine); continue; } if (derObjectIdentifier.Equals(X509Extensions.IssuingDistributionPoint)) { val.Append((object)IssuingDistributionPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); continue; } if (derObjectIdentifier.Equals(X509Extensions.CrlDistributionPoints)) { val.Append((object)CrlDistPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); continue; } if (derObjectIdentifier.Equals(X509Extensions.FreshestCrl)) { val.Append((object)CrlDistPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); continue; } val.Append(derObjectIdentifier.Id); val.Append(" value = ").Append(Asn1Dump.DumpAsString(asn1Object)).Append(newLine); } catch (global::System.Exception) { val.Append(derObjectIdentifier.Id); val.Append(" value = ").Append("*****").Append(newLine); } } else { val.Append(newLine); } }while (enumerator.MoveNext()); } ISet revokedCertificates = GetRevokedCertificates(); if (revokedCertificates != null) { { global::System.Collections.IEnumerator enumerator2 = ((global::System.Collections.IEnumerable)revokedCertificates).GetEnumerator(); try { while (enumerator2.MoveNext()) { X509CrlEntry x509CrlEntry = (X509CrlEntry)enumerator2.get_Current(); val.Append((object)x509CrlEntry); val.Append(newLine); } } finally { global::System.IDisposable disposable = enumerator2 as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } } return(val.ToString()); }
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); string newLine = Platform.NewLine; stringBuilder.Append(" Version: ").Append(Version).Append(newLine); stringBuilder.Append(" IssuerDN: ").Append(IssuerDN).Append(newLine); stringBuilder.Append(" This update: ").Append(ThisUpdate).Append(newLine); stringBuilder.Append(" Next update: ").Append(NextUpdate).Append(newLine); stringBuilder.Append(" Signature Algorithm: ").Append(SigAlgName).Append(newLine); byte[] signature = GetSignature(); stringBuilder.Append(" Signature: "); stringBuilder.Append(Hex.ToHexString(signature, 0, 20)).Append(newLine); for (int i = 20; i < signature.Length; i += 20) { int length = Math.Min(20, signature.Length - i); stringBuilder.Append(" "); stringBuilder.Append(Hex.ToHexString(signature, i, length)).Append(newLine); } X509Extensions extensions = c.TbsCertList.Extensions; if (extensions != null) { IEnumerator enumerator = extensions.ExtensionOids.GetEnumerator(); if (enumerator.MoveNext()) { stringBuilder.Append(" Extensions: ").Append(newLine); } do { DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)enumerator.Current; X509Extension extension = extensions.GetExtension(derObjectIdentifier); if (extension.Value != null) { Asn1Object asn1Object = X509ExtensionUtilities.FromExtensionValue(extension.Value); stringBuilder.Append(" critical(").Append(extension.IsCritical).Append(") "); try { if (derObjectIdentifier.Equals(X509Extensions.CrlNumber)) { stringBuilder.Append(new CrlNumber(DerInteger.GetInstance(asn1Object).PositiveValue)).Append(newLine); } else if (derObjectIdentifier.Equals(X509Extensions.DeltaCrlIndicator)) { stringBuilder.Append("Base CRL: " + new CrlNumber(DerInteger.GetInstance(asn1Object).PositiveValue)).Append(newLine); } else if (derObjectIdentifier.Equals(X509Extensions.IssuingDistributionPoint)) { stringBuilder.Append(IssuingDistributionPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); } else if (derObjectIdentifier.Equals(X509Extensions.CrlDistributionPoints)) { stringBuilder.Append(CrlDistPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); } else if (derObjectIdentifier.Equals(X509Extensions.FreshestCrl)) { stringBuilder.Append(CrlDistPoint.GetInstance((Asn1Sequence)asn1Object)).Append(newLine); } else { stringBuilder.Append(derObjectIdentifier.Id); stringBuilder.Append(" value = ").Append(Asn1Dump.DumpAsString(asn1Object)).Append(newLine); } } catch (Exception) { stringBuilder.Append(derObjectIdentifier.Id); stringBuilder.Append(" value = ").Append("*****").Append(newLine); } } else { stringBuilder.Append(newLine); } }while (enumerator.MoveNext()); } ISet revokedCertificates = GetRevokedCertificates(); if (revokedCertificates != null) { foreach (X509CrlEntry item in revokedCertificates) { stringBuilder.Append(item); stringBuilder.Append(newLine); } } return(stringBuilder.ToString()); }
public override string ToString() { StringBuilder builder = new StringBuilder(); string newLine = Platform.NewLine; builder.Append(" Version: ").Append(this.Version).Append(newLine); builder.Append(" IssuerDN: ").Append(this.IssuerDN).Append(newLine); builder.Append(" This update: ").Append(this.ThisUpdate).Append(newLine); builder.Append(" Next update: ").Append(this.NextUpdate).Append(newLine); builder.Append(" Signature Algorithm: ").Append(this.SigAlgName).Append(newLine); byte[] signature = this.GetSignature(); builder.Append(" Signature: "); builder.Append(Hex.ToHexString(signature, 0, 20)).Append(newLine); for (int i = 20; i < signature.Length; i += 20) { int length = Math.Min(20, signature.Length - i); builder.Append(" "); builder.Append(Hex.ToHexString(signature, i, length)).Append(newLine); } X509Extensions extensions = this.c.TbsCertList.Extensions; if (extensions != null) { IEnumerator enumerator = extensions.ExtensionOids.GetEnumerator(); if (enumerator.MoveNext()) { builder.Append(" Extensions: ").Append(newLine); } do { DerObjectIdentifier current = (DerObjectIdentifier)enumerator.Current; X509Extension extension = extensions.GetExtension(current); if (extension.Value != null) { Asn1Object obj2 = X509ExtensionUtilities.FromExtensionValue(extension.Value); builder.Append(" critical(").Append(extension.IsCritical).Append(") "); try { if (current.Equals(X509Extensions.CrlNumber)) { builder.Append(new CrlNumber(DerInteger.GetInstance(obj2).PositiveValue)).Append(newLine); } else if (current.Equals(X509Extensions.DeltaCrlIndicator)) { builder.Append("Base CRL: " + new CrlNumber(DerInteger.GetInstance(obj2).PositiveValue)).Append(newLine); } else if (current.Equals(X509Extensions.IssuingDistributionPoint)) { builder.Append(IssuingDistributionPoint.GetInstance((Asn1Sequence)obj2)).Append(newLine); } else if (current.Equals(X509Extensions.CrlDistributionPoints)) { builder.Append(CrlDistPoint.GetInstance((Asn1Sequence)obj2)).Append(newLine); } else if (current.Equals(X509Extensions.FreshestCrl)) { builder.Append(CrlDistPoint.GetInstance((Asn1Sequence)obj2)).Append(newLine); } else { builder.Append(current.Id); builder.Append(" value = ").Append(Asn1Dump.DumpAsString((Asn1Encodable)obj2)).Append(newLine); } } catch (Exception) { builder.Append(current.Id); builder.Append(" value = ").Append("*****").Append(newLine); } } else { builder.Append(newLine); } }while (enumerator.MoveNext()); } ISet revokedCertificates = this.GetRevokedCertificates(); if (revokedCertificates != null) { IEnumerator enumerator = revokedCertificates.GetEnumerator(); try { while (enumerator.MoveNext()) { X509CrlEntry current = (X509CrlEntry)enumerator.Current; builder.Append(current); builder.Append(newLine); } } finally { if (enumerator is IDisposable disposable) { IDisposable disposable; disposable.Dispose(); } } } return(builder.ToString()); }