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;
		}
Exemple #2
0
        public EnvelopedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            EncryptedContentInfo encryptedContentInfo,
            Asn1Set unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                version = new DerInteger(2);
            }
            else
            {
                version = new DerInteger(0);

                foreach (object o in recipientInfos)
                {
                    RecipientInfo ri = RecipientInfo.GetInstance(o);

                    if (!ri.Version.Equals(version))
                    {
                        version = new DerInteger(2);
                        break;
                    }
                }
            }

            this.originatorInfo       = originatorInfo;
            this.recipientInfos       = recipientInfos;
            this.encryptedContentInfo = encryptedContentInfo;
            this.unprotectedAttrs     = unprotectedAttrs;
        }
        public AuthenticatedData(
            OriginatorInfo		originatorInfo,
            Asn1Set				recipientInfos,
            AlgorithmIdentifier	macAlgorithm,
            AlgorithmIdentifier	digestAlgorithm,
            ContentInfo			encapsulatedContent,
            Asn1Set				authAttrs,
            Asn1OctetString		mac,
            Asn1Set				unauthAttrs)
        {
            if (digestAlgorithm != null || authAttrs != null)
            {
                if (digestAlgorithm == null || authAttrs == null)
                {
                    throw new ArgumentException("digestAlgorithm and authAttrs must be set together");
                }
            }

            version = new DerInteger(CalculateVersion(originatorInfo));

            this.originatorInfo = originatorInfo;
            this.macAlgorithm = macAlgorithm;
            this.digestAlgorithm = digestAlgorithm;
            this.recipientInfos = recipientInfos;
            this.encapsulatedContentInfo = encapsulatedContent;
            this.authAttrs = authAttrs;
            this.mac = mac;
            this.unauthAttrs = unauthAttrs;
        }
		public AuthEnvelopedData(
			OriginatorInfo			originatorInfo,
			Asn1Set					recipientInfos,
			EncryptedContentInfo	authEncryptedContentInfo,
			Asn1Set					authAttrs,
			Asn1OctetString			mac,
			Asn1Set					unauthAttrs)
		{
			// "It MUST be set to 0."
			this.version = new DerInteger(0);

			this.originatorInfo = originatorInfo;

			// TODO
			// "There MUST be at least one element in the collection."
			this.recipientInfos = recipientInfos;

			this.authEncryptedContentInfo = authEncryptedContentInfo;

			// TODO
			// "The authAttrs MUST be present if the content type carried in
			// EncryptedContentInfo is not id-data."
			this.authAttrs = authAttrs;

			this.mac = mac;

			this.unauthAttrs = unauthAttrs;
	    }
        public AuthEnvelopedData(
            OriginatorInfo originatorInfo,
            Asn1Set recipientInfos,
            EncryptedContentInfo authEncryptedContentInfo,
            Asn1Set authAttrs,
            Asn1OctetString mac,
            Asn1Set unauthAttrs)
        {
            // "It MUST be set to 0."
            this.version = new DerInteger(0);

            this.originatorInfo = originatorInfo;

            // TODO
            // "There MUST be at least one element in the collection."
            this.recipientInfos = recipientInfos;

            this.authEncryptedContentInfo = authEncryptedContentInfo;

            // TODO
            // "The authAttrs MUST be present if the content type carried in
            // EncryptedContentInfo is not id-data."
            this.authAttrs = authAttrs;

            this.mac = mac;

            this.unauthAttrs = unauthAttrs;
        }
		public EnvelopedData(
            OriginatorInfo			originatorInfo,
            Asn1Set					recipientInfos,
            EncryptedContentInfo	encryptedContentInfo,
            Asn1Set					unprotectedAttrs)
        {
            if (originatorInfo != null || unprotectedAttrs != null)
            {
                version = new DerInteger(2);
            }
            else
            {
                version = new DerInteger(0);

				foreach (object o in recipientInfos)
				{
                    RecipientInfo ri = RecipientInfo.GetInstance(o);

					if (!ri.Version.Equals(version))
                    {
                        version = new DerInteger(2);
                        break;
                    }
                }
            }

			this.originatorInfo = originatorInfo;
            this.recipientInfos = recipientInfos;
            this.encryptedContentInfo = encryptedContentInfo;
            this.unprotectedAttrs = unprotectedAttrs;
        }
        private AuthEnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            // TODO
            // "It MUST be set to 0."
            Asn1Object tmp = seq[index++].ToAsn1Object();

            version = (DerInteger)tmp;

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++].ToAsn1Object();
            }

            // TODO
            // "There MUST be at least one element in the collection."
            recipientInfos = Asn1Set.GetInstance(tmp);

            tmp = seq[index++].ToAsn1Object();
            authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);

            tmp = seq[index++].ToAsn1Object();
            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++].ToAsn1Object();
            }
            else
            {
                // TODO
                // "The authAttrs MUST be present if the content type carried in
                // EncryptedContentInfo is not id-data."
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                tmp         = seq[index++].ToAsn1Object();
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
            }
        }
		private AuthEnvelopedData(
			Asn1Sequence	seq)
		{
			int index = 0;

			// TODO
			// "It MUST be set to 0."
			Asn1Object tmp = seq[index++].ToAsn1Object();
			version = (DerInteger)tmp;

			tmp = seq[index++].ToAsn1Object();
			if (tmp is Asn1TaggedObject)
			{
				originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
				tmp = seq[index++].ToAsn1Object();
			}

			// TODO
			// "There MUST be at least one element in the collection."
			recipientInfos = Asn1Set.GetInstance(tmp);

			tmp = seq[index++].ToAsn1Object();
			authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);

			tmp = seq[index++].ToAsn1Object();
			if (tmp is Asn1TaggedObject)
			{
				authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
				tmp = seq[index++].ToAsn1Object();
			}
			else
			{
				// TODO
				// "The authAttrs MUST be present if the content type carried in
				// EncryptedContentInfo is not id-data."
			}

			mac = Asn1OctetString.GetInstance(tmp);

			if (seq.Count > index)
			{
				tmp = seq[index++].ToAsn1Object();
				unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
			}
		}
        public OriginatorInfo GetOriginatorInfo()
        {
            originatorInfoCalled = true;

            if (nextObject == null)
            {
                nextObject = seq.ReadObject();
            }

            if (nextObject is Asn1TaggedObjectParser && ((Asn1TaggedObjectParser)nextObject).TagNo == 0)
            {
                Asn1SequenceParser originatorInfo = (Asn1SequenceParser)((Asn1TaggedObjectParser)nextObject).GetObjectParser(Asn1Tags.Sequence, false);
                nextObject = null;
                return(OriginatorInfo.GetInstance(originatorInfo.ToAsn1Object()));
            }

            return(null);
        }
