Beispiel #1
0
 public SignerInformationStore GetSignerInfos()
 {
     if (_signerInfoStore == null)
     {
         PopulateCertCrlSets();
         IList       list       = Platform.CreateArrayList();
         IDictionary dictionary = Platform.CreateHashtable();
         foreach (object key in _digests.Keys)
         {
             dictionary[key] = DigestUtilities.DoFinal((IDigest)_digests[key]);
         }
         try
         {
             Asn1SetParser    signerInfos = _signedData.GetSignerInfos();
             IAsn1Convertible asn1Convertible;
             while ((asn1Convertible = signerInfos.ReadObject()) != null)
             {
                 SignerInfo instance      = SignerInfo.GetInstance(asn1Convertible.ToAsn1Object());
                 string     digestAlgName = Helper.GetDigestAlgName(instance.DigestAlgorithm.Algorithm.Id);
                 byte[]     digest        = (byte[])dictionary[digestAlgName];
                 list.Add(new SignerInformation(instance, _signedContentType, null, new BaseDigestCalculator(digest)));
             }
         }
         catch (IOException ex)
         {
             throw new CmsException("io exception: " + ex.Message, ex);
         }
         _signerInfoStore = new SignerInformationStore(list);
     }
     return(_signerInfoStore);
 }
Beispiel #2
0
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (signerInfoStore == null)
            {
                IList   signerInfos = Platform.CreateArrayList();
                Asn1Set s           = signedData.SignerInfos;

                foreach (object obj in s)
                {
                    SignerInfo          info        = SignerInfo.GetInstance(obj);
                    DerObjectIdentifier contentType = signedData.EncapContentInfo.ContentType;

                    if (hashes == null)
                    {
                        signerInfos.Add(new SignerInformation(info, contentType, signedContent, null));
                    }
                    else
                    {
                        byte[] hash = (byte[])hashes[info.DigestAlgorithm.Algorithm.Id];

                        signerInfos.Add(new SignerInformation(info, contentType, null, new BaseDigestCalculator(hash)));
                    }
                }

                signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(signerInfoStore);
        }
 private bool CheckForVersion3(global::System.Collections.IList signerInfos)
 {
     global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)signerInfos).GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             SignerInformation signerInformation = (SignerInformation)enumerator.get_Current();
             SignerInfo        instance          = SignerInfo.GetInstance(signerInformation.ToSignerInfo());
             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);
 }
Beispiel #4
0
 private bool CheckForVersion3(IList signerInfos)
 {
     foreach (SignerInformation signerInfo in signerInfos)
     {
         SignerInfo instance = SignerInfo.GetInstance(signerInfo.ToSignerInfo());
         if (instance.Version.Value.IntValue == 3)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
 private bool CheckForVersion3(Asn1Set signerInfs)
 {
     foreach (object signerInf in signerInfs)
     {
         SignerInfo instance = SignerInfo.GetInstance(signerInf);
         if (instance.Version.Value.IntValue == 3)
         {
             return(true);
         }
     }
     return(false);
 }
        private bool CheckForVersion3(
            IList signerInfos)
        {
            foreach (SignerInformation si in signerInfos)
            {
                SignerInfo s = SignerInfo.GetInstance(si.ToSignerInfo());

                if (s.Version.IntValueExact == 3)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
 public SignerInformationStore GetSignerInfos()
 {
     //IL_00e9: Expected O, but got Unknown
     if (_signerInfoStore == null)
     {
         PopulateCertCrlSets();
         global::System.Collections.IList list = Platform.CreateArrayList();
         IDictionary val = Platform.CreateHashtable();
         {
             global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)_digests.get_Keys()).GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     object current = enumerator.get_Current();
                     val.set_Item(current, (object)DigestUtilities.DoFinal((IDigest)_digests.get_Item(current)));
                 }
             }
             finally
             {
                 global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
         try
         {
             Asn1SetParser    signerInfos = _signedData.GetSignerInfos();
             IAsn1Convertible asn1Convertible;
             while ((asn1Convertible = signerInfos.ReadObject()) != null)
             {
                 SignerInfo instance      = SignerInfo.GetInstance(asn1Convertible.ToAsn1Object());
                 string     digestAlgName = Helper.GetDigestAlgName(instance.DigestAlgorithm.Algorithm.Id);
                 byte[]     digest        = (byte[])val.get_Item((object)digestAlgName);
                 list.Add((object)new SignerInformation(instance, _signedContentType, null, new BaseDigestCalculator(digest)));
             }
         }
         catch (IOException val2)
         {
             IOException val3 = val2;
             throw new CmsException("io exception: " + ((global::System.Exception)(object) val3).get_Message(), (global::System.Exception)(object) val3);
         }
         _signerInfoStore = new SignerInformationStore((global::System.Collections.ICollection)list);
     }
     return(_signerInfoStore);
 }
Beispiel #8
0
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (signerInfoStore == null)
            {
                IList   signerInfos = new ArrayList();
                Asn1Set s           = signedData.SignerInfos;

                foreach (object obj in s)
                {
                    signerInfos.Add(new SignerInformation(SignerInfo.GetInstance(obj),
                                                          signedData.EncapContentInfo.ContentType, signedContent, null));
                }

                signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(signerInfoStore);
        }
Beispiel #9
0
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         * @throws CmsException
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (_signerInfoStore == null)
            {
                IList       signerInfos = new ArrayList();
                IDictionary hashes      = new Hashtable();

                foreach (object digestKey in _digests.Keys)
                {
                    hashes[digestKey] = DigestUtilities.DoFinal(
                        (IDigest)_digests[digestKey]);
                }

                try
                {
                    Asn1SetParser    s = _signedData.GetSignerInfos();
                    IAsn1Convertible o;

                    while ((o = s.ReadObject()) != null)
                    {
                        SignerInfo info       = SignerInfo.GetInstance(o.ToAsn1Object());
                        string     digestName = Helper.GetDigestAlgName(
                            info.DigestAlgorithm.ObjectID.Id);

                        byte[] hash = (byte[])hashes[digestName];

                        signerInfos.Add(
                            new SignerInformation(
                                info,
                                new DerObjectIdentifier(_signedContent.ContentType),
                                null,
                                hash));
                    }
                }
                catch (IOException e)
                {
                    throw new CmsException("io exception: " + e.Message, e);
                }

                _signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(_signerInfoStore);
        }
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         * @throws CmsException
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (_signerInfoStore == null)
            {
                PopulateCertCrlSets();

                IList       signerInfos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
                IDictionary hashes      = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();

                foreach (object digestKey in _digests.Keys)
                {
                    hashes[digestKey] = DigestUtilities.DoFinal(
                        (IDigest)_digests[digestKey]);
                }

                try
                {
                    Asn1SetParser    s = _signedData.GetSignerInfos();
                    IAsn1Convertible o;

                    while ((o = s.ReadObject()) != null)
                    {
                        SignerInfo info       = SignerInfo.GetInstance(o.ToAsn1Object());
                        string     digestName = Helper.GetDigestAlgName(
                            info.DigestAlgorithm.Algorithm.Id);

                        byte[] hash = (byte[])hashes[digestName];

                        signerInfos.Add(new SignerInformation(info, _signedContentType, null, new BaseDigestCalculator(hash)));
                    }
                }
                catch (IOException e)
                {
                    throw new CmsException("io exception: " + e.Message, e);
                }

                _signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(_signerInfoStore);
        }
Beispiel #11
0
 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);
 }
