OLD | NEW |
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, private_key.data(), private_key.size()); |
| 46 |
| 47 std::vector<uint8_t> public_key; |
| 48 key->ExportPublicKey(&public_key); |
| 49 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray( |
| 50 env, public_key.data(), public_key.size()); |
| 51 |
| 52 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(), |
| 53 jpublic_key.obj()); |
33 } | 54 } |
34 | 55 |
35 // Indicates webview client that key deletion is complete. | 56 // Indicates webview client that key deletion is complete. |
36 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) { | 57 void OnDeletionComplete(const ScopedJavaGlobalRef<jobject>& callback) { |
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
38 if (callback.is_null()) | 59 if (callback.is_null()) |
39 return; | 60 return; |
40 JNIEnv* env = base::android::AttachCurrentThread(); | 61 JNIEnv* env = base::android::AttachCurrentThread(); |
41 Java_AwTokenBindingManager_onDeletionComplete(env, callback.obj()); | 62 Java_AwTokenBindingManager_onDeletionComplete(env, callback.obj()); |
42 } | 63 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 TokenBindingManager::DeletionCompleteCallback complete_callback = | 112 TokenBindingManager::DeletionCompleteCallback complete_callback = |
92 base::Bind(&OnDeletionComplete, j_callback); | 113 base::Bind(&OnDeletionComplete, j_callback); |
93 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); | 114 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); |
94 } | 115 } |
95 | 116 |
96 bool RegisterTokenBindingManager(JNIEnv* env) { | 117 bool RegisterTokenBindingManager(JNIEnv* env) { |
97 return RegisterNativesImpl(env); | 118 return RegisterNativesImpl(env); |
98 } | 119 } |
99 | 120 |
100 } // android_webview namespace | 121 } // android_webview namespace |
OLD | NEW |