Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: net/android/keystore.cc

Issue 1158923005: Use the exact-width integer types defined in <stdint.h> rather than (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments. Exclude mime_sniffer*. Rebase. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "jni/AndroidKeyStore_jni.h" 12 #include "jni/AndroidKeyStore_jni.h"
13 #include "net/android/android_private_key.h" 13 #include "net/android/android_private_key.h"
14 14
15 using base::android::AttachCurrentThread; 15 using base::android::AttachCurrentThread;
16 using base::android::HasException; 16 using base::android::HasException;
17 using base::android::JavaByteArrayToByteVector; 17 using base::android::JavaByteArrayToByteVector;
18 using base::android::ScopedJavaLocalRef; 18 using base::android::ScopedJavaLocalRef;
19 using base::android::ToJavaByteArray; 19 using base::android::ToJavaByteArray;
20 using base::android::JavaArrayOfByteArrayToStringVector; 20 using base::android::JavaArrayOfByteArrayToStringVector;
21 21
22 namespace net { 22 namespace net {
23 namespace android { 23 namespace android {
24 24
25 bool GetRSAKeyModulus( 25 bool GetRSAKeyModulus(jobject private_key_ref, std::vector<uint8_t>* result) {
26 jobject private_key_ref,
27 std::vector<uint8>* result) {
28 JNIEnv* env = AttachCurrentThread(); 26 JNIEnv* env = AttachCurrentThread();
29 27
30 ScopedJavaLocalRef<jbyteArray> modulus_ref = 28 ScopedJavaLocalRef<jbyteArray> modulus_ref =
31 Java_AndroidKeyStore_getRSAKeyModulus(env, 29 Java_AndroidKeyStore_getRSAKeyModulus(env,
32 GetKeyStore(private_key_ref).obj(), 30 GetKeyStore(private_key_ref).obj(),
33 private_key_ref); 31 private_key_ref);
34 if (modulus_ref.is_null()) 32 if (modulus_ref.is_null())
35 return false; 33 return false;
36 34
37 JavaByteArrayToByteVector(env, modulus_ref.obj(), result); 35 JavaByteArrayToByteVector(env, modulus_ref.obj(), result);
38 return true; 36 return true;
39 } 37 }
40 38
41 bool GetDSAKeyParamQ(jobject private_key_ref, 39 bool GetDSAKeyParamQ(jobject private_key_ref, std::vector<uint8_t>* result) {
42 std::vector<uint8>* result) {
43 JNIEnv* env = AttachCurrentThread(); 40 JNIEnv* env = AttachCurrentThread();
44 41
45 ScopedJavaLocalRef<jbyteArray> q_ref = 42 ScopedJavaLocalRef<jbyteArray> q_ref =
46 Java_AndroidKeyStore_getDSAKeyParamQ( 43 Java_AndroidKeyStore_getDSAKeyParamQ(
47 env, 44 env,
48 GetKeyStore(private_key_ref).obj(), 45 GetKeyStore(private_key_ref).obj(),
49 private_key_ref); 46 private_key_ref);
50 if (q_ref.is_null()) 47 if (q_ref.is_null())
51 return false; 48 return false;
52 49
53 JavaByteArrayToByteVector(env, q_ref.obj(), result); 50 JavaByteArrayToByteVector(env, q_ref.obj(), result);
54 return true; 51 return true;
55 } 52 }
56 53
57 bool GetECKeyOrder(jobject private_key_ref, 54 bool GetECKeyOrder(jobject private_key_ref, std::vector<uint8_t>* result) {
58 std::vector<uint8>* result) {
59 JNIEnv* env = AttachCurrentThread(); 55 JNIEnv* env = AttachCurrentThread();
60 56
61 ScopedJavaLocalRef<jbyteArray> order_ref = 57 ScopedJavaLocalRef<jbyteArray> order_ref =
62 Java_AndroidKeyStore_getECKeyOrder( 58 Java_AndroidKeyStore_getECKeyOrder(
63 env, 59 env,
64 GetKeyStore(private_key_ref).obj(), 60 GetKeyStore(private_key_ref).obj(),
65 private_key_ref); 61 private_key_ref);
66 62
67 if (order_ref.is_null()) 63 if (order_ref.is_null())
68 return false; 64 return false;
69 65
70 JavaByteArrayToByteVector(env, order_ref.obj(), result); 66 JavaByteArrayToByteVector(env, order_ref.obj(), result);
71 return true; 67 return true;
72 } 68 }
73 69
74 bool GetPrivateKeyEncodedBytes(jobject private_key_ref, 70 bool GetPrivateKeyEncodedBytes(jobject private_key_ref,
75 std::vector<uint8>* result) { 71 std::vector<uint8_t>* result) {
76 JNIEnv* env = AttachCurrentThread(); 72 JNIEnv* env = AttachCurrentThread();
77 73
78 ScopedJavaLocalRef<jbyteArray> encoded_ref = 74 ScopedJavaLocalRef<jbyteArray> encoded_ref =
79 Java_AndroidKeyStore_getPrivateKeyEncodedBytes( 75 Java_AndroidKeyStore_getPrivateKeyEncodedBytes(
80 env, 76 env,
81 GetKeyStore(private_key_ref).obj(), 77 GetKeyStore(private_key_ref).obj(),
82 private_key_ref); 78 private_key_ref);
83 if (encoded_ref.is_null()) 79 if (encoded_ref.is_null())
84 return false; 80 return false;
85 81
86 JavaByteArrayToByteVector(env, encoded_ref.obj(), result); 82 JavaByteArrayToByteVector(env, encoded_ref.obj(), result);
87 return true; 83 return true;
88 } 84 }
89 85
90 bool RawSignDigestWithPrivateKey( 86 bool RawSignDigestWithPrivateKey(jobject private_key_ref,
91 jobject private_key_ref, 87 const base::StringPiece& digest,
92 const base::StringPiece& digest, 88 std::vector<uint8_t>* signature) {
93 std::vector<uint8>* signature) {
94 JNIEnv* env = AttachCurrentThread(); 89 JNIEnv* env = AttachCurrentThread();
95 90
96 // Convert message to byte[] array. 91 // Convert message to byte[] array.
97 ScopedJavaLocalRef<jbyteArray> digest_ref = 92 ScopedJavaLocalRef<jbyteArray> digest_ref = ToJavaByteArray(
98 ToJavaByteArray(env, 93 env, reinterpret_cast<const uint8_t*>(digest.data()), digest.length());
99 reinterpret_cast<const uint8*>(digest.data()),
100 digest.length());
101 DCHECK(!digest_ref.is_null()); 94 DCHECK(!digest_ref.is_null());
102 95
103 // Invoke platform API 96 // Invoke platform API
104 ScopedJavaLocalRef<jbyteArray> signature_ref = 97 ScopedJavaLocalRef<jbyteArray> signature_ref =
105 Java_AndroidKeyStore_rawSignDigestWithPrivateKey( 98 Java_AndroidKeyStore_rawSignDigestWithPrivateKey(
106 env, 99 env,
107 GetKeyStore(private_key_ref).obj(), 100 GetKeyStore(private_key_ref).obj(),
108 private_key_ref, 101 private_key_ref,
109 digest_ref.obj()); 102 digest_ref.obj());
110 if (HasException(env) || signature_ref.is_null()) 103 if (HasException(env) || signature_ref.is_null())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 private_key_ref); 152 private_key_ref);
160 env->DeleteGlobalRef(private_key_ref); 153 env->DeleteGlobalRef(private_key_ref);
161 } 154 }
162 155
163 bool RegisterKeyStore(JNIEnv* env) { 156 bool RegisterKeyStore(JNIEnv* env) {
164 return RegisterNativesImpl(env); 157 return RegisterNativesImpl(env);
165 } 158 }
166 159
167 } // namespace android 160 } // namespace android
168 } // namespace net 161 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698