1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-09-28 18:49:56 +02:00

Allow signing with multiple secret keys

This commit is contained in:
Paul Schaub 2020-12-22 22:08:38 +01:00
parent 7edd6bc86d
commit b733b94b9e
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -15,11 +15,6 @@
*/ */
package org.pgpainless.sop.commands; package org.pgpainless.sop.commands;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
@ -31,6 +26,11 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.sop.Print; import org.pgpainless.sop.Print;
import picocli.CommandLine; import picocli.CommandLine;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import static org.pgpainless.sop.Print.err_ln; import static org.pgpainless.sop.Print.err_ln;
import static org.pgpainless.sop.Print.print_ln; import static org.pgpainless.sop.Print.print_ln;
@ -48,22 +48,28 @@ public class Sign implements Runnable {
boolean armor = true; boolean armor = true;
@CommandLine.Option(names = "--as", description = "Defaults to 'binary'. If '--as=text' and the input data is not valid UTF-8, sign fails with return code 53.", @CommandLine.Option(names = "--as", description = "Defaults to 'binary'. If '--as=text' and the input data is not valid UTF-8, sign fails with return code 53.",
paramLabel = "{binary|text}") paramLabel = "{binary|text}")
Type type; Type type;
@CommandLine.Parameters @CommandLine.Parameters(description = "Secret keys used for signing",
File secretKeyFile; paramLabel = "KEY",
arity = "1..*")
File[] secretKeyFile;
@Override @Override
public void run() { public void run() {
PGPSecretKeyRing secretKeys; PGPSecretKeyRing[] secretKeys = new PGPSecretKeyRing[secretKeyFile.length];
try { for (int i = 0, secretKeyFileLength = secretKeyFile.length; i < secretKeyFileLength; i++) {
secretKeys = PGPainless.readKeyRing().secretKeyRing(new FileInputStream(secretKeyFile)); File file = secretKeyFile[i];
} catch (IOException | PGPException e) { try {
err_ln("Error reading secret key ring."); PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(new FileInputStream(file));
err_ln(e.getMessage()); secretKeys[i] = secretKey;
System.exit(1); } catch (IOException | PGPException e) {
return; err_ln("Error reading secret key ring " + file.getName());
err_ln(e.getMessage());
System.exit(1);
return;
}
} }
try { try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();