OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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); | |
Ryan Sleevi
2013/01/31 03:09:53
Is this guaranteed to be no-fail?
digit1
2013/01/31 17:44:30
Yes.
| |
47 return true; | |
48 } | |
49 | |
50 PrivateKeyType GetPrivateKeyType(jobject private_key) { | |
51 JNIEnv* env = AttachCurrentThread(); | |
52 int type = Java_AndroidKeyStore_getPrivateKeyType( | |
53 env, private_key); | |
54 return static_cast<PrivateKeyType>(type); | |
55 } | |
56 | |
57 EVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key) { | |
58 JNIEnv* env = AttachCurrentThread(); | |
59 int pkey = | |
60 Java_AndroidKeyStore_getOpenSSLHandleForPrivateKey(env, private_key); | |
61 return reinterpret_cast<EVP_PKEY*>(pkey); | |
Ryan Sleevi
2013/01/31 03:09:53
Please make sure palmer is happy with this. I'm su
digit1
2013/01/31 17:44:30
I've added a technical note. The address is stored
| |
62 } | |
63 | |
64 bool RegisterKeyStore(JNIEnv* env) { | |
65 return RegisterNativesImpl(env); | |
66 } | |
67 | |
68 } // namespace android | |
69 } // namespace net | |
OLD | NEW |