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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/token_binding_manager_bridge.h" 5 #include "android_webview/native/token_binding_manager_bridge.h"
6 6
7 #include "android_webview/browser/net/token_binding_manager.h" 7 #include "android_webview/browser/net/token_binding_manager.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "crypto/ec_private_key.h" 13 #include "crypto/ec_private_key.h"
13 #include "jni/AwTokenBindingManager_jni.h" 14 #include "jni/AwTokenBindingManager_jni.h"
15 #include "net/base/net_errors.h"
16 #include "net/ssl/channel_id_service.h"
14 17
15 using base::android::ConvertJavaStringToUTF8; 18 using base::android::ConvertJavaStringToUTF8;
16 using base::android::ScopedJavaGlobalRef; 19 using base::android::ScopedJavaGlobalRef;
17 using content::BrowserThread; 20 using content::BrowserThread;
21 using net::ChannelIDService;
18 22
19 namespace android_webview { 23 namespace android_webview {
20 24
21 namespace { 25 namespace {
22 26
23 // Provides the key to the Webview client. 27 // Provides the key to the Webview client.
24 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback, 28 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback,
25 int status, 29 int status,
26 crypto::ECPrivateKey* key) { 30 crypto::ECPrivateKey* key) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI); 31 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28 32
29 // TODO(sgurun) implement conversion and plumbing the keypair to java. 33 JNIEnv* env = base::android::AttachCurrentThread();
30 34
31 JNIEnv* env = base::android::AttachCurrentThread(); 35 if (status != net::OK || !key) {
32 Java_AwTokenBindingManager_onKeyReady(env, callback.obj()); 36 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), nullptr,
37 nullptr);
38 return;
39 }
40
41 std::vector<uint8_t> private_key;
42 key->ExportEncryptedPrivateKey(ChannelIDService::kEPKIPassword, 1,
43 &private_key);
44 ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray(
45 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.
46 private_key.size());
47
48 std::vector<uint8_t> public_key;
49 key->ExportPublicKey(&public_key);
50 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray(
51 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.
52 public_key.size());
53
54 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(),
55 jpublic_key.obj());
33 } 56 }
34 57
35 // Indicates webview client that key deletion is complete. 58 // Indicates webview client that key deletion is complete.
36 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) { 59 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) {
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 if (callback.is_null()) 61 if (callback.is_null())
39 return; 62 return;
40 JNIEnv* env = base::android::AttachCurrentThread(); 63 JNIEnv* env = base::android::AttachCurrentThread();
41 Java_AwTokenBindingManager_onDeletionComplete(env, callback.obj()); 64 Java_AwTokenBindingManager_onDeletionComplete(env, callback.obj());
42 } 65 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 TokenBindingManager::DeletionCompleteCallback complete_callback = 114 TokenBindingManager::DeletionCompleteCallback complete_callback =
92 base::Bind(&OnDeletionComplete, j_callback); 115 base::Bind(&OnDeletionComplete, j_callback);
93 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); 116 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback);
94 } 117 }
95 118
96 bool RegisterTokenBindingManager(JNIEnv* env) { 119 bool RegisterTokenBindingManager(JNIEnv* env) {
97 return RegisterNativesImpl(env); 120 return RegisterNativesImpl(env);
98 } 121 }
99 122
100 } // android_webview namespace 123 } // android_webview namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698