/// <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 } } } }
/// <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(); this.validitystatus = ValidityStatus.Valid; while (ieCertificates.MoveNext()) { if (ieCertificates.Current is SignaturePacket) { SignaturePacket spCert = (SignaturePacket)ieCertificates.Current; TransportablePublicKey tkpSigningKey = pkrRing.Find(spCert.KeyID, true); if (tkpSigningKey == null) { this.validitystatus = ValidityStatus.ValidationKeyUnavailable; 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); if(spCert.SignatureStatus == SignatureStatusTypes.Invalid) { this.validitystatus = ValidityStatus.Invalid; continue; } else if(spCert.SignatureStatus == SignatureStatusTypes.Signing_Key_Not_Available) { this.validitystatus = ValidityStatus.ValidationKeyUnavailable; continue; } else if(spCert.SignatureStatus == SignatureStatusTypes.Not_Verified) { this.validitystatus = ValidityStatus.NotYetValidated; continue; } } else { //TODO: Add code for v3 Signature verification } } } }