• 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 #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 /* Store it in the database. */
34 struct CertPropertyOri {
35     const struct CmContext *context;
36     struct CmBlob *uri;
37     struct CmBlob *alias;
38     struct CmBlob *subjectName;
39     uint32_t store;
40     enum CmAuthStorageLevel level;
41 };
42 
43 int32_t CertManagerInitialize(void);
44 
45 int32_t CertManagerFindCertFileNameByUri(
46     const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, struct CmMutableBlob *path);
47 
48 int32_t CmRemoveAppCert(const struct CmContext *context, const struct CmBlob *keyUri,
49     const uint32_t store);
50 
51 int32_t CmRemoveAllAppCert(const struct CmContext *context);
52 
53 int32_t CmServiceGetAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames,
54     const uint32_t fileSize, uint32_t *fileCount);
55 
56 int32_t CmServiceGetCallingAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames,
57     const uint32_t fileSize, uint32_t *fileCount);
58 
59 void CmFreeFileNames(struct CmBlob *fileNames, const uint32_t fileSize);
60 
61 int32_t CmGetUri(const char *filePath, struct CmBlob *uriBlob);
62 
63 int32_t CmCheckCertCount(const struct CmContext *context, const uint32_t store, const char *fileName);
64 
65 int32_t CmWriteUserCert(const struct CmContext *context, struct CmMutableBlob *pathBlob,
66     const struct CmBlob *userCert, const struct CmBlob *certAlias, struct CmBlob *certUri);
67 
68 int32_t CmStoreUserCert(const char *path, const struct CmBlob *userCert, const char *userCertName);
69 
70 int32_t CmGenerateSaConf(const char *userCertConfigPath, const char *userCertBakupDirPath, const char *userCertName);
71 
72 int32_t CmRemoveUserCert(struct CmMutableBlob *pathBlob, const struct CmBlob *certUri);
73 
74 int32_t CmRmUserCert(const char *usrCertConfigFilepath);
75 
76 int32_t CmRmSaConf(const char *usrCertConfigFilepath);
77 
78 int32_t CmRemoveAllUserCert(const struct CmContext *context, uint32_t store, const struct CmMutableBlob *pathList);
79 
80 /**
81  * @brief Delete the certificate backup file and configuration file
82  *
83  * If userCertConfigFilePath != NULL, the certificate is deleted based on userCertConfigFilePath. Otherwise, the
84  * certificate is deleted based on the path of the certificate configuration file created in context and certUri.
85  *
86  * @param context Context information
87  * @param certUri Certificate uri
88  * @param userCertConfigFilePath The certificate configuration file path
89  * @return int32_t result
90  * @retval 0 success
91  * @retval <0 failure
92  */
93 int32_t CmRemoveBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri,
94                                const char *userCertConfigFilePath);
95 
96 int32_t CmGetDisplayNameByURI(const struct CmBlob *uri, const char *object, struct CmBlob *displayName);
97 
98 int32_t RdbInsertCertProperty(const struct CertPropertyOri *propertyOri);
99 
100 int32_t GetObjNameFromCertData(const struct CmBlob *certData, const struct CmBlob *certAlias,
101     struct CmBlob *objectName);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif