OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "net/android/keystore.h" | 5 #include "net/android/keystore.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 PrivateKeyType GetPrivateKeyType(jobject private_key_ref) { | 118 PrivateKeyType GetPrivateKeyType(jobject private_key_ref) { |
119 JNIEnv* env = AttachCurrentThread(); | 119 JNIEnv* env = AttachCurrentThread(); |
120 int type = Java_AndroidKeyStore_getPrivateKeyType( | 120 int type = Java_AndroidKeyStore_getPrivateKeyType( |
121 env, | 121 env, |
122 GetKeyStore(private_key_ref).obj(), | 122 GetKeyStore(private_key_ref).obj(), |
123 private_key_ref); | 123 private_key_ref); |
124 return static_cast<PrivateKeyType>(type); | 124 return static_cast<PrivateKeyType>(type); |
125 } | 125 } |
126 | 126 |
127 EVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key_ref) { | 127 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key_ref) { |
128 JNIEnv* env = AttachCurrentThread(); | 128 JNIEnv* env = AttachCurrentThread(); |
129 // Note: the pointer is passed as a jint here because that's how it | 129 // Note: the pointer is passed as a jint here because that's how it |
130 // is stored in the Java object. Java doesn't have a primitive type | 130 // is stored in the Java object. Java doesn't have a primitive type |
131 // like intptr_t that matches the size of pointers on the host | 131 // like intptr_t that matches the size of pointers on the host |
132 // machine, and Android only runs on 32-bit CPUs. | 132 // machine, and Android only runs on 32-bit CPUs. |
133 // | 133 // |
134 // Given that this routine shall only be called on Android < 4.2, | 134 // Given that this routine shall only be called on Android < 4.2, |
135 // this won't be a problem in the far future (e.g. when Android gets | 135 // this won't be a problem in the far future (e.g. when Android gets |
136 // ported to 64-bit environments, if ever). | 136 // ported to 64-bit environments, if ever). |
137 long pkey = Java_AndroidKeyStore_getOpenSSLHandleForPrivateKey( | 137 long pkey = Java_AndroidKeyStore_getOpenSSLHandleForPrivateKey( |
138 env, | 138 env, |
139 GetKeyStore(private_key_ref).obj(), | 139 GetKeyStore(private_key_ref).obj(), |
140 private_key_ref); | 140 private_key_ref); |
141 return reinterpret_cast<EVP_PKEY*>(pkey); | 141 return reinterpret_cast<AndroidEVP_PKEY*>(pkey); |
| 142 } |
| 143 |
| 144 ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( |
| 145 jobject private_key_ref) { |
| 146 JNIEnv* env = AttachCurrentThread(); |
| 147 ScopedJavaLocalRef<jobject> engine = |
| 148 Java_AndroidKeyStore_getOpenSSLEngineForPrivateKey( |
| 149 env, |
| 150 GetKeyStore(private_key_ref).obj(), |
| 151 private_key_ref); |
| 152 return engine; |
142 } | 153 } |
143 | 154 |
144 void ReleaseKey(jobject private_key_ref) { | 155 void ReleaseKey(jobject private_key_ref) { |
145 JNIEnv* env = AttachCurrentThread(); | 156 JNIEnv* env = AttachCurrentThread(); |
146 Java_AndroidKeyStore_releaseKey(env, | 157 Java_AndroidKeyStore_releaseKey(env, |
147 GetKeyStore(private_key_ref).obj(), | 158 GetKeyStore(private_key_ref).obj(), |
148 private_key_ref); | 159 private_key_ref); |
149 env->DeleteGlobalRef(private_key_ref); | 160 env->DeleteGlobalRef(private_key_ref); |
150 } | 161 } |
151 | 162 |
152 bool RegisterKeyStore(JNIEnv* env) { | 163 bool RegisterKeyStore(JNIEnv* env) { |
153 return RegisterNativesImpl(env); | 164 return RegisterNativesImpl(env); |
154 } | 165 } |
155 | 166 |
156 } // namespace android | 167 } // namespace android |
157 } // namespace net | 168 } // namespace net |
OLD | NEW |