1 /*
2 **
3 ** Copyright 2019, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #define LOG_TAG "android.hardware.keymaster@4.1 ref impl"
19 #include <log/log.h>
20
21 #include "include/AndroidKeymaster41Device.h"
22
23 #include <keymaster/android_keymaster.h>
24
25 namespace keymaster::V4_1 {
26
27 using V4_0::ng::hidlKeyParams2Km;
28
29 namespace {
30
legacy_enum_conversion(const keymaster_error_t value)31 inline V41ErrorCode legacy_enum_conversion(const keymaster_error_t value) {
32 return static_cast<V41ErrorCode>(value);
33 }
34
35 } // namespace
36
CreateKeymasterDevice(SecurityLevel securityLevel)37 IKeymasterDevice* CreateKeymasterDevice(SecurityLevel securityLevel) {
38 return new AndroidKeymaster41Device(securityLevel);
39 }
40
41 Return<V41ErrorCode>
deviceLocked(bool passwordOnly,const VerificationToken & verificationToken)42 AndroidKeymaster41Device::deviceLocked(bool passwordOnly,
43 const VerificationToken& verificationToken) {
44 keymaster::VerificationToken serializableToken;
45 serializableToken.challenge = verificationToken.challenge;
46 serializableToken.timestamp = verificationToken.timestamp;
47 serializableToken.parameters_verified.Reinitialize(
48 hidlKeyParams2Km(verificationToken.parametersVerified));
49 serializableToken.security_level =
50 static_cast<keymaster_security_level_t>(verificationToken.securityLevel);
51 serializableToken.mac =
52 KeymasterBlob(verificationToken.mac.data(), verificationToken.mac.size());
53 return legacy_enum_conversion(
54 impl_
55 ->DeviceLocked(DeviceLockedRequest(impl_->message_version(), passwordOnly,
56 std::move(serializableToken)))
57 .error);
58 }
59
earlyBootEnded()60 Return<V41ErrorCode> AndroidKeymaster41Device::earlyBootEnded() {
61 return legacy_enum_conversion(impl_->EarlyBootEnded().error);
62 }
63
64 } // namespace keymaster::V4_1
65