1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_LOCAL_CODE_SIGN_CLIENT_H 17 #define OHOS_LOCAL_CODE_SIGN_CLIENT_H 18 19 #include <condition_variable> 20 #include <cstdint> 21 #include <cstring> 22 #include <iostream> 23 #include <mutex> 24 #include <unistd.h> 25 26 #include "byte_buffer.h" 27 #include "errcode.h" 28 #include "local_code_sign_interface.h" 29 #include "iremote_object.h" 30 #include "iservice_registry.h" 31 #include "refbase.h" 32 33 namespace OHOS { 34 namespace Security { 35 namespace CodeSign { 36 class LocalCodeSignClient { 37 public: 38 static LocalCodeSignClient &GetInstance(); 39 int32_t InitLocalCertificate(ByteBuffer &cert); 40 int32_t SignLocalCode(const std::string &ownerID, const std::string &path, ByteBuffer &signature); 41 void OnRemoteLocalCodeSignSvrDied(const wptr<IRemoteObject> &remote); 42 void FinishStartSA(const sptr<IRemoteObject> &remoteObject); 43 void FailStartSA(); 44 45 private: 46 class LocalCodeSignSvrRecipient : public IRemoteObject::DeathRecipient { 47 public: 48 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 49 }; 50 51 LocalCodeSignClient(); 52 ~LocalCodeSignClient(); 53 54 LocalCodeSignClient(const LocalCodeSignClient &source) = delete; 55 LocalCodeSignClient &operator = (const LocalCodeSignClient &source) = delete; 56 57 int32_t StartSA(); 58 void CheckLocalCodeSignProxy(); 59 60 std::mutex proxyMutex_; 61 std::condition_variable proxyConVar_; 62 sptr<LocalCodeSignInterface> localCodeSignProxy_ = nullptr; 63 sptr<LocalCodeSignSvrRecipient> localCodeSignSvrRecipient_ = nullptr; 64 }; 65 66 #ifdef __cplusplus 67 extern "C" { 68 #endif 69 __attribute__((visibility("default"))) LocalCodeSignClient *GetLocalCodeSignClient(); 70 #ifdef __cplusplus 71 } 72 #endif 73 } 74 } 75 } 76 #endif