mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-15 05:09:38 +02:00
pgpainless-cert-d-cli: Add experimental multi-import command.
This command can be used to import GnuPG key rings by calling gpg --export | java -jar pgpainless-cert-d-cli.jar multi-import
This commit is contained in:
parent
8a7bbdbf03
commit
d53d62a6e9
2 changed files with 64 additions and 0 deletions
|
@ -10,6 +10,7 @@ import pgp.cert_d.BaseDirectoryProvider;
|
|||
import pgp.cert_d.SharedPGPCertificateDirectoryImpl;
|
||||
import pgp.cert_d.cli.commands.Get;
|
||||
import pgp.cert_d.cli.commands.Import;
|
||||
import pgp.cert_d.cli.commands.MultiImport;
|
||||
import pgp.cert_d.jdbc.sqlite.SqliteSubkeyLookup;
|
||||
import pgp.certificate_store.SubkeyLookup;
|
||||
import pgp.certificate_store.exception.NotAStoreException;
|
||||
|
@ -22,6 +23,7 @@ import java.sql.SQLException;
|
|||
@CommandLine.Command(
|
||||
subcommands = {
|
||||
Import.class,
|
||||
MultiImport.class,
|
||||
Get.class,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.cli.commands;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.MergeCallback;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@CommandLine.Command(name = "multi-import",
|
||||
description = "Import or update multiple certificates")
|
||||
public class MultiImport implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MultiImport.class);
|
||||
|
||||
// TODO: Replace with proper merge callback
|
||||
private final MergeCallback dummyMerge = new MergeCallback() {
|
||||
@Override
|
||||
public Certificate merge(Certificate data, Certificate existing) throws IOException {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PGPPublicKeyRingCollection certificates = PGPainless.readKeyRing().publicKeyRingCollection(System.in);
|
||||
for (PGPPublicKeyRing cert : certificates) {
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
Certificate certificate = PGPCertDCli.getCertificateDirectory()
|
||||
.insertCertificate(certIn, dummyMerge);
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(certificate.getFingerprint());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO-Error.", e);
|
||||
System.exit(-1);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("Thread interrupted.", e);
|
||||
System.exit(-1);
|
||||
} catch (BadDataException e) {
|
||||
LOGGER.error("Certificate contains bad data.", e);
|
||||
System.exit(-1);
|
||||
} catch (PGPException e) {
|
||||
LOGGER.error("PGP Exception.", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue