mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2025-09-09 10:19:48 +02:00
Compare commits
No commits in common. "3267a330bfd702adb84c0225d489207231a531f1" and "20c6bc4c366b57386129a007f161d2e78a2ddd2a" have entirely different histories.
3267a330bf
...
20c6bc4c36
12 changed files with 43 additions and 103 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
plugins {
|
||||
id 'application'
|
||||
id "com.github.johnrengelman.shadow" version "6.1.0"
|
||||
}
|
||||
|
||||
group 'org.pgpainless'
|
||||
|
@ -19,7 +18,7 @@ dependencies {
|
|||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
// Logging
|
||||
implementation ("org.slf4j:slf4j-nop:$slf4jVersion")
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
|
||||
// pgp.cert.d using PGPainless
|
||||
implementation project(":pgpainless-cert-d")
|
||||
|
@ -37,13 +36,8 @@ test {
|
|||
|
||||
mainClassName = 'pgp.cert_d.cli.PGPCertDCli'
|
||||
|
||||
application {
|
||||
mainClass = mainClassName
|
||||
}
|
||||
|
||||
/*
|
||||
jar {
|
||||
dependsOn(":pgpainless-cert-d:jar")
|
||||
dependsOn(":pgpainless-cert-d:assemble")
|
||||
manifest {
|
||||
attributes 'Main-Class': "$mainClassName"
|
||||
}
|
||||
|
@ -58,5 +52,4 @@ jar {
|
|||
exclude "META-INF/*.RSA"
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package pgp.cert_d.cli;
|
||||
|
||||
import org.pgpainless.certificate_store.CertificateReader;
|
||||
import org.pgpainless.certificate_store.KeyReader;
|
||||
import org.pgpainless.certificate_store.SharedPGPCertificateDirectoryAdapter;
|
||||
import pgp.cert_d.BaseDirectoryProvider;
|
||||
|
@ -12,7 +13,6 @@ 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;
|
||||
|
@ -33,8 +33,7 @@ import java.sql.SQLException;
|
|||
Insert.class,
|
||||
Import.class,
|
||||
Get.class,
|
||||
Setup.class,
|
||||
List.class
|
||||
Setup.class
|
||||
}
|
||||
)
|
||||
public class PGPCertDCli {
|
||||
|
@ -63,6 +62,7 @@ public class PGPCertDCli {
|
|||
|
||||
certificateDirectory = new SharedPGPCertificateDirectoryImpl(
|
||||
baseDirectory,
|
||||
new CertificateReader(),
|
||||
new KeyReader());
|
||||
subkeyLookup = new DatabaseSubkeyLookup(
|
||||
SqliteSubkeyLookupDaoImpl.forDatabaseFile(new File(baseDirectory, "_pgpainless_subkey_map.db")));
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package pgp.cert_d.cli.commands;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -14,40 +13,28 @@ import picocli.CommandLine;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
@CommandLine.Command(name = "export",
|
||||
resourceBundle = "msg_export")
|
||||
public class Export implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Export.class);
|
||||
|
||||
@CommandLine.Option(names = {"-a", "--armor"})
|
||||
boolean armor = false;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificates();
|
||||
OutputStream out = armor ? new ArmoredOutputStream(System.out) : System.out;
|
||||
while (certificates.hasNext()) {
|
||||
try {
|
||||
Certificate certificate = certificates.next();
|
||||
InputStream inputStream = certificate.getInputStream();
|
||||
Streams.pipeAll(inputStream, out);
|
||||
Streams.pipeAll(inputStream, System.out);
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO Error", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
if (armor) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pgp.cert_d.cli.commands;
|
||||
|
||||
import pgp.cert_d.cli.PGPCertDCli;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@CommandLine.Command(name = "list",
|
||||
resourceBundle = "msg_list"
|
||||
)
|
||||
public class List implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Iterator<Certificate> certificates = PGPCertDCli.getCertificateDirectory()
|
||||
.getCertificates();
|
||||
while (certificates.hasNext()) {
|
||||
Certificate certificate = certificates.next();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(certificate.getFingerprint());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=List all certificates in the directory
|
||||
store=Overwrite the default certificate directory path
|
||||
|
||||
# Generic TODO: Remove when bumping picocli to 4.7.0
|
||||
usage.synopsisHeading=Usage:\u0020
|
||||
usage.commandListHeading = %nCommands:%n
|
||||
usage.optionListHeading = %nOptions:%n
|
||||
usage.footerHeading=Powered by picocli%n
|
|
@ -1,11 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
usage.header=Liste alle Zertifikate im Verzeichnis auf
|
||||
store=Überschreibe den Standardpfad des Zertifikatsverzeichnisses
|
||||
|
||||
# Generic TODO: Remove when bumping picocli to 4.7.0
|
||||
usage.synopsisHeading=Aufruf:\u0020
|
||||
usage.commandListHeading=%nBefehle:%n
|
||||
usage.optionListHeading = %nOptionen:%n
|
||||
usage.footerHeading=Powered by Picocli%n
|
|
@ -0,0 +1,22 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.certificate_store;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.pgpainless.PGPainless;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.certificate_store.CertificateReaderBackend;
|
||||
|
||||
public class CertificateReader implements CertificateReaderBackend {
|
||||
|
||||
@Override
|
||||
public Certificate readCertificate(InputStream inputStream) throws IOException {
|
||||
final PGPPublicKeyRing certificate = PGPainless.readKeyRing().publicKeyRing(inputStream);
|
||||
return CertificateFactory.certificateFromPublicKeyRing(certificate);
|
||||
}
|
||||
}
|
|
@ -22,11 +22,6 @@ public class KeyFactory {
|
|||
public static Key keyFromSecretKeyRing(PGPSecretKeyRing secretKeyRing) {
|
||||
|
||||
return new Key() {
|
||||
@Override
|
||||
public String getFingerprint() {
|
||||
return getCertificate().getFingerprint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Certificate getCertificate() {
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeyRing);
|
||||
|
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
package org.pgpainless.certificate_store;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.pgpainless.PGPainless;
|
||||
import pgp.certificate_store.KeyMaterial;
|
||||
import pgp.certificate_store.Key;
|
||||
import pgp.certificate_store.KeyReaderBackend;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
|
||||
|
@ -18,14 +16,8 @@ import java.io.InputStream;
|
|||
public class KeyReader implements KeyReaderBackend {
|
||||
|
||||
@Override
|
||||
public KeyMaterial read(InputStream data) throws IOException, BadDataException {
|
||||
final PGPKeyRing keyRing = PGPainless.readKeyRing().keyRing(data);
|
||||
if (keyRing instanceof PGPPublicKeyRing) {
|
||||
return CertificateFactory.certificateFromPublicKeyRing((PGPPublicKeyRing) keyRing);
|
||||
} else if (keyRing instanceof PGPSecretKeyRing) {
|
||||
return KeyFactory.keyFromSecretKeyRing((PGPSecretKeyRing) keyRing);
|
||||
} else {
|
||||
throw new BadDataException();
|
||||
}
|
||||
public Key readKey(InputStream data) throws IOException, BadDataException {
|
||||
final PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(data);
|
||||
return KeyFactory.keyFromSecretKeyRing(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.bouncycastle.util.encoders.Hex;
|
|||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.certificate_store.CertificateReader;
|
||||
import org.pgpainless.certificate_store.KeyReader;
|
||||
import org.pgpainless.certificate_store.SharedPGPCertificateDirectoryAdapter;
|
||||
import pgp.cert_d.InMemorySubkeyLookup;
|
||||
|
@ -50,7 +51,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
|
|||
@BeforeEach
|
||||
public void setupInstance() throws IOException, NotAStoreException {
|
||||
adapter = new SharedPGPCertificateDirectoryAdapter(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()),
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()),
|
||||
new InMemorySubkeyLookup());
|
||||
store = adapter;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.certificate_store.CertificateReader;
|
||||
import org.pgpainless.certificate_store.KeyReader;
|
||||
import org.pgpainless.key.OpenPgpFingerprint;
|
||||
import org.pgpainless.key.generation.KeySpec;
|
||||
|
@ -58,9 +59,9 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
|
||||
private static Stream<SharedPGPCertificateDirectory> provideTestSubjects() throws IOException, NotAStoreException {
|
||||
return Stream.of(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()),
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()),
|
||||
new CachingSharedPGPCertificateDirectoryWrapper(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()))
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -75,7 +76,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
public void simpleInsertGet(SharedPGPCertificateDirectory directory)
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException,
|
||||
BadDataException, InterruptedException, BadNameException {
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(key);
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
|
@ -132,7 +133,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
BadDataException, InterruptedException {
|
||||
assumeTrue(directory.getLock() instanceof FileLockingMechanism);
|
||||
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(key);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
|
||||
|
@ -149,7 +150,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException,
|
||||
BadDataException, InterruptedException, BadNameException {
|
||||
|
||||
PGPSecretKeyRing trustRootKey = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing trustRootKey = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPPublicKeyRing trustRootCert = PGPainless.extractCertificate(trustRootKey);
|
||||
OpenPgpFingerprint trustRootFingerprint = OpenPgpFingerprint.of(trustRootCert);
|
||||
ByteArrayInputStream trustRootCertIn = new ByteArrayInputStream(trustRootCert.getEncoded());
|
||||
|
@ -158,7 +159,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
final int certificateCount = 3;
|
||||
Map<String, PGPPublicKeyRing> certificateMap = new HashMap<>();
|
||||
for (int i = 0; i < certificateCount; i++) {
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(key);
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
||||
certificateMap.put(fingerprint.toString().toLowerCase(), cert);
|
||||
|
|
|
@ -12,7 +12,7 @@ allprojects {
|
|||
logbackVersion = '1.2.11'
|
||||
junitVersion = '5.8.2'
|
||||
mockitoVersion = '4.5.1'
|
||||
pgpainlessVersion = '1.3.5-SNAPSHOT'
|
||||
pgpainlessVersion = '1.2.1'
|
||||
pgpCertDJavaVersion = '0.1.2-SNAPSHOT'
|
||||
picocliVersion = '4.6.3'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue