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

Unified Diff: android_webview/native/token_binding_manager_bridge.cc

Issue 1631123002: The key conversion algorithm for Token binding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor update Created 4 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: android_webview/native/token_binding_manager_bridge.cc
diff --git a/android_webview/native/token_binding_manager_bridge.cc b/android_webview/native/token_binding_manager_bridge.cc
index 07c690f0c24a0d7820a9e8f67aed2ea145a66fb7..648673502ff7efed14c23867bdfbdbdb3d8af62a 100644
--- a/android_webview/native/token_binding_manager_bridge.cc
+++ b/android_webview/native/token_binding_manager_bridge.cc
@@ -6,15 +6,19 @@
#include "android_webview/browser/net/token_binding_manager.h"
#include "base/android/jni_android.h"
+#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/ec_private_key.h"
#include "jni/AwTokenBindingManager_jni.h"
+#include "net/base/net_errors.h"
+#include "net/ssl/channel_id_service.h"
using base::android::ConvertJavaStringToUTF8;
using base::android::ScopedJavaGlobalRef;
using content::BrowserThread;
+using net::ChannelIDService;
namespace android_webview {
@@ -26,10 +30,29 @@ void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback,
crypto::ECPrivateKey* key) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // TODO(sgurun) implement conversion and plumbing the keypair to java.
-
JNIEnv* env = base::android::AttachCurrentThread();
- Java_AwTokenBindingManager_onKeyReady(env, callback.obj());
+
+ if (status != net::OK || !key) {
+ Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), nullptr,
+ nullptr);
+ return;
+ }
+
+ std::vector<uint8_t> private_key;
+ key->ExportEncryptedPrivateKey(ChannelIDService::kEPKIPassword, 1,
+ &private_key);
+ ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray(
+ env, reinterpret_cast<const uint8_t*>(private_key.data()),
mnaganov (inactive) 2016/01/26 01:37:02 Can we use const_cast here? I guess you are just e
boliu 2016/01/26 01:50:19 Or why cast at all? There is a const overload of
sgurun-gerrit only 2016/01/26 01:57:03 yeah agreed. no need.
+ private_key.size());
+
+ std::vector<uint8_t> public_key;
+ key->ExportPublicKey(&public_key);
+ ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray(
+ env, reinterpret_cast<const uint8_t*>(public_key.data()),
boliu 2016/01/26 01:50:19 ditto
sgurun-gerrit only 2016/01/26 01:57:03 Done.
+ public_key.size());
+
+ Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(),
+ jpublic_key.obj());
}
// Indicates webview client that key deletion is complete.

Powered by Google App Engine
This is Rietveld 408576698