Exemple #10
0
        public static int CalculateVersion(OriginatorInfo origInfo)
        {
            if (origInfo == null)
            {
                return(0);
            }

            int ver = 0;

            foreach (object obj in origInfo.Certificates)
            {
                if (obj is Asn1TaggedObject)
                {
                    Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                    if (tag.TagNo == 2)
                    {
                        ver = 1;
                    }
                    else if (tag.TagNo == 3)
                    {
                        ver = 3;
                        break;
                    }
                }
            }

            foreach (object obj in origInfo.Crls)
            {
                if (obj is Asn1TaggedObject)
                {
                    Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                    if (tag.TagNo == 1)
                    {
                        ver = 3;
                        break;
                    }
                }
            }

            return(ver);
        }
Exemple #11
0
        private AuthenticatedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            Asn1Encodable tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++];
            }

            recipientInfos = Asn1Set.GetInstance(tmp);
            macAlgorithm   = AlgorithmIdentifier.GetInstance(seq[index++]);

            tmp = seq[index++];
            if (tmp is Asn1TaggedObject)
            {
                digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
                tmp             = seq[index++];
            }

            encapsulatedContentInfo = ContentInfo.GetInstance(tmp);

            tmp = seq[index++];
            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp       = seq[index++];
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
        private AuthenticatedData(
            Asn1Sequence	seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            Asn1Encodable tmp = seq[index++];
            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp = seq[index++];
            }

            recipientInfos = Asn1Set.GetInstance(tmp);
            macAlgorithm = AlgorithmIdentifier.GetInstance(seq[index++]);

            tmp = seq[index++];
            if (tmp is Asn1TaggedObject)
            {
                digestAlgorithm = AlgorithmIdentifier.GetInstance((Asn1TaggedObject)tmp, false);
                tmp = seq[index++];
            }

            encapsulatedContentInfo = ContentInfo.GetInstance(tmp);

            tmp = seq[index++];
            if (tmp is Asn1TaggedObject)
            {
                authAttrs = Asn1Set.GetInstance((Asn1TaggedObject)tmp, false);
                tmp = seq[index++];
            }

            mac = Asn1OctetString.GetInstance(tmp);

            if (seq.Count > index)
            {
                unauthAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
Exemple #13
0
        public EnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

            version = (DerInteger)seq[index++];

            object tmp = seq[index++];

            if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject)tmp, false);
                tmp            = seq[index++];
            }

            recipientInfos       = Asn1Set.GetInstance(tmp);
            encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[index++]);

            if (seq.Count > index)
            {
                unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject)seq[index], false);
            }
        }
		public EnvelopedData(
            Asn1Sequence seq)
        {
            int index = 0;

			version = (DerInteger) seq[index++];

			object tmp = seq[index++];

			if (tmp is Asn1TaggedObject)
            {
                originatorInfo = OriginatorInfo.GetInstance((Asn1TaggedObject) tmp, false);
                tmp = seq[index++];
            }

			recipientInfos = Asn1Set.GetInstance(tmp);
            encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[index++]);

			if (seq.Count > index)
            {
				unprotectedAttrs = Asn1Set.GetInstance((Asn1TaggedObject) seq[index], false);
            }
        }
        public static int CalculateVersion(OriginatorInfo origInfo)
        {
            if (origInfo == null)
                return 0;

            int ver = 0;

            foreach (object obj in origInfo.Certificates)
            {
                if (obj is Asn1TaggedObject)
                {
                    Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                    if (tag.TagNo == 2)
                    {
                        ver = 1;
                    }
                    else if (tag.TagNo == 3)
                    {
                        ver = 3;
                        break;
                    }
                }
            }

            foreach (object obj in origInfo.Crls)
            {
                if (obj is Asn1TaggedObject)
                {
                    Asn1TaggedObject tag = (Asn1TaggedObject)obj;

                    if (tag.TagNo == 1)
                    {
                        ver = 3;
                        break;
                    }
                }
            }

            return ver;
        }