mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Remove unnecessary WebOfTrustCertificateStore class
This commit is contained in:
parent
31dd93fe77
commit
b8f77b4bf8
4 changed files with 29 additions and 144 deletions
|
@ -36,9 +36,11 @@ import org.pgpainless.wot.dijkstra.sq.Network;
|
||||||
import org.pgpainless.wot.dijkstra.sq.Optional;
|
import org.pgpainless.wot.dijkstra.sq.Optional;
|
||||||
import org.pgpainless.wot.dijkstra.sq.ReferenceTime;
|
import org.pgpainless.wot.dijkstra.sq.ReferenceTime;
|
||||||
import org.pgpainless.wot.sugar.IterableIterator;
|
import org.pgpainless.wot.sugar.IterableIterator;
|
||||||
|
import org.pgpainless.wot.sugar.PrefixedIterator;
|
||||||
import org.pgpainless.wot.sugar.Supplier;
|
import org.pgpainless.wot.sugar.Supplier;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import pgp.cert_d.PGPCertificateDirectory;
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
import pgp.certificate_store.certificate.Certificate;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate_store.exception.BadDataException;
|
||||||
|
|
||||||
|
@ -58,10 +60,10 @@ public class WebOfTrust implements CertificateAuthority {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebOfTrust.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(WebOfTrust.class);
|
||||||
|
|
||||||
private final WebOfTrustCertificateStore certificateStore;
|
private final PGPCertificateDirectory certificateStore;
|
||||||
private Network network;
|
private Network network;
|
||||||
|
|
||||||
public WebOfTrust(WebOfTrustCertificateStore certificateStore) {
|
public WebOfTrust(PGPCertificateDirectory certificateStore) {
|
||||||
this.certificateStore = certificateStore;
|
this.certificateStore = certificateStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +71,15 @@ public class WebOfTrust implements CertificateAuthority {
|
||||||
* Do the heavy lifting of calculating the web of trust.
|
* Do the heavy lifting of calculating the web of trust.
|
||||||
*/
|
*/
|
||||||
public void initialize() throws BadDataException, IOException {
|
public void initialize() throws BadDataException, IOException {
|
||||||
Iterator<Certificate> certificates = certificateStore.getAllItems();
|
Certificate trustRoot = null;
|
||||||
IterableIterator<Certificate> iterable = new IterableIterator<>(certificates);
|
try {
|
||||||
|
trustRoot = certificateStore.getTrustRootCertificate();
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
Iterator<Certificate> certificates = certificateStore.items();
|
||||||
|
Iterator<Certificate> withTrustRoot = new PrefixedIterator<>(trustRoot, certificates);
|
||||||
|
IterableIterator<Certificate> iterable = new IterableIterator<>(withTrustRoot);
|
||||||
network = fromCertificates(iterable, PGPainless.getPolicy(), Optional.just(ReferenceTime.now()));
|
network = fromCertificates(iterable, PGPainless.getPolicy(), Optional.just(ReferenceTime.now()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package org.pgpainless.wot;
|
|
||||||
|
|
||||||
import org.pgpainless.wot.sugar.PrefixedIterator;
|
|
||||||
import pgp.cert_d.PGPCertificateDirectory;
|
|
||||||
import pgp.cert_d.ReadOnlyPGPCertificateDirectory;
|
|
||||||
import pgp.cert_d.WritingPGPCertificateDirectory;
|
|
||||||
import pgp.cert_d.subkey_lookup.SubkeyLookup;
|
|
||||||
import pgp.certificate_store.certificate.KeyMaterial;
|
|
||||||
import pgp.certificate_store.certificate.KeyMaterialMerger;
|
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import pgp.certificate_store.certificate.Certificate;
|
|
||||||
import pgp.certificate_store.exception.BadNameException;
|
|
||||||
|
|
||||||
public class WebOfTrustCertificateStore implements ReadOnlyPGPCertificateDirectory, WritingPGPCertificateDirectory {
|
|
||||||
|
|
||||||
private final PGPCertificateDirectory directory;
|
|
||||||
|
|
||||||
public WebOfTrustCertificateStore(PGPCertificateDirectory.Backend backend, SubkeyLookup subkeyLookup) {
|
|
||||||
this(new PGPCertificateDirectory(backend, subkeyLookup));
|
|
||||||
}
|
|
||||||
|
|
||||||
public WebOfTrustCertificateStore(PGPCertificateDirectory certificateDirectory) {
|
|
||||||
this.directory = certificateDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<Certificate> getAllItems()
|
|
||||||
throws BadDataException, IOException {
|
|
||||||
Certificate trustRoot;
|
|
||||||
try {
|
|
||||||
trustRoot = getTrustRootCertificate();
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
// ignore
|
|
||||||
trustRoot = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PrefixedIterator<>(trustRoot, items());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getTrustRootCertificate() throws IOException, BadDataException {
|
|
||||||
return directory.getTrustRootCertificate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getTrustRootCertificateIfChanged(long tag) throws IOException, BadDataException {
|
|
||||||
return directory.getTrustRootCertificateIfChanged(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getByFingerprint(String fingerprint) throws IOException, BadNameException, BadDataException {
|
|
||||||
return directory.getByFingerprint(fingerprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getByFingerprintIfChanged(String fingerprint, long tag) throws IOException, BadNameException, BadDataException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getBySpecialName(String specialName) throws IOException, BadNameException, BadDataException {
|
|
||||||
return directory.getBySpecialName(specialName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate getBySpecialNameIfChanged(String specialName, long tag) throws IOException, BadNameException, BadDataException {
|
|
||||||
return directory.getBySpecialNameIfChanged(specialName, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<Certificate> items() {
|
|
||||||
return directory.items();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<String> fingerprints() {
|
|
||||||
return directory.fingerprints();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyMaterial getTrustRoot() throws IOException, BadDataException {
|
|
||||||
return directory.getTrustRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyMaterial insertTrustRoot(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, InterruptedException {
|
|
||||||
return directory.insertTrustRoot(data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyMaterial tryInsertTrustRoot(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException {
|
|
||||||
return directory.tryInsertTrustRoot(data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate insert(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, InterruptedException {
|
|
||||||
return directory.insert(data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate tryInsert(InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException {
|
|
||||||
return directory.tryInsert(data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate insertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, BadNameException, InterruptedException {
|
|
||||||
return directory.insertWithSpecialName(specialName, data, merge);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Certificate tryInsertWithSpecialName(String specialName, InputStream data, KeyMaterialMerger merge) throws IOException, BadDataException, BadNameException {
|
|
||||||
return directory.tryInsertWithSpecialName(specialName, data, merge);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,6 +18,7 @@ import org.pgpainless.wot.dijkstra.sq.CertificationSet;
|
||||||
import org.pgpainless.wot.dijkstra.sq.Network;
|
import org.pgpainless.wot.dijkstra.sq.Network;
|
||||||
import org.pgpainless.wot.testfixtures.TestCertificateStores;
|
import org.pgpainless.wot.testfixtures.TestCertificateStores;
|
||||||
import org.pgpainless.wot.testfixtures.WotTestVectors;
|
import org.pgpainless.wot.testfixtures.WotTestVectors;
|
||||||
|
import pgp.cert_d.PGPCertificateDirectory;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate_store.exception.BadDataException;
|
||||||
|
|
||||||
public class WebOfTrustTest {
|
public class WebOfTrustTest {
|
||||||
|
@ -34,7 +35,7 @@ public class WebOfTrustTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithTwoNodesAndOneDelegation() throws BadDataException, IOException, InterruptedException {
|
public void testWithTwoNodesAndOneDelegation() throws BadDataException, IOException, InterruptedException {
|
||||||
WebOfTrustCertificateStore store = TestCertificateStores.oneDelegationGraph();
|
PGPCertificateDirectory store = TestCertificateStores.oneDelegationGraph();
|
||||||
WebOfTrust wot = new WebOfTrust(store);
|
WebOfTrust wot = new WebOfTrust(store);
|
||||||
wot.initialize();
|
wot.initialize();
|
||||||
Network network = wot.getNetwork();
|
Network network = wot.getNetwork();
|
||||||
|
@ -51,7 +52,7 @@ public class WebOfTrustTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithCrossSignedCertificates()
|
public void testWithCrossSignedCertificates()
|
||||||
throws BadDataException, IOException, InterruptedException {
|
throws BadDataException, IOException, InterruptedException {
|
||||||
WebOfTrustCertificateStore store = TestCertificateStores.disconnectedGraph();
|
PGPCertificateDirectory store = TestCertificateStores.disconnectedGraph();
|
||||||
WebOfTrust wot = new WebOfTrust(store);
|
WebOfTrust wot = new WebOfTrust(store);
|
||||||
wot.initialize();
|
wot.initialize();
|
||||||
Network network = wot.getNetwork();
|
Network network = wot.getNetwork();
|
||||||
|
@ -139,7 +140,7 @@ public class WebOfTrustTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWotCreationOfEmptyCertificates() throws BadDataException, IOException {
|
public void testWotCreationOfEmptyCertificates() throws BadDataException, IOException {
|
||||||
WebOfTrustCertificateStore store = TestCertificateStores.emptyGraph();
|
PGPCertificateDirectory store = TestCertificateStores.emptyGraph();
|
||||||
WebOfTrust wot = new WebOfTrust(store);
|
WebOfTrust wot = new WebOfTrust(store);
|
||||||
wot.initialize();
|
wot.initialize();
|
||||||
Network network = wot.getNetwork();
|
Network network = wot.getNetwork();
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
package org.pgpainless.wot.testfixtures;
|
package org.pgpainless.wot.testfixtures;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.opentest4j.TestAbortedException;
|
import org.opentest4j.TestAbortedException;
|
||||||
import org.pgpainless.certificate_store.KeyMaterialReader;
|
import org.pgpainless.certificate_store.KeyMaterialReader;
|
||||||
import org.pgpainless.wot.WebOfTrustCertificateStore;
|
|
||||||
import pgp.cert_d.PGPCertificateDirectory;
|
import pgp.cert_d.PGPCertificateDirectory;
|
||||||
import pgp.cert_d.backend.InMemoryCertificateDirectoryBackend;
|
import pgp.cert_d.backend.InMemoryCertificateDirectoryBackend;
|
||||||
import pgp.cert_d.subkey_lookup.InMemorySubkeyLookup;
|
import pgp.cert_d.subkey_lookup.InMemorySubkeyLookup;
|
||||||
|
@ -16,9 +18,6 @@ import pgp.certificate_store.certificate.KeyMaterialMerger;
|
||||||
import pgp.certificate_store.certificate.KeyMaterialReaderBackend;
|
import pgp.certificate_store.certificate.KeyMaterialReaderBackend;
|
||||||
import pgp.certificate_store.exception.BadDataException;
|
import pgp.certificate_store.exception.BadDataException;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class TestCertificateStores {
|
public class TestCertificateStores {
|
||||||
|
|
||||||
private static final KeyMaterialMerger merger = new KeyMaterialMerger() {
|
private static final KeyMaterialMerger merger = new KeyMaterialMerger() {
|
||||||
|
@ -28,9 +27,9 @@ public class TestCertificateStores {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static WebOfTrustCertificateStore disconnectedGraph()
|
public static PGPCertificateDirectory disconnectedGraph()
|
||||||
throws BadDataException, IOException, InterruptedException {
|
throws BadDataException, IOException, InterruptedException {
|
||||||
WebOfTrustCertificateStore wotStore = createInMemoryStore();
|
PGPCertificateDirectory wotStore = createInMemoryStore();
|
||||||
|
|
||||||
wotStore.insertTrustRoot(getTestVector("cross_signed/foobankCaCert.asc"), merger);
|
wotStore.insertTrustRoot(getTestVector("cross_signed/foobankCaCert.asc"), merger);
|
||||||
wotStore.insert(getTestVector("cross_signed/foobankEmployeeCert.asc"), merger);
|
wotStore.insert(getTestVector("cross_signed/foobankEmployeeCert.asc"), merger);
|
||||||
|
@ -41,27 +40,26 @@ public class TestCertificateStores {
|
||||||
return wotStore;
|
return wotStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WebOfTrustCertificateStore emptyGraph() {
|
public static PGPCertificateDirectory emptyGraph() {
|
||||||
WebOfTrustCertificateStore wotStore = createInMemoryStore();
|
PGPCertificateDirectory wotStore = createInMemoryStore();
|
||||||
|
|
||||||
return wotStore;
|
return wotStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WebOfTrustCertificateStore oneDelegationGraph() throws BadDataException, IOException, InterruptedException {
|
public static PGPCertificateDirectory oneDelegationGraph() throws BadDataException, IOException, InterruptedException {
|
||||||
WebOfTrustCertificateStore wotStore = createInMemoryStore();
|
PGPCertificateDirectory wotStore = createInMemoryStore();
|
||||||
wotStore.insert(getTestVector("cross_signed/foobankAdminCert.asc"), merger);
|
wotStore.insert(getTestVector("cross_signed/foobankAdminCert.asc"), merger);
|
||||||
wotStore.insert(getTestVector("cross_signed/barbankCaCert.asc"), merger);
|
wotStore.insert(getTestVector("cross_signed/barbankCaCert.asc"), merger);
|
||||||
|
|
||||||
return wotStore;
|
return wotStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WebOfTrustCertificateStore createInMemoryStore() {
|
private static PGPCertificateDirectory createInMemoryStore() {
|
||||||
SubkeyLookup subkeyLookup = new InMemorySubkeyLookup();
|
SubkeyLookup subkeyLookup = new InMemorySubkeyLookup();
|
||||||
KeyMaterialReaderBackend readerBackend = new KeyMaterialReader();
|
KeyMaterialReaderBackend readerBackend = new KeyMaterialReader();
|
||||||
PGPCertificateDirectory.Backend backend = new InMemoryCertificateDirectoryBackend(readerBackend);
|
PGPCertificateDirectory.Backend backend = new InMemoryCertificateDirectoryBackend(readerBackend);
|
||||||
WebOfTrustCertificateStore wotStore = new WebOfTrustCertificateStore(backend, subkeyLookup);
|
PGPCertificateDirectory store = new PGPCertificateDirectory(backend, subkeyLookup);
|
||||||
|
return store;
|
||||||
return wotStore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InputStream requireResource(String resourceName) {
|
private static InputStream requireResource(String resourceName) {
|
||||||
|
|
Loading…
Reference in a new issue