protected PgpSignatureSubpacket(PgpSignatureSubpacket FromPacket) { _eType = FromPacket.eType; _eStatus = FromPacket.eStatus; _iHeaderLength = FromPacket.iHeaderLength; _iDataLength = FromPacket.iDataLength; _abRawBytes = FromPacket.abRawBytes; }
private PgpSignatureSubpacket GetSubpaket(PgpSignatureSubpacket.nSubpacketType eSubpacketType) { PgpSignatureSubpacket Return = null; if (_ltSubpackets != null) { Return = _ltSubpackets.Find(p => p.eType == eSubpacketType); } return(Return); }
public PgpCreationTime(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { if ((_abRawBytes == null) || (_abRawBytes.Length != _iHeaderLength + 5)) { _eStatus = nStatus.ParseError; } else { _Created = GetDateAt(_iHeaderLength + 1); } } }
public PgpRevocationReason(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { if ((_abRawBytes == null) || (_abRawBytes.Length != _iHeaderLength + 2)) { _eStatus = nStatus.ParseError; } else { _eReason = (nRevocationReason)_abRawBytes[_iHeaderLength + 1]; } } }
public PgpKeyExpireTime(PgpSignatureSubpacket FromPacket) : base(FromPacket) { _uSecondsValid = 0; if (_eStatus == nStatus.OK) { if ((_abRawBytes == null) || (_abRawBytes.Length != _iHeaderLength + 5)) { _eStatus = nStatus.ParseError; } else { _uSecondsValid = ((uint)_abRawBytes[_iHeaderLength + 1] << 24) | ((uint)_abRawBytes[_iHeaderLength + 2] << 16) | ((uint)_abRawBytes[_iHeaderLength + 3] << 8) | (uint)_abRawBytes[_iHeaderLength + 4]; } } }
public PgpKeyFlags(PgpSignatureSubpacket FromPacket) : base(FromPacket) { _eFlags = nFlags.None; if (_eStatus == nStatus.OK) { if ((_abRawBytes == null) || (_abRawBytes.Length != _iHeaderLength + 2)) { _eStatus = nStatus.ParseError; } else { eFlags = (nFlags)_abRawBytes[_iHeaderLength + 1]; } } }
public PgpMasterKeyFingerprint(PgpSignatureSubpacket FromPacket) : base(FromPacket) { _abFingerprint = null; if (_eStatus == nStatus.OK) { if ((_abRawBytes == null) || (_abRawBytes.Length != _iHeaderLength + ciSha1FingerprintLength + 2)) { _eStatus = nStatus.ParseError; } else if (_abRawBytes[_iHeaderLength + 1] != cbAllowedVersion) { _eStatus = nStatus.VersionNotSupported; } else { _abFingerprint = CopyFromRawBytes(_iHeaderLength + 2, ciSha1FingerprintLength); } } }
public PgpPreferredSymmetricAlgorithms(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { } }
public PgpIssuerKeyId(PgpSignatureSubpacket FromPacket) : base(FromPacket) { }
public PgpFeatures(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { } }
/// <summary></summary> public void Parse(PgpPublicKey MasterKey, List <PgpToken> ltTokens = null) { bool isThisMasterKey = true; byte bVersion; byte[] abMasterFingerprint; int i, iSubpacketPointer, iSignatureBytes, iUnhashedLength; PgpSignature FoundSubkey; PgpSignatureSubpacket DecodedPgpSubpacket, RawPgpSubpacket; if ((_abRawBytes == null) || (_abRawBytes.Length < _iHeaderLength + ciSignatureHeaderLength) || (_ePacketTag != nPacketTag.Signature)) { _eStatus = nStatus.ParseError; } else if (_eStatus == nStatus.OK) { bVersion = _abRawBytes[_iHeaderLength]; if (bVersion == cbAllowedVersion) { _eSignatureType = (nSignatureType)_abRawBytes[_iHeaderLength + 1]; _ePublicKeyAlgorithm = (nPublicKeyAlgorithm)_abRawBytes[_iHeaderLength + 2]; _eHashAlgorithm = (nHashAlgorithm)_abRawBytes[_iHeaderLength + 3]; _iHashedLength = (_abRawBytes[_iHeaderLength + 4] << 8) | _abRawBytes[_iHeaderLength + 5]; if (((_ePublicKeyAlgorithm == nPublicKeyAlgorithm.RsaEncryptOrSign) || (_ePublicKeyAlgorithm == nPublicKeyAlgorithm.RsaSignOnly)) && (_eHashAlgorithm == nHashAlgorithm.Sha1) || (_eHashAlgorithm == nHashAlgorithm.Sha256) || (_eHashAlgorithm == nHashAlgorithm.Sha384) || (_eHashAlgorithm == nHashAlgorithm.Sha512)) { iSubpacketPointer = _iHeaderLength + ciSignatureHeaderLength; while ((_eStatus == nStatus.OK) && (iSubpacketPointer < _iHeaderLength + ciSignatureHeaderLength + _iHashedLength)) { RawPgpSubpacket = new PgpSignatureSubpacket(_abRawBytes, iSubpacketPointer); if (RawPgpSubpacket.eStatus == nStatus.OK) { switch (RawPgpSubpacket.eType) { case PgpSignatureSubpacket.nSubpacketType.CreationTime: DecodedPgpSubpacket = new PgpCreationTime(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.KeyExpireTime: DecodedPgpSubpacket = new PgpKeyExpireTime(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.PreferredSymmetricAlgorithms: DecodedPgpSubpacket = new PgpPreferredSymmetricAlgorithms(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.IssuerKeyId: DecodedPgpSubpacket = new PgpIssuerKeyId(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.PreferredHashAlgorithms: DecodedPgpSubpacket = new PgpPreferredHashAlgorithms(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.PreferredCompressionAlgorithms: DecodedPgpSubpacket = new PgpPreferredCompressionAlgorithms(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.KeyServerPreferences: DecodedPgpSubpacket = new PgpKeyServerPreferences(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.PrimaryUserId: DecodedPgpSubpacket = new PgpPrimaryUserId(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.KeyFlags: DecodedPgpSubpacket = new PgpKeyFlags(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.RevocationReason: DecodedPgpSubpacket = new PgpRevocationReason(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.Features: DecodedPgpSubpacket = new PgpFeatures(RawPgpSubpacket); break; case PgpSignatureSubpacket.nSubpacketType.MasterKeyFingerprint: DecodedPgpSubpacket = new PgpMasterKeyFingerprint(RawPgpSubpacket); break; default: DecodedPgpSubpacket = null; Console.WriteLine("not implemented: eType=" + RawPgpSubpacket.eType.ToString()); break; } if ((DecodedPgpSubpacket == null) || (DecodedPgpSubpacket.eStatus != nStatus.OK)) { _eStatus = nStatus.ParseError; } else { // Console.WriteLine("found eType=" + RawPgpSubpacket.eType.ToString()); _ltSubpackets.Add(DecodedPgpSubpacket); iSubpacketPointer += (RawPgpSubpacket.iHeaderLength + RawPgpSubpacket.iDataLength); } } else { _eStatus = nStatus.ParseError; } } iUnhashedLength = (_abRawBytes[iSubpacketPointer] << 8) | _abRawBytes[iSubpacketPointer + 1]; iSubpacketPointer += 2; while ((_eStatus == nStatus.OK) && (iSubpacketPointer < _iHashedLength + iUnhashedLength + 8)) { RawPgpSubpacket = new PgpSignatureSubpacket(_abRawBytes, iSubpacketPointer); if (RawPgpSubpacket.eStatus == nStatus.OK) { switch (RawPgpSubpacket.eType) { case PgpSignatureSubpacket.nSubpacketType.IssuerKeyId: DecodedPgpSubpacket = new PgpIssuerKeyId(RawPgpSubpacket); break; default: DecodedPgpSubpacket = null; Console.WriteLine("not implemented: eType=" + RawPgpSubpacket.eType.ToString()); break; } if ((DecodedPgpSubpacket == null) || (DecodedPgpSubpacket.eStatus != nStatus.OK)) { _eStatus = nStatus.ParseError; } else { _ltSubpackets.Add(DecodedPgpSubpacket); iSubpacketPointer += (RawPgpSubpacket.iHeaderLength + RawPgpSubpacket.iDataLength); } } else { _eStatus = nStatus.ParseError; } } _abFingerprint = ComputeFingerprint(); _eTranslatedKeyFlags = TranslateKeyFlags(); if (_abRawBytes.Length > iSubpacketPointer + 2) { _abHashFingerprint = CopyFromRawBytes(iSubpacketPointer, 2); _iSignatureBits = _abRawBytes[iSubpacketPointer + 2] << 8 | _abRawBytes[iSubpacketPointer + 3]; iSignatureBytes = (_iSignatureBits + 7) >> 3; iSubpacketPointer += 4; if (_abRawBytes.Length == iSubpacketPointer + iSignatureBytes) { _abSignature = CopyFromRawBytes(iSubpacketPointer, iSignatureBytes); if (_PublicKeyPacket != null) { _PublicKeyPacket.Signature = this; } abMasterFingerprint = abMasterKeyFingerprint; // do the underlying checks only once if ((abMasterFingerprint != null) && (abMasterFingerprint.Length == ciSha1FingerprintLength) && (MasterKey.Signature != null) && (MasterKey.Signature.abFingerprint != null) && (MasterKey.Signature.abFingerprint.Length == ciSha1FingerprintLength)) { for (i = 0; i < ciSha1FingerprintLength; i++) { isThisMasterKey = isThisMasterKey && (abMasterFingerprint[i] == MasterKey.Signature.abFingerprint[i]); } if (!isThisMasterKey) { MasterKey = null; if (ltTokens != null) { foreach (PgpToken Token in ltTokens) { if (MasterKey == null) { FoundSubkey = Token.GetSubkey(abMasterFingerprint); if (FoundSubkey != null) { MasterKey = FoundSubkey.PublicKeyPacket; } } } } } } if (MasterKey == null) { _eVerified = nVerified.KeyNotFound; } else if (Verify(MasterKey)) { _eVerified = nVerified.True; } else { _eVerified = nVerified.False; } } else { _eStatus = nStatus.ParseError; } } else { _eStatus = nStatus.ParseError; } } else { _eStatus = nStatus.AlgorithmNotSupported; } } else { _eStatus = nStatus.VersionNotSupported; } } // else keep the value of _eStatus from PgpPacketBase }
public PgpPreferredCompressionAlgorithms(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { } }
public PgpPrimaryUserId(PgpSignatureSubpacket FromPacket) : base(FromPacket) { }
public PgpKeyServerPreferences(PgpSignatureSubpacket FromPacket) : base(FromPacket) { if (_eStatus == nStatus.OK) { } }