Add support for --with-key-password to DecryptCmd

This commit is contained in:
Paul Schaub 2022-05-24 22:10:21 +02:00
parent 6438ebc59c
commit 45ee435a18
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -87,6 +87,11 @@ public class DecryptCmd implements Runnable {
paramLabel = "KEY") paramLabel = "KEY")
List<File> keys = new ArrayList<>(); List<File> keys = new ArrayList<>();
@CommandLine.Option(names = "--with-key-password",
description = "Provide indirect file type pointing at passphrase(s) for secret key(s)",
paramLabel = "PASSWORD")
List<String> withKeyPassword = new ArrayList<>();
@Override @Override
public void run() { public void run() {
throwIfOutputExists(verifyOut, VERIFY_OUT); throwIfOutputExists(verifyOut, VERIFY_OUT);
@ -101,6 +106,7 @@ public class DecryptCmd implements Runnable {
setNotBefore(notBefore, decrypt); setNotBefore(notBefore, decrypt);
setWithPasswords(withPassword, decrypt); setWithPasswords(withPassword, decrypt);
setWithSessionKeys(withSessionKey, decrypt); setWithSessionKeys(withSessionKey, decrypt);
setWithKeyPassword(withKeyPassword, decrypt);
setVerifyWith(certs, decrypt); setVerifyWith(certs, decrypt);
setDecryptWith(keys, decrypt); setDecryptWith(keys, decrypt);
@ -229,6 +235,19 @@ public class DecryptCmd implements Runnable {
} }
} }
private void setWithKeyPassword(List<String> withKeyPassword, Decrypt decrypt) {
for (String passwordFile : withKeyPassword) {
try {
String password = FileUtil.stringFromInputStream(FileUtil.getFileInputStream(passwordFile));
decrypt.withKeyPassword(password);
} catch (SOPGPException.UnsupportedOption unsupportedOption) {
throw new SOPGPException.UnsupportedOption(String.format(ERROR_UNSUPPORTED_OPTION, "--with-key-password"), unsupportedOption);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private void setNotAfter(String notAfter, Decrypt decrypt) { private void setNotAfter(String notAfter, Decrypt decrypt) {
Date notAfterDate = DateParser.parseNotAfter(notAfter); Date notAfterDate = DateParser.parseNotAfter(notAfter);
try { try {