blob: 8f4968db516744a0b64957257f3ee968daa6a286 [file] [log] [blame]
David Zeuthenab3e5652019-10-28 13:32:48 -04001/*
2 * Copyright (c) 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.security.identity"
18
19#include <filesystem>
20
21#include <unistd.h>
22
23#include <android-base/logging.h>
24#include <binder/IPCThreadState.h>
25#include <binder/IServiceManager.h>
26
27#include "CredentialStoreFactory.h"
28
29#include <cppbor.h>
30
31using ::std::string;
32
33using ::android::IPCThreadState;
34using ::android::IServiceManager;
35using ::android::sp;
36using ::android::String16;
37using ::android::base::InitLogging;
38using ::android::base::StderrLogger;
39
40using ::android::security::identity::CredentialStoreFactory;
41
42int main(int argc, char* argv[]) {
43 InitLogging(argv, StderrLogger);
44
45 CHECK(argc == 2) << "A directory must be specified";
46 string data_dir = string(argv[1]);
47 CHECK(chdir(data_dir.c_str()) != -1) << "chdir: " << data_dir << ": " << strerror(errno);
48
49 sp<IServiceManager> sm = ::android::defaultServiceManager();
50 sp<CredentialStoreFactory> factory = new CredentialStoreFactory(data_dir);
51
52 auto ret = sm->addService(String16("android.security.identity"), factory);
53 CHECK(ret == ::android::OK) << "Couldn't register binder service";
54 LOG(ERROR) << "Registered binder service";
55
David Zeuthenf635cf02020-05-08 10:58:09 -040056 // This is needed for binder callbacks from keystore on a ICredstoreTokenCallback binder.
57 android::ProcessState::self()->startThreadPool();
58
David Zeuthenab3e5652019-10-28 13:32:48 -040059 IPCThreadState::self()->joinThreadPool();
60
61 return 0;
62}