1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-25 04:54:49 +02:00

Remove unnecessary WebOfTrustCertificateStore class

This commit is contained in:
Paul Schaub 2023-06-27 21:08:25 +02:00
parent 643f2e5e34
commit c4ccfd672d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 29 additions and 144 deletions

View file

@ -36,9 +36,11 @@ import org.pgpainless.wot.dijkstra.sq.Network;
import org.pgpainless.wot.dijkstra.sq.Optional;
import org.pgpainless.wot.dijkstra.sq.ReferenceTime;
import org.pgpainless.wot.sugar.IterableIterator;
import org.pgpainless.wot.sugar.PrefixedIterator;
import org.pgpainless.wot.sugar.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pgp.cert_d.PGPCertificateDirectory;
import pgp.certificate_store.certificate.Certificate;
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 final WebOfTrustCertificateStore certificateStore;
private final PGPCertificateDirectory certificateStore;
private Network network;
public WebOfTrust(WebOfTrustCertificateStore certificateStore) {
public WebOfTrust(PGPCertificateDirectory certificateStore) {
this.certificateStore = certificateStore;
}
@ -69,8 +71,15 @@ public class WebOfTrust implements CertificateAuthority {
* Do the heavy lifting of calculating the web of trust.
*/
public void initialize() throws BadDataException, IOException {
Iterator<Certificate> certificates = certificateStore.getAllItems();
IterableIterator<Certificate> iterable = new IterableIterator<>(certificates);
Certificate trustRoot = null;
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()));
}

View file

@ -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);
}
}

View file

@ -18,6 +18,7 @@ import org.pgpainless.wot.dijkstra.sq.CertificationSet;
import org.pgpainless.wot.dijkstra.sq.Network;
import org.pgpainless.wot.testfixtures.TestCertificateStores;
import org.pgpainless.wot.testfixtures.WotTestVectors;
import pgp.cert_d.PGPCertificateDirectory;
import pgp.certificate_store.exception.BadDataException;
public class WebOfTrustTest {
@ -34,7 +35,7 @@ public class WebOfTrustTest {
@Test
public void testWithTwoNodesAndOneDelegation() throws BadDataException, IOException, InterruptedException {
WebOfTrustCertificateStore store = TestCertificateStores.oneDelegationGraph();
PGPCertificateDirectory store = TestCertificateStores.oneDelegationGraph();
WebOfTrust wot = new WebOfTrust(store);
wot.initialize();
Network network = wot.getNetwork();
@ -51,7 +52,7 @@ public class WebOfTrustTest {
@Test
public void testWithCrossSignedCertificates()
throws BadDataException, IOException, InterruptedException {
WebOfTrustCertificateStore store = TestCertificateStores.disconnectedGraph();
PGPCertificateDirectory store = TestCertificateStores.disconnectedGraph();
WebOfTrust wot = new WebOfTrust(store);
wot.initialize();
Network network = wot.getNetwork();
@ -139,7 +140,7 @@ public class WebOfTrustTest {
@Test
public void testWotCreationOfEmptyCertificates() throws BadDataException, IOException {
WebOfTrustCertificateStore store = TestCertificateStores.emptyGraph();
PGPCertificateDirectory store = TestCertificateStores.emptyGraph();
WebOfTrust wot = new WebOfTrust(store);
wot.initialize();
Network network = wot.getNetwork();

View file

@ -4,9 +4,11 @@
package org.pgpainless.wot.testfixtures;
import java.io.IOException;
import java.io.InputStream;
import org.opentest4j.TestAbortedException;
import org.pgpainless.certificate_store.KeyMaterialReader;
import org.pgpainless.wot.WebOfTrustCertificateStore;
import pgp.cert_d.PGPCertificateDirectory;
import pgp.cert_d.backend.InMemoryCertificateDirectoryBackend;
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.exception.BadDataException;
import java.io.IOException;
import java.io.InputStream;
public class TestCertificateStores {
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 {
WebOfTrustCertificateStore wotStore = createInMemoryStore();
PGPCertificateDirectory wotStore = createInMemoryStore();
wotStore.insertTrustRoot(getTestVector("cross_signed/foobankCaCert.asc"), merger);
wotStore.insert(getTestVector("cross_signed/foobankEmployeeCert.asc"), merger);
@ -41,27 +40,26 @@ public class TestCertificateStores {
return wotStore;
}
public static WebOfTrustCertificateStore emptyGraph() {
WebOfTrustCertificateStore wotStore = createInMemoryStore();
public static PGPCertificateDirectory emptyGraph() {
PGPCertificateDirectory wotStore = createInMemoryStore();
return wotStore;
}
public static WebOfTrustCertificateStore oneDelegationGraph() throws BadDataException, IOException, InterruptedException {
WebOfTrustCertificateStore wotStore = createInMemoryStore();
public static PGPCertificateDirectory oneDelegationGraph() throws BadDataException, IOException, InterruptedException {
PGPCertificateDirectory wotStore = createInMemoryStore();
wotStore.insert(getTestVector("cross_signed/foobankAdminCert.asc"), merger);
wotStore.insert(getTestVector("cross_signed/barbankCaCert.asc"), merger);
return wotStore;
}
private static WebOfTrustCertificateStore createInMemoryStore() {
private static PGPCertificateDirectory createInMemoryStore() {
SubkeyLookup subkeyLookup = new InMemorySubkeyLookup();
KeyMaterialReaderBackend readerBackend = new KeyMaterialReader();
PGPCertificateDirectory.Backend backend = new InMemoryCertificateDirectoryBackend(readerBackend);
WebOfTrustCertificateStore wotStore = new WebOfTrustCertificateStore(backend, subkeyLookup);
return wotStore;
PGPCertificateDirectory store = new PGPCertificateDirectory(backend, subkeyLookup);
return store;
}
private static InputStream requireResource(String resourceName) {