/// <summary> /// Returns true if the given object is the "this" key. /// </summary> /// <remarks> /// The keys are compared by there fingerprint. If the fingerprint /// is the same, the keys are said to be the same. /// </remarks> /// <param name="o">An object that shall be compared against /// this.</param> /// <returns>True if the giben object o is the same as the /// "this" key.</returns> public override bool Equals(object o) { if (o is TransportablePublicKey) { TransportablePublicKey tpkKey = (TransportablePublicKey)o; return(tpkKey.PrimaryKey.Fingerprint == this.PrimaryKey.Fingerprint); } return(false); }
public static TransportablePublicKey[] SplitKeys(string strRadix64) { ArrayList alKeys = new ArrayList(); Packet[] pPackets = Packet.ParsePackets(strRadix64); byte[] bOneKey = new byte[0]; for (int i = 0; i < pPackets.Length; i++) { if (pPackets[i] is PublicKeyPacket) { PublicKeyPacket pkpKey = (PublicKeyPacket)pPackets[i]; if ((pkpKey.Content == ContentTypes.PublicKey) && (bOneKey.Length > 10)) { TransportablePublicKey tpkKey = new TransportablePublicKey(Radix64.Encode(bOneKey, true)); alKeys.Add(tpkKey); bOneKey = new byte[0]; } } byte[] bPacket = pPackets[i].Generate(); byte[] bTmpKey = new byte[bOneKey.Length]; bOneKey.CopyTo(bTmpKey, 0); bOneKey = new byte[bOneKey.Length + bPacket.Length]; Array.Copy(bTmpKey, 0, bOneKey, 0, bTmpKey.Length); Array.Copy(bPacket, 0, bOneKey, bTmpKey.Length, bPacket.Length); } if (bOneKey.Length > 10) { TransportablePublicKey tpkKey = new TransportablePublicKey(Radix64.Encode(bOneKey, true)); alKeys.Add(tpkKey); } TransportablePublicKey[] tpkKeys = new TransportablePublicKey[alKeys.Count]; int iCount = 0; IEnumerator ieKeys = alKeys.GetEnumerator(); while (ieKeys.MoveNext()) { if (!(ieKeys.Current is TransportablePublicKey)) { continue; } tpkKeys[iCount++] = (TransportablePublicKey)ieKeys.Current; } return(tpkKeys); }
/// <summary> /// Verifies the signature of this signed message. /// </summary> /// <remarks>No remarks</remarks> /// <returns>Returns a SignatureStatusType that contains /// whether the signature was valid, invalid or could not be /// verified</returns> /// <param name="pkrKeyRing">The public keyring containing /// all keys known to the local system.</param> public SignatureStatusTypes Verify(PublicKeyRing pkrKeyRing) { TransportablePublicKey tpkKey = pkrKeyRing.Find(spSignature.KeyID); if (tpkKey == null) { return(SignatureStatusTypes.Signing_Key_Not_Available); } PublicKeyPacket pkpKey = tpkKey.FindKey(spSignature.KeyID); spSignature.Verify(lmSignedMessage.Binary, pkpKey); return(spSignature.SignatureStatus); }
/// <summary> /// Validates all certificates belonging the the given public key packet /// and the current certifications. /// </summary> /// <remarks> /// So far only works with v4 signatures! /// </remarks> /// <param name="pkpKey">The public key packet to which the userid /// belongs.</param> /// <param name="pkrRing">A keyring containing all public keys known to /// the system. This is neccessary in order to verify the signatures. /// </param> public void Validate(PublicKeyPacket pkpKey, PublicKeyRing pkrRing) { IEnumerator ieCertificates = Certificates.GetEnumerator(); while (ieCertificates.MoveNext()) { if (ieCertificates.Current is SignaturePacket) { SignaturePacket spCert = (SignaturePacket)ieCertificates.Current; TransportablePublicKey tkpSigningKey = pkrRing.Find(spCert.KeyID); if (tkpSigningKey == null) { continue; } PublicKeyPacket pkpSigningKey = tkpSigningKey.PrimaryKey; if (spCert.Version == SignaturePacketVersionNumbers.v4) { byte[] bKey = new byte[pkpKey.Body.Length + 3]; bKey[0] = 0x99; bKey[1] = (byte)((pkpKey.Body.Length >> 8) & 0xFF); bKey[2] = (byte)(pkpKey.Body.Length & 0xFF); Array.Copy(pkpKey.Body, 0, bKey, 3, pkpKey.Body.Length); byte[] bUserID = new byte[UserID.Body.Length + 5]; bUserID[0] = 0xb4; bUserID[1] = (byte)((UserID.Body.Length >> 24) & 0xFF); bUserID[2] = (byte)((UserID.Body.Length >> 16) & 0xFF); bUserID[3] = (byte)((UserID.Body.Length >> 8) & 0xFF); bUserID[4] = (byte)(UserID.Body.Length & 0xFF); Array.Copy(UserID.Body, 0, bUserID, 5, UserID.Body.Length); byte[] bData = new byte[bUserID.Length + bKey.Length]; Array.Copy(bKey, 0, bData, 0, bKey.Length); Array.Copy(bUserID, 0, bData, bKey.Length, bUserID.Length); spCert.Verify(bData, pkpSigningKey); } else { //TODO: Add code for v3 Signature verification } } } }