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_RAW_FILE_H 17 #define INTERFACES_INNER_API_DLP_RAW_FILE_H 18 19 #include "dlp_file.h" 20 21 namespace OHOS { 22 namespace Security { 23 namespace DlpPermission { 24 25 class DlpRawFile : public DlpFile { 26 public: 27 DlpRawFile(int32_t dlpFd, const std::string &realType); 28 ~DlpRawFile(); 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 36 uint64_t GetFsContentSize() const; 37 void SetOfflineAccess(bool flag); 38 int32_t ParseRawDlpHeader(uint64_t fileLen, uint32_t dlpHeaderSize); 39 int32_t CheckDlpFile(); 40 int32_t HmacCheck(); 41 uint32_t GetOfflineCertSize(void); 42 int32_t DoWriteHeaderAndContactAccount(int32_t inPlainFileFd, uint64_t fileLen); 43 int32_t ProcessDlpFile(); 44 int32_t SetContactAccount(const std::string& contactAccount); 45 int32_t Truncate(uint64_t size); 46 int32_t setAlgType(int32_t inPlainFileFd, const std::string& realFileType); 47 int32_t DoDlpHIAECryptOperation(struct DlpBlob& message1, struct DlpBlob& message2, 48 uint64_t offset, bool isEncrypt); 49 int32_t DoDlpContentCryptyOperation(int32_t inFd, int32_t outFd, uint64_t inOffset, 50 uint64_t inFileLen, bool isEncrypt); 51 52 private: 53 bool IsValidDlpHeader(const struct DlpHeader& head) const; 54 int32_t UpdateDlpFileContentSize(); 55 int32_t GetRawDlpHmac(void); 56 int32_t DoWriteHmacAndCert(uint32_t hmacStrLen, std::string& hmacStr); 57 int32_t DoHmacAndCrypty(int32_t inPlainFileFd, off_t fileLen); 58 int32_t GenFileInRaw(int32_t inPlainFileFd); 59 int32_t RemoveDlpPermissionInRaw(int32_t outPlainFileFd); 60 int32_t DoDlpFileWrite(uint64_t offset, void* buf, uint32_t size); 61 int32_t WriteFirstBlockData(uint64_t offset, void* buf, uint32_t size); 62 63 struct DlpHeader head_; 64 }; 65 } // namespace DlpPermission 66 } // namespace Security 67 } // namespace OHOS 68 #endif /* INTERFACES_INNER_API_DLP_RAW_FILE_H */ 69