1 /* 2 * Copyright 2021, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <trusty_keymaster/TrustySecureClock.h> 18 19 #include <aidl/android/hardware/security/keymint/ErrorCode.h> 20 21 #include <KeyMintUtils.h> 22 23 namespace aidl::android::hardware::security::secureclock::trusty { 24 25 using keymint::km_utils::kmBlob2vector; 26 using keymint::km_utils::kmError2ScopedAStatus; 27 generateTimeStamp(int64_t challenge,TimeStampToken * token)28::ndk::ScopedAStatus TrustySecureClock::generateTimeStamp(int64_t challenge, 29 TimeStampToken* token) { 30 keymaster::VerifyAuthorizationRequest request(impl_->message_version()); 31 request.challenge = challenge; 32 33 auto response = impl_->VerifyAuthorization(request); 34 if (response.error != KM_ERROR_OK) return kmError2ScopedAStatus(response.error); 35 36 token->challenge = response.token.challenge; 37 token->timestamp.milliSeconds = static_cast<int64_t>(response.token.timestamp); 38 token->mac = kmBlob2vector(response.token.mac); 39 return ::ndk::ScopedAStatus::ok(); 40 } 41 42 } // namespace aidl::android::hardware::security::secureclock::trusty 43