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