Esempio n. 1
0
        public override void Parse(TreeBuilder tree)
        {
            tree.SetBookMark();
            Version = tree.ReadByte("Version");
            tree.ReadFormatted("Creation Time", BlockFormat.UnixTime);
            if (Version == 2 || Version == 3 || Version == 4)
            {
                if (Version != 4)
                {
                    tree.ReadNumber("Days Valid", 2);
                }
            }
            else
            {
                throw new NotImplementedException("Unknown Public Key Packet Version Code: " + Version.ToString());
            }

            byte AlgoCode = tree.ReadByte("Public Key Algorithm", PKAlgorithmTypes.Get);

            PublicKeyAlgorithm = PKAlgorithm.CreatePKAlgorithm(AlgoCode);

            if (PublicKeyAlgorithm == null)
            {
                tree.ReadBytes("Unknown Public Key Algorithm");
                return;
            }

            PublicKeyAlgorithm.LoadPublicKey(tree);
            PacketDataPublicKey = tree.ReadBytesFromBookMark();


            if (Version < 4)
            {
                // Only RSA is supported
                var ModN = ((RSA)PublicKeyAlgorithm).ModN;
                //KeyId = BitConverter.ToString(ModN, ModN.Length - 8);
                KeyId = ModN.SubArray(ModN.Length - 8, 8);
            }
            else
            {
                int  l    = PacketDataPublicKey.Length;
                SHA1 shaM = new SHA1Managed();

                byte[] HashContext = new byte[l + 3];
                HashContext[0] = 0x99;
                HashContext[1] = (byte)((l & 0xFF00) >> 8);
                HashContext[2] = (byte)(l & 0x00FF);
                Array.Copy(PacketDataPublicKey, 0, HashContext, 3, l);
                byte[] result = shaM.ComputeHash(HashContext);
                //KeyId = BitConverter.ToString(result, result.Length - 8);
                KeyId = result.SubArray(result.Length - 8, 8);
            }
            tree.AddCalculated("Key Id", BitConverter.ToString(KeyId), KeyId);
        }
Esempio n. 2
0
        public override void Parse(TreeBuilder tree)
        {
            tree.ReadByte("Data Format", true);
            byte FileNameLength = tree.ReadByte();

            byte[] FileNameBytes = tree.ReadBytes("File Name", FileNameLength, true);

            ExtractFileName = System.Text.Encoding.UTF8.GetString(FileNameBytes);

            tree.ReadFormatted("Date/Time", BlockFormat.UnixTime);
            tree.RemainingBytes("Literal Data");

            ThisBlock = tree.CurrentBlock;
            ThisBlock.ProcessBlock += ExtractData;
        }
Esempio n. 3
0
        public void Parse(TreeBuilder tree, int SubPacketsLength)
        {
            long SubPacketsEnd = tree.BaseReader.Position + SubPacketsLength;

            tree.PushByteBlock();

            //if (tree.Position < SubPacketsEnd)
            //    tree.AddChildLevel = true;

            while (tree.BaseReader.Position < SubPacketsEnd)
            {
                byte LengthFinder    = tree.ReadByte();
                uint SubPacketLength = 0;

                if (LengthFinder < 192)
                {
                    SubPacketLength = LengthFinder;
                }
                else if (LengthFinder < 255)
                {
                    byte b = tree.ReadByte();
                    SubPacketLength = (uint)((LengthFinder - 192) << 8) + b + 192;
                }
                else
                {
                    byte[] b = new byte[4];
                    b[0]            = tree.ReadByte();
                    b[1]            = tree.ReadByte();
                    b[2]            = tree.ReadByte();
                    b[3]            = tree.ReadByte();
                    SubPacketLength = Program.GetBigEndian(b, 0, 4);
                }

                byte   SubPacketType = tree.ReadByte();
                string Label         = SignatureSubPacketTypes.Get(SubPacketType);

                int DataLength = (int)SubPacketLength - 1;

                if (SubPacketType == SignatureSubPacketTypes.SignatureCreationTime)
                {
                    tree.ReadFormatted(Label, BlockFormat.UnixTime);
                }
                else if (SubPacketType == SignatureSubPacketTypes.Issuer)
                {
                    Issuer = tree.ReadBytes(Label, 8);
                }
                else if (SubPacketType == SignatureSubPacketTypes.KeyExpirationTime)
                {
                    tree.ReadFormatted(Label, BlockFormat.Days);
                }
                else if (SubPacketType == SignatureSubPacketTypes.PreferredSymmetricAlgorithm)
                {
                    ReadByteTags(tree, Label, DataLength, SymmetricAlgorithmTypes.Get);
                }
                else if (SubPacketType == SignatureSubPacketTypes.PreferredHashAlgorithm)
                {
                    ReadByteTags(tree, Label, DataLength, HashAlgorithmTypes.Get);
                }
                else if (SubPacketType == SignatureSubPacketTypes.PreferredCompressionAlgorithm)
                {
                    ReadByteTags(tree, Label, DataLength, CompressionAlgorithmTypes.Get);
                }
                else if (SubPacketType == SignatureSubPacketTypes.KeyFlags)
                {
                    ReadByteTags(tree, Label, DataLength, KeyFlagsTypes.Get);
                }
                else if (SubPacketType == SignatureSubPacketTypes.PrimaryUserId)
                {
                    tree.ReadBytes(Label, DataLength);
                }
                else if (SubPacketType == SignatureSubPacketTypes.ReasonForRevocation)
                {
                    tree.AddNode(Label);
                    tree.PushByteBlock();
                    tree.ReadByte("Reason", RevocationReasonTypes.Get);
                    tree.ReadBytes("Message", DataLength - 1);
                    tree.PopByteBlock();
                }
                else
                {
                    tree.ReadBytes(Label, DataLength);
                }
            }

            tree.PopByteBlock();
        }