1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-17 00:54:50 +02:00

Improve test for preferred sym algs

This commit is contained in:
Paul Schaub 2021-11-27 17:03:17 +01:00
parent d670b5ee07
commit 27c4fd240d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -18,7 +18,7 @@ import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
@Test
public void onlyAES128() throws IOException, PGPException {
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" +
@ -75,6 +75,9 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
"-----END PGP ARMORED FILE-----\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(
@ -84,5 +87,18 @@ public class RespectPreferredSymmetricAlgorithmDuringEncryptionTest {
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)
.withOptions(
ProducerOptions.encrypt(new EncryptionOptions()
.addRecipient(publicKeys) // no user-id passed
));
encryptionStream.close();
assertEquals(SymmetricKeyAlgorithm.AES_256, encryptionStream.getResult().getEncryptionAlgorithm());
}
}