blob: d2b75a1cd093e1cc6e6248bc790f1b91ffa52363 [file] [log] [blame]
Andrew Scull9ba26572021-05-27 19:20:46 +00001/*
2 * Copyright 2021, 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
17#define LOG_TAG "android.hardware.security.keymint-service"
18
19#include <AndroidKeyMintDevice.h>
20#include <android-base/logging.h>
21#include <android/binder_manager.h>
22#include <android/binder_process.h>
23#include <keymaster/soft_keymaster_logger.h>
24
25using aidl::android::hardware::security::keymint::AndroidKeyMintDevice;
26using aidl::android::hardware::security::keymint::SecurityLevel;
27
28template <typename T, class... Args>
29std::shared_ptr<T> addService(Args&&... args) {
30 std::shared_ptr<T> ser = ndk::SharedRefBase::make<T>(std::forward<Args>(args)...);
31 auto instanceName = std::string(T::descriptor) + "/default";
32 LOG(INFO) << "adding keymint service instance: " << instanceName;
33 binder_status_t status =
34 AServiceManager_addService(ser->asBinder().get(), instanceName.c_str());
35 CHECK(status == STATUS_OK);
36 return ser;
37}
38
39int main() {
40 // Zero threads seems like a useless pool, but below we'll join this thread to it, increasing
41 // the pool size to 1.
42 ABinderProcess_setThreadPoolMaxThreadCount(0);
43 // Add Keymint Service
44 std::shared_ptr<AndroidKeyMintDevice> keyMint =
45 addService<AndroidKeyMintDevice>(SecurityLevel::SOFTWARE);
46
47 // VMs cannot implement the Secure Clock Service
48 // addService<AndroidSecureClock>(keyMint);
49
50 // VMs don't need to implement the Shared Secret Service as the host
51 // facilities the establishment of the shared secret.
52 // addService<AndroidSharedSecret>(keyMint);
53
54 // VMs don't implement the Remotely Provisioned Component Service as the
55 // host facilities provisioning.
56 // addService<AndroidRemotelyProvisionedComponentDevice>(keyMint);
57
58 ABinderProcess_joinThreadPool();
59 return EXIT_FAILURE; // should not reach
60}