コード例 #1
0
        internal static void ReadUserIDs(
            BcpgInputStream bcpgInput,
            out ArrayList ids,
            out ArrayList idTrusts,
            out ArrayList idSigs)
        {
            ids      = new ArrayList();
            idTrusts = new ArrayList();
            idSigs   = new ArrayList();

            while (bcpgInput.NextPacketTag() == PacketTag.UserId ||
                   bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
            {
                Packet obj = bcpgInput.ReadPacket();
                if (obj is UserIdPacket)
                {
                    UserIdPacket id = (UserIdPacket)obj;
                    ids.Add(id.GetId());
                }
                else
                {
                    UserAttributePacket user = (UserAttributePacket)obj;
                    ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets()));
                }

                idTrusts.Add(
                    ReadOptionalTrustPacket(bcpgInput));

                idSigs.Add(
                    ReadSignaturesAndTrust(bcpgInput));
            }
        }
コード例 #2
0
        internal static void ReadUserIDs(
            BcpgInputStream bcpgInput,
            out IList ids,
            out IList idTrusts,
            out IList idSigs)
        {
            ids      = Platform.CreateArrayList();
            idTrusts = Platform.CreateArrayList();
            idSigs   = Platform.CreateArrayList();

            // EDDINGTON
            try
            {
                while (bcpgInput.NextPacketTag() == PacketTag.UserId ||
                       bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
                {
                    Packet obj = bcpgInput.ReadPacket();
                    if (obj is UserIdPacket)
                    {
                        UserIdPacket id = (UserIdPacket)obj;
                        ids.Add(id.GetId());
                    }
                    else
                    {
                        UserAttributePacket user = (UserAttributePacket)obj;
                        ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets()));
                    }

                    idTrusts.Add(
                        ReadOptionalTrustPacket(bcpgInput));

                    idSigs.Add(
                        ReadSignaturesAndTrust(bcpgInput));
                }
            }
            catch (Exception ex)
            {
                // EDDINGTON
                logger.Debug("ReadUserIDs: Exception occured: {0}", ex.Message);
                foreach (var id in ids)
                {
                    var sid = id.ToString();
                    if (id is UserIdPacket)
                    {
                        sid = ((UserIdPacket)id).GetId();
                    }

                    logger.Debug("ReadUserIDs: ID: {0}", sid);
                }

                throw;
            }
        }
コード例 #3
0
ファイル: PgpCertification.cs プロジェクト: 1hub/springburg
        // FIXME: This method is too advanced
        public static PgpCertification GenerateUserCertification(
            PgpSignatureType signatureType,
            PgpKey signingKey,
            PgpPrivateKey signingPrivateKey,
            PgpUserAttributes userAttributes,
            PgpKey userPublicKey,
            PgpSignatureAttributes?hashedAttributes   = null,
            PgpSignatureAttributes?unhashedAttributes = null,
            PgpHashAlgorithm hashAlgorithm            = PgpHashAlgorithm.Sha1)
        {
            if (signingKey == null)
            {
                throw new ArgumentNullException(nameof(signingKey));
            }
            if (signingPrivateKey == null)
            {
                throw new ArgumentNullException(nameof(signingPrivateKey));
            }
            if (signingKey.KeyId != signingPrivateKey.KeyId)
            {
                throw new ArgumentException(SR.Cryptography_OpenPgp_SigningKeyIdMismatch);
            }
            if (userAttributes == null)
            {
                throw new ArgumentNullException(nameof(userAttributes));
            }
            if (userPublicKey == null)
            {
                throw new ArgumentNullException(nameof(userPublicKey));
            }

            var userPacket         = new UserAttributePacket(userAttributes.ToSubpacketArray());
            var signatureGenerator = new PgpSignatureGenerator(signatureType, signingPrivateKey, hashAlgorithm);

            if (hashedAttributes != null)
            {
                signatureGenerator.HashedAttributes = hashedAttributes;
            }
            if (unhashedAttributes != null)
            {
                signatureGenerator.UnhashedAttributes = unhashedAttributes;
            }
            var signature = signatureGenerator.Generate(GenerateCertificationData(signingKey, userPacket, userPublicKey));

            return(new PgpCertification(signature, userPacket, userPublicKey));
        }
