add sloppy test for eddsa signatures
This commit is contained in:
@@ -37,15 +37,20 @@ import org.sufficientlysecure.keychain.KeychainTestRunner;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptInputParcel;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
@@ -56,6 +61,7 @@ import static junit.framework.Assert.assertTrue;
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@RunWith(KeychainTestRunner.class)
|
||||
public class EddsaTest {
|
||||
public static final byte[] SIGNED_BYTES = "hi".getBytes();
|
||||
private KeyWritableRepository keyRepository;
|
||||
private Application context;
|
||||
|
||||
@@ -75,7 +81,7 @@ public class EddsaTest {
|
||||
@Test
|
||||
public void testGpgSampleSignature() throws Exception {
|
||||
// key from GnuPG's test suite, sample msg generated using GnuPG v2.1.18
|
||||
UncachedKeyRing ring = loadKeyringFromResource("/test-keys/eddsa-sample-1-pub.asc");
|
||||
UncachedKeyRing ring = loadPubkeyFromResource("/test-keys/eddsa-sample-1-pub.asc");
|
||||
|
||||
byte[] signedText = readBytesFromResource("/test-keys/eddsa-sample-msg.asc");
|
||||
PgpDecryptVerifyInputParcel pgpDecryptVerifyInputParcel = PgpDecryptVerifyInputParcel.builder()
|
||||
@@ -89,6 +95,32 @@ public class EddsaTest {
|
||||
assertEquals(ring.getMasterKeyId(), result.getSignatureResult().getKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEddsaSign() throws Exception {
|
||||
// key from GnuPG's test suite, sample msg generated using GnuPG v2.1.18
|
||||
UncachedKeyRing ring = loadSeckeyFromResource("/test-keys/eddsa-key.sec");
|
||||
|
||||
PgpSignEncryptData data = PgpSignEncryptData.builder()
|
||||
.setDetachedSignature(true)
|
||||
.setSignatureMasterKeyId(ring.getMasterKeyId())
|
||||
.build();
|
||||
PgpSignEncryptInputParcel inputParcel = PgpSignEncryptInputParcel.createForBytes(
|
||||
data, null, SIGNED_BYTES);
|
||||
|
||||
PgpSignEncryptOperation op = new PgpSignEncryptOperation(context, keyRepository, null);
|
||||
PgpSignEncryptResult result = op.execute(inputParcel, CryptoInputParcel.createCryptoInputParcel());
|
||||
|
||||
assertTrue(result.success());
|
||||
|
||||
PgpDecryptVerifyInputParcel pgpDecryptVerifyInputParcel = PgpDecryptVerifyInputParcel.builder()
|
||||
.setInputBytes(SIGNED_BYTES).setDetachedSignature(result.getDetachedSignature()).build();
|
||||
|
||||
PgpDecryptVerifyOperation decryptVerifyOperation = new PgpDecryptVerifyOperation(context, keyRepository, null);
|
||||
DecryptVerifyResult result2 = decryptVerifyOperation.execute(pgpDecryptVerifyInputParcel, null);
|
||||
|
||||
assertTrue(result2.success());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEddsa() throws Exception {
|
||||
SaveKeyringParcel.Builder builder = SaveKeyringParcel.buildNewKeyringParcel();
|
||||
@@ -106,7 +138,7 @@ public class EddsaTest {
|
||||
assertNotNull(canonicalizedKeyRing);
|
||||
}
|
||||
|
||||
private UncachedKeyRing loadKeyringFromResource(String name) throws Exception {
|
||||
private UncachedKeyRing loadPubkeyFromResource(String name) throws Exception {
|
||||
UncachedKeyRing ring = readRingFromResource(name);
|
||||
SaveKeyringResult saveKeyringResult = keyRepository.savePublicKeyRing(ring);
|
||||
assertTrue(saveKeyringResult.success());
|
||||
@@ -114,6 +146,14 @@ public class EddsaTest {
|
||||
return ring;
|
||||
}
|
||||
|
||||
private UncachedKeyRing loadSeckeyFromResource(String name) throws Exception {
|
||||
UncachedKeyRing ring = readRingFromResource(name);
|
||||
SaveKeyringResult saveKeyringResult = keyRepository.saveSecretKeyRing(ring);
|
||||
assertTrue(saveKeyringResult.success());
|
||||
assertFalse(saveKeyringResult.getLog().containsWarnings());
|
||||
return ring;
|
||||
}
|
||||
|
||||
private byte[] readBytesFromResource(String name) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
InputStream input = EddsaTest.class.getResourceAsStream(name);
|
||||
|
||||
BIN
OpenKeychain/src/test/resources/test-keys/eddsa-key.sec
Normal file
BIN
OpenKeychain/src/test/resources/test-keys/eddsa-key.sec
Normal file
Binary file not shown.
Reference in New Issue
Block a user