• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 CERT_MANAGER_STORAGE_H
17 #define CERT_MANAGER_STORAGE_H
18 
19 #include "cm_type.h"
20 #include "openssl/ossl_typ.h"
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define CERT_DIR            "/data/service/el1/public/cert_manager_service/certificates"
26 #define CREDNTIAL_STORE     "/data/service/el1/public/cert_manager_service/certificates/credential/"
27 #define SYSTEM_CA_STORE     "/system/etc/security/certificates/"
28 #define SYSTEM_CA_STORE_GM  "/system/etc/security/certificates_gm/"
29 #define USER_CA_STORE       "/data/service/el1/public/cert_manager_service/certificates/user/"
30 #define PRI_CREDNTIAL_STORE "/data/service/el1/public/cert_manager_service/certificates/priv_credential/"
31 #define SYS_CREDNTIAL_STORE "/data/service/el1/public/cert_manager_service/certificates/sys_credential/"
32 
33 #define CERT_BACKUP_ROOT_DIR "/data/service/el1/public/cert_manager_service/certificates/user_open"
34 #define CERT_BACKUP_CONFIG_ROOT_DIR "/data/service/el1/public/cert_manager_service/certificates/user_config"
35 #define CERT_BACKUP_DIR_NAME "cacerts"
36 #define CERT_CONFIG_FILE_SUFFIX ".config"
37 #define CERT_BACKUP_FILENAME_FORMAT "%08lx.%d"
38 
39 #define SYSTEM_CA_PATH_COUNT_2 2 /* system root ca path: common alg + gm */
40 #define SYSTEM_CA_PATH_COUNT_1 1 /* system root ca path: common alg */
41 #define SYSTEM_CA_PATH_INDEX 0
42 #define SYSTEM_CA_GM_PATH_INDEX 1
43 
44 int32_t GetRootPath(uint32_t store, char *rootPath, uint32_t pathLen);
45 
46 int32_t ConstructUserIdPath(const struct CmContext *context, uint32_t store,
47     char *userIdPath, uint32_t pathLen);
48 
49 int32_t ConstructUidPath(const struct CmContext *context, uint32_t store,
50     char *uidPath, uint32_t pathLen);
51 
52 int32_t ConstructAuthListPath(const struct CmContext *context, uint32_t store,
53     char *authListPath, uint32_t pathLen);
54 
55 int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *storageBuf);
56 
57 int32_t CmStorageGetAppCert(const struct CmContext *context, uint32_t store,
58     const struct CmBlob *keyUri, struct CmBlob *certBlob);
59 
60 int32_t CmGetCertFilePath(const struct CmContext *context, uint32_t store, struct CmMutableBlob *pathBlob);
61 
62 /**
63  * @brief Construct the absolute path to the {confRootDir}/{userId} directory
64  *
65  * @param[in] userId User ID
66  * @param[out] confUserIdDir The buffer that holds the absolute path of the {confRootDir}/{userId} directory
67  * @param[in] dirLen Maximum length of the confUserIdDir buffer
68  * @return int32_t result
69  * @retval 0 success
70  * @retval <0 failure
71  */
72 int32_t CmGetCertConfUserIdDir(uint32_t userId, char *confUserIdDir, uint32_t dirLen);
73 
74 /**
75  * @brief Construct the absolute path to the {confRootDir}/{userId}/{uid} directory
76  *
77  * @param[in] userId User ID
78  * @param[in] uid User identifier
79  * @param[out] certConfUidDir The buffer that holds the absolute path of the {confRootDir}/{userId}/{uid} directory
80  * @param[in] dirLen Maximum length of the certConfUidDir buffer
81  * @return int32_t result
82  * @retval 0 success
83  * @retval <0 failure
84  */
85 int32_t CmGetCertConfUidDir(uint32_t userId, uint32_t uid, char *certConfUidDir, uint32_t dirLen);
86 
87 /**
88  * @brief Construct the absolute path of the configuration file corresponding to the CA certificate
89  *
90  * @param[in] userId User ID
91  * @param[in] uid User identifier
92  * @param[in] certUri User certificate URI
93  * @param[out] confFilePath The buffer that holds the absolute path of the certificate configuration file
94  * @param[in] confFilePathLen Maximum length of the confFilePath buffer
95  * @return int32_t result
96  * @retval 0 success
97  * @retval <0 failure
98  */
99 int32_t CmGetCertConfPath(uint32_t userId, uint32_t uid, const struct CmBlob *certUri, char *confFilePath,
100                           uint32_t confFilePathLen);
101 
102 /**
103  * @brief Construct the absolute path of the directory where the CA certificate backup file is stored
104  *
105  * @param[in] userId User ID
106  * @param[out] certBackupDir The buffer that holds the absolute path of the {backupRootDir}/{userId} directory
107  * @param[in] certBackupDirLen Maximum length of the certBackupDir buffer
108  * @return int32_t result
109  * @retval 0 success
110  * @retval <0 failure
111  */
112 int32_t CmGetCertBackupDir(uint32_t userId, char *certBackupDir, uint32_t certBackupDirLen);
113 
114 /**
115  * @brief Get the CA certificate backup file name
116  *
117  * @param[in] userCertX509 Certificate data
118  * @param[in] userId User ID
119  * @param[out] certBackupFileName Buffer that stores the backup file name of the user CA certificate
120  * @param[in] certBackupFileNameLen Maximum length of the certBackupFileName buffer
121  * @return int32_t result
122  * @retval 0 success
123  * @retval <0 failure
124  */
125 int32_t CmGetCertBackupFileName(const X509 *userCertX509, uint32_t userId, char *certBackupFileName,
126                                 uint32_t certBackupFileNameLen);
127 
128 /**
129  * @brief Construct the absolute path of the CA certificate backup file
130  *
131  * @param[in] userCertX509 Certificate data
132  * @param[in] userId User ID
133  * @param[out] backupFilePath Buffer that stores the absolute path of the certificate backup file
134  * @param[in] backupFilePathLen Maximum length of the backupFilePath buffer
135  * @return int32_t result
136  * @retval 0 success
137  * @retval <0 failure
138  */
139 int32_t CmGetCertBackupFilePath(const X509 *userCertX509, uint32_t userId, char *backupFilePath,
140                                 uint32_t backupFilePathLen);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /* CERT_MANAGER_STORAGE_H */
147 
148