mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2024-12-29 16:27:56 +01:00
Adopt changes from cert-d-java and pgpainless-core
This commit is contained in:
parent
20c6bc4c36
commit
47e521be01
7 changed files with 25 additions and 38 deletions
pgpainless-cert-d-cli/src/main/java/pgp/cert_d/cli
pgpainless-cert-d/src
main/java/org/pgpainless/certificate_store
test/java/org/pgpainless/cert_d
|
@ -4,7 +4,6 @@
|
|||
|
||||
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;
|
||||
|
@ -62,7 +61,6 @@ public class PGPCertDCli {
|
|||
|
||||
certificateDirectory = new SharedPGPCertificateDirectoryImpl(
|
||||
baseDirectory,
|
||||
new CertificateReader(),
|
||||
new KeyReader());
|
||||
subkeyLookup = new DatabaseSubkeyLookup(
|
||||
SqliteSubkeyLookupDaoImpl.forDatabaseFile(new File(baseDirectory, "_pgpainless_subkey_map.db")));
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// 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,6 +22,11 @@ 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,9 +4,11 @@
|
|||
|
||||
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.Key;
|
||||
import pgp.certificate_store.KeyMaterial;
|
||||
import pgp.certificate_store.KeyReaderBackend;
|
||||
import pgp.certificate_store.exception.BadDataException;
|
||||
|
||||
|
@ -16,8 +18,14 @@ import java.io.InputStream;
|
|||
public class KeyReader implements KeyReaderBackend {
|
||||
|
||||
@Override
|
||||
public Key readKey(InputStream data) throws IOException, BadDataException {
|
||||
final PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(data);
|
||||
return KeyFactory.keyFromSecretKeyRing(key);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ 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;
|
||||
|
@ -51,7 +50,7 @@ public class SharedPGPCertificateDirectoryAdapterTest {
|
|||
@BeforeEach
|
||||
public void setupInstance() throws IOException, NotAStoreException {
|
||||
adapter = new SharedPGPCertificateDirectoryAdapter(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()),
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()),
|
||||
new InMemorySubkeyLookup());
|
||||
store = adapter;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ 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;
|
||||
|
@ -59,9 +58,9 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
|
||||
private static Stream<SharedPGPCertificateDirectory> provideTestSubjects() throws IOException, NotAStoreException {
|
||||
return Stream.of(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()),
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()),
|
||||
new CachingSharedPGPCertificateDirectoryWrapper(
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new CertificateReader(), new KeyReader()))
|
||||
new SharedPGPCertificateDirectoryImpl(tempDir(), new KeyReader()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -76,7 +75,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
public void simpleInsertGet(SharedPGPCertificateDirectory directory)
|
||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException,
|
||||
BadDataException, InterruptedException, BadNameException {
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(key);
|
||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
|
@ -133,7 +132,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
BadDataException, InterruptedException {
|
||||
assumeTrue(directory.getLock() instanceof FileLockingMechanism);
|
||||
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(key);
|
||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||
|
||||
|
@ -150,7 +149,7 @@ public class SharedPGPCertificateDirectoryTest {
|
|||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException,
|
||||
BadDataException, InterruptedException, BadNameException {
|
||||
|
||||
PGPSecretKeyRing trustRootKey = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPSecretKeyRing trustRootKey = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
PGPPublicKeyRing trustRootCert = PGPainless.extractCertificate(trustRootKey);
|
||||
OpenPgpFingerprint trustRootFingerprint = OpenPgpFingerprint.of(trustRootCert);
|
||||
ByteArrayInputStream trustRootCertIn = new ByteArrayInputStream(trustRootCert.getEncoded());
|
||||
|
@ -159,7 +158,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", null);
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing().modernKeyRing("Alice");
|
||||
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.2.1'
|
||||
pgpainlessVersion = '1.3.5-SNAPSHOT'
|
||||
pgpCertDJavaVersion = '0.1.2-SNAPSHOT'
|
||||
picocliVersion = '4.6.3'
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue