OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/android/keystore.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" |
| 11 #include "base/logging.h" |
| 12 |
| 13 #include "jni/AndroidKeyStore_jni.h" |
| 14 |
| 15 using base::android::AttachCurrentThread; |
| 16 using base::android::HasException; |
| 17 using base::android::JavaByteArrayToByteVector; |
| 18 using base::android::ScopedJavaLocalRef; |
| 19 using base::android::ToJavaByteArray; |
| 20 using base::android::JavaArrayOfByteArrayToStringVector; |
| 21 |
| 22 namespace net { |
| 23 namespace android { |
| 24 |
| 25 bool SignWithPrivateKey( |
| 26 jobject private_key_ref, |
| 27 const base::StringPiece& message, |
| 28 std::vector<uint8>* signature) { |
| 29 JNIEnv* env = AttachCurrentThread(); |
| 30 |
| 31 // Convert message to byte[] array. |
| 32 ScopedJavaLocalRef<jbyteArray> message_ref = |
| 33 ToJavaByteArray(env, |
| 34 reinterpret_cast<const uint8*>(message.data()), |
| 35 message.length()); |
| 36 DCHECK(!message_ref.is_null()); |
| 37 |
| 38 // Invoke platform API |
| 39 ScopedJavaLocalRef<jbyteArray> signature_ref = |
| 40 Java_AndroidKeyStore_signWithPrivateKey( |
| 41 env, private_key_ref, message_ref.obj()); |
| 42 if (HasException(env) || signature_ref.is_null()) |
| 43 return false; |
| 44 |
| 45 // Write signature to string. |
| 46 JavaByteArrayToByteVector(env, signature_ref.obj(), signature); |
| 47 return true; |
| 48 } |
| 49 |
| 50 SSLClientCertType GetPrivateKeySigningType(jobject private_key) { |
| 51 JNIEnv* env = AttachCurrentThread(); |
| 52 int type = Java_AndroidKeyStore_getPrivateKeySigningType( |
| 53 env, private_key); |
| 54 return static_cast<SSLClientCertType>(type); |
| 55 } |
| 56 |
| 57 bool RegisterKeyStore(JNIEnv* env) { |
| 58 return RegisterNativesImpl(env); |
| 59 } |
| 60 |
| 61 } // namespace android |
| 62 } // namespace net |
OLD | NEW |