public CmsEnvelopedDataParser(
            Stream envelopedData)
            : base(envelopedData)
        {
            this._attrNotRead  = true;
            this.envelopedData = new EnvelopedDataParser(
                (Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence));

            // TODO Validate version?
            //DerInteger version = this.envelopedData.Version;

            //
            // read the recipients
            //
            Asn1Set recipientInfos = Asn1Set.GetInstance(this.envelopedData.GetRecipientInfos().ToAsn1Object());

            //
            // read the encrypted content info
            //
            EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo();

            this._encAlg = encInfo.ContentEncryptionAlgorithm;
            CmsReadable readable = new CmsProcessableInputStream(
                ((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
                this._encAlg, readable);

            //
            // build the RecipientInformationStore
            //
            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                recipientInfos, secureReadable);
        }
        public CmsAuthEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            AuthEnvelopedData authEnvData = AuthEnvelopedData.GetInstance(contentInfo.Content);

            this.originator = authEnvData.OriginatorInfo;

            //
            // read the recipients
            //
            Asn1Set recipientInfos = authEnvData.RecipientInfos;

            //
            // read the auth-encrypted content info
            //
            EncryptedContentInfo authEncInfo = authEnvData.AuthEncryptedContentInfo;

            this.authEncAlg = authEncInfo.ContentEncryptionAlgorithm;
            CmsSecureReadable secureReadable = new AuthEnvelopedSecureReadable(this);

            //
            // build the RecipientInformationStore
            //
            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                recipientInfos, secureReadable);

            // FIXME These need to be passed to the AEAD cipher as AAD (Additional Authenticated Data)
            this.authAttrs   = authEnvData.AuthAttrs;
            this.mac         = authEnvData.Mac.GetOctets();
            this.unauthAttrs = authEnvData.UnauthAttrs;
        }
Ejemplo n.º 3
0
        public CmsEnvelopedDataParser(
            Stream envelopedData)
            : base(envelopedData)
        {
            this._attrNotRead  = true;
            this.envelopedData = new EnvelopedDataParser(
                (Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence));

            //
            // load the RecepientInfoStore
            //
            Asn1SetParser s         = this.envelopedData.GetRecipientInfos();
            IList         baseInfos = new ArrayList();
            Asn1Set       set       = Asn1Set.GetInstance(s.ToAsn1Object());

            foreach (object o in set)
            {
                baseInfos.Add(RecipientInfo.GetInstance(o));
            }

            //
            // read the encrypted content info
            //
            EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo();

            this._encAlg = encInfo.ContentEncryptionAlgorithm;

            //
            // prime the recepients
            //
            IList  infos      = new ArrayList();
            Stream dataStream = ((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream();

            foreach (Asn1.Cms.RecipientInfo info in baseInfos)
            {
                Asn1Encodable recipInfo = info.Info;
                if (recipInfo is Asn1.Cms.KeyTransRecipientInfo)
                {
                    infos.Add(new KeyTransRecipientInformation(
                                  (KeyTransRecipientInfo)recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is Asn1.Cms.KekRecipientInfo)
                {
                    infos.Add(new KekRecipientInformation(
                                  (KekRecipientInfo)recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is KeyAgreeRecipientInfo)
                {
                    infos.Add(new KeyAgreeRecipientInformation(
                                  (KeyAgreeRecipientInfo)recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is PasswordRecipientInfo)
                {
                    infos.Add(new PasswordRecipientInformation(
                                  (PasswordRecipientInfo)recipInfo, _encAlg, dataStream));
                }
            }

            this.recipientInfoStore = new RecipientInformationStore(infos);
        }
Ejemplo n.º 4
0
        public CmsAuthenticatedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            AuthenticatedData authData = AuthenticatedData.GetInstance(contentInfo.Content);

            //
            // read the encapsulated content info
            //
            ContentInfo encInfo = authData.EncapsulatedContentInfo;

            this.macAlg = authData.MacAlgorithm;
            this.mac    = authData.Mac.GetOctets();

            //
            // load the RecipientInfoStore
            //
            byte[] contentOctets = Asn1OctetString.GetInstance(encInfo.Content).GetOctets();
            IList  infos         = CmsEnvelopedHelper.ReadRecipientInfos(
                authData.RecipientInfos, contentOctets, null, macAlg, null);

            this.authAttrs          = authData.AuthAttrs;
            this.recipientInfoStore = new RecipientInformationStore(infos);
            this.unauthAttrs        = authData.UnauthAttrs;
        }
Ejemplo n.º 5
0
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

			EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

			//
			// read the recipients
			//
			Asn1Set recipientInfos = envData.RecipientInfos;

			//
			// read the encrypted content info
			//
			EncryptedContentInfo encInfo = envData.EncryptedContentInfo;
			this.encAlg = encInfo.ContentEncryptionAlgorithm;
			CmsReadable readable = new CmsProcessableByteArray(encInfo.EncryptedContent.GetOctets());
			CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
				this.encAlg, readable);

			//
			// build the RecipientInformationStore
			//
			this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);

			this.unprotectedAttributes = envData.UnprotectedAttrs;
        }
        public CmsAuthenticatedDataParser(
            Stream envelopedData)
            : base(envelopedData)
        {
            this.authAttrNotRead = true;
            this.authData        = new AuthenticatedDataParser(
                (Asn1SequenceParser)contentInfo.GetContent(Asn1Tags.Sequence));

            // TODO Validate version?
            //DerInteger version = this.authData.getVersion();

            //
            // read the recipients
            //
            Asn1Set recipientInfos = Asn1Set.GetInstance(authData.GetRecipientInfos().ToAsn1Object());

            this.macAlg = authData.GetMacAlgorithm();

            //
            // read the authenticated content info
            //
            ContentInfoParser data     = authData.GetEnapsulatedContentInfo();
            CmsReadable       readable = new CmsProcessableInputStream(
                ((Asn1OctetStringParser)data.GetContent(Asn1Tags.OctetString)).GetOctetStream());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(
                this.macAlg, readable);

            //
            // build the RecipientInformationStore
            //
            this._recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                recipientInfos, secureReadable);
        }
		public CmsAuthenticatedData(
			ContentInfo contentInfo)
		{
			this.contentInfo = contentInfo;

			AuthenticatedData authData = AuthenticatedData.GetInstance(contentInfo.Content);

			//
			// read the recipients
			//
			Asn1Set recipientInfos = authData.RecipientInfos;

			this.macAlg = authData.MacAlgorithm;

			//
			// read the authenticated content info
			//
			ContentInfo encInfo = authData.EncapsulatedContentInfo;
			CmsReadable readable = new CmsProcessableByteArray(
				Asn1OctetString.GetInstance(encInfo.Content).GetOctets());
			CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(
				this.macAlg, readable);

			//
			// build the RecipientInformationStore
			//
			this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);

			this.authAttrs = authData.AuthAttrs;
			this.mac = authData.Mac.GetOctets();
			this.unauthAttrs = authData.UnauthAttrs;
		}
        public CmsAuthEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            AuthEnvelopedData authEnvData = AuthEnvelopedData.GetInstance(contentInfo.Content);

            this.originator = authEnvData.OriginatorInfo;

            //
            // read the encrypted content info
            //
            EncryptedContentInfo authEncInfo = authEnvData.AuthEncryptedContentInfo;

            this.authEncAlg = authEncInfo.ContentEncryptionAlgorithm;

            //
            // load the RecipientInfoStore
            //
            byte[] contentOctets = authEncInfo.EncryptedContent.GetOctets();
            IList  infos         = CmsEnvelopedHelper.ReadRecipientInfos(
                authEnvData.RecipientInfos, contentOctets, null, null, authEncAlg);

            this.recipientInfoStore = new RecipientInformationStore(infos);

            // FIXME These need to be passed to the AEAD cipher as AAD (Additional Authenticated Data)
            this.authAttrs = authEnvData.AuthAttrs;

            this.mac = authEnvData.Mac.GetOctets();

            this.unauthAttrs = authEnvData.UnauthAttrs;
        }
Ejemplo n.º 9
0
        public CmsAuthenticatedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            AuthenticatedData authData = AuthenticatedData.GetInstance(contentInfo.Content);

            //
            // read the recipients
            //
            Asn1Set recipientInfos = authData.RecipientInfos;

            this.macAlg = authData.MacAlgorithm;

            //
            // read the authenticated content info
            //
            ContentInfo encInfo  = authData.EncapsulatedContentInfo;
            CmsReadable readable = new CmsProcessableByteArray(
                Asn1OctetString.GetInstance(encInfo.Content).GetOctets());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(
                this.macAlg, readable);

            //
            // build the RecipientInformationStore
            //
            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                recipientInfos, secureReadable);

            this.authAttrs   = authData.AuthAttrs;
            this.mac         = authData.Mac.GetOctets();
            this.unauthAttrs = authData.UnauthAttrs;
        }
		public CmsAuthEnvelopedData(
			ContentInfo contentInfo)
		{
			this.contentInfo = contentInfo;

			AuthEnvelopedData authEnvData = AuthEnvelopedData.GetInstance(contentInfo.Content);

			this.originator = authEnvData.OriginatorInfo;

			//
	        // read the recipients
	        //
	        Asn1Set recipientInfos = authEnvData.RecipientInfos;

			//
			// read the auth-encrypted content info
			//
			EncryptedContentInfo authEncInfo = authEnvData.AuthEncryptedContentInfo;
			this.authEncAlg = authEncInfo.ContentEncryptionAlgorithm;
			CmsSecureReadable secureReadable = new AuthEnvelopedSecureReadable(this);

			//
			// build the RecipientInformationStore
			//
			this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);

			// FIXME These need to be passed to the AEAD cipher as AAD (Additional Authenticated Data)
			this.authAttrs = authEnvData.AuthAttrs;
			this.mac = authEnvData.Mac.GetOctets();
			this.unauthAttrs = authEnvData.UnauthAttrs;
		}
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

            //
            // read the recipients
            //
            Asn1Set recipientInfos = envData.RecipientInfos;

            //
            // read the encrypted content info
            //
            EncryptedContentInfo encInfo = envData.EncryptedContentInfo;

            this.encAlg = encInfo.ContentEncryptionAlgorithm;
            CmsReadable       readable       = new CmsProcessableByteArray(encInfo.EncryptedContent.GetOctets());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
                this.encAlg, readable);

            //
            // build the RecipientInformationStore
            //
            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                recipientInfos, secureReadable);

            this.unprotectedAttributes = envData.UnprotectedAttrs;
        }
