• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/hardware/interfaces


Commit MetaInfo

Revision091884aedcec117521134fda7faffa0cf4cbc344 (tree)
Zeit2018-11-15 10:57:41
AutorJanis Danisevskis <jdanis@goog...>
Commiterandroid-build-merger

Log Message

Merge "Multi-threaded Keystore" am: 7d6ca3b265
am: f4db2f14ca

Change-Id: I032441d60f79538785974e704a81c79b1d5a1027

Ändern Zusammenfassung

Diff

--- a/wifi/keystore/1.0/default/Android.bp
+++ b/wifi/keystore/1.0/default/Android.bp
@@ -20,4 +20,5 @@ cc_library_shared {
2020 "libutils",
2121 ],
2222 export_include_dirs: ["include"],
23+ cpp_std: "c++17",
2324 }
--- a/wifi/keystore/1.0/default/include/wifikeystorehal/keystore.h
+++ b/wifi/keystore/1.0/default/include/wifikeystorehal/keystore.h
@@ -5,7 +5,7 @@
55 #include <hidl/MQDescriptor.h>
66 #include <hidl/Status.h>
77
8-#include <android/security/IKeystoreService.h>
8+#include <android/security/keystore/IKeystoreService.h>
99 #include <binder/IServiceManager.h>
1010
1111 namespace android {
--- a/wifi/keystore/1.0/default/keystore.cpp
+++ b/wifi/keystore/1.0/default/keystore.cpp
@@ -1,17 +1,22 @@
11 #include <android-base/logging.h>
2-#include <android/security/IKeystoreService.h>
2+#include <android/security/keystore/BnKeystoreOperationResultCallback.h>
3+#include <android/security/keystore/BnKeystoreResponseCallback.h>
4+#include <android/security/keystore/IKeystoreService.h>
35 #include <binder/IServiceManager.h>
46 #include <private/android_filesystem_config.h>
57
68 #include <keystore/KeyCharacteristics.h>
79 #include <keystore/KeymasterArguments.h>
810 #include <keystore/KeymasterBlob.h>
11+#include <keystore/KeystoreResponse.h>
912 #include <keystore/OperationResult.h>
1013 #include <keystore/keymaster_types.h>
1114 #include <keystore/keystore.h>
1215 #include <keystore/keystore_hidl_support.h>
16+#include <keystore/keystore_promises.h>
1317 #include <keystore/keystore_return_types.h>
1418
19+#include <future>
1520 #include <vector>
1621 #include "include/wifikeystorehal/keystore.h"
1722
@@ -37,6 +42,12 @@ using KSReturn = keystore::KeyStoreNativeReturnCode;
3742 namespace {
3843 constexpr const char kKeystoreServiceName[] = "android.security.keystore";
3944 constexpr int32_t UID_SELF = -1;
45+
46+using keystore::KeyCharacteristicsPromise;
47+using keystore::KeystoreExportPromise;
48+using keystore::KeystoreResponsePromise;
49+using keystore::OperationResultPromise;
50+
4051 }; // namespace
4152
4253 #define AT __func__ << ":" << __LINE__ << " "
@@ -48,7 +59,7 @@ namespace keystore {
4859 namespace V1_0 {
4960 namespace implementation {
5061
51-using security::IKeystoreService;
62+using security::keystore::IKeystoreService;
5263 // Methods from ::android::hardware::wifi::keystore::V1_0::IKeystore follow.
5364 Return<void> Keystore::getBlob(const hidl_string& key, getBlob_cb _hidl_cb) {
5465 sp<IKeystoreService> service = interface_cast<IKeystoreService>(
@@ -79,22 +90,33 @@ Return<void> Keystore::getPublicKey(const hidl_string& keyId, getPublicKey_cb _h
7990 return Void();
8091 }
8192
82- ExportResult result;
93+ int32_t error_code;
94+ android::sp<KeystoreExportPromise> promise(new KeystoreExportPromise);
95+ auto future = promise->get_future();
8396 auto binder_result = service->exportKey(
84- String16(keyId.c_str()), static_cast<int32_t>(KeyFormat::X509),
85- KeymasterBlob() /* clientId */, KeymasterBlob() /* appData */, UID_SELF, &result);
97+ promise, String16(keyId.c_str()), static_cast<int32_t>(KeyFormat::X509),
98+ KeymasterBlob() /* clientId */, KeymasterBlob() /* appData */, UID_SELF, &error_code);
8699 if (!binder_result.isOk()) {
87100 LOG(ERROR) << AT << "communication error while calling keystore";
88101 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
89102 return Void();
90103 }
91- if (!result.resultCode.isOk()) {
92- LOG(ERROR) << AT << "exportKey failed: " << int32_t(result.resultCode);
104+
105+ KSReturn rc(error_code);
106+ if (!rc.isOk()) {
107+ LOG(ERROR) << AT << "exportKey failed: " << error_code;
93108 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
94109 return Void();
95110 }
96111
97- _hidl_cb(KeystoreStatusCode::SUCCESS, result.exportData);
112+ auto export_result = future.get();
113+ if (!export_result.resultCode.isOk()) {
114+ LOG(ERROR) << AT << "exportKey failed: " << int32_t(export_result.resultCode);
115+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
116+ return Void();
117+ }
118+
119+ _hidl_cb(KeystoreStatusCode::SUCCESS, export_result.exportData);
98120 return Void();
99121 }
100122
@@ -123,21 +145,33 @@ Return<void> Keystore::sign(const hidl_string& keyId, const hidl_vec<uint8_t>& d
123145 return Void();
124146 }
125147
126- KeyCharacteristics keyCharacteristics;
127148 String16 key_name16(keyId.c_str());
128- int32_t aidl_result;
129- auto binder_result = service->getKeyCharacteristics(
130- key_name16, KeymasterBlob(), KeymasterBlob(), UID_SELF, &keyCharacteristics, &aidl_result);
149+ int32_t error_code;
150+ android::sp<KeyCharacteristicsPromise> kc_promise(new KeyCharacteristicsPromise);
151+ auto kc_future = kc_promise->get_future();
152+ auto binder_result = service->getKeyCharacteristics(kc_promise, key_name16, KeymasterBlob(),
153+ KeymasterBlob(), UID_SELF, &error_code);
131154 if (!binder_result.isOk()) {
132155 LOG(ERROR) << AT << "communication error while calling keystore";
133156 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
134157 return Void();
135158 }
136- if (KSReturn(aidl_result).isOk()) {
137- LOG(ERROR) << AT << "getKeyCharacteristics failed: " << aidl_result;
159+ KSReturn rc(error_code);
160+ if (!rc.isOk()) {
161+ LOG(ERROR) << AT << "getKeyCharacteristics failed: " << error_code;
162+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
163+ return Void();
164+ }
165+
166+ auto [km_response, characteristics] = kc_future.get();
167+
168+ if (KSReturn(km_response.response_code()).isOk()) {
169+ LOG(ERROR) << AT << "getKeyCharacteristics failed: " << km_response.response_code();
170+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
171+ return Void();
138172 }
139173
140- auto algorithm = getKeyAlgoritmFromKeyCharacteristics(keyCharacteristics);
174+ auto algorithm = getKeyAlgoritmFromKeyCharacteristics(characteristics);
141175 if (!algorithm.isOk()) {
142176 LOG(ERROR) << AT << "could not get algorithm from key characteristics";
143177 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
@@ -150,15 +184,25 @@ Return<void> Keystore::sign(const hidl_string& keyId, const hidl_vec<uint8_t>& d
150184 params[2] = Authorization(TAG_ALGORITHM, algorithm.value());
151185
152186 android::sp<android::IBinder> token(new android::BBinder);
153- OperationResult result;
154- binder_result = service->begin(token, key_name16, (int)KeyPurpose::SIGN, true /*pruneable*/,
155- KeymasterArguments(params), std::vector<uint8_t>() /* entropy */,
156- UID_SELF, &result);
187+ sp<OperationResultPromise> promise(new OperationResultPromise());
188+ auto future = promise->get_future();
189+ binder_result = service->begin(promise, token, key_name16, (int)KeyPurpose::SIGN,
190+ true /*pruneable*/, KeymasterArguments(params),
191+ std::vector<uint8_t>() /* entropy */, UID_SELF, &error_code);
157192 if (!binder_result.isOk()) {
158193 LOG(ERROR) << AT << "communication error while calling keystore";
159194 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
160195 return Void();
161196 }
197+
198+ rc = KSReturn(error_code);
199+ if (!rc.isOk()) {
200+ LOG(ERROR) << AT << "Keystore begin returned: " << int32_t(rc);
201+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
202+ return Void();
203+ }
204+
205+ OperationResult result = future.get();
162206 if (!result.resultCode.isOk()) {
163207 LOG(ERROR) << AT << "begin failed: " << int32_t(result.resultCode);
164208 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
@@ -169,13 +213,24 @@ Return<void> Keystore::sign(const hidl_string& keyId, const hidl_vec<uint8_t>& d
169213 const uint8_t* in = dataToSign.data();
170214 size_t len = dataToSign.size();
171215 do {
172- binder_result = service->update(handle, KeymasterArguments(params),
173- std::vector<uint8_t>(in, in + len), &result);
216+ future = {};
217+ binder_result = service->update(promise, handle, KeymasterArguments(params),
218+ std::vector<uint8_t>(in, in + len), &error_code);
174219 if (!binder_result.isOk()) {
175220 LOG(ERROR) << AT << "communication error while calling keystore";
176221 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
177222 return Void();
178223 }
224+
225+ rc = KSReturn(error_code);
226+ if (!rc.isOk()) {
227+ LOG(ERROR) << AT << "Keystore update returned: " << int32_t(rc);
228+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
229+ return Void();
230+ }
231+
232+ result = future.get();
233+
179234 if (!result.resultCode.isOk()) {
180235 LOG(ERROR) << AT << "update failed: " << int32_t(result.resultCode);
181236 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
@@ -183,7 +238,22 @@ Return<void> Keystore::sign(const hidl_string& keyId, const hidl_vec<uint8_t>& d
183238 }
184239 if ((size_t)result.inputConsumed > len) {
185240 LOG(ERROR) << AT << "update consumed more data than provided";
186- service->abort(handle, &aidl_result);
241+ sp<KeystoreResponsePromise> abortPromise(new KeystoreResponsePromise);
242+ auto abortFuture = abortPromise->get_future();
243+ binder_result = service->abort(abortPromise, handle, &error_code);
244+ if (!binder_result.isOk()) {
245+ LOG(ERROR) << AT << "communication error while calling keystore";
246+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
247+ return Void();
248+ }
249+ // This is mainly for logging since we already failed.
250+ // But if abort returned OK we have to wait untill abort calls the callback
251+ // hence the call to abortFuture.get().
252+ if (!KSReturn(error_code).isOk()) {
253+ LOG(ERROR) << AT << "abort failed: " << error_code;
254+ } else if (!(rc = KSReturn(abortFuture.get().response_code())).isOk()) {
255+ LOG(ERROR) << AT << "abort failed: " << int32_t(rc);
256+ }
187257 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
188258 return Void();
189259 }
@@ -191,14 +261,28 @@ Return<void> Keystore::sign(const hidl_string& keyId, const hidl_vec<uint8_t>& d
191261 in += result.inputConsumed;
192262 } while (len > 0);
193263
194- binder_result =
195- service->finish(handle, KeymasterArguments(params), std::vector<uint8_t>() /* signature */,
196- std::vector<uint8_t>() /* entropy */, &result);
264+ future = {};
265+ promise = new OperationResultPromise();
266+ future = promise->get_future();
267+
268+ binder_result = service->finish(promise, handle, KeymasterArguments(params),
269+ std::vector<uint8_t>() /* signature */,
270+ std::vector<uint8_t>() /* entropy */, &error_code);
197271 if (!binder_result.isOk()) {
198272 LOG(ERROR) << AT << "communication error while calling keystore";
199273 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
200274 return Void();
201275 }
276+
277+ rc = KSReturn(error_code);
278+ if (!rc.isOk()) {
279+ LOG(ERROR) << AT << "Keystore finish returned: " << int32_t(rc);
280+ _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});
281+ return Void();
282+ }
283+
284+ result = future.get();
285+
202286 if (!result.resultCode.isOk()) {
203287 LOG(ERROR) << AT << "finish failed: " << int32_t(result.resultCode);
204288 _hidl_cb(KeystoreStatusCode::ERROR_UNKNOWN, {});