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 #include "cert_manager_api.h"
17
18 #include "cm_log.h"
19 #include "cm_mem.h"
20 #include "cm_ipc_client.h"
21 #include "cm_type.h"
22
CmGetAppCert(const struct CmBlob * keyUri,const uint32_t store,struct Credential * certificate)23 CM_API_EXPORT int32_t CmGetAppCert(const struct CmBlob *keyUri, const uint32_t store,
24 struct Credential *certificate)
25 {
26 CM_LOG_D("enter get app certificate");
27 if (keyUri == NULL || certificate == NULL || (store != CM_CREDENTIAL_STORE &&
28 store != CM_PRI_CREDENTIAL_STORE && store != CM_SYS_CREDENTIAL_STORE)) {
29 return CMR_ERROR_INVALID_ARGUMENT;
30 }
31
32 int32_t ret = CmClientGetAppCert(keyUri, store, certificate);
33 CM_LOG_D("leave get app certificate, result = %d", ret);
34 return ret;
35 }
36
CmInit(const struct CmBlob * authUri,const struct CmSignatureSpec * spec,struct CmBlob * handle)37 CM_API_EXPORT int32_t CmInit(const struct CmBlob *authUri, const struct CmSignatureSpec *spec, struct CmBlob *handle)
38 {
39 CM_LOG_D("enter cert manager init");
40 if ((authUri == NULL) || (spec == NULL) || (handle == NULL)) {
41 CM_LOG_E("invalid input arguments");
42 return CMR_ERROR_INVALID_ARGUMENT;
43 }
44
45 int32_t ret = CmClientInit(authUri, spec, handle);
46 CM_LOG_D("leave cert manager init, result = %d", ret);
47 return ret;
48 }
49
CmUpdate(const struct CmBlob * handle,const struct CmBlob * inData)50 CM_API_EXPORT int32_t CmUpdate(const struct CmBlob *handle, const struct CmBlob *inData)
51 {
52 CM_LOG_D("enter cert manager update");
53 if ((handle == NULL) || (inData == NULL)) {
54 CM_LOG_E("invalid input arguments");
55 return CMR_ERROR_INVALID_ARGUMENT;
56 }
57
58 int32_t ret = CmClientUpdate(handle, inData);
59 CM_LOG_D("leave cert manager update, result = %d", ret);
60 return ret;
61 }
62
CmFinish(const struct CmBlob * handle,const struct CmBlob * inData,struct CmBlob * outData)63 CM_API_EXPORT int32_t CmFinish(const struct CmBlob *handle, const struct CmBlob *inData, struct CmBlob *outData)
64 {
65 CM_LOG_D("enter cert manager finish");
66 if ((handle == NULL) || (inData == NULL) || (outData == NULL)) {
67 CM_LOG_E("invalid input arguments");
68 return CMR_ERROR_INVALID_ARGUMENT;
69 }
70
71 int32_t ret = CmClientFinish(handle, inData, outData);
72 CM_LOG_D("leave cert manager finish, result = %d", ret);
73 return ret;
74 }
75
CmAbort(const struct CmBlob * handle)76 CM_API_EXPORT int32_t CmAbort(const struct CmBlob *handle)
77 {
78 CM_LOG_D("enter cert manager abort");
79 if (handle == NULL) {
80 CM_LOG_E("invalid input arguments");
81 return CMR_ERROR_INVALID_ARGUMENT;
82 }
83
84 int32_t ret = CmClientAbort(handle);
85 CM_LOG_D("leave cert manager abort, result = %d", ret);
86 return ret;
87 }