Beispiel #1
0
    public MPInteger(BcpgInputStream bcpgIn)
    {
        if (bcpgIn == null)
        {
            throw new ArgumentNullException("bcpgIn");
        }
        int num = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();

        byte[] array = new byte[(num + 7) / 8];
        bcpgIn.ReadFully(array);
        val = new BigInteger(1, array);
    }
    internal LiteralDataPacket(BcpgInputStream bcpgIn)
        : base(bcpgIn)
    {
        format = bcpgIn.ReadByte();
        int num = bcpgIn.ReadByte();

        fileName = new byte[num];
        for (int i = 0; i != num; i++)
        {
            fileName[i] = (byte)bcpgIn.ReadByte();
        }
        modDate = (long)(uint)((bcpgIn.ReadByte() << 24) | (bcpgIn.ReadByte() << 16) | (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte()) * 1000L;
    }
    internal PublicKeyEncSessionPacket(BcpgInputStream bcpgIn)
    {
        version   = bcpgIn.ReadByte();
        keyId    |= (long)bcpgIn.ReadByte() << 56;
        keyId    |= (long)bcpgIn.ReadByte() << 48;
        keyId    |= (long)bcpgIn.ReadByte() << 40;
        keyId    |= (long)bcpgIn.ReadByte() << 32;
        keyId    |= (long)bcpgIn.ReadByte() << 24;
        keyId    |= (long)bcpgIn.ReadByte() << 16;
        keyId    |= (long)bcpgIn.ReadByte() << 8;
        keyId    |= (uint)bcpgIn.ReadByte();
        algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
        switch (algorithm)
        {
        case PublicKeyAlgorithmTag.RsaGeneral:
        case PublicKeyAlgorithmTag.RsaEncrypt:
            data = new byte[1][]
            {
                new MPInteger(bcpgIn).GetEncoded()
            };
            break;

        case PublicKeyAlgorithmTag.ElGamalEncrypt:
        case PublicKeyAlgorithmTag.ElGamalGeneral:
        {
            MPInteger mPInteger  = new MPInteger(bcpgIn);
            MPInteger mPInteger2 = new MPInteger(bcpgIn);
            data = new byte[2][]
            {
                mPInteger.GetEncoded(),
                    mPInteger2.GetEncoded()
            };
            break;
        }

        case PublicKeyAlgorithmTag.EC:
            data = new byte[1][]
            {
                Streams.ReadAll(bcpgIn)
            };
            break;

        default:
            throw new IOException("unknown PGP public key algorithm encountered");
        }
    }
Beispiel #4
0
    public TrustPacket(BcpgInputStream bcpgIn)
    {
        MemoryStream memoryStream = new MemoryStream();
        int          num;

        while ((num = bcpgIn.ReadByte()) >= 0)
        {
            memoryStream.WriteByte((byte)num);
        }
        levelAndTrustAmount = memoryStream.ToArray();
    }
    protected static byte[] ReadBytesOfEncodedLength(BcpgInputStream bcpgIn)
    {
        int num = bcpgIn.ReadByte();

        if (num == 0 || num == 255)
        {
            throw new IOException("future extensions not yet implemented.");
        }
        byte[] array = new byte[num + 2];
        bcpgIn.ReadFully(array, 2, array.Length - 2);
        array[0] = 6;
        array[1] = (byte)num;
        return(array);
    }
Beispiel #6
0
    public ECDHPublicBcpgKey(BcpgInputStream bcpgIn)
        : base(bcpgIn)
    {
        int num = bcpgIn.ReadByte();

        byte[] array = new byte[num];
        if (array.Length != 3)
        {
            throw new InvalidOperationException("kdf parameters size of 3 expected.");
        }
        bcpgIn.ReadFully(array);
        reserved       = array[0];
        hashFunctionId = (HashAlgorithmTag)array[1];
        symAlgorithmId = (SymmetricKeyAlgorithmTag)array[2];
        VerifyHashAlgorithm();
        VerifySymmetricKeyAlgorithm();
    }
 public override int ReadByte()
 {
     do
     {
         if (dataLength != 0)
         {
             int num = m_in.ReadByte();
             if (num < 0)
             {
                 throw new EndOfStreamException("Premature end of stream in PartialInputStream");
             }
             dataLength--;
             return(num);
         }
     }while (partial && ReadPartialDataLength() >= 0);
     return(-1);
 }
Beispiel #8
0
    internal PublicKeyPacket(BcpgInputStream bcpgIn)
    {
        version = bcpgIn.ReadByte();
        time    = (uint)((bcpgIn.ReadByte() << 24) | (bcpgIn.ReadByte() << 16) | (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte());
        if (version <= 3)
        {
            validDays = ((bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte());
        }
        algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
        switch (algorithm)
        {
        case PublicKeyAlgorithmTag.RsaGeneral:
        case PublicKeyAlgorithmTag.RsaEncrypt:
        case PublicKeyAlgorithmTag.RsaSign:
            key = new RsaPublicBcpgKey(bcpgIn);
            break;

        case PublicKeyAlgorithmTag.Dsa:
            key = new DsaPublicBcpgKey(bcpgIn);
            break;

        case PublicKeyAlgorithmTag.ElGamalEncrypt:
        case PublicKeyAlgorithmTag.ElGamalGeneral:
            key = new ElGamalPublicBcpgKey(bcpgIn);
            break;

        case PublicKeyAlgorithmTag.EC:
            key = new ECDHPublicBcpgKey(bcpgIn);
            break;

        case PublicKeyAlgorithmTag.ECDsa:
            key = new ECDsaPublicBcpgKey(bcpgIn);
            break;

        default:
            throw new IOException("unknown PGP public key algorithm encountered");
        }
    }
Beispiel #9
0
 internal OnePassSignaturePacket(BcpgInputStream bcpgIn)
 {
     version       = bcpgIn.ReadByte();
     sigType       = bcpgIn.ReadByte();
     hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
     keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
     keyId        |= (long)bcpgIn.ReadByte() << 56;
     keyId        |= (long)bcpgIn.ReadByte() << 48;
     keyId        |= (long)bcpgIn.ReadByte() << 40;
     keyId        |= (long)bcpgIn.ReadByte() << 32;
     keyId        |= (long)bcpgIn.ReadByte() << 24;
     keyId        |= (long)bcpgIn.ReadByte() << 16;
     keyId        |= (long)bcpgIn.ReadByte() << 8;
     keyId        |= (uint)bcpgIn.ReadByte();
     nested        = bcpgIn.ReadByte();
 }
 internal SymmetricEncIntegrityPacket(BcpgInputStream bcpgIn)
     : base(bcpgIn)
 {
     version = bcpgIn.ReadByte();
 }
Beispiel #11
0
 internal CompressedDataPacket(
     BcpgInputStream bcpgIn)
     : base(bcpgIn)
 {
     this.algorithm = (CompressionAlgorithmTag)bcpgIn.ReadByte();
 }
 internal SymmetricEncIntegrityPacket(BcpgInputStream bcpgIn)
     : base(bcpgIn)
 {
     this.Version = bcpgIn.ReadByte();
 }
Beispiel #13
0
    internal SignaturePacket(BcpgInputStream bcpgIn)
    {
        version = bcpgIn.ReadByte();
        if (version == 3 || version == 2)
        {
            bcpgIn.ReadByte();
            signatureType = bcpgIn.ReadByte();
            creationTime  = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000;
            keyId        |= (long)bcpgIn.ReadByte() << 56;
            keyId        |= (long)bcpgIn.ReadByte() << 48;
            keyId        |= (long)bcpgIn.ReadByte() << 40;
            keyId        |= (long)bcpgIn.ReadByte() << 32;
            keyId        |= (long)bcpgIn.ReadByte() << 24;
            keyId        |= (long)bcpgIn.ReadByte() << 16;
            keyId        |= (long)bcpgIn.ReadByte() << 8;
            keyId        |= (uint)bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
        }
        else
        {
            if (version != 4)
            {
                throw new Exception("unsupported version: " + version);
            }
            signatureType = bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
            int    num    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer = new byte[num];
            bcpgIn.ReadFully(buffer);
            SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer, writable: false));
            IList list = Platform.CreateArrayList();
            SignatureSubpacket value;
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            hashedData = new SignatureSubpacket[list.Count];
            for (int i = 0; i != hashedData.Length; i++)
            {
                SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[i];
                if (signatureSubpacket is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket).KeyId;
                }
                else if (signatureSubpacket is SignatureCreationTime)
                {
                    creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime());
                }
                hashedData[i] = signatureSubpacket;
            }
            int    num2    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer2 = new byte[num2];
            bcpgIn.ReadFully(buffer2);
            signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, writable: false));
            list.Clear();
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            unhashedData = new SignatureSubpacket[list.Count];
            for (int j = 0; j != unhashedData.Length; j++)
            {
                SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[j];
                if (signatureSubpacket2 is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket2).KeyId;
                }
                unhashedData[j] = signatureSubpacket2;
            }
        }
        fingerprint = new byte[2];
        bcpgIn.ReadFully(fingerprint);
        switch (keyAlgorithm)
        {
        case PublicKeyAlgorithmTag.RsaGeneral:
        case PublicKeyAlgorithmTag.RsaSign:
        {
            MPInteger mPInteger8 = new MPInteger(bcpgIn);
            signature = new MPInteger[1]
            {
                mPInteger8
            };
            return;
        }

        case PublicKeyAlgorithmTag.Dsa:
        {
            MPInteger mPInteger6 = new MPInteger(bcpgIn);
            MPInteger mPInteger7 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger6,
                mPInteger7
            };
            return;
        }

        case PublicKeyAlgorithmTag.ElGamalEncrypt:
        case PublicKeyAlgorithmTag.ElGamalGeneral:
        {
            MPInteger mPInteger3 = new MPInteger(bcpgIn);
            MPInteger mPInteger4 = new MPInteger(bcpgIn);
            MPInteger mPInteger5 = new MPInteger(bcpgIn);
            signature = new MPInteger[3]
            {
                mPInteger3,
                mPInteger4,
                mPInteger5
            };
            return;
        }

        case PublicKeyAlgorithmTag.ECDsa:
        {
            MPInteger mPInteger  = new MPInteger(bcpgIn);
            MPInteger mPInteger2 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger,
                mPInteger2
            };
            return;
        }
        }
        if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
        {
            signature = null;
            MemoryStream memoryStream = new MemoryStream();
            int          num3;
            while ((num3 = bcpgIn.ReadByte()) >= 0)
            {
                memoryStream.WriteByte((byte)num3);
            }
            signatureEncoding = memoryStream.ToArray();
            return;
        }
        throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
    }