void m_initialize(Byte[] rawData) { Asn1Reader asn = new Asn1Reader(rawData); if (asn.Tag != 48) { throw new Asn1InvalidTagException(asn.Offset); } asn.MoveNext(); SerialNumber = Asn1Utils.DecodeInteger(asn.GetTagRawData(), true); asn.MoveNext(); if (asn.Tag != (Byte)Asn1Type.UTCTime && asn.Tag != (Byte)Asn1Type.Generalizedtime) { throw new Asn1InvalidTagException(asn.Offset); } if (asn.Tag == (Byte)Asn1Type.UTCTime) { RevocationDate = Asn1Utils.DecodeUTCTime(asn.GetTagRawData()); } if (asn.Tag == (Byte)Asn1Type.Generalizedtime) { RevocationDate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData()); } if (asn.MoveNext()) { var extensions = new X509ExtensionCollection(); extensions.Decode(asn.GetTagRawData()); X509Extension crlReason = extensions[X509CertExtensions.X509CRLReasonCode]; if (crlReason != null) { ReasonCode = crlReason.RawData[2]; } } RawData = rawData; }
void m_initialize(Byte[] rawData) { Asn1Reader asn = new Asn1Reader(rawData); if (asn.Tag != 48) { throw new InvalidDataException(); } asn.MoveNext(); if (asn.Tag != (Byte)Asn1Type.INTEGER) { throw new InvalidDataException(); } SerialNumber = Asn1Utils.DecodeInteger(asn.GetTagRawData(), true); asn.MoveNext(); if (asn.Tag != (Byte)Asn1Type.UTCTime && asn.Tag != (Byte)Asn1Type.Generalizedtime) { throw new InvalidDataException(); } if (asn.Tag == (Byte)Asn1Type.UTCTime) { RevocationDate = Asn1Utils.DecodeUTCTime(asn.GetTagRawData()); } if (asn.Tag == (Byte)Asn1Type.Generalizedtime) { RevocationDate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData()); } if (asn.MoveNext()) { foreach (X509Extension item in Crypt32Managed.DecodeX509Extensions(asn.GetTagRawData()).Cast <X509Extension>().Where(item => item.Oid.Value == "2.5.29.21")) { ReasonCode = item.RawData[2]; } } RawData = rawData; }
void m_decode(Byte[] rawData) { try { Type = X509CrlType.BaseCrl; var signedInfo = new SignedContentBlob(rawData, ContentBlobType.SignedBlob); // signature and alg signature = signedInfo.Signature.Value; sigUnused = signedInfo.Signature.UnusedBits; SignatureAlgorithm = signedInfo.SignatureAlgorithm.AlgorithmId; // tbs Asn1Reader asn = new Asn1Reader(signedInfo.ToBeSignedData); if (!asn.MoveNext()) { throw new Asn1InvalidTagException(); } // version if (asn.Tag == (Byte)Asn1Type.INTEGER) { Version = (Int32)Asn1Utils.DecodeInteger(asn.GetTagRawData()) + 1; asn.MoveNextCurrentLevel(); } else { Version = 1; } // hash algorithm var h = new AlgorithmIdentifier(asn.GetTagRawData()); if (h.AlgorithmId.Value != SignatureAlgorithm.Value) { throw new CryptographicException("Algorithm mismatch."); } if (!asn.MoveNextCurrentLevel()) { throw new Asn1InvalidTagException(); } // issuer IssuerName = new X500DistinguishedName(asn.GetTagRawData()); // NextUpdate, RevokedCerts and Extensions are optional. Ref: RFC5280, p.118 if (!asn.MoveNextCurrentLevel()) { throw new Asn1InvalidTagException(); } switch (asn.Tag) { case (Byte)Asn1Type.UTCTime: ThisUpdate = Asn1Utils.DecodeUTCTime(asn.GetTagRawData()); break; case (Byte)Asn1Type.Generalizedtime: ThisUpdate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData()); break; default: throw new Asn1InvalidTagException(); } if (!asn.MoveNextCurrentLevel()) { return; } switch (asn.Tag) { case (Byte)Asn1Type.UTCTime: case (Byte)Asn1Type.Generalizedtime: switch (asn.Tag) { case (Byte)Asn1Type.UTCTime: NextUpdate = Asn1Utils.DecodeUTCTime(asn.GetTagRawData()); break; case (Byte)Asn1Type.Generalizedtime: NextUpdate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData()); break; default: throw new Asn1InvalidTagException(); } if (!asn.MoveNextCurrentLevel()) { return; } if (asn.Tag == 48) { getRevCerts(asn); if (!asn.MoveNextCurrentLevel()) { return; } getExts(asn); } else { getExts(asn); } break; case 48: if (asn.Tag == 48) { getRevCerts(asn); if (!asn.MoveNextCurrentLevel()) { return; } getExts(asn); } else { getExts(asn); } break; default: getExts(asn); break; } } catch (Exception e) { throw new CryptographicException("Cannot find the requested object.", e); } }