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 17 #define LOG_TAG "credstore" 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 main(int argc,char * argv[])42int main(int argc, char* argv[]) { 43 InitLogging(argv); 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(INFO) << "Registered binder service"; 55 56 // Credstore is a single-threaded process. So devote the main thread 57 // to handling binder messages. 58 IPCThreadState::self()->joinThreadPool(); 59 60 return 0; 61 } 62