blob: 8fdaee43b6122643041b05c4895142444c9c607a [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
30using namespace ::keymaster;
31using namespace ::aidl::android::hardware::security::keymint::km_utils;
32
33AndroidSecureClock::AndroidSecureClock(std::shared_ptr<keymint::AndroidKeyMintDevice> keymint)
34 : impl_(keymint->getKeymasterImpl()) {}
35
36AndroidSecureClock::~AndroidSecureClock() {}
37
38ScopedAStatus AndroidSecureClock::generateTimeStamp(int64_t challenge, TimeStampToken* token) {
39 GenerateTimestampTokenRequest request(impl_->message_version());
40 request.challenge = challenge;
41 GenerateTimestampTokenResponse response(request.message_version);
42 impl_->GenerateTimestampToken(request, &response);
43 if (response.error != KM_ERROR_OK) {
44 return kmError2ScopedAStatus(response.error);
45 }
46 token->challenge = response.token.challenge;
47 token->timestamp.milliSeconds = static_cast<int64_t>(response.token.timestamp);
48 token->mac = kmBlob2vector(response.token.mac);
49 return ScopedAStatus::ok();
50}
51
52} // namespace aidl::android::hardware::security::secureclock