mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 02:09:42 +02:00
Compare commits
10 commits
c2114dcd5a
...
b66888f695
Author | SHA1 | Date | |
---|---|---|---|
b66888f695 | |||
1cd1978175 | |||
634daf8ffe | |||
c623eb6df2 | |||
d7fa21496a | |||
70c535fecc | |||
7520d8e64d | |||
4b95582077 | |||
9410f778e0 | |||
9c1849abbc |
12 changed files with 80 additions and 51 deletions
|
@ -120,6 +120,9 @@ class ExternalSOP(
|
||||||
val errorMessage = readString(errIn)
|
val errorMessage = readString(errIn)
|
||||||
|
|
||||||
when (exitCode) {
|
when (exitCode) {
|
||||||
|
UnspecificFailure.EXIT_CODE ->
|
||||||
|
throw UnspecificFailure(
|
||||||
|
"External SOP backend reported an unspecific error ($exitCode):\n$errorMessage")
|
||||||
NoSignature.EXIT_CODE ->
|
NoSignature.EXIT_CODE ->
|
||||||
throw NoSignature(
|
throw NoSignature(
|
||||||
"External SOP backend reported error NoSignature ($exitCode):\n$errorMessage")
|
"External SOP backend reported error NoSignature ($exitCode):\n$errorMessage")
|
||||||
|
@ -182,13 +185,16 @@ class ExternalSOP(
|
||||||
"External SOP backend reported error NoHardwareKeyFound ($exitCode):\n$errorMessage")
|
"External SOP backend reported error NoHardwareKeyFound ($exitCode):\n$errorMessage")
|
||||||
HardwareKeyFailure.EXIT_CODE ->
|
HardwareKeyFailure.EXIT_CODE ->
|
||||||
throw HardwareKeyFailure(
|
throw HardwareKeyFailure(
|
||||||
"External SOP backend reported error HardwareKeyFalure ($exitCode):\n$errorMessage")
|
"External SOP backend reported error HardwareKeyFailure ($exitCode):\n$errorMessage")
|
||||||
PrimaryKeyBad.EXIT_CODE ->
|
PrimaryKeyBad.EXIT_CODE ->
|
||||||
throw PrimaryKeyBad(
|
throw PrimaryKeyBad(
|
||||||
"External SOP backend reported error PrimaryKeyBad ($exitCode):\n$errorMessage")
|
"External SOP backend reported error PrimaryKeyBad ($exitCode):\n$errorMessage")
|
||||||
CertUserIdNoMatch.EXIT_CODE ->
|
CertUserIdNoMatch.EXIT_CODE ->
|
||||||
throw CertUserIdNoMatch(
|
throw CertUserIdNoMatch(
|
||||||
"External SOP backend reported error CertUserIdNoMatch ($exitCode):\n$errorMessage")
|
"External SOP backend reported error CertUserIdNoMatch ($exitCode):\n$errorMessage")
|
||||||
|
KeyCannotCertify.EXIT_CODE ->
|
||||||
|
throw KeyCannotCertify(
|
||||||
|
"External SOP backend reported error KeyCannotCertify ($exitCode):\n$errorMessage")
|
||||||
|
|
||||||
// Did you forget to add a case for a new exception type?
|
// Did you forget to add a case for a new exception type?
|
||||||
else ->
|
else ->
|
||||||
|
|
|
@ -12,7 +12,7 @@ import sop.operation.CertifyUserId
|
||||||
|
|
||||||
class CertifyUserIdExternal(binary: String, environment: Properties) : CertifyUserId {
|
class CertifyUserIdExternal(binary: String, environment: Properties) : CertifyUserId {
|
||||||
|
|
||||||
private val commandList = mutableListOf(binary, "version")
|
private val commandList = mutableListOf(binary, "certify-userid")
|
||||||
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
||||||
|
|
||||||
private var argCount = 0
|
private var argCount = 0
|
||||||
|
@ -44,5 +44,5 @@ class CertifyUserIdExternal(binary: String, environment: Properties) : CertifyUs
|
||||||
|
|
||||||
override fun certs(certs: InputStream): Ready =
|
override fun certs(certs: InputStream): Ready =
|
||||||
ExternalSOP.executeTransformingOperation(
|
ExternalSOP.executeTransformingOperation(
|
||||||
Runtime.getRuntime(), commandList.plus(keys), envList, certs)
|
Runtime.getRuntime(), commandList.plus("--").plus(keys), envList, certs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import sop.operation.MergeCerts
|
||||||
|
|
||||||
class MergeCertsExternal(binary: String, environment: Properties) : MergeCerts {
|
class MergeCertsExternal(binary: String, environment: Properties) : MergeCerts {
|
||||||
|
|
||||||
private val commandList = mutableListOf(binary, "version")
|
private val commandList = mutableListOf(binary, "merge-certs")
|
||||||
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
||||||
|
|
||||||
private var argCount = 0
|
private var argCount = 0
|
||||||
|
|
|
@ -12,7 +12,7 @@ import sop.util.UTCUtil
|
||||||
|
|
||||||
class ValidateUserIdExternal(binary: String, environment: Properties) : ValidateUserId {
|
class ValidateUserIdExternal(binary: String, environment: Properties) : ValidateUserId {
|
||||||
|
|
||||||
private val commandList = mutableListOf(binary, "version")
|
private val commandList = mutableListOf(binary, "validate-userid")
|
||||||
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
private val envList = ExternalSOP.propertiesToEnv(environment).toMutableList()
|
||||||
|
|
||||||
private var argCount = 0
|
private var argCount = 0
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.testsuite.external.operation;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
|
import sop.testsuite.operation.CertifyValidateUserIdTest;
|
||||||
|
|
||||||
|
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||||
|
public class ExternalCertifyValidateUserIdTest extends CertifyValidateUserIdTest {
|
||||||
|
|
||||||
|
}
|
13
external-sop/src/test/java/sop/testsuite/external/operation/ExternalChangeKeyPasswordTest.java
vendored
Normal file
13
external-sop/src/test/java/sop/testsuite/external/operation/ExternalChangeKeyPasswordTest.java
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.testsuite.external.operation;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
|
import sop.testsuite.operation.ChangeKeyPasswordTest;
|
||||||
|
|
||||||
|
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||||
|
public class ExternalChangeKeyPasswordTest extends ChangeKeyPasswordTest {
|
||||||
|
|
||||||
|
}
|
13
external-sop/src/test/java/sop/testsuite/external/operation/ExternalMergeCertsTest.java
vendored
Normal file
13
external-sop/src/test/java/sop/testsuite/external/operation/ExternalMergeCertsTest.java
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.testsuite.external.operation;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
|
import sop.testsuite.operation.MergeCertsTest;
|
||||||
|
|
||||||
|
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||||
|
public class ExternalMergeCertsTest extends MergeCertsTest {
|
||||||
|
|
||||||
|
}
|
|
@ -64,7 +64,7 @@ class SopCLI {
|
||||||
@JvmField var EXECUTABLE_NAME = "sop"
|
@JvmField var EXECUTABLE_NAME = "sop"
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Option(names = ["--stacktrace"], scope = ScopeType.INHERIT)
|
@Option(names = ["--stacktrace", "--debug"], scope = ScopeType.INHERIT)
|
||||||
var stacktrace = false
|
var stacktrace = false
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
|
@ -45,7 +45,7 @@ class SopVCLI {
|
||||||
@JvmField var EXECUTABLE_NAME = "sopv"
|
@JvmField var EXECUTABLE_NAME = "sopv"
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@CommandLine.Option(names = ["--stacktrace"], scope = CommandLine.ScopeType.INHERIT)
|
@CommandLine.Option(names = ["--stacktrace", "--debug"], scope = CommandLine.ScopeType.INHERIT)
|
||||||
var stacktrace = false
|
var stacktrace = false
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
|
@ -14,7 +14,6 @@ import sop.exception.SOPGPException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -47,16 +46,17 @@ public class CertifyValidateUserIdTest {
|
||||||
|
|
||||||
// Alice has her own user-id self-certified
|
// Alice has her own user-id self-certified
|
||||||
assertTrue(sop.validateUserId()
|
assertTrue(sop.validateUserId()
|
||||||
.authorities(aliceCert)
|
.authorities(aliceCert)
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.subjects(aliceCert),
|
.subjects(aliceCert),
|
||||||
"Alice accepts her own self-certified user-id");
|
"Alice accepts her own self-certified user-id");
|
||||||
|
|
||||||
// Alice has not yet certified Bobs user-id
|
// Alice has not yet certified Bobs user-id
|
||||||
assertFalse(sop.validateUserId()
|
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
|
||||||
.authorities(aliceCert)
|
sop.validateUserId()
|
||||||
.userId("Bob <bob@pgpainless.org>")
|
.authorities(aliceCert)
|
||||||
.subjects(bobCert),
|
.userId("Bob <bob@pgpainless.org>")
|
||||||
|
.subjects(bobCert),
|
||||||
"Alice has not yet certified Bobs user-id");
|
"Alice has not yet certified Bobs user-id");
|
||||||
|
|
||||||
byte[] bobCertifiedByAlice = sop.certifyUserId()
|
byte[] bobCertifiedByAlice = sop.certifyUserId()
|
||||||
|
@ -67,10 +67,10 @@ public class CertifyValidateUserIdTest {
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertTrue(sop.validateUserId()
|
assertTrue(sop.validateUserId()
|
||||||
.userId("Bob <bob@pgpainless.org>")
|
.userId("Bob <bob@pgpainless.org>")
|
||||||
.authorities(aliceCert)
|
.authorities(aliceCert)
|
||||||
.subjects(bobCertifiedByAlice),
|
.subjects(bobCertifiedByAlice),
|
||||||
"Alice accepts Bobs user-id after she certified it");
|
"Alice accepts Bobs user-id after she certified it");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -132,11 +132,11 @@ public class CertifyValidateUserIdTest {
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
|
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
|
||||||
sop.certifyUserId()
|
sop.certifyUserId()
|
||||||
.userId("Bobby")
|
.userId("Bobby")
|
||||||
.keys(aliceKey)
|
.keys(aliceKey)
|
||||||
.certs(bobCert)
|
.certs(bobCert)
|
||||||
.getBytes(),
|
.getBytes(),
|
||||||
"Alice cannot create a pet-name for Bob without the --no-require-self-sig flag");
|
"Alice cannot create a pet-name for Bob without the --no-require-self-sig flag");
|
||||||
|
|
||||||
byte[] bobWithPetName = sop.certifyUserId()
|
byte[] bobWithPetName = sop.certifyUserId()
|
||||||
|
@ -147,15 +147,16 @@ public class CertifyValidateUserIdTest {
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertTrue(sop.validateUserId()
|
assertTrue(sop.validateUserId()
|
||||||
.userId("Bobby")
|
.userId("Bobby")
|
||||||
.authorities(aliceCert)
|
.authorities(aliceCert)
|
||||||
.subjects(bobWithPetName),
|
.subjects(bobWithPetName),
|
||||||
"Alice accepts the pet-name she gave to Bob");
|
"Alice accepts the pet-name she gave to Bob");
|
||||||
|
|
||||||
assertFalse(sop.validateUserId()
|
assertThrows(SOPGPException.CertUserIdNoMatch.class, () ->
|
||||||
.userId("Bobby")
|
sop.validateUserId()
|
||||||
.authorities(bobWithPetName)
|
.userId("Bobby")
|
||||||
.subjects(bobWithPetName),
|
.authorities(bobWithPetName)
|
||||||
|
.subjects(bobWithPetName),
|
||||||
"Bob does not accept the pet-name Alice gave him");
|
"Bob does not accept the pet-name Alice gave him");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,9 @@ public class GenerateKeyTest extends AbstractSOPTest {
|
||||||
|
|
||||||
assertThrows(SOPGPException.CertCannotEncrypt.class, () ->
|
assertThrows(SOPGPException.CertCannotEncrypt.class, () ->
|
||||||
sop.encrypt().withCert(signingOnlyCert)
|
sop.encrypt().withCert(signingOnlyCert)
|
||||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8)));
|
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
.toByteArrayAndResult()
|
||||||
|
.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|
|
@ -25,18 +25,15 @@ public class MergeCertsTest extends AbstractSOPTest {
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
public void testMergeWithItself(SOP sop) throws IOException {
|
public void testMergeWithItself(SOP sop) throws IOException {
|
||||||
byte[] key = sop.generateKey()
|
byte[] key = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] cert = sop.extractCert()
|
byte[] cert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(key)
|
.key(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] merged = sop.mergeCerts()
|
byte[] merged = sop.mergeCerts()
|
||||||
.noArmor()
|
|
||||||
.updates(cert)
|
.updates(cert)
|
||||||
.baseCertificates(cert)
|
.baseCertificates(cert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -69,20 +66,17 @@ public class MergeCertsTest extends AbstractSOPTest {
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
public void testMergeWithItselfViaBase(SOP sop) throws IOException {
|
public void testMergeWithItselfViaBase(SOP sop) throws IOException {
|
||||||
byte[] key = sop.generateKey()
|
byte[] key = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] cert = sop.extractCert()
|
byte[] cert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(key)
|
.key(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] certs = ArraysKt.plus(cert, cert);
|
byte[] certs = ArraysKt.plus(cert, cert);
|
||||||
|
|
||||||
byte[] merged = sop.mergeCerts()
|
byte[] merged = sop.mergeCerts()
|
||||||
.noArmor()
|
|
||||||
.updates(cert)
|
.updates(cert)
|
||||||
.baseCertificates(certs)
|
.baseCertificates(certs)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -94,23 +88,19 @@ public class MergeCertsTest extends AbstractSOPTest {
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
public void testApplyBaseToUpdate(SOP sop) throws IOException {
|
public void testApplyBaseToUpdate(SOP sop) throws IOException {
|
||||||
byte[] key = sop.generateKey()
|
byte[] key = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] cert = sop.extractCert()
|
byte[] cert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(key)
|
.key(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] update = sop.revokeKey()
|
byte[] update = sop.revokeKey()
|
||||||
.noArmor()
|
|
||||||
.keys(key)
|
.keys(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] merged = sop.mergeCerts()
|
byte[] merged = sop.mergeCerts()
|
||||||
.noArmor()
|
|
||||||
.updates(cert)
|
.updates(cert)
|
||||||
.baseCertificates(update)
|
.baseCertificates(update)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -122,23 +112,19 @@ public class MergeCertsTest extends AbstractSOPTest {
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
public void testApplyUpdateToBase(SOP sop) throws IOException {
|
public void testApplyUpdateToBase(SOP sop) throws IOException {
|
||||||
byte[] key = sop.generateKey()
|
byte[] key = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] cert = sop.extractCert()
|
byte[] cert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(key)
|
.key(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] update = sop.revokeKey()
|
byte[] update = sop.revokeKey()
|
||||||
.noArmor()
|
|
||||||
.keys(key)
|
.keys(key)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] merged = sop.mergeCerts()
|
byte[] merged = sop.mergeCerts()
|
||||||
.noArmor()
|
|
||||||
.updates(update)
|
.updates(update)
|
||||||
.baseCertificates(cert)
|
.baseCertificates(cert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -150,29 +136,24 @@ public class MergeCertsTest extends AbstractSOPTest {
|
||||||
@MethodSource("provideInstances")
|
@MethodSource("provideInstances")
|
||||||
public void testApplyUpdateToMissingBaseDoesNothing(SOP sop) throws IOException {
|
public void testApplyUpdateToMissingBaseDoesNothing(SOP sop) throws IOException {
|
||||||
byte[] aliceKey = sop.generateKey()
|
byte[] aliceKey = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Alice <alice@pgpainless.org>")
|
.userId("Alice <alice@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] aliceCert = sop.extractCert()
|
byte[] aliceCert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(aliceKey)
|
.key(aliceKey)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] bobKey = sop.generateKey()
|
byte[] bobKey = sop.generateKey()
|
||||||
.noArmor()
|
|
||||||
.userId("Bob <bob@pgpainless.org>")
|
.userId("Bob <bob@pgpainless.org>")
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] bobCert = sop.extractCert()
|
byte[] bobCert = sop.extractCert()
|
||||||
.noArmor()
|
|
||||||
.key(bobKey)
|
.key(bobKey)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] merged = sop.mergeCerts()
|
byte[] merged = sop.mergeCerts()
|
||||||
.noArmor()
|
|
||||||
.updates(bobCert)
|
.updates(bobCert)
|
||||||
.baseCertificates(aliceCert)
|
.baseCertificates(aliceCert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue