예제 #1
0
            public RecipientInfo(ASN1 data)
            {
                if (data.Tag != 48)
                {
                    throw new ArgumentException("Invalid RecipientInfo");
                }
                ASN1 aSN = data[0];

                if (aSN.Tag != 2)
                {
                    throw new ArgumentException("missing Version");
                }
                _version = aSN.Value[0];
                ASN1 aSN2 = data[1];

                if (aSN2.Tag == 128 && _version == 3)
                {
                    _ski = aSN2.Value;
                }
                else
                {
                    _issuer = X501.ToString(aSN2[0]);
                    _serial = aSN2[1].Value;
                }
                ASN1 aSN3 = data[2];

                _oid = ASN1Convert.ToOid(aSN3[0]);
                ASN1 aSN4 = data[3];

                _key = aSN4.Value;
            }
예제 #2
0
            public RecipientInfo(ASN1 data)
            {
                if (data.Tag != 48)
                {
                    throw new ArgumentException("Invalid RecipientInfo");
                }
                ASN1 asn = data[0];

                if (asn.Tag != 2)
                {
                    throw new ArgumentException("missing Version");
                }
                this._version = (int)asn.Value[0];
                ASN1 asn2 = data[1];

                if (asn2.Tag == 128 && this._version == 3)
                {
                    this._ski = asn2.Value;
                }
                else
                {
                    this._issuer = X501.ToString(asn2[0]);
                    this._serial = asn2[1].Value;
                }
                ASN1 asn3 = data[2];

                this._oid = ASN1Convert.ToOid(asn3[0]);
                ASN1 asn4 = data[3];

                this._key = asn4.Value;
            }
예제 #3
0
            public EnvelopedData(ASN1 asn1) : this()
            {
                if ((asn1[0].Tag != 0x30) || (asn1[0].Count < 3))
                {
                    throw new ArgumentException("Invalid EnvelopedData");
                }

                if (asn1[0][0].Tag != 0x02)
                {
                    throw new ArgumentException("Invalid version");
                }
                _version = asn1[0][0].Value[0];

                // recipientInfos

                ASN1 recipientInfos = asn1 [0][1];

                if (recipientInfos.Tag != 0x31)
                {
                    throw new ArgumentException("missing RecipientInfos");
                }
                for (int i = 0; i < recipientInfos.Count; i++)
                {
                    ASN1 recipientInfo = recipientInfos [i];
                    _recipientInfos.Add(new RecipientInfo(recipientInfo));
                }

                ASN1 encryptedContentInfo = asn1[0][2];

                if (encryptedContentInfo.Tag != 0x30)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }

                ASN1 contentType = encryptedContentInfo [0];

                if (contentType.Tag != 0x06)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                _content = new ContentInfo(ASN1Convert.ToOid(contentType));

                ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1];

                if (contentEncryptionAlgorithm.Tag != 0x30)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                _encryptionAlgorithm         = new ContentInfo(ASN1Convert.ToOid(contentEncryptionAlgorithm [0]));
                _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1];

                ASN1 encryptedContent = encryptedContentInfo [2];

                if (encryptedContent.Tag != 0x80)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                _encrypted = encryptedContent.Value;
            }
예제 #4
0
        static public ASN1 AlgorithmIdentifier(string oid, ASN1 parameters)
        {
            ASN1 ai = new ASN1(0x30);

            ai.Add(ASN1Convert.FromOid(oid));
            ai.Add(parameters);
            return(ai);
        }
예제 #5
0
        public static ASN1 AlgorithmIdentifier(string oid)
        {
            ASN1 asn = new ASN1(48);

            asn.Add(ASN1Convert.FromOid(oid));
            asn.Add(new ASN1(5));
            return(asn);
        }
예제 #6
0
        public static ASN1 AlgorithmIdentifier(string oid, ASN1 parameters)
        {
            ASN1 aSN = new ASN1(48);

            aSN.Add(ASN1Convert.FromOid(oid));
            aSN.Add(parameters);
            return(aSN);
        }
