Exemplo n.º 1
0
 /// <summary>Remove a certification associated with a given user attributes on a key.</summary>
 /// <param name="key">The key the certifications are to be removed from.</param>
 /// <param name="userAttributes">The user attributes that the certfication is to be removed from.</param>
 /// <param name="certification">The certification to be removed.</param>
 /// <returns>The re-certified key, or null if the certification was not found.</returns>
 public static PgpPublicKey RemoveCertification(
     PgpPublicKey key,
     PgpUserAttributeSubpacketVector userAttributes,
     PgpSignature certification)
 {
     return(RemoveCert(key, userAttributes, certification));
 }
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            PgpUserAttributeSubpacketVector other = obj as PgpUserAttributeSubpacketVector;

            if (other == null)
            {
                return(false);
            }

            if (other.packets.Length != packets.Length)
            {
                return(false);
            }

            for (int i = 0; i != packets.Length; i++)
            {
                if (!other.packets[i].Equals(packets[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>Generate a certification for the passed in userAttributes.</summary>
        /// <param name="userAttributes">The ID we are certifying against the public key.</param>
        /// <param name="pubKey">The key we are certifying against the ID.</param>
        /// <returns>The certification.</returns>
        public PgpSignature GenerateCertification(
            PgpUserAttributeSubpacketVector userAttributes,
            PgpPublicKey pubKey)
        {
            UpdateWithPublicKey(pubKey);

            //
            // hash in the attributes
            //
            try
            {
                MemoryStream bOut = new MemoryStream();
                foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
                {
                    packet.Encode(bOut);
                }
                UpdateWithIdData(0xd1, bOut.ToArray());
            }
            catch (IOException e)
            {
                throw new PgpException("cannot encode subpacket array", e);
            }

            return(this.Generate());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Verify the signature as certifying the passed in public key as associated
        /// with the passed in user attributes.
        /// </summary>
        /// <param name="userAttributes">User attributes the key was stored under.</param>
        /// <param name="key">The key to be verified.</param>
        /// <returns>True, if the signature matches, false otherwise.</returns>
        public bool VerifyCertification(
            PgpUserAttributeSubpacketVector userAttributes,
            PgpPublicKey key)
        {
            UpdateWithPublicKey(key);

            //
            // hash in the userAttributes
            //
            try
            {
                MemoryStream bOut = new MemoryStream();
                foreach (UserAttributeSubpacket packet in userAttributes.ToSubpacketArray())
                {
                    packet.Encode(bOut);
                }
                UpdateWithIdData(0xd1, bOut.ToArray());
            }
            catch (IOException e)
            {
                throw new PgpException("cannot encode subpacket array", e);
            }

            this.Update(sigPck.GetSignatureTrailer());

            return(verifier.GetResult().IsVerified(this.GetSignature()));
        }
Exemplo n.º 5
0
        public void Encode(
            Stream outStream)
        {
            BcpgOutputStream output = BcpgOutputStream.Wrap(outStream);

            output.WritePacket(secret);
            if (pub.trustPk != null)
            {
                output.WritePacket(pub.trustPk);
            }

            if (pub.subSigs == null)        // is not a sub key
            {
                for (int i = 0; i != pub.keySigs.Count; i++)
                {
                    ((PgpSignature)pub.keySigs[i]).Encode(output);
                }

                for (int i = 0; i != pub.ids.Count; i++)
                {
                    if (pub.ids[i] is UserIdPacket)
                    {
                        UserIdPacket id = (UserIdPacket)pub.ids[i];

                        output.WritePacket(id);
                    }
                    else
                    {
                        PgpUserAttributeSubpacketVector v = (PgpUserAttributeSubpacketVector)pub.ids[i];

                        output.WritePacket(new UserAttributePacket(v.ToSubpacketArray()));
                    }

                    if (pub.idTrusts[i] != null)
                    {
                        output.WritePacket((ContainedPacket)pub.idTrusts[i]);
                    }

                    List <PgpSignature> sigs = pub.idSigs[i];

                    for (int j = 0; j != sigs.Count; j++)
                    {
                        sigs[j].Encode(output);
                    }
                }
            }
            else
            {
                for (int j = 0; j != pub.subSigs.Count; j++)
                {
                    ((PgpSignature)pub.subSigs[j]).Encode(output);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>Allows enumeration of signatures associated with the passed in user attributes.</summary>
        /// <param name="userAttributes">The vector of user attributes to be matched.</param>
        /// <returns>An <c>IEnumerable</c> of <c>PgpSignature</c> objects.</returns>
        public IEnumerable GetSignaturesForUserAttribute(
            PgpUserAttributeSubpacketVector userAttributes)
        {
            for (int i = 0; i != ids.Count; i++)
            {
                if (userAttributes.Equals(ids[i]))
                {
                    return(new EnumerableProxy <PgpSignature>((IList <PgpSignature>)idSigs[i]));
                }
            }

            return(null);
        }
Exemplo n.º 7
0
        public void Encode(
            Stream outStr)
        {
            BcpgOutputStream bcpgOut = BcpgOutputStream.Wrap(outStr);

            bcpgOut.WritePacket(publicPk);
            if (trustPk != null)
            {
                bcpgOut.WritePacket(trustPk);
            }

            if (subSigs == null)    // not a sub-key
            {
                foreach (PgpSignature keySig in keySigs)
                {
                    keySig.Encode(bcpgOut);
                }

                for (int i = 0; i != ids.Count; i++)
                {
                    if (ids[i] is string)
                    {
                        string id = (string)ids[i];

                        bcpgOut.WritePacket(new UserIdPacket(id));
                    }
                    else
                    {
                        PgpUserAttributeSubpacketVector v = (PgpUserAttributeSubpacketVector)ids[i];
                        bcpgOut.WritePacket(new UserAttributePacket(v.ToSubpacketArray()));
                    }

                    if (idTrusts[i] != null)
                    {
                        bcpgOut.WritePacket((ContainedPacket)idTrusts[i]);
                    }

                    foreach (PgpSignature sig in (IList)idSigs[i])
                    {
                        sig.Encode(bcpgOut);
                    }
                }
            }
            else
            {
                foreach (PgpSignature subSig in subSigs)
                {
                    subSig.Encode(bcpgOut);
                }
            }
        }