1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-16 09:22:05 +01: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;
@ -51,20 +51,26 @@ public class Sign implements Runnable {
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];
for (int i = 0, secretKeyFileLength = secretKeyFile.length; i < secretKeyFileLength; i++) {
File file = secretKeyFile[i];
try { try {
secretKeys = PGPainless.readKeyRing().secretKeyRing(new FileInputStream(secretKeyFile)); PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(new FileInputStream(file));
secretKeys[i] = secretKey;
} catch (IOException | PGPException e) { } catch (IOException | PGPException e) {
err_ln("Error reading secret key ring."); err_ln("Error reading secret key ring " + file.getName());
err_ln(e.getMessage()); err_ln(e.getMessage());
System.exit(1); System.exit(1);
return; return;
} }
}
try { try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionBuilderInterface.DocumentType documentType = PGPainless.encryptAndOrSign() EncryptionBuilderInterface.DocumentType documentType = PGPainless.encryptAndOrSign()