Add test for signing with protected key without password

This commit is contained in:
Paul Schaub 2023-01-20 14:58:21 +01:00
parent 0d9db2bdd3
commit c95ca8fedc
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 28 additions and 1 deletions

View file

@ -96,7 +96,11 @@ public class DetachedSignExternal implements DetachedSign {
}
data.close();
processOut.close();
try {
processOut.close();
} catch (IOException e) {
// Ignore Stream closed
}
while ((r = processIn.read(buf)) > 0) {
outputStream.write(buf, 0 , r);

View file

@ -166,4 +166,27 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
.signatures(signature)
.data(message));
}
@Test
public void signVerifyWithFreshEncryptedKeyWithoutPassphraseFails() throws IOException {
ignoreIf("sqop", Is.leq, "0.27.2"); // does not return exit code 67 for encrypted keys without passphrase
byte[] keyPassword = "sw0rdf1sh".getBytes(StandardCharsets.UTF_8);
byte[] key = getSop().generateKey()
.userId("Alice <alice@openpgp.org>")
.withKeyPassword(keyPassword)
.generate()
.getBytes();
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
assertThrows(SOPGPException.KeyIsProtected.class, () ->
getSop().detachedSign()
.key(key)
.data(message)
.toByteArrayAndResult()
.getBytes());
}
}