blob: bcebbaf8cf915e76455783486d9992a048aba31c [file] [log] [blame]
Selene Huang31ab4042020-04-29 04:22:39 -07001/*
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
Shawn Willden08a7e432020-12-11 13:05:27 +000017#define LOG_TAG "android.hardware.security.keymint-service"
Selene Huang31ab4042020-04-29 04:22:39 -070018
19#include <android-base/logging.h>
20#include <android/binder_manager.h>
21#include <android/binder_process.h>
22
Shawn Willden08a7e432020-12-11 13:05:27 +000023#include <AndroidKeyMintDevice.h>
Chirag Pathak8960aae2021-01-25 21:37:06 +000024#include <AndroidSecureClock.h>
25#include <AndroidSharedSecret.h>
Selene Huang31ab4042020-04-29 04:22:39 -070026#include <keymaster/soft_keymaster_logger.h>
27
Shawn Willden274bb552020-09-30 22:39:22 -060028#include "RemotelyProvisionedComponent.h"
29
Shawn Willden08a7e432020-12-11 13:05:27 +000030using aidl::android::hardware::security::keymint::AndroidKeyMintDevice;
Shawn Willden274bb552020-09-30 22:39:22 -060031using aidl::android::hardware::security::keymint::RemotelyProvisionedComponent;
Shawn Willden08a7e432020-12-11 13:05:27 +000032using aidl::android::hardware::security::keymint::SecurityLevel;
Chirag Pathak8960aae2021-01-25 21:37:06 +000033using aidl::android::hardware::security::secureclock::AndroidSecureClock;
34using aidl::android::hardware::security::sharedsecret::AndroidSharedSecret;
35
36template <typename T, class... Args>
37std::shared_ptr<T> addService(Args&&... args) {
38 std::shared_ptr<T> ser = ndk::SharedRefBase::make<T>(std::forward<Args>(args)...);
39 auto instanceName = std::string(T::descriptor) + "/default";
40 LOG(INFO) << "adding keymint service instance: " << instanceName;
41 binder_status_t status =
42 AServiceManager_addService(ser->asBinder().get(), instanceName.c_str());
43 CHECK(status == STATUS_OK);
44 return ser;
45}
Selene Huang31ab4042020-04-29 04:22:39 -070046
47int main() {
48 // Zero threads seems like a useless pool, but below we'll join this thread to it, increasing
49 // the pool size to 1.
50 ABinderProcess_setThreadPoolMaxThreadCount(0);
Chirag Pathak8960aae2021-01-25 21:37:06 +000051 // Add Keymint Service
Shawn Willden08a7e432020-12-11 13:05:27 +000052 std::shared_ptr<AndroidKeyMintDevice> keyMint =
Chirag Pathak8960aae2021-01-25 21:37:06 +000053 addService<AndroidKeyMintDevice>(SecurityLevel::SOFTWARE);
54 // Add Secure Clock Service
55 addService<AndroidSecureClock>(keyMint);
56 // Add Shared Secret Service
57 addService<AndroidSharedSecret>(keyMint);
Shawn Willden274bb552020-09-30 22:39:22 -060058 // Add Remotely Provisioned Component Service
59 addService<RemotelyProvisionedComponent>(keyMint);
Selene Huang31ab4042020-04-29 04:22:39 -070060 ABinderProcess_joinThreadPool();
61 return EXIT_FAILURE; // should not reach
62}