コード例 #1
0
        internal PgpEncryptedMessage(IPacketReader packetReader)
        {
            this.packetReader = packetReader;
            this.publicKeyEncSessionPackets    = new List <PublicKeyEncSessionPacket>();
            this.symmetricKeyEncSessionPackets = new List <SymmetricKeyEncSessionPacket>();

            while (packetReader.NextPacketTag() == PacketTag.PublicKeyEncryptedSession ||
                   packetReader.NextPacketTag() == PacketTag.SymmetricKeyEncryptedSessionKey)
            {
                var keyPacket = packetReader.ReadContainedPacket();
                if (keyPacket is SymmetricKeyEncSessionPacket symmetricKeyEncSessionPacket)
                {
                    symmetricKeyEncSessionPackets.Add(symmetricKeyEncSessionPacket);
                }
                else
                {
                    publicKeyEncSessionPackets.Add((PublicKeyEncSessionPacket)keyPacket);
                }
            }

            var packet = packetReader.ReadStreamablePacket();

            if (!(packet.Packet is SymmetricEncDataPacket) &&
                !(packet.Packet is SymmetricEncIntegrityPacket))
            {
                throw new IOException("unexpected packet in stream: " + packet);
            }

            this.encryptedPacket = packet.Packet;
            this.inputStream     = packet.Stream;
        }
コード例 #2
0
ファイル: PgpMessage.cs プロジェクト: 1hub/springburg
        public static PgpMessage ReadMessage(IPacketReader packetReader)
        {
            // Skip over marker packets
            while (IsSkippablePacket(packetReader.NextPacketTag()))
            {
                packetReader.ReadContainedPacket();
            }

            switch (packetReader.NextPacketTag())
            {
            case PacketTag.Signature:
            case PacketTag.OnePassSignature:
                return(new PgpSignedMessage(packetReader));

            case PacketTag.CompressedData:
                return(new PgpCompressedMessage(packetReader));

            case PacketTag.LiteralData:
                return(new PgpLiteralMessage(packetReader));

            case PacketTag.PublicKeyEncryptedSession:
            case PacketTag.SymmetricKeyEncryptedSessionKey:
                return(new PgpEncryptedMessage(packetReader));

            default:
                throw new PgpUnexpectedPacketException();
            }
        }
コード例 #3
0
        public PgpSecretKeyRing(IPacketReader packetReader)
        {
            this.keys         = new List <PgpSecretKey>();
            this.extraPubKeys = new List <PgpPublicKey>();

            PacketTag initialTag = packetReader.NextPacketTag();

            if (initialTag != PacketTag.SecretKey && initialTag != PacketTag.SecretSubkey)
            {
                throw new PgpUnexpectedPacketException();
            }

            SecretKeyPacket secret = (SecretKeyPacket)packetReader.ReadContainedPacket();

            keys.Add(new PgpSecretKey(packetReader, secret, subKey: false));

            // Read subkeys
            while (packetReader.NextPacketTag() == PacketTag.SecretSubkey || packetReader.NextPacketTag() == PacketTag.PublicSubkey)
            {
                if (packetReader.NextPacketTag() == PacketTag.SecretSubkey)
                {
                    SecretSubkeyPacket sub = (SecretSubkeyPacket)packetReader.ReadContainedPacket();
                    keys.Add(new PgpSecretKey(packetReader, sub, subKey: true));
                }
                else
                {
                    PublicSubkeyPacket sub = (PublicSubkeyPacket)packetReader.ReadContainedPacket();
                    extraPubKeys.Add(new PgpPublicKey(packetReader, sub, subKey: true));
                }
            }
        }
