• 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 
16 #include "hks_api.h"
17 #include "hks_param.h"
18 
19 #include "native_huks_api_adapter.h"
20 #include "native_huks_param.h"
21 
HuksAttestAdapter(const struct OH_Huks_Blob * keyAlias,const struct OH_Huks_ParamSet * paramSet,struct OH_Huks_CertChain * certChain)22 int32_t HuksAttestAdapter(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet,
23     struct OH_Huks_CertChain *certChain)
24 {
25     int32_t ret;
26     struct HksParamSet *newParamSet = NULL;
27     do {
28         if (paramSet == NULL) {
29             ret = HKS_ERROR_NULL_POINTER;
30             break;
31         }
32         ret = HksCheckParamSet((struct HksParamSet *)paramSet, paramSet->paramSetSize);
33         if (ret != HKS_SUCCESS) {
34             break;
35         }
36         ret = HksInitParamSet(&newParamSet);
37         if (ret != HKS_SUCCESS) {
38             break;
39         }
40         ret = HksFreshParamSet((struct HksParamSet *)paramSet, false);
41         if (ret != HKS_SUCCESS) {
42             break;
43         }
44         ret = HksAddParams(newParamSet, (const struct HksParam *)paramSet->params, paramSet->paramsCnt);
45         if (ret != HKS_SUCCESS) {
46             break;
47         }
48         struct HksParam isBase64Param = { .tag = HKS_TAG_ATTESTATION_BASE64, .boolParam = true };
49         ret = HksAddParams(newParamSet,  &isBase64Param, 1);
50         if (ret != HKS_SUCCESS) {
51             break;
52         }
53         ret = HksBuildParamSet(&newParamSet);
54         if (ret != HKS_SUCCESS) {
55             break;
56         }
57         ret = HksAttestKey((const struct HksBlob *)keyAlias, (struct HksParamSet *)newParamSet,
58             (struct HksCertChain *)certChain);
59     } while (0);
60     HksFreeParamSet(&newParamSet);
61     return ret;
62 }