/** * Constructor from given details. * <p> * If <code>digestedObjectType</code> is not {@link #publicKeyCert} or * {@link #publicKey} <code>otherObjectTypeID</code> must be given, * otherwise it is ignored.</p> * * @param digestedObjectType The digest object type. * @param otherObjectTypeID The object type ID for * <code>otherObjectDigest</code>. * @param digestAlgorithm The algorithm identifier for the hash. * @param objectDigest The hash value. */ public ObjectDigestInfo( int digestedObjectType, string otherObjectTypeID, AlgorithmIdentifier digestAlgorithm, byte[] objectDigest) { this.digestedObjectType = new DerEnumerated(digestedObjectType); if (digestedObjectType == OtherObjectDigest) { this.otherObjectTypeID = new DerObjectIdentifier(otherObjectTypeID); } this.digestAlgorithm = digestAlgorithm; this.objectDigest = new DerBitString(objectDigest); }
public CrlReason( DerEnumerated reason) : base(reason.Value.IntValue) { }
public OcspResponseStatus(DerEnumerated value) : base(value.Value.IntValue) { }
private ObjectDigestInfo( Asn1Sequence seq) { if (seq.Count > 4 || seq.Count < 3) { throw new ArgumentException("Bad sequence size: " + seq.Count); } digestedObjectType = DerEnumerated.GetInstance(seq[0]); int offset = 0; if (seq.Count == 4) { otherObjectTypeID = DerObjectIdentifier.GetInstance(seq[1]); offset++; } digestAlgorithm = AlgorithmIdentifier.GetInstance(seq[1 + offset]); objectDigest = DerBitString.GetInstance(seq[2 + offset]); }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static void AsString( string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string tab = indent + Tab; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerTaggedObject) { string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(tab, verbose, o.GetObject(), buf); } } else if (obj is BerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is DerUnknownTag) { string hex = Hex.ToHexString(((DerUnknownTag)obj).GetData()); buf.Append(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + hex + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated en = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal ext = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string tab = indent + Tab; if (ext.DirectReference != null) { buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine); } if (ext.IndirectReference != null) { buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine); } if (ext.DataValueDescriptor != null) { AsString(tab, verbose, ext.DataValueDescriptor, buf); } buf.Append(tab + "Encoding: " + ext.Encoding + NewLine); AsString(tab, verbose, ext.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
internal static void GetCertStatus( DateTime validDate, X509Crl crl, Object cert, CertStatus certStatus) { X509Crl bcCRL = null; try { bcCRL = new X509Crl(CertificateList.GetInstance((Asn1Sequence)Asn1Sequence.FromByteArray(crl.GetEncoded()))); } catch (Exception exception) { throw new Exception("Bouncy Castle X509Crl could not be created.", exception); } X509CrlEntry crl_entry = (X509CrlEntry)bcCRL.GetRevokedCertificate(GetSerialNumber(cert)); if (crl_entry == null) { return; } X509Name issuer = GetIssuerPrincipal(cert); if (issuer.Equivalent(crl_entry.GetCertificateIssuer(), true) || issuer.Equivalent(crl.IssuerDN, true)) { DerEnumerated reasonCode = null; if (crl_entry.HasExtensions) { try { reasonCode = DerEnumerated.GetInstance( GetExtensionValue(crl_entry, X509Extensions.ReasonCode)); } catch (Exception e) { new Exception( "Reason code CRL entry extension could not be decoded.", e); } } // for reason keyCompromise, caCompromise, aACompromise or // unspecified if (!(validDate.Ticks < crl_entry.RevocationDate.Ticks) || reasonCode == null || reasonCode.Value.TestBit(0) || reasonCode.Value.TestBit(1) || reasonCode.Value.TestBit(2) || reasonCode.Value.TestBit(8)) { if (reasonCode != null) // (i) or (j) (1) { certStatus.Status = reasonCode.Value.Sign; } else // (i) or (j) (2) { certStatus.Status = CrlReason.Unspecified; } certStatus.RevocationDate = new DateTimeObject(crl_entry.RevocationDate); } } }
public override string ToString() { StringBuilder buf = new StringBuilder(); string nl = Platform.NewLine; buf.Append(" userCertificate: ").Append(this.SerialNumber).Append(nl); buf.Append(" revocationDate: ").Append(this.RevocationDate).Append(nl); buf.Append(" certificateIssuer: ").Append(this.CertificateIssuer).Append(nl); X509Extensions extensions = c.Extensions; if (extensions != null) { IEnumerator e = extensions.ExtensionOids.GetEnumerator(); if (e.MoveNext()) { buf.Append(" crlEntryExtensions:").Append(nl); do { DerObjectIdentifier oid = (DerObjectIdentifier)e.Current; X509Extension ext = extensions.GetExtension(oid); if (ext.Value != null) { Asn1Object obj = Asn1Object.FromByteArray(ext.Value.GetOctets()); buf.Append(" critical(") .Append(ext.IsCritical) .Append(") "); try { if (oid.Equals(X509Extensions.ReasonCode)) { buf.Append(new CrlReason(DerEnumerated.GetInstance(obj))); } else if (oid.Equals(X509Extensions.CertificateIssuer)) { buf.Append("Certificate issuer: ").Append( GeneralNames.GetInstance((Asn1Sequence)obj)); } else { buf.Append(oid.Id); buf.Append(" value = ").Append(Asn1Dump.DumpAsString(obj)); } buf.Append(nl); } catch (Exception) { buf.Append(oid.Id); buf.Append(" value = ").Append("*****").Append(nl); } } else { buf.Append(nl); } }while (e.MoveNext()); } } return(buf.ToString()); }
internal static Asn1Object CreatePrimitiveDerObject(int tagNo, DefiniteLengthInputStream defIn, byte[][] tmpBuffers) { switch (tagNo) { case 1: return(DerBoolean.FromOctetString(GetBuffer(defIn, tmpBuffers))); case 10: return(DerEnumerated.FromOctetString(GetBuffer(defIn, tmpBuffers))); case 6: return(DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers))); default: { byte[] array = defIn.ToArray(); switch (tagNo) { case 3: return(DerBitString.FromAsn1Octets(array)); case 30: return(new DerBmpString(array)); case 24: return(new DerGeneralizedTime(array)); case 27: return(new DerGeneralString(array)); case 25: return(new DerGraphicString(array)); case 22: return(new DerIA5String(array)); case 2: return(new DerInteger(array)); case 5: return(DerNull.Instance); case 18: return(new DerNumericString(array)); case 4: return(new DerOctetString(array)); case 19: return(new DerPrintableString(array)); case 20: return(new DerT61String(array)); case 28: return(new DerUniversalString(array)); case 23: return(new DerUtcTime(array)); case 12: return(new DerUtf8String(array)); case 21: return(new DerVideotexString(array)); case 26: return(new DerVisibleString(array)); default: throw new IOException("unknown tag " + tagNo + " encountered"); } } } }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string text = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable item in (Asn1Sequence)obj) { if (item == null || item is Asn1Null) { buf.Append(text); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text, verbose, item.ToAsn1Object(), buf); } } } else if (obj is DerTaggedObject) { string text2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject derTaggedObject = (DerTaggedObject)obj; buf.Append(derTaggedObject.TagNo.ToString()); buf.Append(']'); if (!derTaggedObject.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (derTaggedObject.IsEmpty()) { buf.Append(text2); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(text2, verbose, derTaggedObject.GetObject(), buf); } } else if (obj is BerSet) { string text3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable item2 in (Asn1Set)obj) { if (item2 == null) { buf.Append(text3); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text3, verbose, item2.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string text4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable item3 in (Asn1Set)obj) { if (item3 == null) { buf.Append(text4); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text4, verbose, item3.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string text5 = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "BER Octet String[" + octets.Length + "] " + text5 + NewLine); } else if (obj is DerOctetString) { byte[] octets2 = ((Asn1OctetString)obj).GetOctets(); string text6 = verbose ? dumpBinaryDataAsString(indent, octets2) : ""; buf.Append(indent + "DER Octet String[" + octets2.Length + "] " + text6 + NewLine); } else if (obj is DerBitString) { DerBitString derBitString = (DerBitString)obj; byte[] bytes = derBitString.GetBytes(); string text7 = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String[" + bytes.Length + ", " + derBitString.PadBits + "] " + text7 + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerGraphicString) { buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine); } else if (obj is DerVideotexString) { buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated derEnumerated = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + derEnumerated.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal derExternal = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string text8 = indent + " "; if (derExternal.DirectReference != null) { buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + NewLine); } if (derExternal.IndirectReference != null) { buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + NewLine); } if (derExternal.DataValueDescriptor != null) { AsString(text8, verbose, derExternal.DataValueDescriptor, buf); } buf.Append(text8 + "Encoding: " + derExternal.Encoding + NewLine); AsString(text8, verbose, derExternal.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
public CrlReason(DerEnumerated reason) : base(reason.IntValueExact) { }
/** * This method provides that encoding and the parameters must be * exactly the same as in {@link #getEncodedPKCS7(byte[],Calendar)}. * * @param secondDigest the content digest * @param signingTime the signing time * @return the byte array representation of the authenticatedAttributes ready to be signed */ private DerSet GetAuthenticatedAttributeSet(byte[] secondDigest, DateTime signingTime, byte[] ocsp, ICollection <byte[]> crlBytes, CryptoStandard sigtype) { Asn1EncodableVector attribute = new Asn1EncodableVector(); Asn1EncodableVector v = new Asn1EncodableVector(); v.Add(new DerObjectIdentifier(SecurityIDs.ID_CONTENT_TYPE)); v.Add(new DerSet(new DerObjectIdentifier(SecurityIDs.ID_PKCS7_DATA))); attribute.Add(new DerSequence(v)); v = new Asn1EncodableVector(); v.Add(new DerObjectIdentifier(SecurityIDs.ID_SIGNING_TIME)); v.Add(new DerSet(new DerUtcTime(signingTime))); attribute.Add(new DerSequence(v)); v = new Asn1EncodableVector(); v.Add(new DerObjectIdentifier(SecurityIDs.ID_MESSAGE_DIGEST)); v.Add(new DerSet(new DerOctetString(secondDigest))); attribute.Add(new DerSequence(v)); bool haveCrl = false; if (crlBytes != null) { foreach (byte[] bCrl in crlBytes) { if (bCrl != null) { haveCrl = true; break; } } } if (ocsp != null || haveCrl) { v = new Asn1EncodableVector(); v.Add(new DerObjectIdentifier(SecurityIDs.ID_ADBE_REVOCATION)); Asn1EncodableVector revocationV = new Asn1EncodableVector(); if (haveCrl) { Asn1EncodableVector v2 = new Asn1EncodableVector(); foreach (byte[] bCrl in crlBytes) { if (bCrl == null) { continue; } Asn1InputStream t = new Asn1InputStream(bCrl); v2.Add(t.ReadObject()); } revocationV.Add(new DerTaggedObject(true, 0, new DerSequence(v2))); } if (ocsp != null) { DerOctetString doctet = new DerOctetString(ocsp); Asn1EncodableVector vo1 = new Asn1EncodableVector(); Asn1EncodableVector v2 = new Asn1EncodableVector(); v2.Add(OcspObjectIdentifiers.PkixOcspBasic); v2.Add(doctet); DerEnumerated den = new DerEnumerated(0); Asn1EncodableVector v3 = new Asn1EncodableVector(); v3.Add(den); v3.Add(new DerTaggedObject(true, 0, new DerSequence(v2))); vo1.Add(new DerSequence(v3)); revocationV.Add(new DerTaggedObject(true, 1, new DerSequence(vo1))); } v.Add(new DerSet(new DerSequence(revocationV))); attribute.Add(new DerSequence(v)); } if (sigtype == CryptoStandard.CADES) { v = new Asn1EncodableVector(); v.Add(new DerObjectIdentifier(SecurityIDs.ID_AA_SIGNING_CERTIFICATE_V2)); Asn1EncodableVector aaV2 = new Asn1EncodableVector(); AlgorithmIdentifier algoId = new AlgorithmIdentifier(new DerObjectIdentifier(digestAlgorithmOid), null); aaV2.Add(algoId); byte[] dig = DigestAlgorithms.Digest(GetHashAlgorithm(), signCert.GetEncoded()); aaV2.Add(new DerOctetString(dig)); v.Add(new DerSet(new DerSequence(new DerSequence(new DerSequence(aaV2))))); attribute.Add(new DerSequence(v)); } return(new DerSet(attribute)); }
internal static void GetCertStatus( DateTime validDate, X509Crl crl, Object cert, CertStatus certStatus) { X509Crl bcCRL = null; try { bcCRL = new X509Crl(CertificateList.GetInstance((Asn1Sequence)Asn1Sequence.FromByteArray(crl.GetEncoded()))); } catch (Exception exception) { throw new Exception("Bouncy Castle X509Crl could not be created.", exception); } X509CrlEntry crl_entry = (X509CrlEntry)bcCRL.GetRevokedCertificate(GetSerialNumber(cert)); if (crl_entry == null) { return; } X509Name issuer = GetIssuerPrincipal(cert); if (!issuer.Equivalent(crl_entry.GetCertificateIssuer(), true) && !issuer.Equivalent(crl.IssuerDN, true)) { return; } int reasonCodeValue = CrlReason.Unspecified; if (crl_entry.HasExtensions) { try { Asn1Object extValue = GetExtensionValue(crl_entry, X509Extensions.ReasonCode); DerEnumerated reasonCode = DerEnumerated.GetInstance(extValue); if (null != reasonCode) { reasonCodeValue = reasonCode.IntValueExact; } } catch (Exception e) { throw new Exception("Reason code CRL entry extension could not be decoded.", e); } } DateTime revocationDate = crl_entry.RevocationDate; if (validDate.Ticks < revocationDate.Ticks) { switch (reasonCodeValue) { case CrlReason.Unspecified: case CrlReason.KeyCompromise: case CrlReason.CACompromise: case CrlReason.AACompromise: break; default: return; } } // (i) or (j) certStatus.Status = reasonCodeValue; certStatus.RevocationDate = new DateTimeObject(revocationDate); }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string text = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator()) { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable == null || asn1Encodable is Asn1Null) { buf.Append(text); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text, verbose, asn1Encodable.ToAsn1Object(), buf); } } return; } } if (obj is DerTaggedObject) { string text2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject derTaggedObject = (DerTaggedObject)obj; buf.Append(derTaggedObject.TagNo.ToString()); buf.Append(']'); if (!derTaggedObject.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(Asn1Dump.NewLine); if (derTaggedObject.IsEmpty()) { buf.Append(text2); buf.Append("EMPTY"); buf.Append(Asn1Dump.NewLine); return; } Asn1Dump.AsString(text2, verbose, derTaggedObject.GetObject(), buf); return; } else { if (obj is BerSet) { string text3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator()) { while (enumerator2.MoveNext()) { Asn1Encodable asn1Encodable2 = (Asn1Encodable)enumerator2.Current; if (asn1Encodable2 == null) { buf.Append(text3); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text3, verbose, asn1Encodable2.ToAsn1Object(), buf); } } return; } } if (obj is DerSet) { string text4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator()) { while (enumerator3.MoveNext()) { Asn1Encodable asn1Encodable3 = (Asn1Encodable)enumerator3.Current; if (asn1Encodable3 == null) { buf.Append(text4); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text4, verbose, asn1Encodable3.ToAsn1Object(), buf); } } return; } } if (obj is DerObjectIdentifier) { buf.Append(string.Concat(new string[] { indent, "ObjectIdentifier(", ((DerObjectIdentifier)obj).Id, ")", Asn1Dump.NewLine })); return; } if (obj is DerBoolean) { buf.Append(string.Concat(new object[] { indent, "Boolean(", ((DerBoolean)obj).IsTrue, ")", Asn1Dump.NewLine })); return; } if (obj is DerInteger) { buf.Append(string.Concat(new object[] { indent, "Integer(", ((DerInteger)obj).Value, ")", Asn1Dump.NewLine })); return; } if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string text5 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets) : ""; buf.Append(string.Concat(new object[] { indent, "BER Octet String[", octets.Length, "] ", text5, Asn1Dump.NewLine })); return; } if (obj is DerOctetString) { byte[] octets2 = ((Asn1OctetString)obj).GetOctets(); string text6 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets2) : ""; buf.Append(string.Concat(new object[] { indent, "DER Octet String[", octets2.Length, "] ", text6, Asn1Dump.NewLine })); return; } if (obj is DerBitString) { DerBitString derBitString = (DerBitString)obj; byte[] bytes = derBitString.GetBytes(); string text7 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(string.Concat(new object[] { indent, "DER Bit String[", bytes.Length, ", ", derBitString.PadBits, "] ", text7, Asn1Dump.NewLine })); return; } if (obj is DerIA5String) { buf.Append(string.Concat(new string[] { indent, "IA5String(", ((DerIA5String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerUtf8String) { buf.Append(string.Concat(new string[] { indent, "UTF8String(", ((DerUtf8String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerPrintableString) { buf.Append(string.Concat(new string[] { indent, "PrintableString(", ((DerPrintableString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerVisibleString) { buf.Append(string.Concat(new string[] { indent, "VisibleString(", ((DerVisibleString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerBmpString) { buf.Append(string.Concat(new string[] { indent, "BMPString(", ((DerBmpString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerT61String) { buf.Append(string.Concat(new string[] { indent, "T61String(", ((DerT61String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerUtcTime) { buf.Append(string.Concat(new string[] { indent, "UTCTime(", ((DerUtcTime)obj).TimeString, ") ", Asn1Dump.NewLine })); return; } if (obj is DerGeneralizedTime) { buf.Append(string.Concat(new string[] { indent, "GeneralizedTime(", ((DerGeneralizedTime)obj).GetTime(), ") ", Asn1Dump.NewLine })); return; } if (obj is BerApplicationSpecific) { buf.Append(Asn1Dump.outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); return; } if (obj is DerApplicationSpecific) { buf.Append(Asn1Dump.outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); return; } if (obj is DerEnumerated) { DerEnumerated derEnumerated = (DerEnumerated)obj; buf.Append(string.Concat(new object[] { indent, "DER Enumerated(", derEnumerated.Value, ")", Asn1Dump.NewLine })); return; } if (obj is DerExternal) { DerExternal derExternal = (DerExternal)obj; buf.Append(indent + "External " + Asn1Dump.NewLine); string text8 = indent + " "; if (derExternal.DirectReference != null) { buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + Asn1Dump.NewLine); } if (derExternal.IndirectReference != null) { buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + Asn1Dump.NewLine); } if (derExternal.DataValueDescriptor != null) { Asn1Dump.AsString(text8, verbose, derExternal.DataValueDescriptor, buf); } buf.Append(string.Concat(new object[] { text8, "Encoding: ", derExternal.Encoding, Asn1Dump.NewLine })); Asn1Dump.AsString(text8, verbose, derExternal.ExternalContent, buf); return; } buf.Append(indent + obj.ToString() + Asn1Dump.NewLine); } }
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); string newLine = Platform.NewLine; stringBuilder.Append(" userCertificate: ").Append(this.SerialNumber).Append(newLine); stringBuilder.Append(" revocationDate: ").Append(this.RevocationDate).Append(newLine); stringBuilder.Append(" certificateIssuer: ").Append(this.GetCertificateIssuer()).Append(newLine); X509Extensions extensions = this.c.Extensions; if (extensions != null) { IEnumerator enumerator = extensions.ExtensionOids.GetEnumerator(); if (enumerator.MoveNext()) { stringBuilder.Append(" crlEntryExtensions:").Append(newLine); while (true) { DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)enumerator.Current; X509Extension extension = extensions.GetExtension(derObjectIdentifier); if (extension.Value != null) { Asn1Object asn1Object = Asn1Object.FromByteArray(extension.Value.GetOctets()); stringBuilder.Append(" critical(").Append(extension.IsCritical).Append(") "); try { if (derObjectIdentifier.Equals(X509Extensions.ReasonCode)) { stringBuilder.Append(new CrlReason(DerEnumerated.GetInstance(asn1Object))); } else if (derObjectIdentifier.Equals(X509Extensions.CertificateIssuer)) { stringBuilder.Append("Certificate issuer: ").Append(GeneralNames.GetInstance((Asn1Sequence)asn1Object)); } else { stringBuilder.Append(derObjectIdentifier.Id); stringBuilder.Append(" value = ").Append(Asn1Dump.DumpAsString(asn1Object)); } stringBuilder.Append(newLine); goto IL_1B0; } catch (Exception) { stringBuilder.Append(derObjectIdentifier.Id); stringBuilder.Append(" value = ").Append("*****").Append(newLine); goto IL_1B0; } goto IL_1A8; } goto IL_1A8; IL_1B0: if (!enumerator.MoveNext()) { break; } continue; IL_1A8: stringBuilder.Append(newLine); goto IL_1B0; } } } return(stringBuilder.ToString()); }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { switch (obj) { case (Asn1Sequence _): { string str = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator.Current; if ((current == null) || (current is Asn1Null)) { buf.Append(str); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator is IDisposable disposable) { IDisposable disposable; disposable.Dispose(); } } break; } default: if (obj is DerTaggedObject) { string str2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject obj2 = (DerTaggedObject)obj; buf.Append(obj2.TagNo.ToString()); buf.Append(']'); if (!obj2.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (obj2.IsEmpty()) { buf.Append(str2); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(str2, verbose, obj2.GetObject(), buf); } } else { switch (obj) { case (BerSet _): { string str3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator(); try { while (enumerator2.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator2.Current; if (current == null) { buf.Append(str3); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str3, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator2 is IDisposable disposable2) { IDisposable disposable2; disposable2.Dispose(); } } break; } default: if (obj is DerSet) { string str4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator(); try { while (enumerator3.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator3.Current; if (current == null) { buf.Append(str4); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str4, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator3 is IDisposable disposable3) { IDisposable disposable3; disposable3.Dispose(); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(string.Concat(new object[] { indent, "Boolean(", ((DerBoolean)obj).IsTrue, ")", NewLine })); } else if (obj is DerInteger) { buf.Append(string.Concat(new object[] { indent, "Integer(", ((DerInteger)obj).Value, ")", NewLine })); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string str5 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets); buf.Append(string.Concat(new object[] { indent, "BER Octet String[", octets.Length, "] ", str5, NewLine })); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string str6 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets); buf.Append(string.Concat(new object[] { indent, "DER Octet String[", octets.Length, "] ", str6, NewLine })); } else if (obj is DerBitString) { DerBitString str7 = (DerBitString)obj; byte[] bytes = str7.GetBytes(); string str8 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, bytes); buf.Append(string.Concat(new object[] { indent, "DER Bit String[", bytes.Length, ", ", str7.PadBits, "] ", str8, NewLine })); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerGraphicString) { buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine); } else if (obj is DerVideotexString) { buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated enumerated = (DerEnumerated)obj; buf.Append(string.Concat(new object[] { indent, "DER Enumerated(", enumerated.Value, ")", NewLine })); } else if (obj is DerExternal) { DerExternal external = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string str9 = indent + " "; if (external.DirectReference != null) { buf.Append(str9 + "Direct Reference: " + external.DirectReference.Id + NewLine); } if (external.IndirectReference != null) { buf.Append(str9 + "Indirect Reference: " + external.IndirectReference.ToString() + NewLine); } if (external.DataValueDescriptor != null) { AsString(str9, verbose, external.DataValueDescriptor, buf); } buf.Append(string.Concat(new object[] { str9, "Encoding: ", external.Encoding, NewLine })); AsString(str9, verbose, external.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } break; } } break; } }