예제 #7
0
        public static ASN1 Attribute(string oid, ASN1 value)
        {
            ASN1 asn = new ASN1(0x30);

            asn.Add(ASN1Convert.FromOid(oid));
            asn.Add(new ASN1(0x31)).Add(value);
            return(asn);
        }
예제 #8
0
        static public ASN1 AlgorithmIdentifier(string oid)
        {
            ASN1 ai = new ASN1(0x30);

            ai.Add(ASN1Convert.FromOid(oid));
            ai.Add(new ASN1(0x05));                     // NULL
            return(ai);
        }
예제 #9
0
        public static ASN1 Attribute(string oid, ASN1 value)
        {
            ASN1 asn = new ASN1(48);

            asn.Add(ASN1Convert.FromOid(oid));
            ASN1 asn2 = asn.Add(new ASN1(49));

            asn2.Add(value);
            return(asn);
        }
예제 #10
0
        public static ASN1 Attribute(string oid, ASN1 value)
        {
            ASN1 aSN = new ASN1(48);

            aSN.Add(ASN1Convert.FromOid(oid));
            ASN1 aSN2 = aSN.Add(new ASN1(49));

            aSN2.Add(value);
            return(aSN);
        }
예제 #11
0
        static public ASN1 Attribute(string oid, ASN1 value)
        {
            ASN1 attr = new ASN1(0x30);

            attr.Add(ASN1Convert.FromOid(oid));
            ASN1 aset = attr.Add(new ASN1(0x31));

            aset.Add(value);
            return(attr);
        }
예제 #12
0
 internal Mono.Security.ASN1 GetASN1()
 {
     Mono.Security.ASN1 asn = new Mono.Security.ASN1(0x30);
     asn.Add(ASN1Convert.FromOid(this.contentType));
     if ((this.content != null) && (this.content.Count > 0))
     {
         asn.Add(this.content);
     }
     return(asn);
 }
예제 #13
0
            internal ASN1 GetASN1()
            {
                ASN1 aSN = new ASN1(48);

                aSN.Add(ASN1Convert.FromOid(contentType));
                if (content != null && content.Count > 0)
                {
                    aSN.Add(content);
                }
                return(aSN);
            }
예제 #14
0
            public SignerInfo(ASN1 asn1)
                : this()
            {
                if (asn1[0].Tag != 48 || asn1[0].Count < 5)
                {
                    throw new ArgumentException("Invalid SignedData");
                }
                if (asn1[0][0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                version = asn1[0][0].Value[0];
                ASN1 aSN = asn1[0][1];

                if (aSN.Tag == 128 && version == 3)
                {
                    ski = aSN.Value;
                }
                else
                {
                    issuer = X501.ToString(aSN[0]);
                    serial = aSN[1].Value;
                }
                ASN1 aSN2 = asn1[0][2];

                hashAlgorithm = ASN1Convert.ToOid(aSN2[0]);
                int  num  = 3;
                ASN1 aSN3 = asn1[0][num];

                if (aSN3.Tag == 160)
                {
                    num++;
                    for (int i = 0; i < aSN3.Count; i++)
                    {
                        authenticatedAttributes.Add(aSN3[i]);
                    }
                }
                num++;
                ASN1 aSN4 = asn1[0][num++];

                if (aSN4.Tag == 4)
                {
                    signature = aSN4.Value;
                }
                ASN1 aSN5 = asn1[0][num];

                if (aSN5 != null && aSN5.Tag == 161)
                {
                    for (int j = 0; j < aSN5.Count; j++)
                    {
                        unauthenticatedAttributes.Add(aSN5[j]);
                    }
                }
            }
예제 #15
0
            internal ASN1 GetASN1()
            {
                ASN1 asn = new ASN1(48);

                asn.Add(ASN1Convert.FromOid(this.contentType));
                if (this.content != null && this.content.Count > 0)
                {
                    asn.Add(this.content);
                }
                return(asn);
            }
예제 #16
0
            public SignerInfo(ASN1 asn1) : this()
            {
                if (asn1[0].Tag != 48 || asn1[0].Count < 5)
                {
                    throw new ArgumentException("Invalid SignedData");
                }
                if (asn1[0][0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                this.version = asn1[0][0].Value[0];
                ASN1 asn2 = asn1[0][1];

                if (asn2.Tag == 128 && this.version == 3)
                {
                    this.ski = asn2.Value;
                }
                else
                {
                    this.issuer = X501.ToString(asn2[0]);
                    this.serial = asn2[1].Value;
                }
                ASN1 asn3 = asn1[0][2];

                this.hashAlgorithm = ASN1Convert.ToOid(asn3[0]);
                int  num  = 3;
                ASN1 asn4 = asn1[0][num];

                if (asn4.Tag == 160)
                {
                    num++;
                    for (int i = 0; i < asn4.Count; i++)
                    {
                        this.authenticatedAttributes.Add(asn4[i]);
                    }
                }
                num++;
                ASN1 asn5 = asn1[0][num++];

                if (asn5.Tag == 4)
                {
                    this.signature = asn5.Value;
                }
                ASN1 asn6 = asn1[0][num];

                if (asn6 != null && asn6.Tag == 161)
                {
                    for (int j = 0; j < asn6.Count; j++)
                    {
                        this.unauthenticatedAttributes.Add(asn6[j]);
                    }
                }
            }
예제 #17
0
            public EnvelopedData(ASN1 asn1)
                : this()
            {
                if (asn1[0].Tag != 48 || asn1[0].Count < 3)
                {
                    throw new ArgumentException("Invalid EnvelopedData");
                }
                if (asn1[0][0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                _version = asn1[0][0].Value[0];
                ASN1 aSN = asn1[0][1];

                if (aSN.Tag != 49)
                {
                    throw new ArgumentException("missing RecipientInfos");
                }
                for (int i = 0; i < aSN.Count; i++)
                {
                    ASN1 data = aSN[i];
                    _recipientInfos.Add(new RecipientInfo(data));
                }
                ASN1 aSN2 = asn1[0][2];

                if (aSN2.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }
                ASN1 aSN3 = aSN2[0];

                if (aSN3.Tag != 6)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                _content = new ContentInfo(ASN1Convert.ToOid(aSN3));
                ASN1 aSN4 = aSN2[1];

                if (aSN4.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                _encryptionAlgorithm         = new ContentInfo(ASN1Convert.ToOid(aSN4[0]));
                _encryptionAlgorithm.Content = aSN4[1];
                ASN1 aSN5 = aSN2[2];

                if (aSN5.Tag != 128)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                _encrypted = aSN5.Value;
            }
예제 #18
0
            public EnvelopedData(ASN1 asn1) : this()
            {
                if (asn1[0].Tag != 48 || asn1[0].Count < 3)
                {
                    throw new ArgumentException("Invalid EnvelopedData");
                }
                if (asn1[0][0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                this._version = asn1[0][0].Value[0];
                ASN1 asn2 = asn1[0][1];

                if (asn2.Tag != 49)
                {
                    throw new ArgumentException("missing RecipientInfos");
                }
                for (int i = 0; i < asn2.Count; i++)
                {
                    ASN1 data = asn2[i];
                    this._recipientInfos.Add(new PKCS7.RecipientInfo(data));
                }
                ASN1 asn3 = asn1[0][2];

                if (asn3.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }
                ASN1 asn4 = asn3[0];

                if (asn4.Tag != 6)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn4));
                ASN1 asn5 = asn3[1];

                if (asn5.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                this._encryptionAlgorithm         = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn5[0]));
                this._encryptionAlgorithm.Content = asn5[1];
                ASN1 asn6 = asn3[2];

                if (asn6.Tag != 128)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                this._encrypted = asn6.Value;
            }
예제 #19
0
            internal ASN1 GetASN1()
            {
                // ContentInfo ::= SEQUENCE {
                ASN1 contentInfo = new ASN1(0x30);

                // contentType ContentType, -> ContentType ::= OBJECT IDENTIFIER
                contentInfo.Add(ASN1Convert.FromOid(contentType));
                // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL
                if ((content != null) && (content.Count > 0))
                {
                    contentInfo.Add(content);
                }
                return(contentInfo);
            }
예제 #20
0
            public EncryptedData(ASN1 asn1) : this()
            {
                if ((asn1.Tag != 0x30) || (asn1.Count < 2))
                {
                    throw new ArgumentException("Invalid EncryptedData");
                }

                if (asn1 [0].Tag != 0x02)
                {
                    throw new ArgumentException("Invalid version");
                }
                _version = asn1 [0].Value [0];

                ASN1 encryptedContentInfo = asn1 [1];

                if (encryptedContentInfo.Tag != 0x30)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }

                ASN1 contentType = encryptedContentInfo [0];

                if (contentType.Tag != 0x06)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                _content = new ContentInfo(ASN1Convert.ToOid(contentType));

                ASN1 contentEncryptionAlgorithm = encryptedContentInfo [1];

                if (contentEncryptionAlgorithm.Tag != 0x30)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                _encryptionAlgorithm         = new ContentInfo(ASN1Convert.ToOid(contentEncryptionAlgorithm [0]));
                _encryptionAlgorithm.Content = contentEncryptionAlgorithm [1];

                ASN1 encryptedContent = encryptedContentInfo [2];

                if (encryptedContent.Tag != 0x80)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                _encrypted = encryptedContent.Value;
            }
예제 #21
0
 public ContentInfo(ASN1 asn1)
 {
     if (asn1.Tag != 48 || (asn1.Count < 1 && asn1.Count > 2))
     {
         throw new ArgumentException("Invalid ASN1");
     }
     if (asn1[0].Tag != 6)
     {
         throw new ArgumentException("Invalid contentType");
     }
     contentType = ASN1Convert.ToOid(asn1[0]);
     if (asn1.Count > 1)
     {
         if (asn1[1].Tag != 160)
         {
             throw new ArgumentException("Invalid content");
         }
         content = asn1[1];
     }
 }
예제 #22
0
 public ContentInfo(Mono.Security.ASN1 asn1)
 {
     if ((asn1.Tag != 0x30) || ((asn1.Count < 1) && (asn1.Count > 2)))
     {
         throw new ArgumentException("Invalid ASN1");
     }
     if (asn1[0].Tag != 6)
     {
         throw new ArgumentException("Invalid contentType");
     }
     this.contentType = ASN1Convert.ToOid(asn1[0]);
     if (asn1.Count > 1)
     {
         if (asn1[1].Tag != 160)
         {
             throw new ArgumentException("Invalid content");
         }
         this.content = asn1[1];
     }
 }
예제 #23
0
            public EncryptedData(ASN1 asn1)
                : this()
            {
                if (asn1.Tag != 48 || asn1.Count < 2)
                {
                    throw new ArgumentException("Invalid EncryptedData");
                }
                if (asn1[0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                _version = asn1[0].Value[0];
                ASN1 aSN = asn1[1];

                if (aSN.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }
                ASN1 aSN2 = aSN[0];

                if (aSN2.Tag != 6)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                _content = new ContentInfo(ASN1Convert.ToOid(aSN2));
                ASN1 aSN3 = aSN[1];

                if (aSN3.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                _encryptionAlgorithm         = new ContentInfo(ASN1Convert.ToOid(aSN3[0]));
                _encryptionAlgorithm.Content = aSN3[1];
                ASN1 aSN4 = aSN[2];

                if (aSN4.Tag != 128)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                _encrypted = aSN4.Value;
            }
예제 #24
0
 public ContentInfo(ASN1 asn1)
 {
     // SEQUENCE with 1 or 2 elements
     if ((asn1.Tag != 0x30) || ((asn1.Count < 1) && (asn1.Count > 2)))
     {
         throw new ArgumentException("Invalid ASN1");
     }
     if (asn1[0].Tag != 0x06)
     {
         throw new ArgumentException("Invalid contentType");
     }
     contentType = ASN1Convert.ToOid(asn1[0]);
     if (asn1.Count > 1)
     {
         if (asn1[1].Tag != 0xA0)
         {
             throw new ArgumentException("Invalid content");
         }
         content = asn1[1];
     }
 }
예제 #25
0
            public EncryptedData(ASN1 asn1) : this()
            {
                if (asn1.Tag != 48 || asn1.Count < 2)
                {
                    throw new ArgumentException("Invalid EncryptedData");
                }
                if (asn1[0].Tag != 2)
                {
                    throw new ArgumentException("Invalid version");
                }
                this._version = asn1[0].Value[0];
                ASN1 asn2 = asn1[1];

                if (asn2.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo");
                }
                ASN1 asn3 = asn2[0];

                if (asn3.Tag != 6)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentType");
                }
                this._content = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn3));
                ASN1 asn4 = asn2[1];

                if (asn4.Tag != 48)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.ContentEncryptionAlgorithmIdentifier");
                }
                this._encryptionAlgorithm         = new PKCS7.ContentInfo(ASN1Convert.ToOid(asn4[0]));
                this._encryptionAlgorithm.Content = asn4[1];
                ASN1 asn5 = asn2[2];

                if (asn5.Tag != 128)
                {
                    throw new ArgumentException("missing EncryptedContentInfo.EncryptedContent");
                }
                this._encrypted = asn5.Value;
            }
예제 #26
0
            public RecipientInfo(ASN1 data)
            {
                if (data.Tag != 0x30)
                {
                    throw new ArgumentException("Invalid RecipientInfo");
                }

                ASN1 version = data [0];

                if (version.Tag != 0x02)
                {
                    throw new ArgumentException("missing Version");
                }
                _version = version.Value [0];

                // issuerAndSerialNumber IssuerAndSerialNumber
                ASN1 subjectIdentifierType = data [1];

                if ((subjectIdentifierType.Tag == 0x80) && (_version == 3))
                {
                    _ski = subjectIdentifierType.Value;
                }
                else
                {
                    _issuer = X501.ToString(subjectIdentifierType [0]);
                    _serial = subjectIdentifierType [1].Value;
                }

                ASN1 keyEncryptionAlgorithm = data [2];

                _oid = ASN1Convert.ToOid(keyEncryptionAlgorithm [0]);

                ASN1 encryptedKey = data [3];

                _key = encryptedKey.Value;
            }
예제 #27
0
            // TODO: INCOMPLETE
            public SignerInfo(ASN1 asn1) : this()
            {
                if ((asn1[0].Tag != 0x30) || (asn1[0].Count < 5))
                {
                    throw new ArgumentException("Invalid SignedData");
                }

                // version Version
                if (asn1[0][0].Tag != 0x02)
                {
                    throw new ArgumentException("Invalid version");
                }
                version = asn1[0][0].Value[0];

                // issuerAndSerialNumber IssuerAndSerialNumber
                ASN1 subjectIdentifierType = asn1 [0][1];

                if ((subjectIdentifierType.Tag == 0x80) && (version == 3))
                {
                    ski = subjectIdentifierType.Value;
                }
                else
                {
                    issuer = X501.ToString(subjectIdentifierType [0]);
                    serial = subjectIdentifierType [1].Value;
                }

                // digestAlgorithm DigestAlgorithmIdentifier
                ASN1 digestAlgorithm = asn1 [0][2];

                hashAlgorithm = ASN1Convert.ToOid(digestAlgorithm [0]);

                // authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL
                int  n = 3;
                ASN1 authAttributes = asn1 [0][n];

                if (authAttributes.Tag == 0xA0)
                {
                    n++;
                    for (int i = 0; i < authAttributes.Count; i++)
                    {
                        authenticatedAttributes.Add(authAttributes [i]);
                    }
                }

                // digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier
                n++;
                // ASN1 digestEncryptionAlgorithm = asn1 [0][n++];
                // string digestEncryptionAlgorithmOid = ASN1Convert.ToOid (digestEncryptionAlgorithm [0]);

                // encryptedDigest EncryptedDigest
                ASN1 encryptedDigest = asn1 [0][n++];

                if (encryptedDigest.Tag == 0x04)
                {
                    signature = encryptedDigest.Value;
                }

                // unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
                ASN1 unauthAttributes = asn1 [0][n];

                if ((unauthAttributes != null) && (unauthAttributes.Tag == 0xA1))
                {
                    for (int i = 0; i < unauthAttributes.Count; i++)
                    {
                        unauthenticatedAttributes.Add(unauthAttributes [i]);
                    }
                }
            }