diff options
author | nagendra modadugu <ngm@google.com> | 2019-01-02 11:57:35 -0800 |
---|---|---|
committer | nagendra modadugu <ngm@google.com> | 2019-01-04 15:40:50 -0800 |
commit | 0e23f8d91cc2d7bbe95d815d0a1f1698909ac2f6 (patch) | |
tree | 1ce363092f396c3164b7dc096314b7ebccd5fc08 | |
parent | 9430f730e342a512536f060fe3afc174c12cb98c (diff) | |
download | android-0e23f8d91cc2d7bbe95d815d0a1f1698909ac2f6.tar.gz |
keymaster: specify current time generate/import
When generating or importing keys, specify the
current time which gets included in the corresponding
blob.
Bug: 122184852
Test: pending
Change-Id: I3a19ac67054473084a7268926c7136667621f1e7
-rw-r--r-- | hals/keymaster/KeymasterDevice.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/hals/keymaster/KeymasterDevice.cpp b/hals/keymaster/KeymasterDevice.cpp index daa17ee..37391cd 100644 --- a/hals/keymaster/KeymasterDevice.cpp +++ b/hals/keymaster/KeymasterDevice.cpp @@ -229,6 +229,20 @@ static ErrorCode status_to_error_code(uint32_t status) } } +static uint64_t ms_since_epoch(void) +{ + uint64_t seconds; + uint64_t milli_seconds; + struct timespec spec; + + ::clock_gettime(CLOCK_REALTIME, &spec); + + seconds = spec.tv_sec; + milli_seconds = spec.tv_nsec / (1000 * 1000); + + return (seconds * 1000) + milli_seconds; +} + #define KM_CALL(meth, request, response) { \ const uint32_t status = _keymaster. meth (request, &response); \ const ErrorCode error_code = translate_error_code(response.error_code()); \ @@ -448,6 +462,7 @@ Return<void> KeymasterDevice::generateKey( _hidl_cb(ErrorCode::INVALID_ARGUMENT, blob, characteristics); return Void(); } + request.set_creation_time_ms(ms_since_epoch()); // Call device. KM_CALLV(GenerateKey, request, response, @@ -512,6 +527,7 @@ Return<void> KeymasterDevice::importKey( _hidl_cb(error, hidl_vec<uint8_t>{}, KeyCharacteristics{}); return Void(); } + request.set_creation_time_ms(ms_since_epoch()); KM_CALLV(ImportKey, request, response, hidl_vec<uint8_t>{}, KeyCharacteristics{}); @@ -1221,6 +1237,7 @@ Return<void> KeymasterDevice::importWrappedKey( _hidl_cb(error, hidl_vec<uint8_t>{}, KeyCharacteristics{}); return Void(); } + request.set_creation_time_ms(ms_since_epoch()); KM_CALLV(ImportWrappedKey, request, response, hidl_vec<uint8_t>{}, KeyCharacteristics{}); |