private void AddCertsFromSet(global::System.Collections.IList certs, Asn1Set certSet) { X509CertificateParser x509CertificateParser = new X509CertificateParser(); global::System.Collections.IEnumerator enumerator = certSet.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current(); try { Asn1Object asn1Object = asn1Encodable.ToAsn1Object(); if (asn1Object is Asn1Sequence) { certs.Add((object)x509CertificateParser.ReadCertificate(asn1Object.GetEncoded())); } } catch (global::System.Exception e) { throw new CmsException("can't re-encode certificate!", e); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } }
private void AddCrlsFromSet(global::System.Collections.IList crls, Asn1Set crlSet) { X509CrlParser x509CrlParser = new X509CrlParser(); global::System.Collections.IEnumerator enumerator = crlSet.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current(); try { crls.Add((object)x509CrlParser.ReadCrl(asn1Encodable.GetEncoded())); } catch (global::System.Exception e) { throw new CmsException("can't re-encode CRL!", e); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } }
protected override bool Asn1Equals(Asn1Object asn1Object) { Asn1Set asn1Set = asn1Object as Asn1Set; if (asn1Set == null) { return(false); } if (Count != asn1Set.Count) { return(false); } IEnumerator enumerator = GetEnumerator(); IEnumerator enumerator2 = asn1Set.GetEnumerator(); while (enumerator.MoveNext() && enumerator2.MoveNext()) { Asn1Object asn1Object2 = GetCurrent(enumerator).ToAsn1Object(); Asn1Object obj = GetCurrent(enumerator2).ToAsn1Object(); if (!asn1Object2.Equals(obj)) { return(false); } } return(true); }
private bool CheckForVersion3(Asn1Set signerInfs) { global::System.Collections.IEnumerator enumerator = signerInfs.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.get_Current(); SignerInfo instance = SignerInfo.GetInstance(current); if (instance.Version.Value.IntValue == 3) { return(true); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } return(false); }
public virtual IX509Store GetCrls() { Asn1Set certificates = originatorInfo.Certificates; if (certificates != null) { global::System.Collections.IList list = Platform.CreateArrayList(certificates.Count); { global::System.Collections.IEnumerator enumerator = certificates.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current(); Asn1Object asn1Object = asn1Encodable.ToAsn1Object(); if (asn1Object is Asn1Sequence) { list.Add((object)new X509Crl(CertificateList.GetInstance(asn1Object))); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } return(X509StoreFactory.Create("CRL/Collection", new X509CollectionStoreParameters((global::System.Collections.ICollection)list))); } return(X509StoreFactory.Create("CRL/Collection", new X509CollectionStoreParameters((global::System.Collections.ICollection)Platform.CreateArrayList()))); }
public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipientInfos, Asn1Set unprotectedAttrs) { if (originatorInfo != null || unprotectedAttrs != null) { return(2); } global::System.Collections.IEnumerator enumerator = recipientInfos.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.get_Current(); RecipientInfo instance = RecipientInfo.GetInstance(current); if (instance.Version.Value.IntValue != 0) { return(2); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } return(0); }
public SignerInformationStore GetCounterSignatures() { Org.BouncyCastle.Asn1.Cms.AttributeTable unsignedAttributes = UnsignedAttributes; if (unsignedAttributes == null) { return(new SignerInformationStore((global::System.Collections.ICollection)Platform.CreateArrayList(0))); } global::System.Collections.IList list = Platform.CreateArrayList(); Asn1EncodableVector all = unsignedAttributes.GetAll(CmsAttributes.CounterSignature); global::System.Collections.IEnumerator enumerator = all.GetEnumerator(); try { while (enumerator.MoveNext()) { Attribute attribute = (Attribute)enumerator.get_Current(); Asn1Set attrValues = attribute.AttrValues; _ = attrValues.Count; _ = 1; { global::System.Collections.IEnumerator enumerator2 = attrValues.GetEnumerator(); try { while (enumerator2.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator2.get_Current(); Org.BouncyCastle.Asn1.Cms.SignerInfo instance = Org.BouncyCastle.Asn1.Cms.SignerInfo.GetInstance(asn1Encodable.ToAsn1Object()); string digestAlgName = CmsSignedHelper.Instance.GetDigestAlgName(instance.DigestAlgorithm.Algorithm.Id); list.Add((object)new SignerInformation(instance, null, null, new CounterSignatureDigestCalculator(digestAlgName, GetSignature()))); } } finally { global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } return(new SignerInformationStore((global::System.Collections.ICollection)list)); }
internal IX509Store CreateAttributeStore(string type, Asn1Set certSet) { //IL_00a4: Expected O, but got Unknown global::System.Collections.IList list = Platform.CreateArrayList(); if (certSet != null) { { global::System.Collections.IEnumerator enumerator = certSet.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current(); try { Asn1Object asn1Object = asn1Encodable.ToAsn1Object(); if (asn1Object is Asn1TaggedObject) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)asn1Object; if (asn1TaggedObject.TagNo == 2) { list.Add((object)new X509V2AttributeCertificate(Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: false).GetEncoded())); } } } catch (global::System.Exception e) { throw new CmsException("can't re-encode attribute certificate!", e); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } } try { return(X509StoreFactory.Create("AttributeCertificate/" + type, new X509CollectionStoreParameters((global::System.Collections.ICollection)list))); } catch (ArgumentException val) { ArgumentException e2 = val; throw new CmsException("can't setup the X509Store", (global::System.Exception)(object) e2); } }
private byte[] GetEContent() { SignerInfo signerInfo = GetSignerInfo(); Asn1Set signedAttributesSet = signerInfo.AuthenticatedAttributes; ContentInfo contentInfo = _signedData.EncapContentInfo; byte[] contentBytes = ((DerOctetString)contentInfo.Content).GetOctets(); if (signedAttributesSet.Count == 0) // signed attributes absent, return content to be signed { return(contentBytes); } else // Signed attributes present (i.e. a structure containing a hash of the content), return that structure to be signed... // This option is taken by ICAO passports. { byte[] attributeBytes = signedAttributesSet.GetDerEncoded(); string digAlg = signerInfo.DigestAlgorithm.ObjectID.Id; // We'd better check that the content actually digests to the hash value contained! ;) IEnumerator attributes = signedAttributesSet.GetEnumerator(); byte[] storedDigestedContent = null; while (attributes.MoveNext()) { Org.BouncyCastle.Asn1.Cms.Attribute attribute = new Org.BouncyCastle.Asn1.Cms.Attribute((Asn1Sequence)attributes.Current); DerObjectIdentifier attrType = attribute.AttrType; if (attrType.Equals(RFC_3369_MESSAGE_DIGEST_OID)) { Asn1Set attrValueSet = attribute.AttrValues; if (attrValueSet.Count != 1) { Console.WriteLine("WARNING: expected only one attribute value in signedAttribute message diegest in eContent!"); } storedDigestedContent = ((DerOctetString)attrValueSet[0]).GetOctets(); } } if (storedDigestedContent == null) { Console.WriteLine("WARNING: error extracting signedAttribute message digest in eContent!"); } byte[] computedDigestedContent = SHA256.Create().ComputeHash(contentBytes); if (!Compare(storedDigestedContent, computedDigestedContent)) { Console.WriteLine("WARNING: error checking signedAttribute message digest in eContent!"); } return(attributeBytes); } }
public SignerInformationStore GetSignerInfos() { if (signerInfoStore == null) { global::System.Collections.IList list = Platform.CreateArrayList(); Asn1Set signerInfos = signedData.SignerInfos; { global::System.Collections.IEnumerator enumerator = signerInfos.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.get_Current(); SignerInfo instance = SignerInfo.GetInstance(current); DerObjectIdentifier contentType = signedData.EncapContentInfo.ContentType; if (hashes == null) { list.Add((object)new SignerInformation(instance, contentType, signedContent, null)); continue; } byte[] digest = (byte[])hashes.get_Item((object)instance.DigestAlgorithm.Algorithm.Id); list.Add((object)new SignerInformation(instance, contentType, null, new BaseDigestCalculator(digest))); } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } signerInfoStore = new SignerInformationStore((global::System.Collections.ICollection)list); } return(signerInfoStore); }
private DerInteger CalculateVersion(DerObjectIdentifier contentOid, Asn1Set certs, Asn1Set crls, Asn1Set signerInfs) { bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; if (certs != null) { { global::System.Collections.IEnumerator enumerator = certs.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.get_Current(); if (current is Asn1TaggedObject) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)current; if (asn1TaggedObject.TagNo == 1) { flag3 = true; } else if (asn1TaggedObject.TagNo == 2) { flag4 = true; } else if (asn1TaggedObject.TagNo == 3) { flag = true; break; } } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } } if (flag) { return(Version5); } if (crls != null) { { global::System.Collections.IEnumerator enumerator = crls.GetEnumerator(); try { while (enumerator.MoveNext()) { object current2 = enumerator.get_Current(); if (current2 is Asn1TaggedObject) { flag2 = true; break; } } } finally { global::System.IDisposable disposable2 = enumerator as global::System.IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } } if (flag2) { return(Version5); } if (flag4) { return(Version4); } if (flag3 || !CmsObjectIdentifiers.Data.Equals(contentOid) || CheckForVersion3(signerInfs)) { return(Version3); } return(Version1); }