mirror of
https://codeberg.org/PGPainless/cert-d-pgpainless.git
synced 2025-09-09 18:29:49 +02:00
Compare commits
No commits in common. "76a5a91fe03cca7ba22685c351722181f1b8f1be" and "f21802523acb2c56b41d2926cfc5158a126cc9f2" have entirely different histories.
76a5a91fe0
...
f21802523a
6 changed files with 34 additions and 30 deletions
|
@ -42,14 +42,11 @@ public class PGPCertDCli {
|
||||||
|
|
||||||
static PGPainlessCertD certificateDirectory;
|
static PGPainlessCertD certificateDirectory;
|
||||||
|
|
||||||
// https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/
|
|
||||||
public static final int EXIT_CODE_NOT_A_STORE = 30;
|
|
||||||
|
|
||||||
private int executionStrategy(CommandLine.ParseResult parseResult) {
|
private int executionStrategy(CommandLine.ParseResult parseResult) {
|
||||||
try {
|
try {
|
||||||
initStore();
|
initStore();
|
||||||
} catch (NotAStoreException | SQLException e) {
|
} catch (NotAStoreException | SQLException e) {
|
||||||
return EXIT_CODE_NOT_A_STORE;
|
return -1;
|
||||||
}
|
}
|
||||||
return new CommandLine.RunLast().execute(parseResult);
|
return new CommandLine.RunLast().execute(parseResult);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import pgp.certificate_store.exception.BadNameException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
@CommandLine.Command(name = "get",
|
@CommandLine.Command(name = "get",
|
||||||
resourceBundle = "msg_get")
|
resourceBundle = "msg_get")
|
||||||
|
@ -27,10 +26,6 @@ public class Get implements Runnable {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Get.class);
|
||||||
|
|
||||||
// https://www.cyberciti.biz/faq/linux-bash-exit-status-set-exit-statusin-bash/
|
|
||||||
public static final int EXIT_CODE_NO_SUCH_ELEMENT = 2;
|
|
||||||
public static final int EXIT_CODE_IO_ERROR = 5;
|
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-a", "--armor"})
|
@CommandLine.Option(names = {"-a", "--armor"})
|
||||||
boolean armor = false;
|
boolean armor = false;
|
||||||
|
|
||||||
|
@ -38,16 +33,16 @@ public class Get implements Runnable {
|
||||||
paramLabel = "IDENTIFIER",
|
paramLabel = "IDENTIFIER",
|
||||||
arity = "1"
|
arity = "1"
|
||||||
)
|
)
|
||||||
String identifier;
|
String identifer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
KeyMaterial record;
|
KeyMaterial record;
|
||||||
if (SpecialNames.lookupSpecialName(identifier) != null) {
|
if (SpecialNames.lookupSpecialName(identifer) != null) {
|
||||||
record = PGPCertDCli.getCertificateDirectory().getBySpecialName(identifier);
|
record = PGPCertDCli.getCertificateDirectory().getBySpecialName(identifer);
|
||||||
} else {
|
} else {
|
||||||
record = PGPCertDCli.getCertificateDirectory().getByFingerprint(identifier.toLowerCase());
|
record = PGPCertDCli.getCertificateDirectory().getByFingerprint(identifer.toLowerCase());
|
||||||
}
|
}
|
||||||
if (record == null) {
|
if (record == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -62,12 +57,9 @@ public class Get implements Runnable {
|
||||||
Streams.pipeAll(record.getInputStream(), System.out);
|
Streams.pipeAll(record.getInputStream(), System.out);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
LOGGER.debug("Certificate not found.", e);
|
|
||||||
System.exit(EXIT_CODE_NO_SUCH_ELEMENT);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("IO Error", e);
|
LOGGER.error("IO Error", e);
|
||||||
System.exit(EXIT_CODE_IO_ERROR);
|
System.exit(-1);
|
||||||
} catch (BadDataException e) {
|
} catch (BadDataException e) {
|
||||||
LOGGER.error("Certificate file contains bad data.", e);
|
LOGGER.error("Certificate file contains bad data.", e);
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package pgp.cert_d.cli;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class DummyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,12 +27,11 @@ import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SetupTest {
|
public class SetupTest {
|
||||||
|
@ -54,7 +53,7 @@ public class SetupTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSetupGeneratesTrustRoot()
|
public void testSetupGeneratesTrustRoot()
|
||||||
throws BadDataException, IOException {
|
throws BadDataException, IOException {
|
||||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
assertNull(store.getTrustRoot());
|
||||||
|
|
||||||
PGPCertDCli.main(new String[] {"setup"});
|
PGPCertDCli.main(new String[] {"setup"});
|
||||||
KeyMaterial trustRoot = store.getTrustRoot();
|
KeyMaterial trustRoot = store.getTrustRoot();
|
||||||
|
@ -69,7 +68,7 @@ public class SetupTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSetupWithPassword()
|
public void testSetupWithPassword()
|
||||||
throws BadDataException, IOException, PGPException {
|
throws BadDataException, IOException, PGPException {
|
||||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
assertNull(store.getTrustRoot());
|
||||||
|
|
||||||
PGPCertDCli.main(new String[] {"setup", "--with-password", "sw0rdf1sh"});
|
PGPCertDCli.main(new String[] {"setup", "--with-password", "sw0rdf1sh"});
|
||||||
KeyMaterial trustRoot = store.getTrustRoot();
|
KeyMaterial trustRoot = store.getTrustRoot();
|
||||||
|
@ -88,7 +87,7 @@ public class SetupTest {
|
||||||
public void testSetupImportFromStdin()
|
public void testSetupImportFromStdin()
|
||||||
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
|
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
|
||||||
BadDataException, IOException {
|
BadDataException, IOException {
|
||||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
assertNull(store.getTrustRoot());
|
||||||
|
|
||||||
PGPSecretKeyRing trustRoot = PGPainless.generateKeyRing()
|
PGPSecretKeyRing trustRoot = PGPainless.generateKeyRing()
|
||||||
.modernKeyRing("trust-root");
|
.modernKeyRing("trust-root");
|
||||||
|
@ -109,7 +108,7 @@ public class SetupTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSetupOverridesExistingTrustRoot()
|
public void testSetupOverridesExistingTrustRoot()
|
||||||
throws BadDataException, IOException {
|
throws BadDataException, IOException {
|
||||||
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
|
assertNull(store.getTrustRoot());
|
||||||
|
|
||||||
PGPCertDCli.main(new String[] {"setup"});
|
PGPCertDCli.main(new String[] {"setup"});
|
||||||
KeyMaterial trustRoot = store.getTrustRoot();
|
KeyMaterial trustRoot = store.getTrustRoot();
|
||||||
|
|
|
@ -7,7 +7,7 @@ package org.pgpainless.cert_d;
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -20,7 +20,6 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -75,8 +74,8 @@ public class SharedPGPCertificateDirectoryTest {
|
||||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(cert);
|
||||||
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
ByteArrayInputStream certIn = new ByteArrayInputStream(cert.getEncoded());
|
||||||
|
|
||||||
// standard case: no cert found
|
// standard case: get() is null
|
||||||
assertThrows(NoSuchElementException.class, () -> directory.getByFingerprint(fingerprint.toString().toLowerCase()));
|
assertNull(directory.getByFingerprint(fingerprint.toString().toLowerCase()));
|
||||||
|
|
||||||
// insert and check returned certs fingerprint
|
// insert and check returned certs fingerprint
|
||||||
Certificate certificate = directory.insert(certIn, dummyMerge);
|
Certificate certificate = directory.insert(certIn, dummyMerge);
|
||||||
|
@ -100,8 +99,8 @@ public class SharedPGPCertificateDirectoryTest {
|
||||||
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(trustRoot);
|
OpenPgpFingerprint fingerprint = OpenPgpFingerprint.of(trustRoot);
|
||||||
ByteArrayInputStream certIn = new ByteArrayInputStream(trustRoot.getEncoded());
|
ByteArrayInputStream certIn = new ByteArrayInputStream(trustRoot.getEncoded());
|
||||||
|
|
||||||
// standard case: no cert found
|
// standard case: get() is null
|
||||||
assertThrows(NoSuchElementException.class, () -> directory.getBySpecialName("trust-root"));
|
assertNull(directory.getBySpecialName("trust-root"));
|
||||||
|
|
||||||
// insert and check returned certs fingerprint
|
// insert and check returned certs fingerprint
|
||||||
Certificate certificate = directory.insertWithSpecialName("trust-root", certIn, dummyMerge);
|
Certificate certificate = directory.insertWithSpecialName("trust-root", certIn, dummyMerge);
|
||||||
|
|
|
@ -13,7 +13,7 @@ allprojects {
|
||||||
junitVersion = '5.8.2'
|
junitVersion = '5.8.2'
|
||||||
mockitoVersion = '4.5.1'
|
mockitoVersion = '4.5.1'
|
||||||
pgpainlessVersion = '1.3.5'
|
pgpainlessVersion = '1.3.5'
|
||||||
pgpCertDJavaVersion = '0.2.1'
|
pgpCertDJavaVersion = '0.2.0'
|
||||||
picocliVersion = '4.6.3'
|
picocliVersion = '4.6.3'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue