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 "dslm_ohos_init.h"
17
18 #include <string.h>
19
20 #include "utils_log.h"
21 #include "dslm_credential_utils.h"
22 #include "dslm_ohos_request.h"
23 #include "device_security_defines.h"
24
25 #define DSLM_CRED_STR_LEN_MAX 4096
26
InitOhosDslmCred(DslmCredInfo * credInfo)27 int32_t InitOhosDslmCred(DslmCredInfo *credInfo)
28 {
29 SECURITY_LOG_INFO("start");
30 char credStr[DSLM_CRED_STR_LEN_MAX] = {0};
31 int32_t ret = GetCredFromCurrentDevice(credStr, DSLM_CRED_STR_LEN_MAX);
32 if (ret != SUCCESS) {
33 SECURITY_LOG_ERROR("read cred data from file failed");
34 return ret;
35 }
36
37 ret = VerifyDslmCredential(credStr, credInfo, NULL);
38 if (ret != SUCCESS) {
39 SECURITY_LOG_ERROR("verifyCredData failed!");
40 return ret;
41 }
42 credInfo->credType = CRED_TYPE_STANDARD;
43
44 SECURITY_LOG_INFO("success, self security level is %{public}d", credInfo->credLevel);
45 return SUCCESS;
46 }