| 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_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "crypto/ec_private_key.h" | 13 #include "crypto/ec_private_key.h" |
| 14 #include "jni/AwTokenBindingManager_jni.h" | 14 #include "jni/AwTokenBindingManager_jni.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/ssl/channel_id_service.h" | |
| 17 | 16 |
| 18 using base::android::ConvertJavaStringToUTF8; | 17 using base::android::ConvertJavaStringToUTF8; |
| 19 using base::android::ScopedJavaGlobalRef; | 18 using base::android::ScopedJavaGlobalRef; |
| 20 using content::BrowserThread; | 19 using content::BrowserThread; |
| 21 using net::ChannelIDService; | |
| 22 | 20 |
| 23 namespace android_webview { | 21 namespace android_webview { |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| 26 | 24 |
| 27 // Provides the key to the Webview client. | 25 // Provides the key to the Webview client. |
| 28 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback, | 26 void OnKeyReady(const ScopedJavaGlobalRef<jobject>& callback, |
| 29 int status, | 27 int status, |
| 30 crypto::ECPrivateKey* key) { | 28 crypto::ECPrivateKey* key) { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 32 | 30 |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 31 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 | 32 |
| 35 if (status != net::OK || !key) { | 33 if (status != net::OK || !key) { |
| 36 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), nullptr, | 34 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), nullptr, |
| 37 nullptr); | 35 nullptr); |
| 38 return; | 36 return; |
| 39 } | 37 } |
| 40 | 38 |
| 41 std::vector<uint8_t> private_key; | 39 std::vector<uint8_t> private_key; |
| 42 key->ExportEncryptedPrivateKey(ChannelIDService::kEPKIPassword, 1, | 40 key->ExportPrivateKey(&private_key); |
| 43 &private_key); | |
| 44 ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray( | 41 ScopedJavaLocalRef<jbyteArray> jprivate_key = base::android::ToJavaByteArray( |
| 45 env, private_key.data(), private_key.size()); | 42 env, private_key.data(), private_key.size()); |
| 46 | 43 |
| 47 std::vector<uint8_t> public_key; | 44 std::vector<uint8_t> public_key; |
| 48 key->ExportPublicKey(&public_key); | 45 key->ExportPublicKey(&public_key); |
| 49 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray( | 46 ScopedJavaLocalRef<jbyteArray> jpublic_key = base::android::ToJavaByteArray( |
| 50 env, public_key.data(), public_key.size()); | 47 env, public_key.data(), public_key.size()); |
| 51 | 48 |
| 52 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(), | 49 Java_AwTokenBindingManager_onKeyReady(env, callback.obj(), jprivate_key.obj(), |
| 53 jpublic_key.obj()); | 50 jpublic_key.obj()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 TokenBindingManager::DeletionCompleteCallback complete_callback = | 109 TokenBindingManager::DeletionCompleteCallback complete_callback = |
| 113 base::Bind(&OnDeletionComplete, j_callback); | 110 base::Bind(&OnDeletionComplete, j_callback); |
| 114 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); | 111 TokenBindingManager::GetInstance()->DeleteAllKeys(complete_callback); |
| 115 } | 112 } |
| 116 | 113 |
| 117 bool RegisterTokenBindingManager(JNIEnv* env) { | 114 bool RegisterTokenBindingManager(JNIEnv* env) { |
| 118 return RegisterNativesImpl(env); | 115 return RegisterNativesImpl(env); |
| 119 } | 116 } |
| 120 | 117 |
| 121 } // android_webview namespace | 118 } // android_webview namespace |
| OLD | NEW |