Beispiel #12
0
 public SignerInformationStore GetSignerInfos()
 {
     if (signerInfoStore == null)
     {
         IList   list        = Platform.CreateArrayList();
         Asn1Set signerInfos = signedData.SignerInfos;
         foreach (object item in signerInfos)
         {
             SignerInfo          instance    = SignerInfo.GetInstance(item);
             DerObjectIdentifier contentType = signedData.EncapContentInfo.ContentType;
             if (hashes == null)
             {
                 list.Add(new SignerInformation(instance, contentType, signedContent, null));
             }
             else
             {
                 byte[] digest = (byte[])hashes[instance.DigestAlgorithm.Algorithm.Id];
                 list.Add(new SignerInformation(instance, contentType, null, new BaseDigestCalculator(digest)));
             }
         }
         signerInfoStore = new SignerInformationStore(list);
     }
     return(signerInfoStore);
 }
Beispiel #13
0
        /**
         * Return a SignerInformationStore containing the counter signatures attached to this
         * signer. If no counter signatures are present an empty store is returned.
         */
        public SignerInformationStore GetCounterSignatures()
        {
            // TODO There are several checks implied by the RFC3852 comments that are missing

            /*
             * The countersignature attribute MUST be an unsigned attribute; it MUST
             * NOT be a signed attribute, an authenticated attribute, an
             * unauthenticated attribute, or an unprotected attribute.
             */
            Asn1.Cms.AttributeTable unsignedAttributeTable = UnsignedAttributes;
            if (unsignedAttributeTable == null)
            {
                return(new SignerInformationStore(Platform.CreateArrayList(0)));
            }

            IList counterSignatures = Platform.CreateArrayList();

            /*
             * The UnsignedAttributes syntax is defined as a SET OF Attributes.  The
             * UnsignedAttributes in a signerInfo may include multiple instances of
             * the countersignature attribute.
             */
            Asn1EncodableVector allCSAttrs = unsignedAttributeTable.GetAll(CmsAttributes.CounterSignature);

            foreach (Asn1.Cms.Attribute counterSignatureAttribute in allCSAttrs)
            {
                /*
                 * A countersignature attribute can have multiple attribute values.  The
                 * syntax is defined as a SET OF AttributeValue, and there MUST be one
                 * or more instances of AttributeValue present.
                 */
                Asn1Set values = counterSignatureAttribute.AttrValues;
                if (values.Count < 1)
                {
                    // TODO Throw an appropriate exception?
                }

                foreach (Asn1Encodable asn1Obj in values)
                {
                    /*
                     * Countersignature values have the same meaning as SignerInfo values
                     * for ordinary signatures, except that:
                     *
                     * 1. The signedAttributes field MUST NOT contain a content-type
                     *    attribute; there is no content type for countersignatures.
                     *
                     * 2. The signedAttributes field MUST contain a message-digest
                     *    attribute if it contains any other attributes.
                     *
                     * 3. The input to the message-digesting process is the contents
                     *    octets of the DER encoding of the signatureValue field of the
                     *    SignerInfo value with which the attribute is associated.
                     */
                    SignerInfo si = SignerInfo.GetInstance(asn1Obj.ToAsn1Object());

                    string digestName = CmsSignedHelper.Instance.GetDigestAlgName(si.DigestAlgorithm.ObjectID.Id);

                    counterSignatures.Add(new SignerInformation(si, null, null, new CounterSignatureDigestCalculator(digestName, GetSignature())));
                }
            }

            return(new SignerInformationStore(counterSignatures));
        }