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