コード例 #4
0
 internal static void ReadUserIDs(BcpgInputStream bcpgInput, out IList ids, out IList idTrusts, out IList idSigs)
 {
     ids      = Platform.CreateArrayList();
     idTrusts = Platform.CreateArrayList();
     idSigs   = Platform.CreateArrayList();
     while (bcpgInput.NextPacketTag() == PacketTag.UserId || bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
     {
         Packet packet = bcpgInput.ReadPacket();
         if (packet is UserIdPacket)
         {
             UserIdPacket userIdPacket = (UserIdPacket)packet;
             ids.Add(userIdPacket.GetId());
         }
         else
         {
             UserAttributePacket userAttributePacket = (UserAttributePacket)packet;
             ids.Add(new PgpUserAttributeSubpacketVector(userAttributePacket.GetSubpackets()));
         }
         idTrusts.Add(ReadOptionalTrustPacket(bcpgInput));
         idSigs.Add(ReadSignaturesAndTrust(bcpgInput));
     }
 }
コード例 #5
0
        public PgpSecretKeyRing(
            Stream inputStream)
        {
            this.keys = new ArrayList();

            BcpgInputStream bcpgInput  = BcpgInputStream.Wrap(inputStream);
            PacketTag       initialTag = bcpgInput.NextPacketTag();

            if (initialTag != PacketTag.SecretKey && initialTag != PacketTag.SecretSubkey)
            {
                throw new IOException(
                          "secret key ring doesn't start with secret key tag: " +
                          "tag 0x" + initialTag.ToString("X"));
            }

            SecretKeyPacket secret   = (SecretKeyPacket)bcpgInput.ReadPacket();
            TrustPacket     trust    = null;
            ArrayList       keySigs  = new ArrayList();
            ArrayList       ids      = new ArrayList();
            ArrayList       idTrusts = new ArrayList();
            ArrayList       idSigs   = new ArrayList();
            IDigest         sha;

            try
            {
                sha = DigestUtilities.GetDigest("SHA1");
            }
            catch (Exception)
            {
                throw new IOException("can't find SHA1 digest");
            }

            //
            // ignore GPG comment packets if found.
            //
            while (bcpgInput.NextPacketTag() == PacketTag.Experimental2)
            {
                bcpgInput.ReadPacket();
            }

            if (bcpgInput.NextPacketTag() == PacketTag.Trust)
            {
                trust = (TrustPacket)bcpgInput.ReadPacket();  // ignore for the moment
            }

            //
            // revocation and direct signatures
            //
            while (bcpgInput.NextPacketTag() == PacketTag.Signature)
            {
                try
                {
                    keySigs.Add(new PgpSignature(bcpgInput));
                }
                catch (PgpException e)
                {
                    throw new IOException("can't create signature object: " + e.Message + ", cause: " + e.InnerException.ToString());
                }
            }

            while (bcpgInput.NextPacketTag() == PacketTag.UserId ||
                   bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
            {
                object    obj     = bcpgInput.ReadPacket();
                ArrayList sigList = new ArrayList();

                if (obj is UserIdPacket)
                {
                    UserIdPacket id = (UserIdPacket)obj;
                    ids.Add(id.GetId());
                }
                else
                {
                    UserAttributePacket user = (UserAttributePacket)obj;
                    ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets()));
                }

                if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                {
                    idTrusts.Add(bcpgInput.ReadPacket());
                }
                else
                {
                    idTrusts.Add(null);
                }

                idSigs.Add(sigList);

                while (bcpgInput.NextPacketTag() == PacketTag.Signature)
                {
                    SignaturePacket s = (SignaturePacket)bcpgInput.ReadPacket();

                    if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                    {
                        sigList.Add(new PgpSignature(s, (TrustPacket)bcpgInput.ReadPacket()));
                    }
                    else
                    {
                        sigList.Add(new PgpSignature(s));
                    }
                }
            }

            keys.Add(new PgpSecretKey(secret, trust, sha, keySigs, ids, idTrusts, idSigs));

            while (bcpgInput.NextPacketTag() == PacketTag.SecretSubkey)
            {
                SecretSubkeyPacket sub      = (SecretSubkeyPacket)bcpgInput.ReadPacket();
                TrustPacket        subTrust = null;
                ArrayList          sigList  = new ArrayList();

                //
                // ignore GPG comment packets if found.
                //
                while (bcpgInput.NextPacketTag() == PacketTag.Experimental2)
                {
                    bcpgInput.ReadPacket();
                }

                if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                {
                    subTrust = (TrustPacket)bcpgInput.ReadPacket();
                }

                while (bcpgInput.NextPacketTag() == PacketTag.Signature)
                {
                    SignaturePacket s = (SignaturePacket)bcpgInput.ReadPacket();

                    if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                    {
                        sigList.Add(new PgpSignature(s, (TrustPacket)bcpgInput.ReadPacket()));
                    }
                    else
                    {
                        sigList.Add(new PgpSignature(s));
                    }
                }

                keys.Add(new PgpSecretKey(sub, subTrust, sha, sigList));
            }
        }
