blob: 8092e348ad111a11d7437fa0aac12e601d87849a [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>
Max Bires261a0492021-04-19 18:55:56 -070024#include <AndroidRemotelyProvisionedComponentDevice.h>
Chirag Pathak8960aae2021-01-25 21:37:06 +000025#include <AndroidSecureClock.h>
26#include <AndroidSharedSecret.h>
Selene Huang31ab4042020-04-29 04:22:39 -070027#include <keymaster/soft_keymaster_logger.h>
28
Shawn Willden08a7e432020-12-11 13:05:27 +000029using aidl::android::hardware::security::keymint::AndroidKeyMintDevice;
Max Bires261a0492021-04-19 18:55:56 -070030using aidl::android::hardware::security::keymint::AndroidRemotelyProvisionedComponentDevice;
Shawn Willden08a7e432020-12-11 13:05:27 +000031using aidl::android::hardware::security::keymint::SecurityLevel;
Chirag Pathak8960aae2021-01-25 21:37:06 +000032using aidl::android::hardware::security::secureclock::AndroidSecureClock;
33using aidl::android::hardware::security::sharedsecret::AndroidSharedSecret;
34
35template <typename T, class... Args>
36std::shared_ptr<T> addService(Args&&... args) {
37 std::shared_ptr<T> ser = ndk::SharedRefBase::make<T>(std::forward<Args>(args)...);
38 auto instanceName = std::string(T::descriptor) + "/default";
39 LOG(INFO) << "adding keymint service instance: " << instanceName;
40 binder_status_t status =
41 AServiceManager_addService(ser->asBinder().get(), instanceName.c_str());
42 CHECK(status == STATUS_OK);
43 return ser;
44}
Selene Huang31ab4042020-04-29 04:22:39 -070045
46int main() {
47 // Zero threads seems like a useless pool, but below we'll join this thread to it, increasing
48 // the pool size to 1.
49 ABinderProcess_setThreadPoolMaxThreadCount(0);
Chirag Pathak8960aae2021-01-25 21:37:06 +000050 // Add Keymint Service
Shawn Willden08a7e432020-12-11 13:05:27 +000051 std::shared_ptr<AndroidKeyMintDevice> keyMint =
Chirag Pathak8960aae2021-01-25 21:37:06 +000052 addService<AndroidKeyMintDevice>(SecurityLevel::SOFTWARE);
53 // Add Secure Clock Service
54 addService<AndroidSecureClock>(keyMint);
55 // Add Shared Secret Service
56 addService<AndroidSharedSecret>(keyMint);
Shawn Willden274bb552020-09-30 22:39:22 -060057 // Add Remotely Provisioned Component Service
Max Bires261a0492021-04-19 18:55:56 -070058 addService<AndroidRemotelyProvisionedComponentDevice>(keyMint);
Selene Huang31ab4042020-04-29 04:22:39 -070059 ABinderProcess_joinThreadPool();
60 return EXIT_FAILURE; // should not reach
61}