コード例 #1
0
 public KeyPacket(KeyPacket keyPacket)
 {
     this.version         = keyPacket.Version;
     this.time            = keyPacket.time;
     this.algorithm       = keyPacket.Algorithm;
     this.keyBytes        = keyPacket.keyBytes.AsSpan(0, keyPacket.PublicKeyLength).ToArray();
     this.publicKeyLength = keyPacket.publicKeyLength;
 }
コード例 #2
0
 public PublicKeyEncSessionPacket(
     long keyId,
     PgpPublicKeyAlgorithm algorithm,
     ReadOnlySpan <byte> sessionKey)
 {
     this.version    = 3;
     this.keyId      = keyId;
     this.algorithm  = algorithm;
     this.sessionKey = sessionKey.ToArray();
 }
コード例 #3
0
 /// <summary>Construct a version 4 public key packet.</summary>
 public KeyPacket(
     PgpPublicKeyAlgorithm algorithm,
     DateTime time,
     byte[] keyBytes)
 {
     this.version   = 4;
     this.time      = new DateTimeOffset(time, TimeSpan.Zero).ToUnixTimeSeconds();
     this.algorithm = algorithm;
     this.keyBytes  = keyBytes;
     UpdatePublicKeyLength();
 }
コード例 #4
0
 public OnePassSignaturePacket(
     PgpSignatureType sigType,
     PgpHashAlgorithm hashAlgorithm,
     PgpPublicKeyAlgorithm keyAlgorithm,
     long keyId,
     bool isNested)
 {
     this.version       = 3;
     this.sigType       = sigType;
     this.hashAlgorithm = hashAlgorithm;
     this.keyAlgorithm  = keyAlgorithm;
     this.keyId         = keyId;
     this.nested        = (isNested) ? 0 : 1;
 }
コード例 #5
0
 private static byte[] CreateData(
     RevocationKeyTag signatureClass,
     PgpPublicKeyAlgorithm keyAlgorithm,
     byte[] fingerprint)
 {
     // 1 octet of class,
     // 1 octet of public-key algorithm ID,
     // 20 octets of fingerprint
     byte[] data = new byte[2 + fingerprint.Length];
     data[0] = (byte)signatureClass;
     data[1] = (byte)keyAlgorithm;
     fingerprint.CopyTo(data, 2);
     return(data);
 }
コード例 #6
0
        public void Finish(
            int version,
            PgpPublicKeyAlgorithm keyAlgorithm,
            DateTime creationTime,
            SignatureSubpacket[] hashedSubpackets)
        {
            if (version == 3)
            {
                long time = new DateTimeOffset(creationTime, TimeSpan.Zero).ToUnixTimeSeconds();

                sig.TransformBlock(new byte[] {
                    (byte)signatureType,
                    (byte)(time >> 24),
                    (byte)(time >> 16),
                    (byte)(time >> 8),
                    (byte)(time)
                }, 0, 5, null, 0);
            }
            else
            {
                sig.TransformBlock(new byte[] {
                    (byte)version,
                    (byte)this.SignatureType,
                    (byte)keyAlgorithm,
                    (byte)this.HashAlgorithm
                }, 0, 4, null, 0);

                MemoryStream hOut = new MemoryStream();
                foreach (var hashedSubpacket in hashedSubpackets)
                {
                    hashedSubpacket.Encode(hOut);
                }

                sig.TransformBlock(new byte[] { (byte)(hOut.Length >> 8), (byte)hOut.Length }, 0, 2, null, 0);
                sig.TransformBlock(hOut.GetBuffer(), 0, (int)hOut.Length, null, 0);

                int hDataLength = 4 + (int)hOut.Length + 2;
                sig.TransformBlock(new byte[] {
                    (byte)version,
                    (byte)0xff,
                    (byte)(hDataLength >> 24),
                    (byte)(hDataLength >> 16),
                    (byte)(hDataLength >> 8),
                    (byte)(hDataLength)
                }, 0, 6, null, 0);
            }

            sig.TransformFinalBlock(Array.Empty <byte>(), 0, 0);
        }
