mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 10:49:39 +02:00
Update SOP implementation to the latest spec version
See https://datatracker.ietf.org/doc/html/draft-dkg-openpgp-stateless-cli-03
This commit is contained in:
parent
5e0ca369bf
commit
1cb49f4b12
21 changed files with 348 additions and 112 deletions
|
@ -51,7 +51,7 @@ public class EncryptDecryptRoundTripTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void basicRoundTripWithKey() throws IOException, SOPGPException.CertCannotSign {
|
||||
public void basicRoundTripWithKey() throws IOException, SOPGPException.KeyCannotSign {
|
||||
byte[] encrypted = sop.encrypt()
|
||||
.signWith(aliceKey)
|
||||
.withCert(aliceCert)
|
||||
|
@ -74,7 +74,7 @@ public class EncryptDecryptRoundTripTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void basicRoundTripWithoutArmorUsingKey() throws IOException, SOPGPException.CertCannotSign {
|
||||
public void basicRoundTripWithoutArmorUsingKey() throws IOException, SOPGPException.KeyCannotSign {
|
||||
byte[] aliceKeyNoArmor = sop.generateKey()
|
||||
.userId("Alice <alice@unarmored.org>")
|
||||
.noArmor()
|
||||
|
@ -189,16 +189,6 @@ public class EncryptDecryptRoundTripTest {
|
|||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decrypt_withKeyWithMultipleKeysFails() {
|
||||
byte[] keys = new byte[aliceKey.length + bobKey.length];
|
||||
System.arraycopy(aliceKey, 0, keys, 0 , aliceKey.length);
|
||||
System.arraycopy(bobKey, 0, keys, aliceKey.length, bobKey.length);
|
||||
|
||||
assertThrows(SOPGPException.BadData.class, () -> sop.decrypt()
|
||||
.withKey(keys));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decrypt_withKeyWithPasswordProtectionFails() {
|
||||
String passwordProtectedKey = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
|
|
|
@ -13,13 +13,11 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -56,7 +54,7 @@ public class SignTest {
|
|||
byte[] signature = sop.sign()
|
||||
.key(key)
|
||||
.data(data)
|
||||
.getBytes();
|
||||
.toByteArrayAndResult().getBytes();
|
||||
|
||||
assertTrue(new String(signature).startsWith("-----BEGIN PGP SIGNATURE-----"));
|
||||
|
||||
|
@ -76,7 +74,7 @@ public class SignTest {
|
|||
.key(key)
|
||||
.noArmor()
|
||||
.data(data)
|
||||
.getBytes();
|
||||
.toByteArrayAndResult().getBytes();
|
||||
|
||||
assertFalse(new String(signature).startsWith("-----BEGIN PGP SIGNATURE-----"));
|
||||
|
||||
|
@ -95,7 +93,7 @@ public class SignTest {
|
|||
byte[] signature = sop.sign()
|
||||
.key(key)
|
||||
.data(data)
|
||||
.getBytes();
|
||||
.toByteArrayAndResult().getBytes();
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.verify()
|
||||
.cert(cert)
|
||||
|
@ -109,7 +107,7 @@ public class SignTest {
|
|||
byte[] signature = sop.sign()
|
||||
.key(key)
|
||||
.data(data)
|
||||
.getBytes();
|
||||
.toByteArrayAndResult().getBytes();
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.verify()
|
||||
.cert(cert)
|
||||
|
@ -124,22 +122,12 @@ public class SignTest {
|
|||
.mode(SignAs.Text)
|
||||
.key(key)
|
||||
.data(data)
|
||||
.getBytes();
|
||||
.toByteArrayAndResult().getBytes();
|
||||
|
||||
PGPSignature sig = SignatureUtils.readSignatures(signature).get(0);
|
||||
assertEquals(SignatureType.CANONICAL_TEXT_DOCUMENT.getCode(), sig.getSignatureType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectKeyRingCollection() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
|
||||
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob", null);
|
||||
PGPSecretKeyRingCollection collection = new PGPSecretKeyRingCollection(Arrays.asList(key1, key2));
|
||||
byte[] keys = collection.getEncoded();
|
||||
|
||||
assertThrows(SOPGPException.BadData.class, () -> sop.sign().key(keys));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectEncryptedKey() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
PGPSecretKeyRing key = PGPainless.generateKeyRing()
|
||||
|
|
|
@ -5,19 +5,48 @@
|
|||
package org.pgpainless.sop;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sop.SOP;
|
||||
|
||||
public class VersionTest {
|
||||
|
||||
private static SOP sop;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
sop = new SOPImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersion() {
|
||||
assertNotNull(new SOPImpl().version().getVersion());
|
||||
String version = sop.version().getVersion();
|
||||
assertNotNull(version);
|
||||
assertFalse(version.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertNameEqualsPGPainless() {
|
||||
assertEquals("PGPainless-SOP", new SOPImpl().version().getName());
|
||||
assertEquals("PGPainless-SOP", sop.version().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBackendVersion() {
|
||||
String backendVersion = sop.version().getBackendVersion();
|
||||
assertNotNull(backendVersion);
|
||||
assertFalse(backendVersion.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExtendedVersion() {
|
||||
String extendedVersion = sop.version().getExtendedVersion();
|
||||
assertNotNull(extendedVersion);
|
||||
assertFalse(extendedVersion.isEmpty());
|
||||
|
||||
String firstLine = extendedVersion.split("\n")[0];
|
||||
assertEquals(sop.version().getName() + " " + sop.version().getVersion(), firstLine);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue