1 /* 2 * Copyright (c) 2023-2024 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_SERVICE_H 17 #define OHOS_LOCAL_CODE_SIGN_SERVICE_H 18 19 #include "event_handler.h" 20 #include "event_runner.h" 21 #include "local_code_sign_stub.h" 22 #include "singleton.h" 23 #include "system_ability.h" 24 25 namespace OHOS { 26 namespace Security { 27 namespace CodeSign { 28 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 29 class LocalCodeSignService : public SystemAbility, public LocalCodeSignStub { 30 DECLARE_DELAYED_SINGLETON(LocalCodeSignService); 31 DECLARE_SYSTEM_ABILITY(LocalCodeSignService); 32 public: 33 void OnStart() override; 34 void OnStop() override; 35 36 int32_t InitLocalCertificate(const ByteBuffer &challenge, ByteBuffer &cert) override; 37 int32_t SignLocalCode(const std::string &ownerID, const std::string &filePath, ByteBuffer &signature) override; 38 void DelayUnloadTask() override; 39 private: 40 bool Init(); 41 std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_; 42 ServiceRunningState state_; 43 }; 44 } 45 } 46 } 47 #endif 48