Index: net/android/keystore.cc |
diff --git a/net/android/keystore.cc b/net/android/keystore.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9a6373d5ac55fe442faedfeb934dbbc845e43879 |
--- /dev/null |
+++ b/net/android/keystore.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/android/keystore.h" |
+ |
+#include <vector> |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_array.h" |
+#include "base/logging.h" |
+ |
+#include "jni/AndroidKeyStore_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::HasException; |
+using base::android::JavaByteArrayToByteVector; |
+using base::android::ScopedJavaLocalRef; |
+using base::android::ToJavaByteArray; |
+using base::android::JavaArrayOfByteArrayToStringVector; |
+ |
+namespace net { |
+namespace android { |
+ |
+bool SignWithPrivateKey( |
+ jobject private_key_ref, |
+ const base::StringPiece& message, |
+ std::vector<uint8>* signature) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ |
+ // Convert message to byte[] array. |
+ ScopedJavaLocalRef<jbyteArray> message_ref = |
+ ToJavaByteArray(env, |
+ reinterpret_cast<const uint8*>(message.data()), |
+ message.length()); |
+ DCHECK(!message_ref.is_null()); |
+ |
+ // Invoke platform API |
+ ScopedJavaLocalRef<jbyteArray> signature_ref = |
+ Java_AndroidKeyStore_signWithPrivateKey( |
+ env, private_key_ref, message_ref.obj()); |
+ if (HasException(env) || signature_ref.is_null()) |
+ return false; |
+ |
+ // Write signature to string. |
+ JavaByteArrayToByteVector(env, signature_ref.obj(), signature); |
+ return true; |
+} |
+ |
+SSLClientCertType GetPrivateKeySigningType(jobject private_key) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ int type = Java_AndroidKeyStore_getPrivateKeySigningType( |
+ env, private_key); |
+ return static_cast<SSLClientCertType>(type); |
+} |
+ |
+bool RegisterKeyStore(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace android |
+} // namespace net |