summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordavidben <davidben@chromium.org>2015-06-09 11:34:27 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-09 18:34:49 +0000
commit370b6fa36eb7277ade9547ca3bbecd5fb9a9e5a8 (patch)
tree8076a1e8ecfedb9a413b5f8cfcd159a0f6f0b71a /net
parent235e9eecc197ceca0682483f93414159a3979d87 (diff)
downloadchromium_src-370b6fa36eb7277ade9547ca3bbecd5fb9a9e5a8.zip
chromium_src-370b6fa36eb7277ade9547ca3bbecd5fb9a9e5a8.tar.gz
chromium_src-370b6fa36eb7277ade9547ca3bbecd5fb9a9e5a8.tar.bz2
Remove ICS and remnants of DSA support for Android key store.
This removes one of the three client auth codepaths (the one that gets the raw encoded key bytes) as well as remnants of DSA support, removed with BoringSSL. IRemoteAndroidKeyStore is an RPC interface, so it cannot be changed, but document that some RPC calls are unused. BUG=463669 Review URL: https://codereview.chromium.org/1162063003 Cr-Commit-Position: refs/heads/master@{#333537}
Diffstat (limited to 'net')
-rw-r--r--net/android/java/src/org/chromium/net/AndroidKeyStore.java31
-rw-r--r--net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java23
-rw-r--r--net/android/java/src/org/chromium/net/IRemoteAndroidKeyStore.aidl3
-rw-r--r--net/android/java/src/org/chromium/net/RemoteAndroidKeyStore.java19
-rw-r--r--net/android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java6
-rw-r--r--net/android/keystore.cc31
-rw-r--r--net/android/keystore.h23
-rw-r--r--net/android/keystore_openssl.cc81
8 files changed, 41 insertions, 176 deletions
diff --git a/net/android/java/src/org/chromium/net/AndroidKeyStore.java b/net/android/java/src/org/chromium/net/AndroidKeyStore.java
index 3c7e6fc..89ace17 100644
--- a/net/android/java/src/org/chromium/net/AndroidKeyStore.java
+++ b/net/android/java/src/org/chromium/net/AndroidKeyStore.java
@@ -28,19 +28,6 @@ public interface AndroidKeyStore {
byte[] getRSAKeyModulus(AndroidPrivateKey key);
/**
- * Returns the 'Q' parameter of a given DSA private key as a byte
- * buffer.
- * This can be used by native code to convert it into an OpenSSL BIGNUM
- * object where DSA_size() works as expected.
- *
- * @param key A PrivateKey instance. Must implement DSAKey.
- * @return A byte buffer corresponding to the Q parameter. This is
- * a big-endian representation of a BigInteger.
- */
- @CalledByNative
- byte[] getDSAKeyParamQ(AndroidPrivateKey key);
-
- /**
* Returns the 'order' parameter of a given ECDSA private key as a
* a byte buffer.
* @param key A PrivateKey instance. Must implement ECKey.
@@ -51,17 +38,6 @@ public interface AndroidKeyStore {
byte[] getECKeyOrder(AndroidPrivateKey key);
/**
- * Returns the encoded data corresponding to a given PrivateKey.
- * Note that this will fail for platform keys on Android 4.0.4
- * and higher. It can be used on 4.0.3 and older platforms to
- * route around the platform bug described below.
- * @param key A PrivateKey instance
- * @return encoded key as PKCS#8 byte array, can be null.
- */
- @CalledByNative
- byte[] getPrivateKeyEncodedBytes(AndroidPrivateKey key);
-
- /**
* Sign a given message with a given PrivateKey object. This method
* shall only be used to implement signing in the context of SSL
* client certificate support.
@@ -77,10 +53,9 @@ public interface AndroidKeyStore {
* combined, 36-byte MD5+SHA1 message digest or a DigestInfo
* value wrapping a message digest.
*
- * - For a DSA and ECDSA private keys, this should be equivalent to
- * calling DSA_sign(0,...) and ECDSA_sign(0,...) respectively. The
- * message must be a hash and the function shall compute a direct
- * DSA/ECDSA signature for it.
+ * - For a ECDSA private keys, this should be equivalent to calling
+ * ECDSA_sign(0,...). The message must be a hash and the function shall
+ * compute a direct ECDSA signature for it.
*
* @param key The PrivateKey handle.
* @param message The message to sign.
diff --git a/net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java b/net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java
index 3fbf60c..5e66427 100644
--- a/net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java
+++ b/net/android/java/src/org/chromium/net/DefaultAndroidKeyStore.java
@@ -10,9 +10,6 @@ import java.lang.reflect.Method;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Signature;
-import java.security.interfaces.DSAKey;
-import java.security.interfaces.DSAParams;
-import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.ECKey;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.RSAKey;
@@ -62,17 +59,6 @@ public class DefaultAndroidKeyStore implements AndroidKeyStore {
}
@Override
- public byte[] getDSAKeyParamQ(AndroidPrivateKey key) {
- PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
- if (javaKey instanceof DSAKey) {
- DSAParams params = ((DSAKey) javaKey).getParams();
- return params.getQ().toByteArray();
- }
- Log.w(TAG, "Not a DSAKey instance!");
- return null;
- }
-
- @Override
public byte[] getECKeyOrder(AndroidPrivateKey key) {
PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
if (javaKey instanceof ECKey) {
@@ -84,12 +70,6 @@ public class DefaultAndroidKeyStore implements AndroidKeyStore {
}
@Override
- public byte[] getPrivateKeyEncodedBytes(AndroidPrivateKey key) {
- PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
- return javaKey.getEncoded();
- }
-
- @Override
public byte[] rawSignDigestWithPrivateKey(AndroidPrivateKey key,
byte[] message) {
PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
@@ -103,8 +83,6 @@ public class DefaultAndroidKeyStore implements AndroidKeyStore {
// on Android 4.0.x and 4.1.x. Fixed in 4.2 and higher.
// See https://android-review.googlesource.com/#/c/40352/
signature = Signature.getInstance("NONEwithRSA");
- } else if (javaKey instanceof DSAPrivateKey) {
- signature = Signature.getInstance("NONEwithDSA");
} else if (javaKey instanceof ECPrivateKey) {
signature = Signature.getInstance("NONEwithECDSA");
}
@@ -133,7 +111,6 @@ public class DefaultAndroidKeyStore implements AndroidKeyStore {
public int getPrivateKeyType(AndroidPrivateKey key) {
PrivateKey javaKey = ((DefaultAndroidPrivateKey) key).getJavaKey();
if (javaKey instanceof RSAPrivateKey) return PrivateKeyType.RSA;
- if (javaKey instanceof DSAPrivateKey) return PrivateKeyType.DSA;
if (javaKey instanceof ECPrivateKey) {
return PrivateKeyType.ECDSA;
} else {
diff --git a/net/android/java/src/org/chromium/net/IRemoteAndroidKeyStore.aidl b/net/android/java/src/org/chromium/net/IRemoteAndroidKeyStore.aidl
index ee4c65d..97b21b7 100644
--- a/net/android/java/src/org/chromium/net/IRemoteAndroidKeyStore.aidl
+++ b/net/android/java/src/org/chromium/net/IRemoteAndroidKeyStore.aidl
@@ -23,8 +23,11 @@ interface IRemoteAndroidKeyStore {
// Remote calls for AndroidKeyStore - these functions are performing operations
// with a PrivateKey in the remote process using the handle provided by
// |getPrivateKeyHandle|.
+
byte[] getRSAKeyModulus(in int handle);
+ // Deprecated: This RPC is never used.
byte[] getPrivateKeyEncodedBytes(in int handle);
+ // Deprecated: This RPC is never used.
byte[] getDSAKeyParamQ(in int handle);
byte[] getECKeyOrder(in int handle);
byte[] rawSignDigestWithPrivateKey(in int handle, in byte[] message);
diff --git a/net/android/java/src/org/chromium/net/RemoteAndroidKeyStore.java b/net/android/java/src/org/chromium/net/RemoteAndroidKeyStore.java
index 3d22d71..f732c45 100644
--- a/net/android/java/src/org/chromium/net/RemoteAndroidKeyStore.java
+++ b/net/android/java/src/org/chromium/net/RemoteAndroidKeyStore.java
@@ -55,18 +55,6 @@ public class RemoteAndroidKeyStore implements AndroidKeyStore {
}
@Override
- public byte[] getDSAKeyParamQ(AndroidPrivateKey key) {
- RemotePrivateKey remoteKey = (RemotePrivateKey) key;
- try {
- Log.d(TAG, "getDSAKeyParamQ");
- return mRemoteManager.getDSAKeyParamQ(remoteKey.getHandle());
- } catch (RemoteException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- @Override
public byte[] getECKeyOrder(AndroidPrivateKey key) {
RemotePrivateKey remoteKey = (RemotePrivateKey) key;
try {
@@ -103,13 +91,6 @@ public class RemoteAndroidKeyStore implements AndroidKeyStore {
}
@Override
- public byte[] getPrivateKeyEncodedBytes(AndroidPrivateKey key) {
- // This should not be called as it's only for older versions of Android.
- assert false;
- return null;
- }
-
- @Override
public long getOpenSSLHandleForPrivateKey(AndroidPrivateKey privateKey) {
// This should not be called as it's only for older versions of Android.
assert false;
diff --git a/net/android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java b/net/android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java
index 865b1ef..a4cb947 100644
--- a/net/android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java
+++ b/net/android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java
@@ -16,6 +16,9 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
+/**
+ * Utility functions to create Android platform keys in tests.
+ */
@JNINamespace("net::android")
public class AndroidKeyStoreTestUtil {
@@ -35,9 +38,6 @@ public class AndroidKeyStoreTestUtil {
case PrivateKeyType.RSA:
algorithm = "RSA";
break;
- case PrivateKeyType.DSA:
- algorithm = "DSA";
- break;
case PrivateKeyType.ECDSA:
algorithm = "EC";
break;
diff --git a/net/android/keystore.cc b/net/android/keystore.cc
index dd37939..4fa8dbf 100644
--- a/net/android/keystore.cc
+++ b/net/android/keystore.cc
@@ -36,21 +36,6 @@ bool GetRSAKeyModulus(jobject private_key_ref, std::vector<uint8_t>* result) {
return true;
}
-bool GetDSAKeyParamQ(jobject private_key_ref, std::vector<uint8_t>* result) {
- JNIEnv* env = AttachCurrentThread();
-
- ScopedJavaLocalRef<jbyteArray> q_ref =
- Java_AndroidKeyStore_getDSAKeyParamQ(
- env,
- GetKeyStore(private_key_ref).obj(),
- private_key_ref);
- if (q_ref.is_null())
- return false;
-
- JavaByteArrayToByteVector(env, q_ref.obj(), result);
- return true;
-}
-
bool GetECKeyOrder(jobject private_key_ref, std::vector<uint8_t>* result) {
JNIEnv* env = AttachCurrentThread();
@@ -67,22 +52,6 @@ bool GetECKeyOrder(jobject private_key_ref, std::vector<uint8_t>* result) {
return true;
}
-bool GetPrivateKeyEncodedBytes(jobject private_key_ref,
- std::vector<uint8_t>* result) {
- JNIEnv* env = AttachCurrentThread();
-
- ScopedJavaLocalRef<jbyteArray> encoded_ref =
- Java_AndroidKeyStore_getPrivateKeyEncodedBytes(
- env,
- GetKeyStore(private_key_ref).obj(),
- private_key_ref);
- if (encoded_ref.is_null())
- return false;
-
- JavaByteArrayToByteVector(env, encoded_ref.obj(), result);
- return true;
-}
-
bool RawSignDigestWithPrivateKey(jobject private_key_ref,
const base::StringPiece& digest,
std::vector<uint8_t>* signature) {
diff --git a/net/android/keystore.h b/net/android/keystore.h
index 1186ef6d..b794799 100644
--- a/net/android/keystore.h
+++ b/net/android/keystore.h
@@ -27,11 +27,14 @@ struct AndroidEVP_PKEY;
// values are shared with Java through org.chromium.net.PrivateKeyType.
// Example: PRIVATE_KEY_TYPE_RSA.
//
+// This enum is used as part of an RPC interface, so new values must be
+// appended and not reused.
+//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
enum PrivateKeyType {
PRIVATE_KEY_TYPE_RSA = 0,
- PRIVATE_KEY_TYPE_DSA = 1,
+ // Obsolete: PRIVATE_KEY_TYPE_DSA = 1,
PRIVATE_KEY_TYPE_ECDSA = 2,
PRIVATE_KEY_TYPE_INVALID = 255,
};
@@ -47,15 +50,6 @@ enum PrivateKeyType {
NET_EXPORT bool GetRSAKeyModulus(jobject private_key,
std::vector<uint8_t>* modulus);
-// Returns the Q parameter of a given DSAPrivateKey platform object,
-// as a series of bytes, in big-endian representation. This can be used
-// with BN_bin2bn() to convert to an OpenSSL BIGNUM.
-// |private_key| is a JNI reference for the private key.
-// |q| will receive the result bytes on success.
-// Returns true on success, or false on failure (e.g. if the key is
-// not DSA).
-NET_EXPORT bool GetDSAKeyParamQ(jobject private_key, std::vector<uint8_t>* q);
-
// Returns the order parameter of a given ECPrivateKey platform object,
// as a series of bytes, in big-endian representation. This can be used
// with BN_bin2bn() to convert to an OpenSSL BIGNUM.
@@ -65,15 +59,6 @@ NET_EXPORT bool GetDSAKeyParamQ(jobject private_key, std::vector<uint8_t>* q);
// not EC).
bool GetECKeyOrder(jobject private_key, std::vector<uint8_t>* order);
-// Returns the encoded PKCS#8 representation of a private key.
-// This only works on Android 4.0.3 and older releases for platform keys
-// (i.e. all keys except those explicitely generated by the application).
-// |private_key| is a JNI reference for the private key.
-// |encoded| will receive the encoded data on success.
-// Returns true on success, or false on failure (e.g. on 4.0.4 or higher).
-bool GetPrivateKeyEncodedBytes(jobject private_key,
- std::vector<uint8_t>* encoded);
-
// Compute the signature of a given message, which is actually a hash,
// using a private key. For more details, please read the comments for the
// rawSignDigestWithPrivateKey method in AndroidKeyStore.java.
diff --git a/net/android/keystore_openssl.cc b/net/android/keystore_openssl.cc
index dfd3b1f..3907e59 100644
--- a/net/android/keystore_openssl.cc
+++ b/net/android/keystore_openssl.cc
@@ -6,13 +6,11 @@
#include <jni.h>
#include <openssl/bn.h>
-#include <openssl/dsa.h>
#include <openssl/ec.h>
#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
-#include <openssl/x509.h>
#include <stdint.h>
#include "base/android/build_info.h"
@@ -35,9 +33,8 @@
// are required to sign the digest during the OpenSSL handshake for TLS.
//
// The OpenSSL EVP_PKEY type is a generic wrapper around key pairs.
-// Internally, it can hold a pointer to a RSA, DSA or ECDSA structure,
-// which model keypair implementations of each respective crypto
-// algorithm.
+// Internally, it can hold a pointer to a RSA or ECDSA structure, which model
+// keypair implementations of each respective crypto algorithm.
//
// The RSA type has a 'method' field pointer to a vtable-like structure
// called a RSA_METHOD. This contains several function pointers that
@@ -71,8 +68,8 @@ namespace {
extern const RSA_METHOD android_rsa_method;
extern const ECDSA_METHOD android_ecdsa_method;
-// KeyExData contains the data that is contained in the EX_DATA of the RSA, DSA
-// and ECDSA objects that are created to wrap Android system keys.
+// KeyExData contains the data that is contained in the EX_DATA of the RSA and
+// EC_KEY objects that are created to wrap Android system keys.
struct KeyExData {
// private_key contains a reference to a Java, private-key object.
jobject private_key;
@@ -80,13 +77,13 @@ struct KeyExData {
// might not be ABI compatible with Chromium).
AndroidRSA* legacy_rsa;
// cached_size contains the "size" of the key. This is the size of the
- // modulus (in bytes) for RSA, or the group order size for (EC)DSA. This
+ // modulus (in bytes) for RSA, or the group order size for ECDSA. This
// avoids calling into Java to calculate the size.
size_t cached_size;
};
-// ExDataDup is called when one of the RSA, DSA or EC_KEY objects is
-// duplicated. We don't support this and it should never happen.
+// ExDataDup is called when one of the RSA or EC_KEY objects is duplicated. We
+// don't support this and it should never happen.
int ExDataDup(CRYPTO_EX_DATA* to,
const CRYPTO_EX_DATA* from,
void** from_d,
@@ -97,7 +94,7 @@ int ExDataDup(CRYPTO_EX_DATA* to,
return 0;
}
-// ExDataFree is called when one of the RSA, DSA or EC_KEY objects is freed.
+// ExDataFree is called when one of the RSA or EC_KEY objects is freed.
void ExDataFree(void* parent,
void* ptr,
CRYPTO_EX_DATA* ad,
@@ -113,7 +110,7 @@ void ExDataFree(void* parent,
}
}
-// BoringSSLEngine is a BoringSSL ENGINE that implements RSA, DSA and ECDSA by
+// BoringSSLEngine is a BoringSSL ENGINE that implements RSA and ECDSA by
// forwarding the requested operations to the Java libraries.
class BoringSSLEngine {
public:
@@ -402,53 +399,31 @@ crypto::ScopedEVP_PKEY GetRsaPkeyWrapper(jobject private_key) {
return CreateRsaPkeyWrapper(private_key, nullptr, tracer);
}
- // Route around platform bug: if Android < 4.2, then
- // base::android::RawSignDigestWithPrivateKey() cannot work, so instead, try
- // to get the system OpenSSL's EVP_PKEY begin this PrivateKey object.
+ // Route around platform limitation: if Android < 4.2, then
+ // base::android::RawSignDigestWithPrivateKey() cannot work, so try to get the
+ // system OpenSSL's EVP_PKEY backing this PrivateKey object.
AndroidEVP_PKEY* sys_pkey =
GetOpenSSLSystemHandleForPrivateKey(private_key);
- if (sys_pkey != NULL) {
- if (sys_pkey->type != ANDROID_EVP_PKEY_RSA) {
- LOG(ERROR) << "Private key has wrong type!";
- return nullptr;
- }
-
- AndroidRSA* sys_rsa = sys_pkey->pkey.rsa;
- if (sys_rsa->engine) {
- // |private_key| may not have an engine if the PrivateKey did not come
- // from the key store, such as in unit tests.
- if (strcmp(sys_rsa->engine->id, "keystore") == 0) {
- LeakEngine(private_key);
- } else {
- NOTREACHED();
- }
- }
-
- return CreateRsaPkeyWrapper(private_key, sys_rsa, tracer);
- }
-
- // GetOpenSSLSystemHandleForPrivateKey() will fail on Android 4.0.3 and
- // earlier. However, it is possible to get the key content with
- // PrivateKey.getEncoded() on these platforms. Note that this method may
- // return false on 4.0.4 and later.
- std::vector<uint8_t> encoded;
- if (!GetPrivateKeyEncodedBytes(private_key, &encoded) || encoded.empty()) {
- LOG(ERROR) << "Can't get private key data!";
+ if (sys_pkey == nullptr)
return nullptr;
- }
- const uint8_t* p = &encoded[0];
- ScopedPKCS8_PRIV_KEY_INFO pkcs8(
- d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, encoded.size()));
- if (!pkcs8.get() || p != &encoded[0] + encoded.size()) {
- LOG(ERROR) << "Can't decode PrivateKeyInfo";
+
+ if (sys_pkey->type != ANDROID_EVP_PKEY_RSA) {
+ LOG(ERROR) << "Private key has wrong type!";
return nullptr;
}
- crypto::ScopedEVP_PKEY pkey(EVP_PKCS82PKEY(pkcs8.get()));
- if (!pkey || EVP_PKEY_id(pkey.get()) != EVP_PKEY_RSA) {
- LOG(ERROR) << "Can't decode RSA key";
- return nullptr;
+
+ AndroidRSA* sys_rsa = sys_pkey->pkey.rsa;
+ if (sys_rsa->engine) {
+ // |private_key| may not have an engine if the PrivateKey did not come
+ // from the key store, such as in unit tests.
+ if (strcmp(sys_rsa->engine->id, "keystore") == 0) {
+ LeakEngine(private_key);
+ } else {
+ NOTREACHED();
+ }
}
- return pkey.Pass();
+
+ return CreateRsaPkeyWrapper(private_key, sys_rsa, tracer);
}
// Custom ECDSA_METHOD that uses the platform APIs.