Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1259)

Unified Diff: net/android/keystore.cc

Issue 11571059: Add net/android/keystore.h (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Appease the angry 'findbugs' gods. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/android/keystore.cc
diff --git a/net/android/keystore.cc b/net/android/keystore.cc
new file mode 100644
index 0000000000000000000000000000000000000000..448dc69979948972f3e9843bb72968a8a25d66c2
--- /dev/null
+++ b/net/android/keystore.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2013 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);
Ryan Sleevi 2013/01/31 03:09:53 Is this guaranteed to be no-fail?
digit1 2013/01/31 17:44:30 Yes.
+ return true;
+}
+
+PrivateKeyType GetPrivateKeyType(jobject private_key) {
+ JNIEnv* env = AttachCurrentThread();
+ int type = Java_AndroidKeyStore_getPrivateKeyType(
+ env, private_key);
+ return static_cast<PrivateKeyType>(type);
+}
+
+EVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key) {
+ JNIEnv* env = AttachCurrentThread();
+ int pkey =
+ Java_AndroidKeyStore_getOpenSSLHandleForPrivateKey(env, private_key);
+ return reinterpret_cast<EVP_PKEY*>(pkey);
Ryan Sleevi 2013/01/31 03:09:53 Please make sure palmer is happy with this. I'm su
digit1 2013/01/31 17:44:30 I've added a technical note. The address is stored
+}
+
+bool RegisterKeyStore(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698