コード例 #7
0
        internal KeyPacket(Stream bcpgIn)
        {
            this.version = bcpgIn.ReadByte();
            this.time    = ((uint)bcpgIn.ReadByte() << 24) | ((uint)bcpgIn.ReadByte() << 16) | ((uint)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte();

            if (version <= 3)
            {
                this.validDays = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            }

            this.algorithm = (PgpPublicKeyAlgorithm)bcpgIn.ReadByte();
            this.keyBytes  = bcpgIn.ReadAll();

            UpdatePublicKeyLength();
        }
コード例 #8
0
        internal PublicKeyEncSessionPacket(Stream 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 = (PgpPublicKeyAlgorithm)bcpgIn.ReadByte();

            sessionKey = bcpgIn.ReadAll();
        }
コード例 #9
0
        internal OnePassSignaturePacket(Stream bcpgIn)
        {
            version       = bcpgIn.ReadByte();
            sigType       = (PgpSignatureType)bcpgIn.ReadByte();
            hashAlgorithm = (PgpHashAlgorithm)bcpgIn.ReadByte();
            keyAlgorithm  = (PgpPublicKeyAlgorithm)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();
        }
コード例 #10
0
ファイル: SignaturePacket.cs プロジェクト: 1hub/springburg
 public SignaturePacket(
     int version,
     PgpSignatureType signatureType,
     long keyId,
     PgpPublicKeyAlgorithm keyAlgorithm,
     PgpHashAlgorithm hashAlgorithm,
     DateTime creationTime,
     SignatureSubpacket[] hashedData,
     SignatureSubpacket[] unhashedData,
     byte[] fingerprint,
     byte[] signature)
 {
     this.version       = version;
     this.signatureType = signatureType;
     this.keyId         = keyId;
     this.keyAlgorithm  = keyAlgorithm;
     this.hashAlgorithm = hashAlgorithm;
     this.hashedData    = hashedData;
     this.unhashedData  = unhashedData;
     this.fingerprint   = fingerprint;
     this.signature     = signature;
     this.creationTime  = creationTime;
 }
コード例 #11
0
ファイル: SignaturePacket.cs プロジェクト: 1hub/springburg
        internal SignaturePacket(Stream bcpgIn)
        {
            version = bcpgIn.ReadByte();

            if (version == 3 || version == 2)
            {
                //                int l =
                bcpgIn.ReadByte();

                signatureType = (PgpSignatureType)bcpgIn.ReadByte();
                creationTime  = DateTimeOffset.FromUnixTimeSeconds(
                    ((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()).UtcDateTime;

                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  = (PgpPublicKeyAlgorithm)bcpgIn.ReadByte();
                hashAlgorithm = (PgpHashAlgorithm)bcpgIn.ReadByte();

                hashedData   = Array.Empty <SignatureSubpacket>();
                unhashedData = Array.Empty <SignatureSubpacket>();
            }
            else if (version == 4)
            {
                signatureType = (PgpSignatureType)bcpgIn.ReadByte();
                keyAlgorithm  = (PgpPublicKeyAlgorithm)bcpgIn.ReadByte();
                hashAlgorithm = (PgpHashAlgorithm)bcpgIn.ReadByte();

                int    hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] hashed       = new byte[hashedLength];

                if (bcpgIn.ReadFully(hashed) < hashed.Length)
                {
                    throw new EndOfStreamException();
                }

                //
                // read the signature sub packet data.
                //
                SignatureSubpacketParser sIn = new SignatureSubpacketParser(new MemoryStream(hashed, false));

                IList <SignatureSubpacket> v = new List <SignatureSubpacket>();
                SignatureSubpacket?        sub;
                while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                    if (sub is IssuerKeyId issuerKeyId)
                    {
                        keyId = issuerKeyId.KeyId;
                    }
                    else if (sub is SignatureCreationTime signatureCreationTime)
                    {
                        creationTime = signatureCreationTime.Time;
                    }
                }

                hashedData = v.ToArray();

                int    unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] unhashed       = new byte[unhashedLength];

                if (bcpgIn.ReadFully(unhashed) < unhashed.Length)
                {
                    throw new EndOfStreamException();
                }

                sIn = new SignatureSubpacketParser(new MemoryStream(unhashed, false));

                v.Clear();
                while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                    if (sub is IssuerKeyId issuerKeyId && keyId == 0)
                    {
                        keyId = issuerKeyId.KeyId;
                    }
                }

                unhashedData = v.ToArray();
            }
            else
            {
                throw new PgpException("unsupported version: " + version);
            }

            fingerprint = new byte[2];
            if (bcpgIn.ReadFully(fingerprint) < fingerprint.Length)
            {
                throw new EndOfStreamException();
            }

            signature = bcpgIn.ReadAll();
        }
コード例 #12
0
 public PublicSubkeyPacket(PgpPublicKeyAlgorithm algorithm, DateTime creationTime, byte[] keyBytes)
     : base(algorithm, creationTime, keyBytes)
 {
 }
コード例 #13
0
 public RevocationKey(bool isCritical, RevocationKeyTag signatureClass, PgpPublicKeyAlgorithm keyAlgorithm, byte[] fingerprint)
     : base(SignatureSubpacketTag.RevocationKey, isCritical, false, CreateData(signatureClass, keyAlgorithm, fingerprint))
 {
 }
コード例 #14
0
 /// <summary>
 /// Sets revocation key sub packet
 /// </summary>
 public void SetRevocationKey(bool isCritical, PgpPublicKeyAlgorithm keyAlgorithm, byte[] fingerprint)
 {
     subpackets[SignatureSubpacketTag.RevocationKey] = new RevocationKey(isCritical, RevocationKeyTag.ClassDefault, keyAlgorithm, fingerprint);
 }