1 /* 2 * Copyright (c) 2025 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 INTERFACES_INNER_API_DLP_ZIP_FILE_H 17 #define INTERFACES_INNER_API_DLP_ZIP_FILE_H 18 19 #include "dlp_file.h" 20 21 namespace OHOS { 22 namespace Security { 23 namespace DlpPermission { 24 25 class DlpZipFile : public DlpFile { 26 public: 27 DlpZipFile(int32_t dlpFd, const std::string &workDir, int64_t index, const std::string &realType); 28 ~DlpZipFile(); 29 int32_t UpdateCertAndText(const std::vector<uint8_t>& cert, struct DlpBlob certBlob); 30 int32_t SetEncryptCert(const struct DlpBlob& cert); 31 int32_t GenFile(int32_t inPlainFileFd); 32 int32_t RemoveDlpPermission(int outPlainFileFd); 33 int32_t DlpFileRead(uint64_t offset, void* buf, uint32_t size, bool& hasRead, int32_t uid); 34 int32_t DlpFileWrite(uint64_t offset, void* buf, uint32_t size); 35 uint64_t GetFsContentSize() const; 36 int32_t CheckDlpFile(); 37 void SetOfflineAccess(bool flag); 38 bool CleanTmpFile(); 39 int32_t HmacCheck(); 40 uint32_t GetOfflineCertSize(void); 41 int32_t ProcessDlpFile(); 42 int32_t SetContactAccount(const std::string& contactAccount); 43 int32_t Truncate(uint64_t size); 44 int32_t DoDlpContentCryptyOperation(int32_t inFd, int32_t outFd, uint64_t inOffset, 45 uint64_t inFileLen, bool isEncrypt); 46 private: 47 int32_t DoDlpContentCopyOperation(int32_t inFd, int32_t outFd, uint64_t inOffset, uint64_t inFileLen); 48 int32_t UpdateDlpFileContentSize(); 49 bool ParseDlpInfo(); 50 bool ParseCert(); 51 bool ParseEncData(); 52 int32_t GenEncData(int32_t inPlainFileFd); 53 int32_t GenFileInZip(int32_t inPlainFileFd); 54 int32_t RemoveDlpPermissionInZip(int32_t outPlainFileFd); 55 int32_t GetHmacVal(int32_t encFile, std::string& hmacStr); 56 int32_t GenerateHmacVal(int32_t encFile, struct DlpBlob& out); 57 int32_t AddGeneralInfoToBuff(int32_t encFile); 58 int32_t DoDlpFileWrite(uint64_t offset, void* buf, uint32_t size); 59 int32_t WriteFirstBlockData(uint64_t offset, void* buf, uint32_t size); 60 std::string workDir_ = ""; 61 std::string dirIndex_; 62 uint32_t certSize_; 63 std::vector<std::string> extraInfo_; 64 }; 65 } // namespace DlpPermission 66 } // namespace Security 67 } // namespace OHOS 68 #endif /* INTERFACES_INNER_API_DLP_ZIP_FILE_H */ 69