コード例 #6
0
        public PgpPublicKeyRing(
            Stream inputStream)
        {
            this.keys = new ArrayList();

            BcpgInputStream bcpgInput = BcpgInputStream.Wrap(inputStream);

            PacketTag initialTag = bcpgInput.NextPacketTag();

            if (initialTag != PacketTag.PublicKey && initialTag != PacketTag.PublicSubkey)
            {
                throw new IOException(
                          "public key ring doesn't start with public key tag: " +
                          "tag 0x" + initialTag.ToString("X"));
            }

            PublicKeyPacket pubPk;
            TrustPacket     trustPk;
            ArrayList       keySigs = new ArrayList();
            ArrayList       ids     = new ArrayList();
            ArrayList       idTrust = new ArrayList();
            ArrayList       idSigs  = new ArrayList();

            pubPk   = (PublicKeyPacket)bcpgInput.ReadPacket();
            trustPk = null;
            if (bcpgInput.NextPacketTag() == PacketTag.Trust)
            {
                trustPk = (TrustPacket)bcpgInput.ReadPacket();
            }

            //
            // direct signatures and revocations
            //
            while (bcpgInput.NextPacketTag() == PacketTag.Signature)
            {
                try
                {
                    SignaturePacket s = (SignaturePacket)bcpgInput.ReadPacket();

                    if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                    {
                        keySigs.Add(new PgpSignature(s, (TrustPacket)bcpgInput.ReadPacket()));
                    }
                    else
                    {
                        keySigs.Add(new PgpSignature(s));
                    }
                }
                catch (PgpException e)
                {
                    throw new IOException("can't create signature object: " + e.Message + ", cause: " + e.InnerException.ToString());
                }
            }

            while (bcpgInput.NextPacketTag() == PacketTag.UserId ||
                   bcpgInput.NextPacketTag() == PacketTag.UserAttribute)
            {
                object obj = bcpgInput.ReadPacket();

                if (obj is UserIdPacket)
                {
                    UserIdPacket id = (UserIdPacket)obj;
                    ids.Add(id.GetId());
                }
                else
                {
                    UserAttributePacket user = (UserAttributePacket)obj;
                    ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets()));
                }

                if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                {
                    idTrust.Add(bcpgInput.ReadPacket());
                }
                else
                {
                    idTrust.Add(null);
                }

                ArrayList sigList = new ArrayList();

                idSigs.Add(sigList);

                while (bcpgInput.NextPacketTag() == PacketTag.Signature)
                {
                    try
                    {
                        SignaturePacket s    = (SignaturePacket)bcpgInput.ReadPacket();
                        PacketTag       next = bcpgInput.NextPacketTag();
                        TrustPacket     tp   = (next == PacketTag.Trust)
                            ?    (TrustPacket)bcpgInput.ReadPacket()
                            :    null;

                        PgpSignature pgpSig = new PgpSignature(s, tp);
                        sigList.Add(pgpSig);
                    }
                    catch (PgpException e)
                    {
                        throw new IOException("can't create signature object: " + e.Message + ", cause: " + e.InnerException.ToString());
                    }
                }
            }

            keys.Add(new PgpPublicKey(pubPk, trustPk, keySigs, ids, idTrust, idSigs));

            while (bcpgInput.NextPacketTag() == PacketTag.PublicSubkey)
            {
                PublicKeyPacket pk     = (PublicKeyPacket)bcpgInput.ReadPacket();
                TrustPacket     kTrust = null;

                if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                {
                    kTrust = (TrustPacket)bcpgInput.ReadPacket();
                }

                ArrayList sigList = new ArrayList();

                try
                {
                    //
                    // PGP 8 actually leaves out the signature.
                    //
                    while (bcpgInput.NextPacketTag() == PacketTag.Signature)
                    {
                        SignaturePacket s = (SignaturePacket)bcpgInput.ReadPacket();

                        if (bcpgInput.NextPacketTag() == PacketTag.Trust)
                        {
                            sigList.Add(new PgpSignature(s, (TrustPacket)bcpgInput.ReadPacket()));
                        }
                        else
                        {
                            sigList.Add(new PgpSignature(s));
                        }
                    }
                }
                catch (PgpException e)
                {
                    throw new IOException("can't create signature object: " + e.Message + ", cause: " + e.InnerException.ToString());
                }

                keys.Add(new PgpPublicKey(pk, kTrust, sigList));
            }
        }