summaryrefslogtreecommitdiff
path: root/keymaster
diff options
context:
space:
mode:
authorShawn Willden <swillden@google.com>2018-06-14 16:52:23 -0600
committerShawn Willden <swillden@google.com>2018-06-19 07:17:23 -0600
commite8c37cbff30ea5bad52fa039b460bfbf72b42bab (patch)
treea91fff456780a3d61894aea10da7cf3a8f7b1615 /keymaster
parent0706a3f55032d44e84a02743ce8cbddced642b4a (diff)
downloadcrosshatch-e8c37cbff30ea5bad52fa039b460bfbf72b42bab.tar.gz
Add utility to wait for strongbox keymaster to be ready
It's important that vold not be started until both keymaster HALs are running, or strongbox won't work. This utility waits until both are ready, then returns. Bug: 90406546 Test: Manual Change-Id: Ida0aa0e5f41b5fe65c814cc2d3cd37c565b0a4a1
Diffstat (limited to 'keymaster')
-rw-r--r--keymaster/Android.bp27
-rw-r--r--keymaster/wait_for_strongbox.cpp59
2 files changed, 86 insertions, 0 deletions
diff --git a/keymaster/Android.bp b/keymaster/Android.bp
new file mode 100644
index 00000000..02d52a96
--- /dev/null
+++ b/keymaster/Android.bp
@@ -0,0 +1,27 @@
+//
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary {
+ name: "wait_for_strongbox",
+ relative_install_path: "hw",
+ srcs: [ "wait_for_strongbox.cpp" ],
+ cflags: [ "-Werror", "-Wall" ],
+ shared_libs: [
+ "android.hardware.keymaster@4.0",
+ "libbase",
+ "libkeymaster4support",
+ ],
+ proprietary: true,
+}
diff --git a/keymaster/wait_for_strongbox.cpp b/keymaster/wait_for_strongbox.cpp
new file mode 100644
index 00000000..7516774f
--- /dev/null
+++ b/keymaster/wait_for_strongbox.cpp
@@ -0,0 +1,59 @@
+/*
+ ** Copyright 2018, The Android Open Source Project
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+
+#include <unistd.h>
+
+#define LOG_TAG "wait_for_strongbox"
+#include <android-base/logging.h>
+
+#include <keymasterV4_0/Keymaster.h>
+
+using android::hardware::keymaster::V4_0::SecurityLevel;
+using android::hardware::keymaster::V4_0::support::Keymaster;
+
+useconds_t kWaitTimeMicroseconds = 10 * 1000; // 10 milliseconds
+
+int main() {
+ for (unsigned cycleCount = 0; /* Forever */; ++cycleCount) {
+ auto keymasters = Keymaster::enumerateAvailableDevices();
+
+ bool foundStrongBox = false;
+ bool foundTee = false;
+ for (auto &dev : keymasters) {
+ SecurityLevel securityLevel = dev->halVersion().securityLevel;
+ uint8_t majorVersion = dev->halVersion().majorVersion;
+ if (securityLevel == SecurityLevel::STRONGBOX && majorVersion == 4) {
+ foundStrongBox = true;
+ }
+ if (securityLevel == SecurityLevel::TRUSTED_ENVIRONMENT && majorVersion == 4) {
+ foundTee = true;
+ }
+ }
+
+ if (foundTee && foundStrongBox) {
+ return 0;
+ }
+ if (cycleCount % 10 == 1) {
+ if (!foundStrongBox) {
+ LOG(WARNING) << "Still waiting for StrongBox Keymaster";
+ }
+ if (!foundTee) {
+ LOG(WARNING) << "Still waiting for TEE Keymaster";
+ }
+ }
+ usleep(kWaitTimeMicroseconds);
+ }
+}