blob: 53a92cca20eb3267bb99eab33697888a6ed5994b [file] [log] [blame]
Shawn Willdenc67a8aa2017-12-03 17:51:29 -07001/*
2 **
3 ** Copyright 2017, 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#include "Keymaster3.h"
19
20#include <android-base/logging.h>
21
22#include <keystore/keystore_hidl_support.h>
23
24namespace keystore {
25
26using android::hardware::hidl_string;
27
28void Keymaster3::getVersionIfNeeded() {
29 if (haveVersion_) return;
30
31 auto rc = km3_dev_->getHardwareFeatures(
32 [&](bool isSecure, bool supportsEllipticCurve, bool supportsSymmetricCryptography,
33 bool supportsAttestation, bool supportsAllDigests, const hidl_string& keymasterName,
34 const hidl_string& keymasterAuthorName) {
35 isSecure_ = isSecure;
36 supportsEllipticCurve_ = supportsEllipticCurve;
37 supportsSymmetricCryptography_ = supportsSymmetricCryptography;
38 supportsAttestation_ = supportsAttestation;
39 supportsAllDigests_ = supportsAllDigests;
40 keymasterName_ = keymasterName;
41 authorName_ = keymasterAuthorName;
42
43 if (!isSecure) {
44 majorVersion_ = 3; // SW version is 3 (don't think this should happen).
45 } else if (supportsAttestation) {
46 majorVersion_ = 2; // Could be 3, no real difference.
47 } else if (supportsSymmetricCryptography) {
48 majorVersion_ = 1;
49 } else {
50 majorVersion_ = 0;
51 }
52 });
53
54 CHECK(rc.isOk()) << "Got error " << rc.description() << " trying to get hardware features";
55}
56
57Keymaster::VersionResult Keymaster3::halVersion() {
58 getVersionIfNeeded();
59 return {ErrorCode::OK, majorVersion_, isSecure_, supportsEllipticCurve_};
60}
61
62} // namespace keystore