blob: b3a41ecad44430eb335bb2db9dd3da6c654dce6b [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
David Zeuthen62d43bf2021-03-31 10:41:27 -040017#define LOG_TAG "credstore"
David Zeuthenab3e5652019-10-28 13:32:48 -040018
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>
Tri Vo71e8cc12023-01-17 15:37:50 -080026#include <binder/ProcessState.h>
David Zeuthenab3e5652019-10-28 13:32:48 -040027
28#include "CredentialStoreFactory.h"
29
30#include <cppbor.h>
31
32using ::std::string;
33
34using ::android::IPCThreadState;
35using ::android::IServiceManager;
Tri Vo71e8cc12023-01-17 15:37:50 -080036using ::android::ProcessState;
David Zeuthenab3e5652019-10-28 13:32:48 -040037using ::android::sp;
38using ::android::String16;
39using ::android::base::InitLogging;
40using ::android::base::StderrLogger;
41
42using ::android::security::identity::CredentialStoreFactory;
43
44int main(int argc, char* argv[]) {
Hasini Gunasinghe1b531b92021-03-02 00:34:58 +000045 InitLogging(argv);
David Zeuthenab3e5652019-10-28 13:32:48 -040046
47 CHECK(argc == 2) << "A directory must be specified";
48 string data_dir = string(argv[1]);
49 CHECK(chdir(data_dir.c_str()) != -1) << "chdir: " << data_dir << ": " << strerror(errno);
50
51 sp<IServiceManager> sm = ::android::defaultServiceManager();
52 sp<CredentialStoreFactory> factory = new CredentialStoreFactory(data_dir);
53
54 auto ret = sm->addService(String16("android.security.identity"), factory);
55 CHECK(ret == ::android::OK) << "Couldn't register binder service";
David Zeuthen62d43bf2021-03-31 10:41:27 -040056 LOG(INFO) << "Registered binder service";
David Zeuthenab3e5652019-10-28 13:32:48 -040057
Tri Vo71e8cc12023-01-17 15:37:50 -080058 // Credstore needs one thread to handle binder messages and one to handle
59 // asynchronous responses from RKPD.
60 ProcessState::self()->setThreadPoolMaxThreadCount(2);
61 ProcessState::self()->startThreadPool();
Hasini Gunasinghe4b462a52021-03-22 13:33:23 +000062 IPCThreadState::self()->joinThreadPool();
63
David Zeuthenab3e5652019-10-28 13:32:48 -040064 return 0;
65}