mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2025-09-10 03:39:40 +02:00
Compare commits
No commits in common. "70367e98f022d0cd27a2b384af8945d5dcfb17a6" and "f91c5065fc88b8a0509a9401af59422fbae9544e" have entirely different histories.
70367e98f0
...
f91c5065fc
29 changed files with 49 additions and 407 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -5,18 +5,6 @@ SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
# Cert-D-Java Changelog
|
# Cert-D-Java Changelog
|
||||||
|
|
||||||
## 0.1.2-SNAPSHOT
|
|
||||||
- `pgp-certificate-store`:
|
|
||||||
- Rework `Certificate`, `Key` to inherit from `KeyMaterial`
|
|
||||||
- Rename `CertificateReaderBackend` to `KeyMaterialReaderBackend`
|
|
||||||
- Rename `CertificateMerger` to `KeyMaterialMerger`
|
|
||||||
- Rework `PGPCertificateStore` class
|
|
||||||
- `pgp-cert-d-java`:
|
|
||||||
- Rework `PGPCertificateDirectory` class by separating out backend logic
|
|
||||||
- Split interface into `ReadOnlyPGPCertificateDirectory` and `WritingPGPCertificateDirectory`
|
|
||||||
- `pgp-cert-d-java-jdbc-sqlite-lookup`:
|
|
||||||
- Add `DatabaseSubkeyLookupFactory`
|
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
- Bump `slf4j` to `1.7.36`
|
- Bump `slf4j` to `1.7.36`
|
||||||
- Bump `logback` to `1.2.11`
|
- Bump `logback` to `1.2.11`
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.cert_d.jdbc.sqlite;
|
|
||||||
|
|
||||||
import pgp.cert_d.subkey_lookup.SubkeyLookup;
|
|
||||||
import pgp.cert_d.subkey_lookup.SubkeyLookupFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of {@link SubkeyLookupFactory} which creates a SQLite-based {@link DatabaseSubkeyLookup}.
|
|
||||||
*/
|
|
||||||
public class DatabaseSubkeyLookupFactory implements SubkeyLookupFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
|
||||||
File databaseFile = new File(baseDirectory, "_pgpainless_subkey_map.db");
|
|
||||||
SubkeyLookupDao dao;
|
|
||||||
try {
|
|
||||||
if (!databaseFile.exists()) {
|
|
||||||
databaseFile.createNewFile();
|
|
||||||
}
|
|
||||||
dao = SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile);
|
|
||||||
} catch (SQLException | IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return new DatabaseSubkeyLookup(dao);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,8 +26,6 @@ dependencies {
|
||||||
// Logging
|
// Logging
|
||||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||||
|
|
||||||
api project(":pgp-certificate-store")
|
|
||||||
|
|
||||||
// SQL Subkey table
|
// SQL Subkey table
|
||||||
testImplementation project(":pgp-cert-d-java-jdbc-sqlite-lookup")
|
testImplementation project(":pgp-cert-d-java-jdbc-sqlite-lookup")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,8 @@ package pgp.cert_d;
|
||||||
|
|
||||||
import pgp.cert_d.backend.FileBasedCertificateDirectoryBackend;
|
import pgp.cert_d.backend.FileBasedCertificateDirectoryBackend;
|
||||||
import pgp.cert_d.backend.InMemoryCertificateDirectoryBackend;
|
import pgp.cert_d.backend.InMemoryCertificateDirectoryBackend;
|
||||||
import pgp.cert_d.subkey_lookup.InMemorySubkeyLookup;
|
import pgp.cert_d.exception.NotAStoreException;
|
||||||
import pgp.cert_d.subkey_lookup.SubkeyLookup;
|
import pgp.certificate.KeyMaterialReaderBackend;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialReaderBackend;
|
|
||||||
import pgp.certificate_store.exception.NotAStoreException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -20,18 +18,18 @@ public final class PGPCertificateDirectories {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPCertificateDirectory inMemoryCertificateDirectory(KeyMaterialReaderBackend keyReader) {
|
public static PGPCertificateDirectory inMemoryCertificateDirectory(KeyMaterialReaderBackend keyReader) {
|
||||||
return new PGPCertificateDirectory(new InMemoryCertificateDirectoryBackend(keyReader), new InMemorySubkeyLookup());
|
return new PGPCertificateDirectory(new InMemoryCertificateDirectoryBackend(keyReader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPCertificateDirectory defaultFileBasedCertificateDirectory(KeyMaterialReaderBackend keyReader, SubkeyLookup subkeyLookup)
|
public static PGPCertificateDirectory defaultFileBasedCertificateDirectory(KeyMaterialReaderBackend keyReader)
|
||||||
throws NotAStoreException {
|
throws NotAStoreException {
|
||||||
return fileBasedCertificateDirectory(keyReader, BaseDirectoryProvider.getDefaultBaseDir(), subkeyLookup);
|
return fileBasedCertificateDirectory(keyReader, BaseDirectoryProvider.getDefaultBaseDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPCertificateDirectory fileBasedCertificateDirectory(
|
public static PGPCertificateDirectory fileBasedCertificateDirectory(
|
||||||
KeyMaterialReaderBackend keyReader, File baseDirectory, SubkeyLookup subkeyLookup)
|
KeyMaterialReaderBackend keyReader, File baseDirectory)
|
||||||
throws NotAStoreException {
|
throws NotAStoreException {
|
||||||
return new PGPCertificateDirectory(
|
return new PGPCertificateDirectory(
|
||||||
new FileBasedCertificateDirectoryBackend(baseDirectory, keyReader), subkeyLookup);
|
new FileBasedCertificateDirectoryBackend(baseDirectory, keyReader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,28 +4,23 @@
|
||||||
|
|
||||||
package pgp.cert_d;
|
package pgp.cert_d;
|
||||||
|
|
||||||
import pgp.cert_d.subkey_lookup.SubkeyLookup;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterial;
|
import pgp.certificate.Certificate;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
import pgp.certificate.KeyMaterial;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate.KeyMaterialMerger;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class PGPCertificateDirectory
|
public class PGPCertificateDirectory
|
||||||
implements ReadOnlyPGPCertificateDirectory, WritingPGPCertificateDirectory, SubkeyLookup {
|
implements ReadOnlyPGPCertificateDirectory, WritingPGPCertificateDirectory {
|
||||||
|
|
||||||
private final Backend backend;
|
private final Backend backend;
|
||||||
private final SubkeyLookup subkeyLookup;
|
|
||||||
|
|
||||||
public PGPCertificateDirectory(Backend backend, SubkeyLookup subkeyLookup) {
|
public PGPCertificateDirectory(Backend backend) {
|
||||||
this.backend = backend;
|
this.backend = backend;
|
||||||
this.subkeyLookup = subkeyLookup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,7 +83,6 @@ public class PGPCertificateDirectory
|
||||||
throws IOException, BadDataException, InterruptedException {
|
throws IOException, BadDataException, InterruptedException {
|
||||||
backend.getLock().lockDirectory();
|
backend.getLock().lockDirectory();
|
||||||
KeyMaterial inserted = backend.doInsertTrustRoot(data, merge);
|
KeyMaterial inserted = backend.doInsertTrustRoot(data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +94,6 @@ public class PGPCertificateDirectory
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
KeyMaterial inserted = backend.doInsertTrustRoot(data, merge);
|
KeyMaterial inserted = backend.doInsertTrustRoot(data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +105,6 @@ public class PGPCertificateDirectory
|
||||||
throws IOException, BadDataException, InterruptedException {
|
throws IOException, BadDataException, InterruptedException {
|
||||||
backend.getLock().lockDirectory();
|
backend.getLock().lockDirectory();
|
||||||
Certificate inserted = backend.doInsert(data, merge);
|
Certificate inserted = backend.doInsert(data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +116,6 @@ public class PGPCertificateDirectory
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Certificate inserted = backend.doInsert(data, merge);
|
Certificate inserted = backend.doInsert(data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +125,6 @@ public class PGPCertificateDirectory
|
||||||
throws IOException, BadDataException, BadNameException, InterruptedException {
|
throws IOException, BadDataException, BadNameException, InterruptedException {
|
||||||
backend.getLock().lockDirectory();
|
backend.getLock().lockDirectory();
|
||||||
Certificate inserted = backend.doInsertWithSpecialName(specialName, data, merge);
|
Certificate inserted = backend.doInsertWithSpecialName(specialName, data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
@ -146,21 +136,10 @@ public class PGPCertificateDirectory
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Certificate inserted = backend.doInsertWithSpecialName(specialName, data, merge);
|
Certificate inserted = backend.doInsertWithSpecialName(specialName, data, merge);
|
||||||
subkeyLookup.storeCertificateSubkeyIds(inserted.getFingerprint(), inserted.getSubkeyIds());
|
|
||||||
backend.getLock().releaseDirectory();
|
backend.getLock().releaseDirectory();
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getCertificateFingerprintsForSubkeyId(long subkeyId) throws IOException {
|
|
||||||
return subkeyLookup.getCertificateFingerprintsForSubkeyId(subkeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void storeCertificateSubkeyIds(String certificate, List<Long> subkeyIds) throws IOException {
|
|
||||||
subkeyLookup.storeCertificateSubkeyIds(certificate, subkeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Backend {
|
public interface Backend {
|
||||||
|
|
||||||
LockingMechanism getLock();
|
LockingMechanism getLock();
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.cert_d;
|
|
||||||
|
|
||||||
import pgp.certificate_store.PGPCertificateStore;
|
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapter class to adapt a {@link PGPCertificateDirectory} to the {@link PGPCertificateStore} interface.
|
|
||||||
*/
|
|
||||||
public class PGPCertificateStoreAdapter implements PGPCertificateStore {
|
|
||||||
|
|
||||||
private final PGPCertificateDirectory directory;
|
|
||||||
|
|
||||||
public PGPCertificateStoreAdapter(PGPCertificateDirectory directory) {
|
|
||||||
this.directory = directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getCertificate(String identifier)
|
|
||||||
throws IOException, BadNameException, BadDataException {
|
|
||||||
if (SpecialNames.lookupSpecialName(identifier) != null) {
|
|
||||||
return directory.getBySpecialName(identifier);
|
|
||||||
} else {
|
|
||||||
return directory.getByFingerprint(identifier.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<Certificate> getCertificatesBySubkeyId(long subkeyId)
|
|
||||||
throws IOException, BadDataException {
|
|
||||||
Set<String> fingerprints = directory.getCertificateFingerprintsForSubkeyId(subkeyId);
|
|
||||||
Set<Certificate> certificates = new HashSet<>();
|
|
||||||
for (String fingerprint : fingerprints) {
|
|
||||||
try {
|
|
||||||
certificates.add(directory.getByFingerprint(fingerprint));
|
|
||||||
} catch (BadNameException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return certificates.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate insertCertificate(InputStream data, KeyMaterialMerger merge)
|
|
||||||
throws IOException, InterruptedException, BadDataException {
|
|
||||||
Certificate certificate = directory.insert(data, merge);
|
|
||||||
return certificate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate insertCertificateBySpecialName(String specialName, InputStream data, KeyMaterialMerger merge)
|
|
||||||
throws IOException, InterruptedException, BadDataException, BadNameException {
|
|
||||||
return directory.insertWithSpecialName(specialName, data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<Certificate> getCertificates() {
|
|
||||||
return directory.items();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<String> getFingerprints() {
|
|
||||||
return directory.fingerprints();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
package pgp.cert_d;
|
package pgp.cert_d;
|
||||||
|
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
import pgp.certificate.Certificate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
|
|
||||||
package pgp.cert_d;
|
package pgp.cert_d;
|
||||||
|
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterial;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
import pgp.certificate.Certificate;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate.KeyMaterial;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
import pgp.certificate.KeyMaterialMerger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
|
@ -6,13 +6,13 @@ package pgp.cert_d.backend;
|
||||||
|
|
||||||
import pgp.cert_d.PGPCertificateDirectory;
|
import pgp.cert_d.PGPCertificateDirectory;
|
||||||
import pgp.cert_d.SpecialNames;
|
import pgp.cert_d.SpecialNames;
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterial;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
import pgp.cert_d.exception.NotAStoreException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialReaderBackend;
|
import pgp.certificate.Certificate;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate.KeyMaterial;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
import pgp.certificate.KeyMaterialMerger;
|
||||||
import pgp.certificate_store.exception.NotAStoreException;
|
import pgp.certificate.KeyMaterialReaderBackend;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
|
@ -6,12 +6,12 @@ package pgp.cert_d.backend;
|
||||||
|
|
||||||
import pgp.cert_d.PGPCertificateDirectory;
|
import pgp.cert_d.PGPCertificateDirectory;
|
||||||
import pgp.cert_d.SpecialNames;
|
import pgp.cert_d.SpecialNames;
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterial;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
import pgp.certificate.Certificate;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialReaderBackend;
|
import pgp.certificate.KeyMaterial;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate.KeyMaterialMerger;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
import pgp.certificate.KeyMaterialReaderBackend;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.exception;
|
package pgp.cert_d.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data was not a valid OpenPGP cert or key in binary format.
|
* The data was not a valid OpenPGP cert or key in binary format.
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.exception;
|
package pgp.cert_d.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provided name was neither a valid fingerprint, nor a known special name.
|
* Provided name was neither a valid fingerprint, nor a known special name.
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.exception;
|
package pgp.cert_d.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base dir cannot possibly contain a store.
|
* The base dir cannot possibly contain a store.
|
|
@ -5,4 +5,4 @@
|
||||||
/**
|
/**
|
||||||
* Exceptions.
|
* Exceptions.
|
||||||
*/
|
*/
|
||||||
package pgp.certificate_store.exception;
|
package pgp.cert_d.exception;
|
|
@ -1,14 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.cert_d.subkey_lookup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class InMemorySubkeyLookupFactory implements SubkeyLookupFactory {
|
|
||||||
@Override
|
|
||||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
|
||||||
return new InMemorySubkeyLookup();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.cert_d.subkey_lookup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public interface SubkeyLookupFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link SubkeyLookup} instance that lives in the given baseDirectory.
|
|
||||||
*
|
|
||||||
* @param baseDirectory base directory
|
|
||||||
* @return subkey lookup
|
|
||||||
*/
|
|
||||||
SubkeyLookup createFileBasedInstance(File baseDirectory);
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenPGP certificate (public key).
|
* OpenPGP certificate (public key).
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenPGP key (secret key).
|
* OpenPGP key (secret key).
|
|
@ -2,11 +2,10 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface KeyMaterial {
|
public interface KeyMaterial {
|
||||||
|
@ -37,5 +36,5 @@ public interface KeyMaterial {
|
||||||
* @return subkeys
|
* @return subkeys
|
||||||
* @throws IOException in case of an IO error
|
* @throws IOException in case of an IO error
|
||||||
*/
|
*/
|
||||||
List<Long> getSubkeyIds() throws IOException;
|
Set<Long> getSubkeyIds() throws IOException;
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
||||||
|
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.cert_d.exception.BadDataException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
|
@ -5,4 +5,4 @@
|
||||||
/**
|
/**
|
||||||
* General OpenPGP Certificate Storage related classes.
|
* General OpenPGP Certificate Storage related classes.
|
||||||
*/
|
*/
|
||||||
package pgp.certificate_store.certificate;
|
package pgp.certificate;
|
|
@ -7,7 +7,7 @@ package pgp.cert_d;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import pgp.cert_d.backend.FileBasedCertificateDirectoryBackend;
|
import pgp.cert_d.backend.FileBasedCertificateDirectoryBackend;
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
import pgp.cert_d.exception.BadNameException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<!--
|
|
||||||
SPDX-FileCopyrightText: 2022 Paul Schaub <info@pgpainless.org>
|
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
|
||||||
-->
|
|
||||||
|
|
||||||
# PGP Certificate Store Definitions
|
|
||||||
|
|
||||||
[](https://javadoc.io/doc/org.pgpainless/pgp-certificate-store)
|
|
||||||
[](https://search.maven.org/artifact/org.pgpainless/pgp-certificate-store)
|
|
||||||
|
|
||||||
This module contains API definitions for an OpenPGP certificate store.
|
|
||||||
A certificate store is used to store public key certificates only.
|
|
|
@ -1,36 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id 'java-library'
|
|
||||||
}
|
|
||||||
|
|
||||||
group 'org.pgpainless'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'ru.vyarus.animalsniffer'
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// animal sniffer for ensuring Android API compatibility
|
|
||||||
signature "net.sf.androidscents.signature:android-api-level-${minAndroidSdk}:2.3.3_r2@signature"
|
|
||||||
|
|
||||||
// JUnit for testing
|
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
|
||||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
|
||||||
|
|
||||||
// Logging
|
|
||||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
|
||||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
|
||||||
}
|
|
||||||
|
|
||||||
animalsniffer {
|
|
||||||
sourceSets = [sourceSets.main]
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.certificate_store;
|
|
||||||
|
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for an OpenPGP certificate (public key) store.
|
|
||||||
*/
|
|
||||||
public interface PGPCertificateStore {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the certificate that matches the given identifier.
|
|
||||||
* If no matching certificate can be found, return null.
|
|
||||||
*
|
|
||||||
* @param identifier identifier for a certificate.
|
|
||||||
* @return certificate or null
|
|
||||||
*
|
|
||||||
* @throws IOException in case of an IO-error
|
|
||||||
* @throws BadNameException if the identifier is invalid
|
|
||||||
* @throws BadDataException if the certificate file contains invalid data
|
|
||||||
*/
|
|
||||||
Certificate getCertificate(String identifier)
|
|
||||||
throws IOException, BadNameException, BadDataException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an {@link Iterator} over all certificates in the store that contain a subkey with the given
|
|
||||||
* subkey id.
|
|
||||||
* @param subkeyId id of the subkey
|
|
||||||
* @return iterator
|
|
||||||
*
|
|
||||||
* @throws IOException in case of an IO error
|
|
||||||
* @throws BadDataException if any of the certificate files contains invalid data
|
|
||||||
*/
|
|
||||||
Iterator<Certificate> getCertificatesBySubkeyId(long subkeyId)
|
|
||||||
throws IOException, BadDataException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a certificate into the store.
|
|
||||||
* If an instance of the certificate is already present in the store, the given {@link KeyMaterialMerger} will be
|
|
||||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
|
||||||
* will be stored in the store and returned.
|
|
||||||
*
|
|
||||||
* This method will block until a write-lock on the store can be acquired.
|
|
||||||
*
|
|
||||||
* @param data input stream containing the new certificate instance
|
|
||||||
* @param merge callback for merging with an existing certificate instance
|
|
||||||
* @return merged certificate
|
|
||||||
*
|
|
||||||
* @throws IOException in case of an IO-error
|
|
||||||
* @throws InterruptedException in case the inserting thread gets interrupted
|
|
||||||
* @throws BadDataException if the data stream does not contain valid OpenPGP data
|
|
||||||
*/
|
|
||||||
Certificate insertCertificate(InputStream data, KeyMaterialMerger merge)
|
|
||||||
throws IOException, InterruptedException, BadDataException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a certificate into the store.
|
|
||||||
* The certificate will be stored under the given special name instead of its fingerprint.
|
|
||||||
*
|
|
||||||
* If an instance of the certificate is already present under the special name in the store, the given {@link KeyMaterialMerger} will be
|
|
||||||
* used to merge both the existing and the new instance of the {@link Certificate}. The resulting merged certificate
|
|
||||||
* will be stored in the store and returned.
|
|
||||||
*
|
|
||||||
* This method will block until a write-lock on the store can be acquired.
|
|
||||||
*
|
|
||||||
* @param specialName special name of the certificate
|
|
||||||
* @param data input stream containing the new certificate instance
|
|
||||||
* @param merge callback for merging with an existing certificate instance
|
|
||||||
* @return merged certificate or null if the store cannot be locked
|
|
||||||
*
|
|
||||||
* @throws IOException in case of an IO-error
|
|
||||||
* @throws InterruptedException if the thread is interrupted
|
|
||||||
* @throws BadDataException if the certificate file does not contain valid OpenPGP data
|
|
||||||
* @throws BadNameException if the special name is unknown
|
|
||||||
*/
|
|
||||||
Certificate insertCertificateBySpecialName(String specialName, InputStream data, KeyMaterialMerger merge)
|
|
||||||
throws IOException, InterruptedException, BadDataException, BadNameException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an {@link Iterator} containing all certificates in the store.
|
|
||||||
* The iterator will contain both certificates addressed by special names and by fingerprints.
|
|
||||||
*
|
|
||||||
* @return certificates
|
|
||||||
*/
|
|
||||||
Iterator<Certificate> getCertificates();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an {@link Iterator} containing all certificate fingerprints from the store.
|
|
||||||
* Note that this only includes the fingerprints of certificate primary keys, not those of subkeys.
|
|
||||||
*
|
|
||||||
* @return fingerprints
|
|
||||||
*/
|
|
||||||
Iterator<String> getFingerprints();
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract definitions of an OpenPGP certificate store.
|
|
||||||
*/
|
|
||||||
package pgp.certificate_store;
|
|
|
@ -1,16 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package pgp.certificate_store;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class DummyTest {
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
rootProject.name = 'cert-d-java'
|
rootProject.name = 'cert-d-java'
|
||||||
|
|
||||||
include 'pgp-certificate-store',
|
include 'pgp-cert-d-java',
|
||||||
'pgp-cert-d-java',
|
|
||||||
'pgp-cert-d-java-jdbc-sqlite-lookup'
|
'pgp-cert-d-java-jdbc-sqlite-lookup'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue