1 /* 2 * Copyright (c) 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 CODE_SIGN_LOCAL_KEY_HELPER_H 17 #define CODE_SIGN_LOCAL_KEY_HELPER_H 18 19 #include <fstream> 20 #include <iostream> 21 #include <string> 22 23 #include "errcode.h" 24 #include "log.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace CodeSign { 29 30 const std::string PROC_KEYS_FILE = "/proc/keys"; 31 const std::string LOCAL_KEY_NAME = "local_key"; 32 GetEnforceFileResult()33int GetEnforceFileResult() 34 { 35 std::ifstream in(PROC_KEYS_FILE); 36 std::string line; 37 while (in >> line) { 38 if (line.find(LOCAL_KEY_NAME) != line.npos) { 39 return CS_SUCCESS; 40 } 41 } 42 LOG_WARN("local key not found"); 43 return CS_ERR_ENABLE; 44 } 45 } 46 } 47 } 48 #endif