blob: 25597898a5b26db93b0027ff9a16cd7db11bf46a [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>
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[]) {
Hasini Gunasinghe1b531b92021-03-02 00:34:58 +000043 InitLogging(argv);
David Zeuthenab3e5652019-10-28 13:32:48 -040044
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";
David Zeuthen62d43bf2021-03-31 10:41:27 -040054 LOG(INFO) << "Registered binder service";
David Zeuthenab3e5652019-10-28 13:32:48 -040055
Hasini Gunasinghe4b462a52021-03-22 13:33:23 +000056 // Credstore is a single-threaded process. So devote the main thread
57 // to handling binder messages.
58 IPCThreadState::self()->joinThreadPool();
59
David Zeuthenab3e5652019-10-28 13:32:48 -040060 return 0;
61}