David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 1 | /* |
| 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 Zeuthen | 62d43bf | 2021-03-31 10:41:27 -0400 | [diff] [blame] | 17 | #define LOG_TAG "credstore" |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 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 | |
| 31 | using ::std::string; |
| 32 | |
| 33 | using ::android::IPCThreadState; |
| 34 | using ::android::IServiceManager; |
| 35 | using ::android::sp; |
| 36 | using ::android::String16; |
| 37 | using ::android::base::InitLogging; |
| 38 | using ::android::base::StderrLogger; |
| 39 | |
| 40 | using ::android::security::identity::CredentialStoreFactory; |
| 41 | |
| 42 | int main(int argc, char* argv[]) { |
Hasini Gunasinghe | 1b531b9 | 2021-03-02 00:34:58 +0000 | [diff] [blame] | 43 | InitLogging(argv); |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 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"; |
David Zeuthen | 62d43bf | 2021-03-31 10:41:27 -0400 | [diff] [blame] | 54 | LOG(INFO) << "Registered binder service"; |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 55 | |
Hasini Gunasinghe | 4b462a5 | 2021-03-22 13:33:23 +0000 | [diff] [blame] | 56 | // Credstore is a single-threaded process. So devote the main thread |
| 57 | // to handling binder messages. |
| 58 | IPCThreadState::self()->joinThreadPool(); |
| 59 | |
David Zeuthen | ab3e565 | 2019-10-28 13:32:48 -0400 | [diff] [blame] | 60 | return 0; |
| 61 | } |