diff options
author | Michael Ryleev <gmar@google.com> | 2018-09-18 15:43:57 -0700 |
---|---|---|
committer | Michael Ryleev <gmar@google.com> | 2018-09-18 16:12:24 -0700 |
commit | bfccad24747339aaa0e8d11a0361f5c91061af7d (patch) | |
tree | d1149a01db6f1a495ca8e0a2b75a27381ff3c05a /trusty | |
parent | d800caf34551dc1547efdf4152604ea326c614bc (diff) | |
download | system_core-bfccad24747339aaa0e8d11a0361f5c91061af7d.tar.gz system_core-bfccad24747339aaa0e8d11a0361f5c91061af7d.tar.bz2 system_core-bfccad24747339aaa0e8d11a0361f5c91061af7d.zip |
trusty: keymaster3: Modify TrustyKeymaster3Device::update method
Modify TrustyKeymaster3Device::update method to handle the case when
amount of input data received exceeds a maximum amount supported by
underlying transport. In such case, only send an portion of data that
fits and allow higher levels to take care of the rest.
This is not an ideal fix as it is not very efficient for large sets
of data but at least it should work in more cases.
Test: android.keystore.cts
Change-Id: Id7360d0da3b87493193d480fc0c78c65dc1fc51f
Diffstat (limited to 'trusty')
-rw-r--r-- | trusty/keymaster/3.0/TrustyKeymaster3Device.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp b/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp index 8e3b3b127..0849ee959 100644 --- a/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp +++ b/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp @@ -21,6 +21,7 @@ #include <cutils/log.h> #include <keymaster/android_keymaster_messages.h> #include <trusty_keymaster/TrustyKeymaster3Device.h> +#include <trusty_keymaster/ipc/trusty_keymaster_ipc.h> using ::keymaster::AbortOperationRequest; using ::keymaster::AbortOperationResponse; @@ -393,20 +394,32 @@ Return<void> TrustyKeymaster3Device::update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, const hidl_vec<uint8_t>& input, update_cb _hidl_cb) { UpdateOperationRequest request; + UpdateOperationResponse response; + hidl_vec<KeyParameter> resultParams; + hidl_vec<uint8_t> resultBlob; + uint32_t resultConsumed = 0; + request.op_handle = operationHandle; - request.input.Reinitialize(input.data(), input.size()); request.additional_params.Reinitialize(KmParamSet(inParams)); - UpdateOperationResponse response; - impl_->UpdateOperation(request, &response); + size_t inp_size = input.size(); + size_t ser_size = request.SerializedSize(); - uint32_t resultConsumed = 0; - hidl_vec<KeyParameter> resultParams; - hidl_vec<uint8_t> resultBlob; - if (response.error == KM_ERROR_OK) { - resultConsumed = response.input_consumed; - resultParams = kmParamSet2Hidl(response.output_params); - resultBlob = kmBuffer2hidlVec(response.output); + if (ser_size > TRUSTY_KEYMASTER_SEND_BUF_SIZE) { + response.error = KM_ERROR_INVALID_INPUT_LENGTH; + } else { + if (ser_size + inp_size > TRUSTY_KEYMASTER_SEND_BUF_SIZE) { + inp_size = TRUSTY_KEYMASTER_SEND_BUF_SIZE - ser_size; + } + request.input.Reinitialize(input.data(), inp_size); + + impl_->UpdateOperation(request, &response); + + if (response.error == KM_ERROR_OK) { + resultConsumed = response.input_consumed; + resultParams = kmParamSet2Hidl(response.output_params); + resultBlob = kmBuffer2hidlVec(response.output); + } } _hidl_cb(legacy_enum_conversion(response.error), resultConsumed, resultParams, resultBlob); return Void(); |