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 #ifndef CERT_MANAGER_H
16 #define CERT_MANAGER_H
17 
18 #include "cm_type.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define CM_ERROR(rc)  (int32_t) (rc)
25 
26 #define CERT_DIR            "/data/service/el1/public/cert_manager_service/certificates"
27 #define CREDNTIAL_STORE     "/data/service/el1/public/cert_manager_service/certificates/credential/"
28 #define SYSTEM_CA_STORE     "/system/etc/security/certificates/"
29 #define USER_CA_STORE       "/data/service/el1/public/cert_manager_service/certificates/user/"
30 #define APP_CA_STORE        "/data/service/el1/public/cert_manager_service/certificates/priv_credential/"
31 #define CREDENTIAL_STORE    "./certificates/credential/"
32 
33 int32_t CertManagerInitialize(void);
34 
35 int32_t CertManagerFindCertFileNameByUri(
36     const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, struct CmMutableBlob *path);
37 
38 int32_t CmRemoveAppCert(const struct CmContext *context, const struct CmBlob *keyUri,
39     const uint32_t store);
40 
41 int32_t CmRemoveAllAppCert(const struct CmContext *context);
42 
43 int32_t CmServiceGetAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames,
44     const uint32_t fileSize, uint32_t *fileCount);
45 
46 int32_t CmServiceGetCallingAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames,
47     const uint32_t fileSize, uint32_t *fileCount);
48 
49 void CmFreeFileNames(struct CmBlob *fileNames, const uint32_t fileSize);
50 
51 int32_t CmGetUri(const char *filePath, struct CmBlob *uriBlob);
52 
53 int32_t CmCheckCertCount(const struct CmContext *context, const uint32_t store, const char *fileName);
54 
55 int32_t CmWriteUserCert(const struct CmContext *context, struct CmMutableBlob *pathBlob,
56     const struct CmBlob *userCert, const struct CmBlob *certAlias, struct CmBlob *certUri);
57 
58 int32_t CmStoreUserCert(const char *path, const struct CmBlob *userCert, const char *userCertName);
59 
60 int32_t CmGenerateSaConf(const char *userCertConfigPath, const char *userCertBakupDirPath, const char *userCertName);
61 
62 int32_t CmRemoveUserCert(struct CmMutableBlob *pathBlob, const struct CmBlob *certUri);
63 
64 int32_t CmRmUserCert(const char *usrCertConfigFilepath);
65 
66 int32_t CmRmSaConf(const char *usrCertConfigFilepath);
67 
68 int32_t CmRemoveAllUserCert(const struct CmContext *context, uint32_t store, const struct CmMutableBlob *pathList);
69 
70 /**
71  * @brief Delete the certificate backup file and configuration file
72  *
73  * If userCertConfigFilePath != NULL, the certificate is deleted based on userCertConfigFilePath. Otherwise, the
74  * certificate is deleted based on the path of the certificate configuration file created in context and certUri.
75  *
76  * @param context Context information
77  * @param certUri Certificate uri
78  * @param userCertConfigFilePath The certificate configuration file path
79  * @return int32_t result
80  * @retval 0 success
81  * @retval <0 failure
82  */
83 int32_t CmRemoveBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri,
84                                const char *userCertConfigFilePath);
85 
86 int32_t CmGetDisplayNameByURI(const struct CmBlob *uri, const char *object, struct CmBlob *displayName);
87 
88 int32_t RdbInsertCertProperty(const struct CmContext *context, const struct CmBlob *uri,
89     const struct CmBlob *alias, const struct CmBlob *subjectName, uint32_t store);
90 
91 int32_t GetObjNameFromCertData(const struct CmBlob *certData, const struct CmBlob *certAlias,
92     struct CmBlob *objectName);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif