1 /*
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
19 #include <aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.h>
20 #include <android-base/logging.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_process.h>
23
24 #include "IdentityCredentialStore.h"
25
26 #include "FakeSecureHardwareProxy.h"
27
28 using ::android::sp;
29 using ::android::base::InitLogging;
30 using ::android::base::LogdLogger;
31 using ::android::base::LogId;
32 using ::android::base::LogSeverity;
33 using ::android::base::StderrLogger;
34
35 using ::aidl::android::hardware::identity::IdentityCredentialStore;
36 using ::aidl::android::hardware::security::keymint::IRemotelyProvisionedComponent;
37 using ::android::hardware::identity::FakeSecureHardwareProxyFactory;
38 using ::android::hardware::identity::SecureHardwareProxyFactory;
39
ComboLogger(LogId id,LogSeverity severity,const char * tag,const char * file,unsigned int line,const char * message)40 void 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
main(int,char * argv[])48 int main(int /*argc*/, char* argv[]) {
49 InitLogging(argv, ComboLogger);
50
51 sp<SecureHardwareProxyFactory> hwProxyFactory = new FakeSecureHardwareProxyFactory();
52 const std::string remotelyProvisionedComponentName =
53 std::string(IRemotelyProvisionedComponent::descriptor) + "/default";
54
55 ABinderProcess_setThreadPoolMaxThreadCount(0);
56 std::shared_ptr<IdentityCredentialStore> store =
57 ndk::SharedRefBase::make<IdentityCredentialStore>(hwProxyFactory,
58 remotelyProvisionedComponentName);
59
60 const std::string instance = std::string() + IdentityCredentialStore::descriptor + "/default";
61 binder_status_t status = AServiceManager_addService(store->asBinder().get(), instance.c_str());
62 CHECK_EQ(status, STATUS_OK);
63
64 ABinderProcess_joinThreadPool();
65 return EXIT_FAILURE; // should not reach
66 }
67