コード例 #4
0
ファイル: PgpUser.cs プロジェクト: 1hub/springburg
        internal PgpUser(IPacketReader packetReader, PgpKey publicKey)
        {
            Debug.Assert(packetReader.NextPacketTag() == PacketTag.UserId || packetReader.NextPacketTag() == PacketTag.UserAttribute);

            //this.publicKey = publicKey;
            this.userPacket  = packetReader.ReadContainedPacket();
            this.trustPacket = packetReader.NextPacketTag() == PacketTag.Trust ? (TrustPacket)packetReader.ReadContainedPacket() : null;

            selfCertifications   = new List <PgpCertification>();
            otherCertifications  = new List <PgpCertification>();
            revocationSignatures = new List <PgpCertification>();

            while (packetReader.NextPacketTag() == PacketTag.Signature)
            {
                var signaturePacket      = (SignaturePacket)packetReader.ReadContainedPacket();
                var signatureTrustPacket = packetReader.NextPacketTag() == PacketTag.Trust ? (TrustPacket)packetReader.ReadContainedPacket() : null;
                var signature            = new PgpSignature(signaturePacket, signatureTrustPacket);
                AddCertification(publicKey, signature);
            }
        }
コード例 #5
0
ファイル: PgpKey.cs プロジェクト: 1hub/springburg
        private protected PgpKey(IPacketReader packetReader, KeyPacket keyPacket, bool subKey)
            : this(keyPacket)
        {
            // Ignore GPG comment packets if found.
            while (packetReader.NextPacketTag() == PacketTag.Experimental2)
            {
                packetReader.ReadContainedPacket();
            }

            this.trustPacket = packetReader.NextPacketTag() == PacketTag.Trust ? (TrustPacket)packetReader.ReadContainedPacket() : null;

            while (packetReader.NextPacketTag() == PacketTag.Signature)
            {
                SignaturePacket signaturePacket      = (SignaturePacket)packetReader.ReadContainedPacket();
                TrustPacket?    signatureTrustPacket = packetReader.NextPacketTag() == PacketTag.Trust ? (TrustPacket)packetReader.ReadContainedPacket() : null;
                var             signature            = new PgpSignature(signaturePacket, signatureTrustPacket);
                this.keyCertifications.Add(new PgpCertification(signature, null, this));
            }

            if (!subKey)
            {
                while (packetReader.NextPacketTag() == PacketTag.UserId ||
                       packetReader.NextPacketTag() == PacketTag.UserAttribute)
                {
                    ids.Add(new PgpUser(packetReader, this));
                }
            }
        }
コード例 #6
0
        public PgpPublicKeyRingBundle(IPacketReader packetReader)
        {
            this.pubRings = new Dictionary <long, PgpPublicKeyRing>();
            this.order    = new List <long>();

            while (packetReader.NextPacketTag() == PacketTag.PublicKey)
            {
                var  keyRing = new PgpPublicKeyRing(packetReader);
                long key     = keyRing.GetPublicKey().KeyId;
                pubRings.Add(key, keyRing);
                order.Add(key);
            }
        }
コード例 #7
0
ファイル: PgpPublicKeyRing.cs プロジェクト: 1hub/springburg
        public PgpPublicKeyRing(IPacketReader packetReader)
        {
            this.keys = new List <PgpPublicKey>();

            PacketTag initialTag = packetReader.NextPacketTag();

            if (initialTag != PacketTag.PublicKey && initialTag != PacketTag.PublicSubkey)
            {
                throw new PgpUnexpectedPacketException();
            }

            PublicKeyPacket pubPk = (PublicKeyPacket)packetReader.ReadContainedPacket();

            keys.Add(new PgpPublicKey(packetReader, pubPk, subKey: false));

            // Read subkeys
            while (packetReader.NextPacketTag() == PacketTag.PublicSubkey)
            {
                pubPk = (PublicSubkeyPacket)packetReader.ReadContainedPacket();
                keys.Add(new PgpPublicKey(packetReader, pubPk, subKey: true));
            }
        }
コード例 #8
0
ファイル: PgpSignedMessage.cs プロジェクト: 1hub/springburg
 public PacketTag NextPacketTag() => innerReader.NextPacketTag();