drop key encryption altogether for empty passphrase

This commit is contained in:
Vincent Breitmoser 2017-06-13 12:41:54 +02:00
parent 3057eaa813
commit dfdfd733f3
2 changed files with 8 additions and 6 deletions

View file

@ -1330,10 +1330,14 @@ public class PgpKeyOperation {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.getCharArray()); Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.getCharArray());
// Build key encryptor based on new passphrase // Build key encryptor based on new passphrase
PBESecretKeyEncryptor keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder( PBESecretKeyEncryptor keyEncryptorNew = null;
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc, if (newPassphrase != null && !newPassphrase.isEmpty()) {
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT) keyEncryptorNew = new JcePBESecretKeyEncryptorBuilder(
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(newPassphrase.getCharArray()); PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO, encryptorHashCalc,
PgpSecurityConstants.SECRET_KEY_ENCRYPTOR_S2K_COUNT)
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME)
.build(newPassphrase.getCharArray());
}
boolean keysModified = false; boolean keysModified = false;
for (PGPSecretKey sKey : new IterableIterator<>(sKR.getSecretKeys())) { for (PGPSecretKey sKey : new IterableIterator<>(sKR.getSecretKeys())) {

View file

@ -1192,8 +1192,6 @@ public class PgpKeyOperationTest {
Assert.assertTrue("key modification must succeed", result.success()); Assert.assertTrue("key modification must succeed", result.success());
Assert.assertFalse("log must not contain a warning", Assert.assertFalse("log must not contain a warning",
result.getLog().containsWarnings()); result.getLog().containsWarnings());
Assert.assertTrue("log must contain an empty passphrase retry notice",
result.getLog().containsType(LogType.MSG_MF_PASSPHRASE_EMPTY_RETRY));
modified = result.getRing(); modified = result.getRing();
} }