mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-01-09 11:48:00 +01:00
Rely on ProviderFactory for access to BouncyCastleProvider
This commit is contained in:
parent
ead54cb00b
commit
cd4bf1ef96
11 changed files with 20 additions and 43 deletions
|
@ -51,6 +51,7 @@ import org.pgpainless.key.generation.type.KeyType;
|
||||||
import org.pgpainless.key.generation.type.RSA_GENERAL;
|
import org.pgpainless.key.generation.type.RSA_GENERAL;
|
||||||
import org.pgpainless.key.generation.type.curve.EllipticCurve;
|
import org.pgpainless.key.generation.type.curve.EllipticCurve;
|
||||||
import org.pgpainless.key.generation.type.length.RsaLength;
|
import org.pgpainless.key.generation.type.length.RsaLength;
|
||||||
|
import org.pgpainless.provider.ProviderFactory;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public class KeyRingBuilder implements KeyRingBuilderInterface {
|
public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||||
|
@ -160,6 +161,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||||
|
|
||||||
// Hash Calculator
|
// Hash Calculator
|
||||||
PGPDigestCalculator calculator = new JcaPGPDigestCalculatorProviderBuilder()
|
PGPDigestCalculator calculator = new JcaPGPDigestCalculatorProviderBuilder()
|
||||||
|
.setProvider(ProviderFactory.getProvider())
|
||||||
.build()
|
.build()
|
||||||
.get(HashAlgorithm.SHA1.getAlgorithmId());
|
.get(HashAlgorithm.SHA1.getAlgorithmId());
|
||||||
|
|
||||||
|
@ -183,7 +185,8 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||||
|
|
||||||
// Signer for creating self-signature
|
// Signer for creating self-signature
|
||||||
PGPContentSignerBuilder signer = new JcaPGPContentSignerBuilder(
|
PGPContentSignerBuilder signer = new JcaPGPContentSignerBuilder(
|
||||||
certKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId());
|
certKey.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId())
|
||||||
|
.setProvider(ProviderFactory.getProvider());
|
||||||
|
|
||||||
PGPSignatureSubpacketVector hashedSubPackets = certKeySpec.getSubpackets();
|
PGPSignatureSubpacketVector hashedSubPackets = certKeySpec.getSubpackets();
|
||||||
|
|
||||||
|
@ -212,7 +215,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||||
throws NoSuchAlgorithmException, PGPException,
|
throws NoSuchAlgorithmException, PGPException,
|
||||||
InvalidAlgorithmParameterException {
|
InvalidAlgorithmParameterException {
|
||||||
KeyType type = spec.getKeyType();
|
KeyType type = spec.getKeyType();
|
||||||
KeyPairGenerator certKeyGenerator = KeyPairGenerator.getInstance(type.getName());
|
KeyPairGenerator certKeyGenerator = KeyPairGenerator.getInstance(type.getName(), ProviderFactory.getProvider());
|
||||||
certKeyGenerator.initialize(type.getAlgorithmSpec());
|
certKeyGenerator.initialize(type.getAlgorithmSpec());
|
||||||
|
|
||||||
// Create raw Key Pair
|
// Create raw Key Pair
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import java.security.Security;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.pgpainless.provider.ProviderFactory;
|
|
||||||
|
|
||||||
public abstract class AbstractPGPainlessTest {
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void registerProvider() {
|
|
||||||
Security.insertProviderAt(ProviderFactory.getProvider(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,7 +42,7 @@ import org.pgpainless.key.generation.type.RSA_GENERAL;
|
||||||
import org.pgpainless.key.generation.type.length.RsaLength;
|
import org.pgpainless.key.generation.type.length.RsaLength;
|
||||||
import org.pgpainless.util.BCUtil;
|
import org.pgpainless.util.BCUtil;
|
||||||
|
|
||||||
public class BCUtilTest extends AbstractPGPainlessTest {
|
public class BCUtilTest {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(BCUtil.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(BCUtil.class.getName());
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,9 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
|
||||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
||||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.pgpainless.provider.ProviderFactory;
|
||||||
|
|
||||||
public class BouncycastleExportSubkeys extends AbstractPGPainlessTest {
|
public class BouncycastleExportSubkeys {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
|
public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
|
||||||
|
@ -51,7 +52,7 @@ public class BouncycastleExportSubkeys extends AbstractPGPainlessTest {
|
||||||
|
|
||||||
// Generate master key
|
// Generate master key
|
||||||
|
|
||||||
generator = KeyPairGenerator.getInstance("ECDSA");
|
generator = KeyPairGenerator.getInstance("ECDSA", ProviderFactory.getProvider());
|
||||||
generator.initialize(new ECNamedCurveGenParameterSpec("P-256"));
|
generator.initialize(new ECNamedCurveGenParameterSpec("P-256"));
|
||||||
|
|
||||||
pair = generator.generateKeyPair();
|
pair = generator.generateKeyPair();
|
||||||
|
@ -77,7 +78,7 @@ public class BouncycastleExportSubkeys extends AbstractPGPainlessTest {
|
||||||
|
|
||||||
// Generate sub key
|
// Generate sub key
|
||||||
|
|
||||||
generator = KeyPairGenerator.getInstance("ECDH");
|
generator = KeyPairGenerator.getInstance("ECDH", ProviderFactory.getProvider());
|
||||||
generator.initialize(new ECNamedCurveGenParameterSpec("P-256"));
|
generator.initialize(new ECNamedCurveGenParameterSpec("P-256"));
|
||||||
|
|
||||||
pair = generator.generateKeyPair();
|
pair = generator.generateKeyPair();
|
||||||
|
@ -86,11 +87,13 @@ public class BouncycastleExportSubkeys extends AbstractPGPainlessTest {
|
||||||
// Assemble key
|
// Assemble key
|
||||||
|
|
||||||
PGPDigestCalculator calculator = new JcaPGPDigestCalculatorProviderBuilder()
|
PGPDigestCalculator calculator = new JcaPGPDigestCalculatorProviderBuilder()
|
||||||
|
.setProvider(ProviderFactory.getProvider())
|
||||||
.build()
|
.build()
|
||||||
.get(HashAlgorithmTags.SHA1);
|
.get(HashAlgorithmTags.SHA1);
|
||||||
|
|
||||||
PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(
|
PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(
|
||||||
pgpMasterKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA512);
|
pgpMasterKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA512)
|
||||||
|
.setProvider(ProviderFactory.getProvider());
|
||||||
|
|
||||||
PGPKeyRingGenerator pgpGenerator = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
|
PGPKeyRingGenerator pgpGenerator = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
|
||||||
pgpMasterKey, "alice@wonderland.lit", calculator, subPackets.generate(), null,
|
pgpMasterKey, "alice@wonderland.lit", calculator, subPackets.generate(), null,
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||||
import org.pgpainless.util.BCUtil;
|
import org.pgpainless.util.BCUtil;
|
||||||
|
|
||||||
public class EncryptDecryptTest extends AbstractPGPainlessTest {
|
public class EncryptDecryptTest {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(EncryptDecryptTest.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(EncryptDecryptTest.class.getName());
|
||||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.pgpainless.key.collection.PGPKeyRing;
|
import org.pgpainless.key.collection.PGPKeyRing;
|
||||||
|
|
||||||
public class ImportExportKeyTest extends AbstractPGPainlessTest {
|
public class ImportExportKeyTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the export and import of a key ring with sub keys.
|
* Test the export and import of a key ring with sub keys.
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||||
/**
|
/**
|
||||||
* Class used to determine the length of cipher-text depending on used algorithms.
|
* Class used to determine the length of cipher-text depending on used algorithms.
|
||||||
*/
|
*/
|
||||||
public class LengthTest extends AbstractPGPainlessTest {
|
public class LengthTest {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(LengthTest.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(LengthTest.class.getName());
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
|
|
||||||
public class OpenPgpV4FingerprintTest extends AbstractPGPainlessTest {
|
public class OpenPgpV4FingerprintTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void fpTooShort() {
|
public void fpTooShort() {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.Test;
|
||||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public class SymmetricTest extends AbstractPGPainlessTest {
|
public class SymmetricTest {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(SymmetricTest.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SymmetricTest.class.getName());
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||||
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
|
|
||||||
public class TestKeys extends AbstractPGPainlessTest {
|
public class TestKeys {
|
||||||
|
|
||||||
private static final KeyFingerPrintCalculator calc = new BcKeyFingerprintCalculator();
|
private static final KeyFingerPrintCalculator calc = new BcKeyFingerprintCalculator();
|
||||||
private static PGPSecretKeyRing julietSecretKeyRing = null;
|
private static PGPSecretKeyRing julietSecretKeyRing = null;
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||||
|
|
||||||
public class TestKeysTest extends AbstractPGPainlessTest {
|
public class TestKeysTest {
|
||||||
|
|
||||||
private final PGPSecretKeyRing juliet;
|
private final PGPSecretKeyRing juliet;
|
||||||
private final PGPSecretKeyRing romeo;
|
private final PGPSecretKeyRing romeo;
|
||||||
|
|
Loading…
Reference in a new issue