diff options
author | David Hook <dgh@cryptoworkshop.com> | 2013-11-25 07:09:39 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2013-11-25 07:09:39 +0400 |
commit | 5d182ad897835ffdefcad494d1485391c0a6ad7b (patch) | |
tree | ce0d5184dbef9a14452fc8a56b4f05828b8b26dc /pkix/src | |
parent | 554892cf98c9d489eac3c082a3ce93fa2d75556c (diff) |
compatibility updates
Diffstat (limited to 'pkix/src')
-rw-r--r-- | pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/JcaAlgorithmParametersConverter.java | 44 | ||||
-rw-r--r-- | pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/OperatorHelper.java | 88 |
2 files changed, 126 insertions, 6 deletions
diff --git a/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/JcaAlgorithmParametersConverter.java b/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/JcaAlgorithmParametersConverter.java new file mode 100644 index 00000000..b46a7eb3 --- /dev/null +++ b/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/JcaAlgorithmParametersConverter.java @@ -0,0 +1,44 @@ +package org.bouncycastle.operator.jcajce; + + +import java.io.IOException; +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.spec.AlgorithmParameterSpec; + +import org.bouncycastle.asn1.ASN1Encodable; +import org.bouncycastle.asn1.ASN1ObjectIdentifier; +import org.bouncycastle.asn1.ASN1Primitive; +import org.bouncycastle.asn1.DEROctetString; +import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; +import org.bouncycastle.asn1.pkcs.RSAESOAEPparams; +import org.bouncycastle.asn1.x509.AlgorithmIdentifier; +import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; + +public class JcaAlgorithmParametersConverter +{ + public JcaAlgorithmParametersConverter() + { + } + + public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algId, AlgorithmParameters parameters) + throws InvalidAlgorithmParameterException + { + try + { + ASN1Encodable params = ASN1Primitive.fromByteArray(parameters.getEncoded()); + + return new AlgorithmIdentifier(algId, params); + } + catch (IOException e) + { + throw new InvalidAlgorithmParameterException("unable to encode parameters object: " + e.getMessage()); + } + } + + public AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier algorithm, AlgorithmParameterSpec algorithmSpec) + throws InvalidAlgorithmParameterException + { + throw new InvalidAlgorithmParameterException("unknown parameter spec passed."); + } +} diff --git a/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/OperatorHelper.java b/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/OperatorHelper.java index 885357a0..77ed2197 100644 --- a/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/OperatorHelper.java +++ b/pkix/src/main/jdk1.3/org/bouncycastle/operator/jcajce/OperatorHelper.java @@ -2,14 +2,20 @@ package org.bouncycastle.operator.jcajce; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.security.AlgorithmParameters; import java.security.GeneralSecurityException; +import java.security.KeyFactory; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.security.PublicKey; import java.security.Signature; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +//import java.security.spec.PSSParameterSpec; +import java.security.spec.X509EncodedKeySpec; import java.util.HashMap; import java.util.Map; @@ -27,13 +33,13 @@ import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.pkcs.RSASSAPSSparams; import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.jcajce.JcaJceHelper; +import org.bouncycastle.jcajce.JcaJceUtils; import org.bouncycastle.operator.OperatorCreationException; -//import java.security.spec.PSSParameterSpec; - class OperatorHelper { private static final Map oids = new HashMap(); @@ -67,7 +73,16 @@ class OperatorHelper oids.put(NISTObjectIdentifiers.dsa_with_sha224, "SHA224WITHDSA"); oids.put(NISTObjectIdentifiers.dsa_with_sha256, "SHA256WITHDSA"); - asymmetricWrapperAlgNames.put(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.rsaEncryption.getId()), "RSA/ECB/PKCS1Padding"); + oids.put(OIWObjectIdentifiers.idSHA1, "SHA-1"); + oids.put(NISTObjectIdentifiers.id_sha224, "SHA-224"); + oids.put(NISTObjectIdentifiers.id_sha256, "SHA-256"); + oids.put(NISTObjectIdentifiers.id_sha384, "SHA-384"); + oids.put(NISTObjectIdentifiers.id_sha512, "SHA-512"); + oids.put(TeleTrusTObjectIdentifiers.ripemd128, "RIPEMD-128"); + oids.put(TeleTrusTObjectIdentifiers.ripemd160, "RIPEMD-160"); + oids.put(TeleTrusTObjectIdentifiers.ripemd256, "RIPEMD-256"); + + asymmetricWrapperAlgNames.put(PKCSObjectIdentifiers.rsaEncryption, "RSA/ECB/PKCS1Padding"); symmetricWrapperAlgNames.put(PKCSObjectIdentifiers.id_alg_CMS3DESwrap, "DESEDEWrap"); symmetricWrapperAlgNames.put(PKCSObjectIdentifiers.id_alg_CMSRC2wrap, "RC2Wrap"); @@ -95,7 +110,7 @@ class OperatorHelper this.helper = helper; } -Cipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm, Map extraAlgNames) + Cipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm, Map extraAlgNames) throws OperatorCreationException { try @@ -172,6 +187,41 @@ Cipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm, Map extraAlgNames } } + AlgorithmParameters createAlgorithmParameters(AlgorithmIdentifier cipherAlgId) + throws OperatorCreationException + { + AlgorithmParameters parameters; + + if (cipherAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.rsaEncryption)) + { + return null; + } + + try + { + parameters = helper.createAlgorithmParameters(cipherAlgId.getAlgorithm().getId()); + } + catch (NoSuchAlgorithmException e) + { + return null; // There's a good chance there aren't any! + } + catch (NoSuchProviderException e) + { + throw new OperatorCreationException("cannot create algorithm parameters: " + e.getMessage(), e); + } + + try + { + parameters.init(cipherAlgId.getParameters().toASN1Primitive().getEncoded()); + } + catch (IOException e) + { + throw new OperatorCreationException("cannot initialise algorithm parameters: " + e.getMessage(), e); + } + + return parameters; + } + MessageDigest createDigest(AlgorithmIdentifier digAlgId) throws GeneralSecurityException { @@ -246,12 +296,11 @@ Cipher createAsymmetricWrapper(ASN1ObjectIdentifier algorithm, Map extraAlgNames // When the id-RSASSA-PSS algorithm identifier is used for a signature, // the AlgorithmIdentifier parameters field MUST contain RSASSA-PSS-params. /* -Can;t do this pre-jdk1.4 if (algorithm.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { AlgorithmParameters params = helper.createAlgorithmParameters(algName); - params.init(algorithm.getParameters().toASN1Primitive().getEncoded(), "ASN.1"); + JcaJceUtils.loadParameters(params, algorithm.getParameters()); PSSParameterSpec spec = (PSSParameterSpec)params.getParameterSpec(PSSParameterSpec.class); sig.setParameter(spec); @@ -361,6 +410,33 @@ Can;t do this pre-jdk1.4 } } + public PublicKey convertPublicKey(SubjectPublicKeyInfo publicKeyInfo) + throws OperatorCreationException + { + try + { + KeyFactory keyFact = helper.createKeyFactory(publicKeyInfo.getAlgorithm().getAlgorithm().getId()); + + return keyFact.generatePublic(new X509EncodedKeySpec(publicKeyInfo.getEncoded())); + } + catch (IOException e) + { + throw new OperatorCreationException("cannot get encoded form of key: " + e.getMessage(), e); + } + catch (NoSuchAlgorithmException e) + { + throw new OperatorCreationException("cannot create key factory: " + e.getMessage(), e); + } + catch (NoSuchProviderException e) + { + throw new OperatorCreationException("cannot find factory provider: " + e.getMessage(), e); + } + catch (InvalidKeySpecException e) + { + throw new OperatorCreationException("cannot create key factory: " + e.getMessage(), e); + } + } + // TODO: put somewhere public so cause easily accessed private static class OpCertificateException extends CertificateException |