mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2025-09-09 18:29:49 +02:00
Adopt changes from cert-d-java rewrite
This commit is contained in:
parent
3267a330bf
commit
c7cdf4c353
15 changed files with 101 additions and 483 deletions
|
@ -10,10 +10,8 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.certificate_store.CertificateFactory;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.CertificateMerger;
|
||||
import pgp.certificate_store.Key;
|
||||
import pgp.certificate_store.KeyMerger;
|
||||
import pgp.certificate.KeyMaterial;
|
||||
import pgp.certificate.KeyMaterialMerger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
@ -21,16 +19,16 @@ import java.util.Iterator;
|
|||
public class MergeCallbacks {
|
||||
|
||||
/**
|
||||
* Return a {@link CertificateMerger} that merges the two copies of the same certificate (same primary key) into one
|
||||
* Return a {@link KeyMaterialMerger} that merges the two copies of the same certificate (same primary key) into one
|
||||
* combined certificate.
|
||||
*
|
||||
* @return merging callback
|
||||
*/
|
||||
public static CertificateMerger mergeCertificates() {
|
||||
return new CertificateMerger() {
|
||||
public static KeyMaterialMerger mergeCertificates() {
|
||||
return new KeyMaterialMerger() {
|
||||
|
||||
@Override
|
||||
public Certificate merge(Certificate data, Certificate existing) throws IOException {
|
||||
public KeyMaterial merge(KeyMaterial data, KeyMaterial existing) throws IOException {
|
||||
try {
|
||||
PGPPublicKeyRing existingCert = PGPainless.readKeyRing().publicKeyRing(existing.getInputStream());
|
||||
PGPPublicKeyRing updatedCert = PGPainless.readKeyRing().publicKeyRing(data.getInputStream());
|
||||
|
@ -97,26 +95,26 @@ public class MergeCallbacks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return an implementation of {@link CertificateMerger} that ignores the existing certificate and instead
|
||||
* Return an implementation of {@link KeyMaterialMerger} that ignores the existing certificate and instead
|
||||
* returns the first instance.
|
||||
*
|
||||
* @return overriding callback
|
||||
*/
|
||||
public static CertificateMerger overrideCertificate() {
|
||||
public static KeyMaterialMerger overrideCertificate() {
|
||||
// noinspection Convert2Lambda
|
||||
return new CertificateMerger() {
|
||||
return new KeyMaterialMerger() {
|
||||
@Override
|
||||
public Certificate merge(Certificate data, Certificate existing) {
|
||||
public KeyMaterial merge(KeyMaterial data, KeyMaterial existing) {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static KeyMerger overrideKey() {
|
||||
public static KeyMaterialMerger overrideKey() {
|
||||
// noinspection Convert2Lambda
|
||||
return new KeyMerger() {
|
||||
return new KeyMaterialMerger() {
|
||||
@Override
|
||||
public Key merge(Key data, Key existing) {
|
||||
public KeyMaterial merge(KeyMaterial data, KeyMaterial existing) {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,21 +4,15 @@
|
|||
|
||||
package pgp.cert_d.cli;
|
||||
|
||||
import org.pgpainless.certificate_store.KeyReader;
|
||||
import org.pgpainless.certificate_store.SharedPGPCertificateDirectoryAdapter;
|
||||
import org.pgpainless.certificate_store.PGPainlessCertD;
|
||||
import pgp.cert_d.BaseDirectoryProvider;
|
||||
import pgp.cert_d.SharedPGPCertificateDirectoryImpl;
|
||||
import pgp.cert_d.NotAStoreException;
|
||||
import pgp.cert_d.cli.commands.Export;
|
||||
import pgp.cert_d.cli.commands.Get;
|
||||
import pgp.cert_d.cli.commands.Insert;
|
||||
import pgp.cert_d.cli.commands.Import;
|
||||
import pgp.cert_d.cli.commands.List;
|
||||
import pgp.cert_d.cli.commands.Setup;
|
||||
import pgp.cert_d.jdbc.sqlite.DatabaseSubkeyLookup;
|
||||
import pgp.cert_d.jdbc.sqlite.SqliteSubkeyLookupDaoImpl;
|
||||
import pgp.certificate_store.SubkeyLookup;
|
||||
import pgp.certificate_store.exception.NotAStoreException;
|
||||
import pgp.certificate_store.CertificateDirectory;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -43,7 +37,7 @@ public class PGPCertDCli {
|
|||
scope = CommandLine.ScopeType.INHERIT)
|
||||
File baseDirectory;
|
||||
|
||||
private static CertificateDirectory certificateDirectory;
|
||||
private static PGPainlessCertD certificateDirectory;
|
||||
|
||||
private int executionStrategy(CommandLine.ParseResult parseResult) {
|
||||
try {
|
||||
|
@ -55,19 +49,11 @@ public class PGPCertDCli {
|
|||
}
|
||||
|
||||
private void initStore() throws NotAStoreException, SQLException {
|
||||
SharedPGPCertificateDirectoryImpl certificateDirectory;
|
||||
SubkeyLookup subkeyLookup;
|
||||
if (baseDirectory == null) {
|
||||
baseDirectory = BaseDirectoryProvider.getDefaultBaseDir();
|
||||
}
|
||||
|
||||
certificateDirectory = new SharedPGPCertificateDirectoryImpl(
|
||||
baseDirectory,
|
||||
new KeyReader());
|
||||
subkeyLookup = new DatabaseSubkeyLookup(
|
||||
SqliteSubkeyLookupDaoImpl.forDatabaseFile(new File(baseDirectory, "_pgpainless_subkey_map.db")));
|
||||
|
||||
PGPCertDCli.certificateDirectory = new SharedPGPCertificateDirectoryAdapter(certificateDirectory, subkeyLookup);
|
||||
PGPCertDCli.certificateDirectory = PGPainlessCertD.fileBased(baseDirectory);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -77,7 +63,7 @@ public class PGPCertDCli {
|
|||
.execute(args);
|
||||
}
|
||||
|
||||
public static CertificateDirectory getCertificateDirectory() {
|
||||
public static PGPainlessCertD getCertificateDirectory() {
|
||||
return certificateDirectory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.bouncycastle.util.io.Streams;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +29,7 @@ public class Export implements Runnable {
|
|||
@Override
|
||||
public void run() {
|
||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificates();
|
||||
.items();
|
||||
OutputStream out = armor ? new ArmoredOutputStream(System.out) : System.out;
|
||||
while (certificates.hasNext()) {
|
||||
try {
|
||||
|
|
|
@ -9,10 +9,10 @@ import java.io.IOException;
|
|||
import org.bouncycastle.util.io.Streams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.BadDataException;
|
||||
import pgp.cert_d.BadNameException;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate_store.exception.BadNameException;
|
||||
import pgp.certificate.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
@CommandLine.Command(name = "get",
|
||||
|
@ -31,7 +31,7 @@ public class Get implements Runnable {
|
|||
public void run() {
|
||||
try {
|
||||
Certificate certificate = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificate(identifer);
|
||||
.getByFingerprint(identifer);
|
||||
if (certificate == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.BadDataException;
|
||||
import pgp.cert_d.cli.MergeCallbacks;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -32,7 +32,7 @@ public class Import implements Runnable {
|
|||
for (PGPPublicKeyRing cert : certificates) {
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
Certificate certificate = PGPCertDCli.getCertificateDirectory()
|
||||
.insertCertificate(certIn, MergeCallbacks.mergeCertificates());
|
||||
.insert(certIn, MergeCallbacks.mergeCertificates());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO-Error.", e);
|
||||
|
|
|
@ -6,10 +6,10 @@ package pgp.cert_d.cli.commands;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.BadDataException;
|
||||
import pgp.cert_d.cli.MergeCallbacks;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import pgp.certificate.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -24,7 +24,7 @@ public class Insert implements Runnable {
|
|||
public void run() {
|
||||
try {
|
||||
Certificate certificate = PGPCertDCli.getCertificateDirectory()
|
||||
.insertCertificate(System.in, MergeCallbacks.mergeCertificates());
|
||||
.insert(System.in, MergeCallbacks.mergeCertificates());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO-Error.", e);
|
||||
System.exit(-1);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package pgp.cert_d.cli.commands;
|
||||
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
@ -18,7 +18,7 @@ public class List implements Runnable {
|
|||
@Override
|
||||
public void run() {
|
||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificates();
|
||||
.items();
|
||||
while (certificates.hasNext()) {
|
||||
Certificate certificate = certificates.next();
|
||||
// CHECKSTYLE:OFF
|
||||
|
|
|
@ -15,9 +15,9 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
|
|||
import org.pgpainless.util.Passphrase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pgp.cert_d.BadDataException;
|
||||
import pgp.cert_d.cli.MergeCallbacks;
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue