1 *e1997b9aSAndroid Build Coastguard Worker /* 2 *e1997b9aSAndroid Build Coastguard Worker * Copyright (c) 2019, The Android Open Source Project 3 *e1997b9aSAndroid Build Coastguard Worker * 4 *e1997b9aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5 *e1997b9aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6 *e1997b9aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7 *e1997b9aSAndroid Build Coastguard Worker * 8 *e1997b9aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9 *e1997b9aSAndroid Build Coastguard Worker * 10 *e1997b9aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11 *e1997b9aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12 *e1997b9aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 *e1997b9aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14 *e1997b9aSAndroid Build Coastguard Worker * limitations under the License. 15 *e1997b9aSAndroid Build Coastguard Worker */ 16 *e1997b9aSAndroid Build Coastguard Worker 17 *e1997b9aSAndroid Build Coastguard Worker #define LOG_TAG "credstore" 18 *e1997b9aSAndroid Build Coastguard Worker 19 *e1997b9aSAndroid Build Coastguard Worker #include <filesystem> 20 *e1997b9aSAndroid Build Coastguard Worker 21 *e1997b9aSAndroid Build Coastguard Worker #include <unistd.h> 22 *e1997b9aSAndroid Build Coastguard Worker 23 *e1997b9aSAndroid Build Coastguard Worker #include <android-base/logging.h> 24 *e1997b9aSAndroid Build Coastguard Worker #include <binder/IPCThreadState.h> 25 *e1997b9aSAndroid Build Coastguard Worker #include <binder/IServiceManager.h> 26 *e1997b9aSAndroid Build Coastguard Worker #include <binder/ProcessState.h> 27 *e1997b9aSAndroid Build Coastguard Worker 28 *e1997b9aSAndroid Build Coastguard Worker #include "CredentialStoreFactory.h" 29 *e1997b9aSAndroid Build Coastguard Worker 30 *e1997b9aSAndroid Build Coastguard Worker #include <cppbor.h> 31 *e1997b9aSAndroid Build Coastguard Worker 32 *e1997b9aSAndroid Build Coastguard Worker using ::std::string; 33 *e1997b9aSAndroid Build Coastguard Worker 34 *e1997b9aSAndroid Build Coastguard Worker using ::android::IPCThreadState; 35 *e1997b9aSAndroid Build Coastguard Worker using ::android::IServiceManager; 36 *e1997b9aSAndroid Build Coastguard Worker using ::android::ProcessState; 37 *e1997b9aSAndroid Build Coastguard Worker using ::android::sp; 38 *e1997b9aSAndroid Build Coastguard Worker using ::android::String16; 39 *e1997b9aSAndroid Build Coastguard Worker using ::android::base::InitLogging; 40 *e1997b9aSAndroid Build Coastguard Worker using ::android::base::StderrLogger; 41 *e1997b9aSAndroid Build Coastguard Worker 42 *e1997b9aSAndroid Build Coastguard Worker using ::android::security::identity::CredentialStoreFactory; 43 *e1997b9aSAndroid Build Coastguard Worker main(int argc,char * argv[])44 *e1997b9aSAndroid Build Coastguard Workerint main(int argc, char* argv[]) { 45 *e1997b9aSAndroid Build Coastguard Worker InitLogging(argv); 46 *e1997b9aSAndroid Build Coastguard Worker 47 *e1997b9aSAndroid Build Coastguard Worker CHECK(argc == 2) << "A directory must be specified"; 48 *e1997b9aSAndroid Build Coastguard Worker string data_dir = string(argv[1]); 49 *e1997b9aSAndroid Build Coastguard Worker CHECK(chdir(data_dir.c_str()) != -1) << "chdir: " << data_dir << ": " << strerror(errno); 50 *e1997b9aSAndroid Build Coastguard Worker 51 *e1997b9aSAndroid Build Coastguard Worker sp<IServiceManager> sm = ::android::defaultServiceManager(); 52 *e1997b9aSAndroid Build Coastguard Worker sp<CredentialStoreFactory> factory = new CredentialStoreFactory(data_dir); 53 *e1997b9aSAndroid Build Coastguard Worker 54 *e1997b9aSAndroid Build Coastguard Worker auto ret = sm->addService(String16("android.security.identity"), factory); 55 *e1997b9aSAndroid Build Coastguard Worker CHECK(ret == ::android::OK) << "Couldn't register binder service"; 56 *e1997b9aSAndroid Build Coastguard Worker LOG(INFO) << "Registered binder service"; 57 *e1997b9aSAndroid Build Coastguard Worker 58 *e1997b9aSAndroid Build Coastguard Worker // Credstore needs one thread to handle binder messages and one to handle 59 *e1997b9aSAndroid Build Coastguard Worker // asynchronous responses from RKPD. 60 *e1997b9aSAndroid Build Coastguard Worker ProcessState::self()->setThreadPoolMaxThreadCount(2); 61 *e1997b9aSAndroid Build Coastguard Worker ProcessState::self()->startThreadPool(); 62 *e1997b9aSAndroid Build Coastguard Worker IPCThreadState::self()->joinThreadPool(); 63 *e1997b9aSAndroid Build Coastguard Worker 64 *e1997b9aSAndroid Build Coastguard Worker return 0; 65 *e1997b9aSAndroid Build Coastguard Worker } 66