1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Fix test for algorithm preference extraction

This commit is contained in:
Paul Schaub 2022-01-15 02:29:39 +01:00
parent 1cbeafb3ad
commit 9de196d6c5

View file

@ -19,80 +19,41 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
@Test
public void algorithmPreferencesAreRespectedDependingOnEncryptionTarget() throws IOException, PGPException {
// Key has [AES128] as preferred symm. algo on latest user-id cert
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
// Key has AES256, AES192, AES128 as primary user-ids sym algo prefs,
// and AES128 as secondary user-id prefs
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"Version: PGPainless\n" +
"Comment: 7E13 2E9C EAE8 7E7B AD6C 5329 94CE B847 EEFB 044B\n" +
"Comment: Bob Babbage <bob@openpgp.example>\n" +
"\n" +
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
"/seOXpgecTdOcVttfzC8ycIKrt3aQTiwOG/ctaR4Bk/t6ayNFfdUNxHWk4WCKzdz\n" +
"/56fW2O0F23qIRd8UUJp5IIlN4RDdRCtdhVQIAuzvp2oVy/LaS2kxQoKvph/5pQ/\n" +
"5whqsyroEWDJoSV0yOb25B/iwk/pLUFoyhDG9bj0kIzDxrEqW+7Ba8nocQlecMF3\n" +
"X5KMN5kp2zraLv9dlBBpWW43XktjcCZgMy20SouraVma8Je/ECwUWYUiAZxLIlMv\n" +
"9CurEOtxUw6N3RdOtLmYZS9uEnn5y1UkF88o8Nku890uk6BrewFzJyLAx5wRZ4F0\n" +
"qV/yq36UWQ0JB/AUGhHVPdFf6pl6eaxBwT5GXvbBUibtf8YI2og5RsgTWtXfU7eb\n" +
"SGXrl5ZMpbA6mbfhd0R8aPxWfmDWiIOhBufhMCvUHh1sApMKVZnvIff9/0Dca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64R+77\n" +
"BEsWoQR+Ey6c6uh+e61sUymUzrhH7vsESwKeAQKbAQWWAgMBAAKLBwWVCgkICwAA\n" +
"y0wBAIhAEpQgJRizHitPx3WUpIYbKq3R5jAO34NnlmTzNVj6AP9aWHPsW5r7HuQh\n" +
"xJz+8zdCOuAxKv6tvHthSWJ64VWDDrg4BGHiIZ4SCisGAQQBl1UBBQEBB0CEIv13\n" +
"/qTXR0wiUG5DVZCWh/KLKrF5TemUfYXA/kBTOAMBCAeIdQQYFgoAHQUCYeIhngKe\n" +
"AQKbDAWWAgMBAASLCQgHBZUKCQgLAAoJEJTOuEfu+wRLwC4A/0/VDPPDE6kT/8C3\n" +
"9d8ekZkQE38o2nC58E62AjM5O2x6AQDMd0gcoKIxPi9uRi3nVsNS233a3MxFEjpe\n" +
"qqgyBnqxBLgzBGHiIZ4WCSsGAQQB2kcPAQEHQP7IGdT9moutwtys4A/ndkWJVWn/\n" +
"zkoOn3cSad1bP8y8iNUEGBYKAH0FAmHiIZ4CngECmwIFlgIDAQAEiwkIBwWVCgkI\n" +
"C18gBBkWCgAGBQJh4iGeAAoJENcuZc0+RPVgrucBAI+IzpplBIpySOIyzHJdjeFt\n" +
"ikwTBOY3OTriY2Z62Ec6AQDhVxO7LZuH3mTCklj4HelfMrhlqUlnYr7qCIjzI5BY\n" +
"BwAKCRCUzrhH7vsES4snAP4qzlEbaHpN7ZPomCOHD7J2+CHlyTtsRP45XWVCqNH1\n" +
"jAEAmzz5Lu67k97AzArpoGHgYh492w5BfdApV8BCaTW4AgI=\n" +
"=XwJQ\n" +
"-----END PGP PUBLIC KEY BLOCK-----\n";
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
// Encrypt to the user-id
// PGPainless should extract algorithm preferences from the latest user-id sig in this case (AES-128)
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions(
ProducerOptions.encrypt(new EncryptionOptions()
.addRecipient(publicKeys, "Bob Babbage <bob@openpgp.example>")
));
encryptionStream.close();
assertEquals(SymmetricKeyAlgorithm.AES_128, encryptionStream.getResult().getEncryptionAlgorithm());
// Encrypt without specifying user-id
// PGPainless should now inspect the subkey binding sig for algorithm preferences (AES256, AES192, AES128)
out = new ByteArrayOutputStream();
encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
// PGPainless now inspects the primary user-ids signature to get sym alg prefs (AES256, AES192, AES128)
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionStream encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions(
ProducerOptions.encrypt(new EncryptionOptions()
.addRecipient(publicKeys) // no user-id passed
@ -100,5 +61,29 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
encryptionStream.close();
assertEquals(SymmetricKeyAlgorithm.AES_256, encryptionStream.getResult().getEncryptionAlgorithm());
// Encrypt to the primary user-id
// PGPainless should extract algorithm preferences from the latest user-id sig in this case (AES-256, AES-192, AES-128)
out = new ByteArrayOutputStream();
encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions(
ProducerOptions.encrypt(new EncryptionOptions()
.addRecipient(publicKeys, "Bob Babbage <bob@openpgp.example>")
));
encryptionStream.close();
assertEquals(SymmetricKeyAlgorithm.AES_256, encryptionStream.getResult().getEncryptionAlgorithm());
// Encrypt to the secondary user-id
// PGPainless extracts algorithm preferences from secondary user-id sig, in this case AES-128
out = new ByteArrayOutputStream();
encryptionStream = PGPainless.encryptAndOrSign().onOutputStream(out)
.withOptions(
ProducerOptions.encrypt(new EncryptionOptions()
.addRecipient(publicKeys, "Bobby128 <bobby@aes128.example>")
));
encryptionStream.close();
assertEquals(SymmetricKeyAlgorithm.AES_128, encryptionStream.getResult().getEncryptionAlgorithm());
}
}