diff --git a/build.gradle b/build.gradle index acc80057..0e9c7a08 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,10 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' + /* + compile 'org.bouncycastle:bcprov-debug-jdk15on:1.60' + /*/ compile 'org.bouncycastle:bcprov-jdk15on:1.60' + //*/ compile 'org.bouncycastle:bcpg-jdk15on:1.60' } diff --git a/src/main/java/org/pgpainless/pgpainless/key/selection/key/impl/SignedByMasterKey.java b/src/main/java/org/pgpainless/pgpainless/key/selection/key/impl/SignedByMasterKey.java index 19f91e6c..c06a7b08 100644 --- a/src/main/java/org/pgpainless/pgpainless/key/selection/key/impl/SignedByMasterKey.java +++ b/src/main/java/org/pgpainless/pgpainless/key/selection/key/impl/SignedByMasterKey.java @@ -15,7 +15,6 @@ */ package org.pgpainless.pgpainless.key.selection.key.impl; -import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.logging.Level; diff --git a/src/test/java/org/pgpainless/pgpainless/BCUtilTest.java b/src/test/java/org/pgpainless/pgpainless/BCUtilTest.java index 7d506910..10aac211 100644 --- a/src/test/java/org/pgpainless/pgpainless/BCUtilTest.java +++ b/src/test/java/org/pgpainless/pgpainless/BCUtilTest.java @@ -129,10 +129,15 @@ public class BCUtilTest extends AbstractPGPainlessTest { public void removeUnsignedKeysECTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException { - PGPSecretKeyRing alice = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); + PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); + PGPSecretKeyRing secCleaned = BCUtil.removeUnassociatedKeysFromKeyRing(secretKeys, secretKeys.getPublicKey()); - PGPSecretKeyRing after = BCUtil.removeUnassociatedKeysFromKeyRing(alice, alice.getPublicKey()); + assertTrue(Arrays.equals(secretKeys.getEncoded(), secCleaned.getEncoded())); + + PGPPublicKeyRing publicKeys = BCUtil.publicKeyRingFromSecretKeyRing(secretKeys); + PGPPublicKeyRing pubCleaned = BCUtil.removeUnassociatedKeysFromKeyRing(publicKeys, publicKeys.getPublicKey()); + + assertTrue(Arrays.equals(publicKeys.getEncoded(), pubCleaned.getEncoded())); - assertTrue(Arrays.equals(alice.getEncoded(), after.getEncoded())); } } diff --git a/src/test/java/org/pgpainless/pgpainless/ImportExportKeyTest.java b/src/test/java/org/pgpainless/pgpainless/ImportExportKeyTest.java new file mode 100644 index 00000000..5d806771 --- /dev/null +++ b/src/test/java/org/pgpainless/pgpainless/ImportExportKeyTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2018 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pgpainless.pgpainless; + +import static junit.framework.TestCase.assertTrue; + +import java.io.IOException; +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Security; +import java.util.Arrays; + +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.openpgp.PGPException; +import org.bouncycastle.openpgp.PGPPublicKeyRing; +import org.bouncycastle.openpgp.PGPSecretKeyRing; +import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; +import org.junit.Test; +import org.pgpainless.pgpainless.util.BCUtil; + +public class ImportExportKeyTest { + + static { + Security.addProvider(new BouncyCastleProvider()); + } + + /** + * This test is failing. Not sure if a bug in BC or in my code... + * @throws PGPException very + * @throws NoSuchAlgorithmException much + * @throws NoSuchProviderException some + * @throws InvalidAlgorithmParameterException annoying + * @throws IOException exceptions + */ + @Test + public void test() + throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, + IOException { + PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@bla.blub"); + PGPPublicKeyRing publicKeys = BCUtil.publicKeyRingFromSecretKeyRing(secretKeys); + + BcKeyFingerprintCalculator calc = new BcKeyFingerprintCalculator(); + byte[] bytes = publicKeys.getEncoded(); + PGPPublicKeyRing parsed = new PGPPublicKeyRing(bytes, calc); + assertTrue(Arrays.equals(publicKeys.getEncoded(), parsed.getEncoded())); + } +}