1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Fix key selection and create test for BC issue

This commit is contained in:
Paul Schaub 2018-07-11 19:01:13 +02:00
parent 154a2b832f
commit 743fbf5ee4
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 73 additions and 4 deletions

View file

@ -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'
}

View file

@ -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;

View file

@ -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()));
}
}

View file

@ -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()));
}
}