1 /*
2 * Copyright (c) 2024 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 <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include "hvb.h"
20
21 static struct hvb_cert_data g_testCert[1] = {
22 {
23 .partition_name = "boot",
24 .data = {
25 .addr = NULL,
26 .size = 0,
27 },
28 .verify_result = HVB_OK,
29 },
30 };
31
32 static struct hvb_verified_data g_testVd = {
33 .num_loaded_certs = 1,
34 .certs = &g_testCert[0],
35 };
36
hvb_chain_verify(struct hvb_ops * ops,const char * rvt_ptn,const char * const * hash_ptn_list,struct hvb_verified_data ** out_vd)37 enum hvb_errno hvb_chain_verify(struct hvb_ops *ops, const char *rvt_ptn, const char *const *hash_ptn_list,
38 struct hvb_verified_data **out_vd)
39 {
40 char *verifyValue = getenv("VERIFY_VALUE");
41
42 printf("[Replace]:hvb_chain_verify in\n");
43
44 if ((verifyValue == NULL) || (strcmp(verifyValue, "Fail") == 0)) {
45 *out_vd = NULL;
46 return HVB_ERROR_INVALID_ARGUMENT;
47 }
48 if (strcmp(verifyValue, "PartFail") == 0) {
49 *out_vd = &g_testVd;
50 return HVB_ERROR_UNSUPPORTED_VERSION;
51 }
52 if (strcmp(verifyValue, "Succeed") == 0) {
53 *out_vd = &g_testVd;
54 return HVB_OK;
55 }
56
57 return HVB_OK;
58 }
59
hvb_chain_verify_data_free(struct hvb_verified_data * vd)60 void hvb_chain_verify_data_free(struct hvb_verified_data *vd)
61 {
62 vd = NULL;
63 return;
64 }
65