diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/OpaqueKeyTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/OpaqueKeyTest.java new file mode 100644 index 000000000..37c605613 --- /dev/null +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/OpaqueKeyTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2017 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.pgp; + + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.shadows.ShadowLog; +import org.sufficientlysecure.keychain.KeychainTestRunner; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.support.TestDataUtil; + +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertArrayEquals; + + +@SuppressWarnings("WeakerAccess") +@RunWith(KeychainTestRunner.class) +public class OpaqueKeyTest { + @BeforeClass + public static void setUpOnce() throws Exception { + ShadowLog.stream = System.out; + } + + @Test + public void testOpaqueSubKey__canonicalize__shouldFail() throws Exception { + // key from GnuPG's test suite, sample msg generated using GnuPG v2.1.18 + // TODO use for actual tests once eddsa is supported! + UncachedKeyRing ring = readRingFromResource("/test-keys/eddsa-sample-1-pub.asc"); + + OperationLog log = new OperationLog(); + ring.canonicalize(log, 0); + + assertTrue(log.containsType(LogType.MSG_KC_ERROR_MASTER_ALGO)); + } + + @Test + public void testOpaqueSubKey__canonicalize__shouldStrip() throws Exception { + UncachedKeyRing ring = readRingFromResource("/test-keys/eddsa-subkey.pub.asc"); + + OperationLog log = new OperationLog(); + CanonicalizedKeyRing canonicalizedKeyRing = ring.canonicalize(log, 0); + + assertNotNull(canonicalizedKeyRing); + assertTrue(log.containsType(LogType.MSG_KC_SUB_UNKNOWN_ALGO)); + } + + @Test + public void testOpaqueSubKey__reencode__shouldBeIdentical() throws Exception { + byte[] rawKeyData = TestDataUtil.readFully( + OpaqueKeyTest.class.getResourceAsStream("/test-keys/eddsa-subkey.pub.asc")); + + UncachedKeyRing ring = UncachedKeyRing.decodeFromData(rawKeyData); + + assertArrayEquals(rawKeyData, ring.getEncoded()); + } + + UncachedKeyRing readRingFromResource(String name) throws Exception { + return UncachedKeyRing.fromStream(OpaqueKeyTest.class.getResourceAsStream(name)).next(); + } + +} \ No newline at end of file diff --git a/OpenKeychain/src/test/resources/test-keys/eddsa-sample-1-pub.asc b/OpenKeychain/src/test/resources/test-keys/eddsa-sample-1-pub.asc new file mode 100644 index 000000000..5a65453ef --- /dev/null +++ b/OpenKeychain/src/test/resources/test-keys/eddsa-sample-1-pub.asc @@ -0,0 +1,15 @@ +pub ed25519/97965A9A 2014-08-19 + Key fingerprint = C959 BDBA FA32 A2F8 9A15 3B67 8CFD E121 9796 5A9A + Keygrip = 0DD40284FF992CD24DC4AAC367037E066FCEE26A +uid [ unknown] EdDSA sample key 1 (draft-koch-eddsa-for-openpgp-00) + +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v2 + +mDMEU/NfCxYJKwYBBAHaRw8BAQdAPwmJlL3ZFu1AUxl5NOSofIBzOhKA1i+AEJku +Q+47JAa0NEVkRFNBIHNhbXBsZSBrZXkgMSAoZHJhZnQta29jaC1lZGRzYS1mb3It +b3BlbnBncC0wMCmIeQQTFggAIQUCU/NfCwIbAwULCQgHAgYVCAkKCwIEFgIDAQIe +AQIXgAAKCRCM/eEhl5ZamnNOAP9pKn5wz3jPsgy9p65zxz1+xJEr/cczFQx/tYkk +49tkeAD+P9jJE4SFD2lVofxn1e22H7YLvcVyHDOA9gpYWTNXiAU= +=Jbi7 +-----END PGP PUBLIC KEY BLOCK----- diff --git a/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.pub.asc b/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.pub.asc new file mode 100644 index 000000000..f5f6faad1 Binary files /dev/null and b/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.pub.asc differ diff --git a/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.sec.asc b/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.sec.asc new file mode 100644 index 000000000..bd4f04de3 Binary files /dev/null and b/OpenKeychain/src/test/resources/test-keys/eddsa-subkey.sec.asc differ diff --git a/extern/bouncycastle b/extern/bouncycastle index 0e2e96778..3153790ed 160000 --- a/extern/bouncycastle +++ b/extern/bouncycastle @@ -1 +1 @@ -Subproject commit 0e2e96778b2aaf55dc582748de9b7827ab01086f +Subproject commit 3153790edfdb13d41a7cf6ef8d1a9313f4aa2a32