Ejemplo n.º 12
0
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

            //
            // read the encrypted content info
            //
            EncryptedContentInfo encInfo = envData.EncryptedContentInfo;

            this.encAlg = encInfo.ContentEncryptionAlgorithm;

            //
            // load the RecipientInfoStore
            //
            Asn1Set s     = envData.RecipientInfos;
            IList   infos = new ArrayList();

            byte[] contentOctets = encInfo.EncryptedContent.GetOctets();

            foreach (Asn1Encodable ae in s)
            {
                RecipientInfo info          = RecipientInfo.GetInstance(ae);
                MemoryStream  contentStream = new MemoryStream(contentOctets, false);

                object type = info.Info;

                if (type is KeyTransRecipientInfo)
                {
                    infos.Add(new KeyTransRecipientInformation(
                                  (KeyTransRecipientInfo)type, encAlg, contentStream));
                }
                else if (type is KekRecipientInfo)
                {
                    infos.Add(new KekRecipientInformation(
                                  (KekRecipientInfo)type, encAlg, contentStream));
                }
                else if (type is KeyAgreeRecipientInfo)
                {
                    infos.Add(new KeyAgreeRecipientInformation(
                                  (KeyAgreeRecipientInfo)type, encAlg, contentStream));
                }
                else if (type is PasswordRecipientInfo)
                {
                    infos.Add(new PasswordRecipientInformation(
                                  (PasswordRecipientInfo)type, encAlg, contentStream));
                }
            }

            this.recipientInfoStore    = new RecipientInformationStore(infos);
            this.unprotectedAttributes = envData.UnprotectedAttrs;
        }
Ejemplo n.º 13
0
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

			EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

			//
            // read the encrypted content info
            //
            EncryptedContentInfo encInfo = envData.EncryptedContentInfo;

			this.encAlg = encInfo.ContentEncryptionAlgorithm;

			//
            // load the RecipientInfoStore
            //
            Asn1Set	s = envData.RecipientInfos;
			IList infos = new ArrayList();
			byte[] contentOctets = encInfo.EncryptedContent.GetOctets();

			foreach (Asn1Encodable ae in s)
            {
                RecipientInfo info = RecipientInfo.GetInstance(ae);
				MemoryStream contentStream = new MemoryStream(contentOctets, false);

				object type = info.Info;

				if (type is KeyTransRecipientInfo)
				{
					infos.Add(new KeyTransRecipientInformation(
						(KeyTransRecipientInfo) type, encAlg, contentStream));
				}
				else if (type is KekRecipientInfo)
				{
					infos.Add(new KekRecipientInformation(
						(KekRecipientInfo) type, encAlg, contentStream));
				}
				else if (type is KeyAgreeRecipientInfo)
				{
					infos.Add(new KeyAgreeRecipientInformation(
						(KeyAgreeRecipientInfo) type, encAlg, contentStream));
				}
				else if (type is PasswordRecipientInfo)
				{
					infos.Add(new PasswordRecipientInformation(
						(PasswordRecipientInfo) type, encAlg, contentStream));
				}
            }

            this.recipientInfoStore = new RecipientInformationStore(infos);
            this.unprotectedAttributes = envData.UnprotectedAttrs;
        }
        public CmsEnvelopedDataParser(Stream envelopedData) : base(envelopedData)
        {
            this._attrNotRead  = true;
            this.envelopedData = new EnvelopedDataParser((Asn1SequenceParser)this.contentInfo.GetContent(16));
            Asn1Set instance = Asn1Set.GetInstance(this.envelopedData.GetRecipientInfos().ToAsn1Object());
            EncryptedContentInfoParser encryptedContentInfo = this.envelopedData.GetEncryptedContentInfo();

            this._encAlg = encryptedContentInfo.ContentEncryptionAlgorithm;
            CmsReadable       readable       = new CmsProcessableInputStream(((Asn1OctetStringParser)encryptedContentInfo.GetEncryptedContent(4)).GetOctetStream());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(this._encAlg, readable);

            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(instance, secureReadable);
        }
        }        //IL_0003: Unknown result type (might be due to invalid IL or missing references)

        //IL_000d: Expected O, but got Unknown


        public CmsAuthenticatedDataParser(Stream envelopedData)
            : base(envelopedData)
        {
            authAttrNotRead = true;
            authData        = new AuthenticatedDataParser((Asn1SequenceParser)contentInfo.GetContent(16));
            Asn1Set instance = Asn1Set.GetInstance(authData.GetRecipientInfos().ToAsn1Object());

            macAlg = authData.GetMacAlgorithm();
            ContentInfoParser enapsulatedContentInfo = authData.GetEnapsulatedContentInfo();
            CmsReadable       readable       = new CmsProcessableInputStream(((Asn1OctetStringParser)enapsulatedContentInfo.GetContent(4)).GetOctetStream());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(macAlg, readable);

            _recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(instance, secureReadable);
        }
Ejemplo n.º 16
0
        public CmsEnvelopedData(ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;
            EnvelopedData        instance             = EnvelopedData.GetInstance(contentInfo.Content);
            Asn1Set              recipientInfos       = instance.RecipientInfos;
            EncryptedContentInfo encryptedContentInfo = instance.EncryptedContentInfo;

            encAlg = encryptedContentInfo.ContentEncryptionAlgorithm;
            CmsReadable       readable       = new CmsProcessableByteArray(encryptedContentInfo.EncryptedContent.GetOctets());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(encAlg, readable);

            recipientInfoStore    = CmsEnvelopedHelper.BuildRecipientInformationStore(recipientInfos, secureReadable);
            unprotectedAttributes = instance.UnprotectedAttrs;
        }
Ejemplo n.º 17
0
        public CmsAuthenticatedData(ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;
            AuthenticatedData instance       = AuthenticatedData.GetInstance(contentInfo.Content);
            Asn1Set           recipientInfos = instance.RecipientInfos;

            this.macAlg = instance.MacAlgorithm;
            ContentInfo       encapsulatedContentInfo = instance.EncapsulatedContentInfo;
            CmsReadable       readable       = new CmsProcessableByteArray(Asn1OctetString.GetInstance(encapsulatedContentInfo.Content).GetOctets());
            CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(this.macAlg, readable);

            this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(recipientInfos, secureReadable);
            this.authAttrs          = instance.AuthAttrs;
            this.mac         = instance.Mac.GetOctets();
            this.unauthAttrs = instance.UnauthAttrs;
        }
Ejemplo n.º 18
0
        public CmsAuthEnvelopedData(ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;
            AuthEnvelopedData instance = AuthEnvelopedData.GetInstance(contentInfo.Content);

            originator = instance.OriginatorInfo;
            Asn1Set recipientInfos = instance.RecipientInfos;
            EncryptedContentInfo authEncryptedContentInfo = instance.AuthEncryptedContentInfo;

            authEncAlg = authEncryptedContentInfo.ContentEncryptionAlgorithm;
            CmsSecureReadable secureReadable = new AuthEnvelopedSecureReadable(this);

            recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(recipientInfos, secureReadable);
            authAttrs          = instance.AuthAttrs;
            mac         = instance.Mac.GetOctets();
            unauthAttrs = instance.UnauthAttrs;
        }
Ejemplo n.º 19
0
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            try
            {
                EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

                if (envData.OriginatorInfo != null)
                {
                    originatorInfo = new OriginatorInformation(envData.OriginatorInfo);
                }

                //
                // read the recipients
                //
                Asn1Set recipientInfos = envData.RecipientInfos;

                //
                // read the encrypted content info
                //
                EncryptedContentInfo encInfo = envData.EncryptedContentInfo;
                this.encAlg = encInfo.ContentEncryptionAlgorithm;
                CmsReadable        readable       = new CmsProcessableByteArray(encInfo.EncryptedContent.GetOctets());
                ICmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
                    this.encAlg, readable);

                //
                // build the RecipientInformationStore
                //
                this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
                    recipientInfos, this.encAlg, secureReadable);

                this.unprotectedAttributes = envData.UnprotectedAttrs;
            }
            catch (Exception e)
            {
                throw new CmsException("malformed content", e);
            }
        }
Ejemplo n.º 20
0
        public CmsEnvelopedDataParser(
            Stream envelopedData)
            : base(envelopedData)
        {
            this._attrNotRead  = true;
            this.envelopedData = new EnvelopedDataParser(
                (Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence));

            // TODO Validate version?
            //DerInteger version = this.envelopedData.Version;

            //
            // load the RecipientInfoStore
            //
            Asn1SetParser s         = this.envelopedData.GetRecipientInfos();
            IList         baseInfos = new ArrayList();

            IAsn1Convertible entry;

            while ((entry = s.ReadObject()) != null)
            {
                baseInfos.Add(RecipientInfo.GetInstance(entry.ToAsn1Object()));
            }

            //
            // read the encrypted content info
            //
            EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo();

            this._encAlg = encInfo.ContentEncryptionAlgorithm;

            //
            // prime the recipients
            //
            Stream contentStream = ((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream();
            IList  infos         = CmsEnvelopedHelper.ReadRecipientInfos(
                baseInfos, contentStream, _encAlg, null, null);

            this.recipientInfoStore = new RecipientInformationStore(infos);
        }
        public CmsAuthenticatedDataParser(
            Stream envelopedData)
            : base(envelopedData)
        {
            this.authAttrNotRead = true;
            this.authData        = new AuthenticatedDataParser(
                (Asn1SequenceParser)contentInfo.GetContent(Asn1Tags.Sequence));

            // TODO Validate version?
            //DerInteger version = this.authData.getVersion();

            //
            // load the RecipientInfoStore
            //
            Asn1SetParser s         = authData.GetRecipientInfos();
            IList         baseInfos = new ArrayList();

            IAsn1Convertible entry;

            while ((entry = s.ReadObject()) != null)
            {
                baseInfos.Add(RecipientInfo.GetInstance(entry.ToAsn1Object()));
            }

            this.macAlg = authData.GetMacAlgorithm();

            //
            // read the encrypted content info
            //
            ContentInfoParser data = authData.GetEnapsulatedContentInfo();

            //
            // prime the recipients
            //
            Stream contentStream = ((Asn1OctetStringParser)data.GetContent(Asn1Tags.OctetString)).GetOctetStream();
            IList  infos         = CmsEnvelopedHelper.ReadRecipientInfos(
                baseInfos, contentStream, null, macAlg, null);

            _recipientInfoStore = new RecipientInformationStore(infos);
        }
Ejemplo n.º 22
0
        public CmsEnvelopedData(
            ContentInfo contentInfo)
        {
            this.contentInfo = contentInfo;

            EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);

            //
            // read the encrypted content info
            //
            EncryptedContentInfo encInfo = envData.EncryptedContentInfo;

            this.encAlg = encInfo.ContentEncryptionAlgorithm;

            //
            // load the RecipientInfoStore
            //
            byte[] contentOctets = encInfo.EncryptedContent.GetOctets();
            IList  infos         = CmsEnvelopedHelper.ReadRecipientInfos(
                envData.RecipientInfos, contentOctets, encAlg, null, null);

            this.recipientInfoStore    = new RecipientInformationStore(infos);
            this.unprotectedAttributes = envData.UnprotectedAttrs;
        }
		public CmsAuthenticatedDataParser(
			Stream envelopedData)
			: base(envelopedData)
		{
			this.authAttrNotRead = true;
			this.authData = new AuthenticatedDataParser(
				(Asn1SequenceParser)contentInfo.GetContent(Asn1Tags.Sequence));

			// TODO Validate version?
			//DerInteger version = this.authData.getVersion();

			//
			// read the recipients
			//
			Asn1Set recipientInfos = Asn1Set.GetInstance(authData.GetRecipientInfos().ToAsn1Object());

			this.macAlg = authData.GetMacAlgorithm();

			//
			// read the authenticated content info
			//
			ContentInfoParser data = authData.GetEnapsulatedContentInfo();
			CmsReadable readable = new CmsProcessableInputStream(
				((Asn1OctetStringParser)data.GetContent(Asn1Tags.OctetString)).GetOctetStream());
			CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(
				this.macAlg, readable);

			//
			// build the RecipientInformationStore
			//
			this._recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);
		}
        public CmsEnvelopedDataParser(
			Stream envelopedData)
            : base(envelopedData)
        {
            this._attrNotRead = true;
            this.envelopedData = new EnvelopedDataParser(
                (Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence));

            // TODO Validate version?
            //			DerInteger version = this.envelopedData.Version;

            //
            // load the RecipientInfoStore
            //
            Asn1SetParser s = this.envelopedData.GetRecipientInfos();
            IList baseInfos = new ArrayList();

            IAsn1Convertible entry;
            while ((entry = s.ReadObject()) != null)
            {
                baseInfos.Add(RecipientInfo.GetInstance(entry.ToAsn1Object()));
            }

            //
            // read the encrypted content info
            //
            EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo();

            this._encAlg = encInfo.ContentEncryptionAlgorithm;

            //
            // prime the recipients
            //
            IList infos = new ArrayList();
            Stream dataStream = ((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream();

            foreach (Asn1.Cms.RecipientInfo info in baseInfos)
            {
                Asn1Encodable recipInfo = info.Info;
                if (recipInfo is Asn1.Cms.KeyTransRecipientInfo)
                {
                    infos.Add(new KeyTransRecipientInformation(
                        (KeyTransRecipientInfo) recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is Asn1.Cms.KekRecipientInfo)
                {
                    infos.Add(new KekRecipientInformation(
                        (KekRecipientInfo) recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is KeyAgreeRecipientInfo)
                {
                    infos.Add(new KeyAgreeRecipientInformation(
                        (KeyAgreeRecipientInfo) recipInfo, _encAlg, dataStream));
                }
                else if (recipInfo is PasswordRecipientInfo)
                {
                    infos.Add(new PasswordRecipientInformation(
                        (PasswordRecipientInfo) recipInfo, _encAlg, dataStream));
                }
            }

            this.recipientInfoStore = new RecipientInformationStore(infos);
        }
Ejemplo n.º 25
0
		private static void ConfirmDataReceived(RecipientInformationStore recipients,
			byte[] expectedData, X509Certificate reciCert, AsymmetricKeyParameter reciPrivKey)
		{
			RecipientID rid = new RecipientID();
			rid.Issuer = PrincipalUtilities.GetIssuerX509Principal(reciCert);
			rid.SerialNumber = reciCert.SerialNumber;

			RecipientInformation recipient = recipients[rid];
			Assert.IsNotNull(recipient);

			byte[] actualData = recipient.GetContent(reciPrivKey);
			Assert.IsTrue(Arrays.AreEqual(expectedData, actualData));
		}
		public CmsEnvelopedDataParser(
			Stream envelopedData)
			: base(envelopedData)
		{
			this._attrNotRead = true;
			this.envelopedData = new EnvelopedDataParser(
				(Asn1SequenceParser)this.contentInfo.GetContent(Asn1Tags.Sequence));

			// TODO Validate version?
			//DerInteger version = this.envelopedData.Version;

			//
			// read the recipients
			//
			Asn1Set recipientInfos = Asn1Set.GetInstance(this.envelopedData.GetRecipientInfos().ToAsn1Object());

			//
			// read the encrypted content info
			//
			EncryptedContentInfoParser encInfo = this.envelopedData.GetEncryptedContentInfo();
			this._encAlg = encInfo.ContentEncryptionAlgorithm;
			CmsReadable readable = new CmsProcessableInputStream(
				((Asn1OctetStringParser)encInfo.GetEncryptedContent(Asn1Tags.OctetString)).GetOctetStream());
			CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
				this._encAlg, readable);

			//
			// build the RecipientInformationStore
			//
			this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
				recipientInfos, secureReadable);
		}
Ejemplo n.º 27
0
		private static void ConfirmNumberRecipients(RecipientInformationStore recipients, int count)
		{
			Assert.AreEqual(count, recipients.GetRecipients().Count);
		}