blob: ed3c4cbccea82996c8f236b3817f65cb4482199e [file] [log] [blame]
David Zeuthen81603152020-02-11 22:04:24 -05001/*
2 * Copyright 2019, 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.identity-service"
18
Seth Moore1bf823c2022-01-25 23:04:37 +000019#include <aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.h>
David Zeuthen81603152020-02-11 22:04:24 -050020#include <android-base/logging.h>
21#include <android/binder_manager.h>
22#include <android/binder_process.h>
23
24#include "IdentityCredentialStore.h"
25
David Zeuthen630de2a2020-05-11 14:04:54 -040026#include "FakeSecureHardwareProxy.h"
27
28using ::android::sp;
David Zeuthena8ed82c2020-05-08 10:03:28 -040029using ::android::base::InitLogging;
Seth Moore3fc3c4c2022-01-25 23:04:37 +000030using ::android::base::LogdLogger;
31using ::android::base::LogId;
32using ::android::base::LogSeverity;
David Zeuthena8ed82c2020-05-08 10:03:28 -040033using ::android::base::StderrLogger;
34
David Zeuthen630de2a2020-05-11 14:04:54 -040035using ::aidl::android::hardware::identity::IdentityCredentialStore;
Seth Moore1bf823c2022-01-25 23:04:37 +000036using ::aidl::android::hardware::security::keymint::IRemotelyProvisionedComponent;
David Zeuthen630de2a2020-05-11 14:04:54 -040037using ::android::hardware::identity::FakeSecureHardwareProxyFactory;
38using ::android::hardware::identity::SecureHardwareProxyFactory;
David Zeuthen81603152020-02-11 22:04:24 -050039
Seth Moore3fc3c4c2022-01-25 23:04:37 +000040void ComboLogger(LogId id, LogSeverity severity, const char* tag, const char* file,
41 unsigned int line, const char* message) {
42 StderrLogger(id, severity, tag, file, line, message);
43
44 static LogdLogger logdLogger;
45 logdLogger(id, severity, tag, file, line, message);
46}
47
David Zeuthena8ed82c2020-05-08 10:03:28 -040048int main(int /*argc*/, char* argv[]) {
Seth Moore3fc3c4c2022-01-25 23:04:37 +000049 InitLogging(argv, ComboLogger);
David Zeuthena8ed82c2020-05-08 10:03:28 -040050
David Zeuthen630de2a2020-05-11 14:04:54 -040051 sp<SecureHardwareProxyFactory> hwProxyFactory = new FakeSecureHardwareProxyFactory();
Seth Moore1bf823c2022-01-25 23:04:37 +000052 const std::string remotelyProvisionedComponentName =
53 std::string(IRemotelyProvisionedComponent::descriptor) + "/default";
David Zeuthen630de2a2020-05-11 14:04:54 -040054
David Zeuthen81603152020-02-11 22:04:24 -050055 ABinderProcess_setThreadPoolMaxThreadCount(0);
56 std::shared_ptr<IdentityCredentialStore> store =
Seth Moore1bf823c2022-01-25 23:04:37 +000057 ndk::SharedRefBase::make<IdentityCredentialStore>(hwProxyFactory,
58 remotelyProvisionedComponentName);
David Zeuthen81603152020-02-11 22:04:24 -050059
60 const std::string instance = std::string() + IdentityCredentialStore::descriptor + "/default";
David Zeuthen81603152020-02-11 22:04:24 -050061 binder_status_t status = AServiceManager_addService(store->asBinder().get(), instance.c_str());
Steven Morelandffb03992021-12-14 01:45:47 +000062 CHECK_EQ(status, STATUS_OK);
David Zeuthen81603152020-02-11 22:04:24 -050063
64 ABinderProcess_joinThreadPool();
65 return EXIT_FAILURE; // should not reach
66}