bouncy-gpg icon indicating copy to clipboard operation
bouncy-gpg copied to clipboard

Provide a custom `SignatureValidationStrategy`

Open bjansen opened this issue 3 years ago • 2 comments

I have a use case where I need to check that decrypted data has been signed by any of two given keys. The current API RequireSpecificSignatureValidationStrategy supports an "AND" verification, but I need an "OR" verification.

I think it would be nice if users had the possibility to provide their own instance of SignatureValidationStrategy. This way they can use custom strategies without having to submit PRs here and wait for a release.

Maybe a new method named andValidateSignatureMatches(SignatureValidationStrategy) in name.neuhalfen.projects.crypto.bouncycastle.openpgp.BuildDecryptionInputStreamAPI.Validation:

BouncyGPG
	.decryptAndVerifyStream()
	.withConfig(...)
	.andValidateSignatureMatches(mySignatureValidationStrategy)
	.fromEncryptedInputStream(cipherTextStream);

bjansen avatar May 03 '21 20:05 bjansen

Well I guess I can bypass the builder API and use this instead:

DecryptionStreamFactory.create(
	getKeyringConfig(),
	myStrategy
).wrapWithDecryptAndVerify(cipherTextStream)

Is it safe to use DecryptionStreamFactory directly? Is there a chance this API will change or be removed in the future?

bjansen avatar May 04 '21 09:05 bjansen

I think your point on being able to specify a custom SignatureValidationStrategy is nice and should be further discussed with the author. In the interim however, you might be able to take care of the issue by using the below function (if the two keys are present in the decryption key ring)

andValidateSomeoneSigned

But it would only validate that one of the keys in the keyring signed this message (not a particular subset) So, something like

BouncyGPG
	.decryptAndVerifyStream()
	.withConfig(...)
	.andValidateSomeoneSigned(mySignatureValidationStrategy)
	.fromEncryptedInputStream(cipherTextStream);

Sauhardstark avatar Jul 29 '21 16:07 Sauhardstark