diff --git a/external-sop/src/main/java/sop/external/operation/DetachedSignExternal.java b/external-sop/src/main/java/sop/external/operation/DetachedSignExternal.java index 3deabb2..1f9aa81 100644 --- a/external-sop/src/main/java/sop/external/operation/DetachedSignExternal.java +++ b/external-sop/src/main/java/sop/external/operation/DetachedSignExternal.java @@ -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); diff --git a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java index 3354389..5dca76d 100644 --- a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java @@ -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 ") + .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()); + } + }