1 /* 2 * Copyright (c) 2021-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 HKS_STORAGE_H 17 #define HKS_STORAGE_H 18 19 #include "hks_storage_utils.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #ifndef _CUT_AUTHENTICATE_ 26 #ifdef _STORAGE_LITE_ 27 int32_t HksStoreKeyBlob(const struct HksStoreFileInfo *fileInfo, const struct HksBlob *keyAlias, 28 uint32_t storageType, const struct HksBlob *keyBlob); 29 30 int32_t HksStoreDeleteKeyBlob(const struct HksStoreFileInfo *fileInfo, 31 const struct HksBlob *keyAlias, uint32_t storageType); 32 33 int32_t HksStoreIsKeyBlobExist(const struct HksStoreFileInfo *fileInfo, 34 const struct HksBlob *keyAlias, uint32_t storageType); 35 36 int32_t HksStoreGetKeyBlob(const struct HksStoreInfo *fileInfoPath, 37 const struct HksBlob *keyAlias, uint32_t storageType, struct HksBlob *keyBlob); 38 39 int32_t HksStoreGetKeyBlobSize(const struct HksBlob *processName, 40 const struct HksBlob *keyAlias, uint32_t storageType, uint32_t *keyBlobSize); 41 42 int32_t HksGetKeyCountByProcessName(const struct HksBlob *processName, uint32_t *fileCount); 43 #else // _STORAGE_LITE_ 44 45 int32_t HksStoreKeyBlob(const struct HksStoreFileInfo *fileInfo, const struct HksBlob *keyBlob); 46 47 int32_t HksStoreDeleteKeyBlob(const struct HksStoreFileInfo *fileInfo); 48 49 int32_t HksStoreIsKeyBlobExist(const struct HksStoreFileInfo *fileInfo); 50 51 int32_t HksStoreGetKeyBlob(const struct HksStoreInfo *fileInfoPath, struct HksBlob *keyBlob); 52 53 int32_t HksStoreGetKeyBlobSize(const struct HksStoreInfo *fileInfoPath, uint32_t *keyBlobSize); 54 55 int32_t HksGetKeyCountByProcessName(const struct HksStoreFileInfo *fileInfo, uint32_t *fileCount); 56 57 int32_t HksStorageWriteFile( 58 const char *path, const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len); 59 60 #endif // _STORAGE_LITE_ 61 #endif // _CUT_AUTHENTICATE_ 62 63 int32_t HksGetKeyAliasByProcessName(const struct HksStoreFileInfo *fileInfo, struct HksKeyInfo *keyInfoList, 64 uint32_t *listCount); 65 66 int32_t HksStoreDestroy(const struct HksBlob *processName); 67 68 void HksServiceDeleteUserIDKeyAliasFile(const struct HksBlob *userId); 69 70 void HksServiceDeleteUIDKeyAliasFile(const struct HksProcessInfo *processInfo); 71 72 int32_t HksListAliasesByProcessName(const struct HksStoreFileInfo *fileInfo, struct HksKeyAliasSet **outData); 73 74 int32_t HksStorageCopyKeyBlobFile(const char *srcPath, const char *srcFileName, 75 const char *destPath, const char *destFileName); 76 77 int32_t HksStoreRenameKeyAlias(const struct HksStoreFileInfo *oldFileInfo, 78 const struct HksStoreFileInfo *newFileInfo, bool isCopy); 79 80 #ifdef HKS_ENABLE_SMALL_TO_SERVICE 81 int32_t HksIsOldKeyPathCleared(uint32_t *keyCount); 82 #endif 83 84 #ifdef _STORAGE_LITE_ 85 86 #define HKS_KEY_STORE_FILE_NAME "hks_keystore" 87 88 int32_t HksLoadFileToBuffer(void); 89 90 int32_t HksFileBufferRefresh(void); 91 92 int32_t HksStoreGetToatalSize(uint32_t *size); 93 94 int32_t HksStoreGetKeyInfoList(struct HksKeyInfo *keyInfoList, uint32_t *listCount); 95 96 #endif /* _STORAGE_LITE_ */ 97 98 #ifdef __cplusplus 99 } 100 #endif 101 102 #endif /* HKS_STORAGE_H */