Beispiel #1
0
        private AsymmetricKeyParameter GetSenderPublicKey(
            AsymmetricKeyParameter receiverPrivateKey,
            OriginatorIdentifierOrKey originator)
        {
            OriginatorPublicKey opk = originator.OriginatorPublicKey;

            if (opk != null)
            {
                return(GetPublicKeyFromOriginatorPublicKey(receiverPrivateKey, opk));
            }

            OriginatorID origID = new OriginatorID();

            IssuerAndSerialNumber iAndSN = originator.IssuerAndSerialNumber;

            if (iAndSN != null)
            {
                origID.Issuer       = iAndSN.Name;
                origID.SerialNumber = iAndSN.SerialNumber.Value;
            }
            else
            {
                SubjectKeyIdentifier ski = originator.SubjectKeyIdentifier;

                origID.SubjectKeyIdentifier = ski.GetKeyIdentifier();
            }

            return(GetPublicKeyFromOriginatorID(origID));
        }
        internal KeyTransRecipientInformation(
            KeyTransRecipientInfo info,
            CmsSecureReadable secureReadable)
            : base(info.KeyEncryptionAlgorithm, secureReadable)
        {
            this.info = info;
            this.rid  = new RecipientID();

            RecipientIdentifier r = info.RecipientIdentifier;

            try
            {
                if (r.IsTagged)
                {
                    Asn1OctetString octs = Asn1OctetString.GetInstance(r.ID);

                    rid.SubjectKeyIdentifier = octs.GetOctets();
                }
                else
                {
                    IssuerAndSerialNumber iAnds = IssuerAndSerialNumber.GetInstance(r.ID);

                    rid.Issuer       = iAnds.Name;
                    rid.SerialNumber = iAnds.SerialNumber.Value;
                }
            }
            catch (IOException)
            {
                throw new ArgumentException("invalid rid in KeyTransRecipientInformation");
            }
        }
        public static IssuerAndSerialNumber GetInstance(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            IssuerAndSerialNumber existing = obj as IssuerAndSerialNumber;

            if (existing != null)
            {
                return(existing);
            }
            return(new IssuerAndSerialNumber(Asn1Sequence.GetInstance(obj)));
        }
        internal SignerInformation(
            SignerInfo info,
            DerObjectIdentifier contentType,
            CmsProcessable content,
            IDigestCalculator digestCalculator)
        {
            this.info               = info;
            this.sid                = new SignerID();
            this.contentType        = contentType;
            this.isCounterSignature = contentType == null;

            try
            {
                SignerIdentifier s = info.SignerID;

                if (s.IsTagged)
                {
                    Asn1OctetString octs = Asn1OctetString.GetInstance(s.ID);

                    sid.SubjectKeyIdentifier = octs.GetEncoded();
                }
                else
                {
                    IssuerAndSerialNumber iAnds =
                        IssuerAndSerialNumber.GetInstance(s.ID);

                    sid.Issuer       = iAnds.Name;
                    sid.SerialNumber = iAnds.SerialNumber.Value;
                }
            }
            catch (IOException)
            {
                throw new ArgumentException("invalid sid in SignerInfo");
            }

            this.digestAlgorithm      = info.DigestAlgorithm;
            this.signedAttributeSet   = info.AuthenticatedAttributes;
            this.unsignedAttributeSet = info.UnauthenticatedAttributes;
            this.encryptionAlgorithm  = info.DigestEncryptionAlgorithm;
            this.signature            = info.EncryptedDigest.GetOctets();

            this.content          = content;
            this.digestCalculator = digestCalculator;
        }
        /**
         * return an KeyAgreeRecipientIdentifier object from the given object.
         *
         * @param obj the object we want converted.
         * @exception ArgumentException if the object cannot be converted.
         */
        public static KeyAgreeRecipientIdentifier GetInstance(
            object obj)
        {
            if (obj == null || obj is KeyAgreeRecipientIdentifier)
            {
                return((KeyAgreeRecipientIdentifier)obj);
            }

            if (obj is Asn1Sequence)
            {
                return(new KeyAgreeRecipientIdentifier(IssuerAndSerialNumber.GetInstance(obj)));
            }

            if (obj is Asn1TaggedObject && ((Asn1TaggedObject)obj).TagNo == 0)
            {
                return(new KeyAgreeRecipientIdentifier(RecipientKeyIdentifier.GetInstance(
                                                           (Asn1TaggedObject)obj, false)));
            }

            throw new ArgumentException("Invalid KeyAgreeRecipientIdentifier: " + Platform.GetTypeName(obj), "obj");
        }
Beispiel #6
0
        internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info,
                                               CmsSecureReadable secureReadable)
        {
            try
            {
                foreach (Asn1Encodable rek in info.RecipientEncryptedKeys)
                {
                    RecipientEncryptedKey id = RecipientEncryptedKey.GetInstance(rek.ToAsn1Object());

                    RecipientID rid = new RecipientID();

                    KeyAgreeRecipientIdentifier karid = id.Identifier;

                    IssuerAndSerialNumber iAndSN = karid.IssuerAndSerialNumber;
                    if (iAndSN != null)
                    {
                        rid.Issuer       = iAndSN.Name;
                        rid.SerialNumber = iAndSN.SerialNumber.Value;
                    }
                    else
                    {
                        RecipientKeyIdentifier rKeyID = karid.RKeyID;

                        // Note: 'date' and 'other' fields of RecipientKeyIdentifier appear to be only informational

                        rid.SubjectKeyIdentifier = rKeyID.SubjectKeyIdentifier.GetOctets();
                    }

                    infos.Add(new KeyAgreeRecipientInformation(info, rid, id.EncryptedKey,
                                                               secureReadable));
                }
            }
            catch (IOException e)
            {
                throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", e);
            }
        }
 public RecipientIdentifier(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
Beispiel #8
0
 public OriginatorIdentifierOrKey(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
Beispiel #9
0
 public SignerIdentifier(
     IssuerAndSerialNumber id)
 {
     this.id = id;
 }
 public KeyAgreeRecipientIdentifier(
     IssuerAndSerialNumber issuerSerial)
 {
     this.issuerSerial = issuerSerial;
 }