blob: 4c69621fa5d58a1bb56c9d0152d13d6b9aae98c1 [file] [log] [blame]
Chirag Pathak7a079942021-01-25 20:16:30 +00001/*
2 * Copyright 2020, 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#define LOG_TAG "android.hardware.security.secureclock-impl"
18#include <log/log.h>
19
20#include "AndroidSecureClock.h"
21
22#include <aidl/android/hardware/security/keymint/ErrorCode.h>
23
24#include "KeyMintUtils.h"
25#include <keymaster/android_keymaster.h>
26#include <keymaster/keymaster_configuration.h>
27
28namespace aidl::android::hardware::security::secureclock {
29
Shawn Willden9a3792e2021-04-08 09:38:14 -060030using keymaster::GenerateTimestampTokenRequest;
31using keymaster::GenerateTimestampTokenResponse;
32using keymint::km_utils::kmBlob2vector;
33using keymint::km_utils::kmError2ScopedAStatus;
Chirag Pathak7a079942021-01-25 20:16:30 +000034
Shawn Willden9a3792e2021-04-08 09:38:14 -060035AndroidSecureClock::AndroidSecureClock(
36 const std::shared_ptr<keymint::AndroidKeyMintDevice>& keymint)
Chirag Pathak7a079942021-01-25 20:16:30 +000037 : impl_(keymint->getKeymasterImpl()) {}
38
39AndroidSecureClock::~AndroidSecureClock() {}
40
41ScopedAStatus AndroidSecureClock::generateTimeStamp(int64_t challenge, TimeStampToken* token) {
42 GenerateTimestampTokenRequest request(impl_->message_version());
43 request.challenge = challenge;
44 GenerateTimestampTokenResponse response(request.message_version);
45 impl_->GenerateTimestampToken(request, &response);
46 if (response.error != KM_ERROR_OK) {
47 return kmError2ScopedAStatus(response.error);
48 }
49 token->challenge = response.token.challenge;
50 token->timestamp.milliSeconds = static_cast<int64_t>(response.token.timestamp);
51 token->mac = kmBlob2vector(response.token.mac);
52 return ScopedAStatus::ok();
53}
54
55} // namespace aidl::android::hardware::security::secureclock