Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Split OpenSSLRSAPrivateCrtKey from OpenSSLRSAPrivateKey

Change-Id: I6a58044162758b3b74db5d17e9044f97dbe53bae
  • Loading branch information...
commit 5b7f91c1e6e208187cef57ab8a5de0a7f35e817f 1 parent 3e6dd45
Brian Carlstrom authored
View
2  luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLEngine.java
@@ -62,7 +62,7 @@ public PrivateKey getPrivateKeyById(String id) throws InvalidKeyException {
final int keyType = NativeCrypto.EVP_PKEY_type(keyRef);
switch (keyType) {
case NativeCrypto.EVP_PKEY_RSA:
- return new OpenSSLRSAPrivateKey(new OpenSSLKey(keyRef, this));
+ return OpenSSLRSAPrivateKey.getInstance(new OpenSSLKey(keyRef, this));
case NativeCrypto.EVP_PKEY_DSA:
return new OpenSSLDSAPrivateKey(new OpenSSLKey(keyRef, this));
default:
View
7 luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyFactory.java
@@ -61,7 +61,7 @@ protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpe
if (keySpec instanceof RSAPrivateCrtKeySpec) {
RSAPrivateCrtKeySpec rsaKeySpec = (RSAPrivateCrtKeySpec) keySpec;
- return new OpenSSLRSAPrivateKey(rsaKeySpec);
+ return new OpenSSLRSAPrivateCrtKey(rsaKeySpec);
} else if (keySpec instanceof RSAPrivateKeySpec) {
RSAPrivateKeySpec rsaKeySpec = (RSAPrivateKeySpec) keySpec;
@@ -72,7 +72,7 @@ protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpe
try {
final OpenSSLKey key = new OpenSSLKey(
NativeCrypto.d2i_PKCS8_PRIV_KEY_INFO(pkcs8KeySpec.getEncoded()));
- return new OpenSSLRSAPrivateKey(key);
+ return OpenSSLRSAPrivateKey.getInstance(key);
} catch (Exception e) {
throw new InvalidKeySpecException(e);
}
@@ -110,8 +110,7 @@ protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpe
if (RSAPrivateKeySpec.class.equals(keySpec)) {
BigInteger modulus = rsaKey.getModulus();
BigInteger privateExponent = rsaKey.getPrivateExponent();
- return (T) new RSAPrivateCrtKeySpec(modulus, null, privateExponent, null, null,
- null, null, null);
+ return (T) new RSAPrivateKeySpec(modulus, privateExponent);
} else if (RSAPrivateCrtKeySpec.class.equals(keySpec)) {
BigInteger modulus = rsaKey.getModulus();
BigInteger publicExponent = rsaKey.getPublicExponent();
View
2  luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAKeyPairGenerator.java
@@ -44,7 +44,7 @@ public KeyPair generateKeyPair() {
final OpenSSLKey key = new OpenSSLKey(NativeCrypto.RSA_generate_key_ex(modulusBits,
publicExponent));
- PrivateKey privKey = new OpenSSLRSAPrivateKey(key);
+ PrivateKey privKey = OpenSSLRSAPrivateKey.getInstance(key);
PublicKey pubKey = new OpenSSLRSAPublicKey(key);
return new KeyPair(pubKey, privKey);
View
289 luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAPrivateCrtKey.java
@@ -0,0 +1,289 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.apache.harmony.xnet.provider.jsse;
+
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.interfaces.RSAPrivateCrtKey;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.RSAPrivateCrtKeySpec;
+
+public class OpenSSLRSAPrivateCrtKey extends OpenSSLRSAPrivateKey implements RSAPrivateCrtKey {
+ private BigInteger publicExponent;
+
+ private BigInteger primeP;
+
+ private BigInteger primeQ;
+
+ private BigInteger primeExponentP;
+
+ private BigInteger primeExponentQ;
+
+ private BigInteger crtCoefficient;
+
+ OpenSSLRSAPrivateCrtKey(OpenSSLKey key) {
+ super(key);
+ }
+
+ OpenSSLRSAPrivateCrtKey(OpenSSLKey key, byte[][] params) {
+ super(key, params);
+ }
+
+ public OpenSSLRSAPrivateCrtKey(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
+ super(init(rsaKeySpec));
+ }
+
+ private static OpenSSLKey init(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
+ BigInteger modulus = rsaKeySpec.getModulus();
+ BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
+
+ if (modulus == null) {
+ throw new InvalidKeySpecException("modulus == null");
+ } else if (privateExponent == null) {
+ throw new InvalidKeySpecException("privateExponent == null");
+ }
+
+ try {
+ /*
+ * OpenSSL uses the public modulus to do RSA blinding. If
+ * the public modulus is not available, the call to
+ * EVP_PKEY_new_RSA will turn off blinding for this key
+ * instance.
+ */
+ final BigInteger publicExponent = rsaKeySpec.getPublicExponent();
+ final BigInteger primeP = rsaKeySpec.getPrimeP();
+ final BigInteger primeQ = rsaKeySpec.getPrimeQ();
+ final BigInteger primeExponentP = rsaKeySpec.getPrimeExponentP();
+ final BigInteger primeExponentQ = rsaKeySpec.getPrimeExponentQ();
+ final BigInteger crtCoefficient = rsaKeySpec.getCrtCoefficient();
+
+ return new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
+ modulus.toByteArray(),
+ publicExponent == null ? null : publicExponent.toByteArray(),
+ privateExponent.toByteArray(),
+ primeP == null ? null : primeP.toByteArray(),
+ primeQ == null ? null : primeQ.toByteArray(),
+ primeExponentP == null ? null : primeExponentP.toByteArray(),
+ primeExponentQ == null ? null : primeExponentQ.toByteArray(),
+ crtCoefficient == null ? null : crtCoefficient.toByteArray()));
+ } catch (Exception e) {
+ throw new InvalidKeySpecException(e);
+ }
+ }
+
+ static OpenSSLKey getInstance(RSAPrivateCrtKey rsaPrivateKey) throws InvalidKeyException {
+ BigInteger modulus = rsaPrivateKey.getModulus();
+ BigInteger privateExponent = rsaPrivateKey.getPrivateExponent();
+
+ if (modulus == null) {
+ throw new InvalidKeyException("modulus == null");
+ } else if (privateExponent == null) {
+ throw new InvalidKeyException("privateExponent == null");
+ }
+
+ try {
+ /*
+ * OpenSSL uses the public modulus to do RSA blinding. If
+ * the public modulus is not available, the call to
+ * EVP_PKEY_new_RSA will turn off blinding for this key
+ * instance.
+ */
+ final BigInteger publicExponent = rsaPrivateKey.getPublicExponent();
+ final BigInteger primeP = rsaPrivateKey.getPrimeP();
+ final BigInteger primeQ = rsaPrivateKey.getPrimeQ();
+ final BigInteger primeExponentP = rsaPrivateKey.getPrimeExponentP();
+ final BigInteger primeExponentQ = rsaPrivateKey.getPrimeExponentQ();
+ final BigInteger crtCoefficient = rsaPrivateKey.getCrtCoefficient();
+
+ return new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
+ modulus.toByteArray(),
+ publicExponent == null ? null : publicExponent.toByteArray(),
+ privateExponent.toByteArray(),
+ primeP == null ? null : primeP.toByteArray(),
+ primeQ == null ? null : primeQ.toByteArray(),
+ primeExponentP == null ? null : primeExponentP.toByteArray(),
+ primeExponentQ == null ? null : primeExponentQ.toByteArray(),
+ crtCoefficient == null ? null : crtCoefficient.toByteArray()));
+ } catch (Exception e) {
+ throw new InvalidKeyException(e);
+ }
+ }
+
+ @Override
+ synchronized void readParams(byte[][] params) {
+ super.readParams(params);
+ // params[0] read in super.readParams
+ if (params[1] != null) {
+ publicExponent = new BigInteger(params[1]);
+ }
+ // params[2] read in super.readParams
+ if (params[3] != null) {
+ primeP = new BigInteger(params[3]);
+ }
+ if (params[4] != null) {
+ primeQ = new BigInteger(params[4]);
+ }
+ if (params[5] != null) {
+ primeExponentP = new BigInteger(params[5]);
+ }
+ if (params[6] != null) {
+ primeExponentQ = new BigInteger(params[6]);
+ }
+ if (params[7] != null) {
+ crtCoefficient = new BigInteger(params[7]);
+ }
+ }
+
+ @Override
+ public BigInteger getPublicExponent() {
+ ensureReadParams();
+ return publicExponent;
+ }
+
+ @Override
+ public BigInteger getPrimeP() {
+ ensureReadParams();
+ return primeP;
+ }
+
+ @Override
+ public BigInteger getPrimeQ() {
+ ensureReadParams();
+ return primeQ;
+ }
+
+ @Override
+ public BigInteger getPrimeExponentP() {
+ ensureReadParams();
+ return primeExponentP;
+ }
+
+ @Override
+ public BigInteger getPrimeExponentQ() {
+ ensureReadParams();
+ return primeExponentQ;
+ }
+
+ @Override
+ public BigInteger getCrtCoefficient() {
+ ensureReadParams();
+ return crtCoefficient;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+
+ if (o instanceof OpenSSLRSAPrivateCrtKey) {
+ OpenSSLRSAPrivateCrtKey other = (OpenSSLRSAPrivateCrtKey) o;
+
+ /*
+ * We can shortcut the true case, but it still may be equivalent but
+ * different copies.
+ */
+ if (getOpenSSLKey().equals(other.getOpenSSLKey())) {
+ return true;
+ }
+ }
+
+ if (o instanceof RSAPrivateCrtKey) {
+ ensureReadParams();
+ RSAPrivateCrtKey other = (RSAPrivateCrtKey) o;
+
+ return getModulus().equals(other.getModulus())
+ && publicExponent.equals(other.getPublicExponent())
+ && getPrivateExponent().equals(other.getPrivateExponent())
+ && primeP.equals(other.getPrimeP()) && primeQ.equals(other.getPrimeQ())
+ && primeExponentP.equals(other.getPrimeExponentP())
+ && primeExponentQ.equals(other.getPrimeExponentQ())
+ && crtCoefficient.equals(other.getCrtCoefficient());
+ }
+
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ int hashCode = super.hashCode();
+ if (publicExponent != null) {
+ hashCode ^= publicExponent.hashCode();
+ }
+ return hashCode;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("OpenSSLRSAPrivateCrtKey{");
+
+ if (getOpenSSLKey().getEngine() != null) {
+ sb.append("key=");
+ sb.append(getOpenSSLKey());
+ sb.append('}');
+ return sb.toString();
+ }
+
+ ensureReadParams();
+ sb.append("modulus=");
+ sb.append(getModulus().toString(16));
+ sb.append(',');
+
+ if (publicExponent != null) {
+ sb.append("publicExponent=");
+ sb.append(publicExponent.toString(16));
+ sb.append(',');
+ }
+
+ sb.append("privateExponent=");
+ sb.append(getPrivateExponent().toString(16));
+ sb.append(',');
+
+ if (primeP != null) {
+ sb.append("primeP=");
+ sb.append(primeP.toString(16));
+ sb.append(',');
+ }
+
+ if (primeQ != null) {
+ sb.append("primeQ=");
+ sb.append(primeQ.toString(16));
+ sb.append(',');
+ }
+
+ if (primeExponentP != null) {
+ sb.append("primeExponentP=");
+ sb.append(primeExponentP.toString(16));
+ sb.append(',');
+ }
+
+ if (primeExponentQ != null) {
+ sb.append("primeExponentQ=");
+ sb.append(primeExponentQ.toString(16));
+ sb.append(',');
+ }
+
+ if (crtCoefficient != null) {
+ sb.append("crtCoefficient=");
+ sb.append(crtCoefficient.toString(16));
+ sb.append(',');
+ }
+
+ return sb.toString();
+ }
+}
View
271 luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLRSAPrivateKey.java
@@ -18,13 +18,11 @@
import java.math.BigInteger;
import java.security.InvalidKeyException;
-import java.security.interfaces.RSAPrivateCrtKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.spec.InvalidKeySpecException;
-import java.security.spec.RSAPrivateCrtKeySpec;
import java.security.spec.RSAPrivateKeySpec;
-public class OpenSSLRSAPrivateKey implements RSAPrivateCrtKey {
+public class OpenSSLRSAPrivateKey implements RSAPrivateKey {
private static final long serialVersionUID = 4872170254439578735L;
private final OpenSSLKey key;
@@ -33,29 +31,27 @@
private BigInteger modulus;
- private BigInteger publicExponent;
-
private BigInteger privateExponent;
- private BigInteger primeP;
-
- private BigInteger primeQ;
-
- private BigInteger primeExponentP;
-
- private BigInteger primeExponentQ;
-
- private BigInteger crtCoefficient;
-
OpenSSLRSAPrivateKey(OpenSSLKey key) {
this.key = key;
}
- OpenSSLKey getOpenSSLKey() {
+ OpenSSLRSAPrivateKey(OpenSSLKey key, byte[][] params) {
+ this(key);
+ readParams(params);
+ fetchedParams = true;
+ }
+
+ final OpenSSLKey getOpenSSLKey() {
return key;
}
public OpenSSLRSAPrivateKey(RSAPrivateKeySpec rsaKeySpec) throws InvalidKeySpecException {
+ this(init(rsaKeySpec));
+ }
+
+ private static OpenSSLKey init(RSAPrivateKeySpec rsaKeySpec) throws InvalidKeySpecException {
final BigInteger modulus = rsaKeySpec.getModulus();
final BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
@@ -66,7 +62,7 @@ public OpenSSLRSAPrivateKey(RSAPrivateKeySpec rsaKeySpec) throws InvalidKeySpecE
}
try {
- key = new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
+ return new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
modulus.toByteArray(),
null,
privateExponent.toByteArray(),
@@ -80,41 +76,12 @@ public OpenSSLRSAPrivateKey(RSAPrivateKeySpec rsaKeySpec) throws InvalidKeySpecE
}
}
- public OpenSSLRSAPrivateKey(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
- BigInteger modulus = rsaKeySpec.getModulus();
- BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
-
- if (modulus == null) {
- throw new InvalidKeySpecException("modulus == null");
- } else if (privateExponent == null) {
- throw new InvalidKeySpecException("privateExponent == null");
- }
-
- try {
- /*
- * OpenSSL uses the public modulus to do RSA blinding. Regular
- * RSAPrivateKey does not have the public modulus, so we can only
- * possibly support RSAPrivateCrtKey without turning off blinding.
- */
- final BigInteger publicExponent = rsaKeySpec.getPublicExponent();
- final BigInteger primeP = rsaKeySpec.getPrimeP();
- final BigInteger primeQ = rsaKeySpec.getPrimeQ();
- final BigInteger primeExponentP = rsaKeySpec.getPrimeExponentP();
- final BigInteger primeExponentQ = rsaKeySpec.getPrimeExponentQ();
- final BigInteger crtCoefficient = rsaKeySpec.getCrtCoefficient();
-
- key = new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
- modulus.toByteArray(),
- publicExponent == null ? null : publicExponent.toByteArray(),
- privateExponent.toByteArray(),
- primeP == null ? null : primeP.toByteArray(),
- primeQ == null ? null : primeQ.toByteArray(),
- primeExponentP == null ? null : primeExponentP.toByteArray(),
- primeExponentQ == null ? null : primeExponentQ.toByteArray(),
- crtCoefficient == null ? null : crtCoefficient.toByteArray()));
- } catch (Exception e) {
- throw new InvalidKeySpecException(e);
- }
+ static OpenSSLRSAPrivateKey getInstance(OpenSSLKey key) {
+ byte[][] params = NativeCrypto.get_RSA_private_params(key.getPkeyContext());
+ if (params[1] != null) {
+ return new OpenSSLRSAPrivateCrtKey(key, params);
+ }
+ return new OpenSSLRSAPrivateKey(key, params);
}
static OpenSSLKey getInstance(RSAPrivateKey rsaPrivateKey) throws InvalidKeyException {
@@ -142,50 +109,36 @@ static OpenSSLKey getInstance(RSAPrivateKey rsaPrivateKey) throws InvalidKeyExce
}
}
- static OpenSSLKey getInstance(RSAPrivateCrtKey rsaPrivateKey) throws InvalidKeyException {
- BigInteger modulus = rsaPrivateKey.getModulus();
- BigInteger privateExponent = rsaPrivateKey.getPrivateExponent();
-
- if (modulus == null) {
- throw new InvalidKeyException("modulus == null");
- } else if (privateExponent == null) {
- throw new InvalidKeyException("privateExponent == null");
+ synchronized final void ensureReadParams() {
+ if (fetchedParams) {
+ return;
}
+ readParams(NativeCrypto.get_RSA_private_params(key.getPkeyContext()));
+ fetchedParams = true;
+ }
- try {
- /*
- * OpenSSL uses the public modulus to do RSA blinding. Regular
- * RSAPrivateKey does not have the public modulus, so we can only
- * possibly support RSAPrivateCrtKey without turning off blinding.
- */
- final BigInteger publicExponent = rsaPrivateKey.getPublicExponent();
- final BigInteger primeP = rsaPrivateKey.getPrimeP();
- final BigInteger primeQ = rsaPrivateKey.getPrimeQ();
- final BigInteger primeExponentP = rsaPrivateKey.getPrimeExponentP();
- final BigInteger primeExponentQ = rsaPrivateKey.getPrimeExponentQ();
- final BigInteger crtCoefficient = rsaPrivateKey.getCrtCoefficient();
-
- return new OpenSSLKey(NativeCrypto.EVP_PKEY_new_RSA(
- modulus.toByteArray(),
- publicExponent == null ? null : publicExponent.toByteArray(),
- privateExponent.toByteArray(),
- primeP == null ? null : primeP.toByteArray(),
- primeQ == null ? null : primeQ.toByteArray(),
- primeExponentP == null ? null : primeExponentP.toByteArray(),
- primeExponentQ == null ? null : primeExponentQ.toByteArray(),
- crtCoefficient == null ? null : crtCoefficient.toByteArray()));
- } catch (Exception e) {
- throw new InvalidKeyException(e);
+ void readParams(byte[][] params) {
+ if (params[0] == null || params[2] == null) {
+ throw new RuntimeException("modulus == null || privateExponent == null");
}
+ modulus = new BigInteger(params[0]);
+ privateExponent = new BigInteger(params[2]);
}
@Override
- public String getAlgorithm() {
- return "RSA";
+ public final BigInteger getPrivateExponent() {
+ ensureReadParams();
+ return privateExponent;
+ }
+
+ @Override
+ public final BigInteger getModulus() {
+ ensureReadParams();
+ return modulus;
}
@Override
- public String getFormat() {
+ public final byte[] getEncoded() {
/*
* If we're using an OpenSSL ENGINE, there's no guarantee we can export
* the key. Returning {@code null} tells the caller that there's no
@@ -195,11 +148,10 @@ public String getFormat() {
return null;
}
- return "PKCS#8";
+ return NativeCrypto.i2d_PKCS8_PRIV_KEY_INFO(key.getPkeyContext());
}
- @Override
- public byte[] getEncoded() {
+ public final String getFormat() {
/*
* If we're using an OpenSSL ENGINE, there's no guarantee we can export
* the key. Returning {@code null} tells the caller that there's no
@@ -209,92 +161,12 @@ public String getFormat() {
return null;
}
- return NativeCrypto.i2d_PKCS8_PRIV_KEY_INFO(key.getPkeyContext());
- }
-
- private void ensureReadParams() {
- if (fetchedParams) {
- return;
- }
-
- byte[][] params = NativeCrypto.get_RSA_private_params(key.getPkeyContext());
- if (params[0] == null || params[2] == null) {
- throw new RuntimeException("modulus == null || privateExponent == null");
- }
-
- modulus = new BigInteger(params[0]);
-
- if (params[1] != null) {
- publicExponent = new BigInteger(params[1]);
- }
-
- privateExponent = new BigInteger(params[2]);
-
- if (params[3] != null) {
- primeP = new BigInteger(params[3]);
- }
- if (params[4] != null) {
- primeQ = new BigInteger(params[4]);
- }
- if (params[5] != null) {
- primeExponentP = new BigInteger(params[5]);
- }
- if (params[6] != null) {
- primeExponentQ = new BigInteger(params[6]);
- }
- if (params[7] != null) {
- crtCoefficient = new BigInteger(params[7]);
- }
-
- fetchedParams = true;
- }
-
- @Override
- public BigInteger getModulus() {
- ensureReadParams();
- return modulus;
- }
-
- @Override
- public BigInteger getPublicExponent() {
- ensureReadParams();
- return publicExponent;
- }
-
- @Override
- public BigInteger getPrivateExponent() {
- ensureReadParams();
- return privateExponent;
- }
-
- @Override
- public BigInteger getPrimeP() {
- ensureReadParams();
- return primeP;
- }
-
- @Override
- public BigInteger getPrimeQ() {
- ensureReadParams();
- return primeQ;
- }
-
- @Override
- public BigInteger getPrimeExponentP() {
- ensureReadParams();
- return primeExponentP;
- }
-
- @Override
- public BigInteger getPrimeExponentQ() {
- ensureReadParams();
- return primeExponentQ;
+ return "PKCS#8";
}
@Override
- public BigInteger getCrtCoefficient() {
- ensureReadParams();
- return crtCoefficient;
+ public final String getAlgorithm() {
+ return "RSA";
}
@Override
@@ -315,18 +187,7 @@ public boolean equals(Object o) {
}
}
- if (o instanceof RSAPrivateCrtKey) {
- ensureReadParams();
- RSAPrivateCrtKey other = (RSAPrivateCrtKey) o;
-
- return modulus.equals(other.getModulus())
- && publicExponent.equals(other.getPublicExponent())
- && privateExponent.equals(other.getPrivateExponent())
- && primeP.equals(other.getPrimeP()) && primeQ.equals(other.getPrimeQ())
- && primeExponentP.equals(other.getPrimeExponentP())
- && primeExponentQ.equals(other.getPrimeExponentQ())
- && crtCoefficient.equals(other.getCrtCoefficient());
- } else if (o instanceof RSAPrivateKey) {
+ if (o instanceof RSAPrivateKey) {
ensureReadParams();
RSAPrivateKey other = (RSAPrivateKey) o;
@@ -340,11 +201,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
ensureReadParams();
-
int hashCode = modulus.hashCode() ^ privateExponent.hashCode();
- if (publicExponent != null) {
- hashCode ^= publicExponent.hashCode();
- }
return hashCode;
}
@@ -364,46 +221,10 @@ public String toString() {
sb.append(modulus.toString(16));
sb.append(',');
- if (publicExponent != null) {
- sb.append("publicExponent=");
- sb.append(publicExponent.toString(16));
- sb.append(',');
- }
-
sb.append("privateExponent=");
sb.append(privateExponent.toString(16));
sb.append(',');
- if (primeP != null) {
- sb.append("primeP=");
- sb.append(primeP.toString(16));
- sb.append(',');
- }
-
- if (primeQ != null) {
- sb.append("primeQ=");
- sb.append(primeQ.toString(16));
- sb.append(',');
- }
-
- if (primeExponentP != null) {
- sb.append("primeExponentP=");
- sb.append(primeExponentP.toString(16));
- sb.append(',');
- }
-
- if (primeExponentQ != null) {
- sb.append("primeExponentQ=");
- sb.append(primeExponentQ.toString(16));
- sb.append(',');
- }
-
- if (crtCoefficient != null) {
- sb.append("crtCoefficient=");
- sb.append(crtCoefficient.toString(16));
- sb.append(',');
- }
-
return sb.toString();
}
}
View
2  luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSignature.java
@@ -148,7 +148,7 @@ protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException
}
RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey;
- key = OpenSSLRSAPrivateKey.getInstance(rsaPrivateKey);
+ key = OpenSSLRSAPrivateCrtKey.getInstance(rsaPrivateKey);
} else if (privateKey instanceof RSAPrivateKey) {
if (engineType != EngineType.RSA) {
throw new InvalidKeyException("Signature not initialized as RSA");
View
51 support/src/test/java/tests/security/KeyFactoryTest.java
@@ -46,50 +46,17 @@ protected void setUp() throws Exception {
factory = getFactory();
}
- private KeyFactory getFactory() {
- try {
- return KeyFactory.getInstance(algorithmName);
- } catch (NoSuchAlgorithmException e) {
- fail(e.getMessage());
- }
- return null;
+ private KeyFactory getFactory() throws Exception {
+ return KeyFactory.getInstance(algorithmName);
}
- public void testKeyFactory() {
- PrivateKeySpec privateKeySpec = null;
- try {
- privateKeySpec = factory.getKeySpec(DefaultKeys.getPrivateKey(algorithmName),
- privateKeySpecClass);
- } catch (InvalidKeySpecException e) {
- fail(e.getMessage());
- } catch (NoSuchAlgorithmException e) {
- fail(e.getMessage());
- }
-
- PrivateKey privateKey = null;
- try {
- privateKey = factory.generatePrivate(privateKeySpec);
- } catch (InvalidKeySpecException e) {
- fail(e.getMessage());
- }
-
- PublicKeySpec publicKeySpec = null;
- try {
- publicKeySpec = factory.getKeySpec(DefaultKeys.getPublicKey(algorithmName),
- publicKeySpecClass);
- } catch (InvalidKeySpecException e) {
- fail(e.getMessage());
- } catch (NoSuchAlgorithmException e) {
- fail(e.getMessage());
- }
-
- PublicKey publicKey = null;
- try {
- publicKey = factory.generatePublic(publicKeySpec);
- } catch (InvalidKeySpecException e) {
- fail(e.getMessage());
- }
-
+ public void testKeyFactory() throws Exception {
+ PrivateKeySpec privateKeySpec = factory.getKeySpec(DefaultKeys.getPrivateKey(algorithmName),
+ privateKeySpecClass);
+ PrivateKey privateKey = factory.generatePrivate(privateKeySpec);
+ PublicKeySpec publicKeySpec = factory.getKeySpec(DefaultKeys.getPublicKey(algorithmName),
+ publicKeySpecClass);
+ PublicKey publicKey = factory.generatePublic(publicKeySpec);
check(new KeyPair(publicKey, privateKey));
}
Please sign in to comment.
Something went wrong with that request. Please try again.