1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define TLOG_TAG "hwbcc-srv-impl"
18
19 #include <dice/android.h>
20 #include <lib/hwbcc/common/swbcc.h>
21 #include <lib/hwbcc/srv/srv.h>
22 #include <lib/tipc/tipc_srv.h>
23 #include <lk/err_ptr.h>
24 #include <string.h>
25 #include <trusty_log.h>
26 #include <uapi/err.h>
27
main(void)28 int main(void) {
29 int rc;
30 struct tipc_hset* hset;
31 struct hwbcc_ops ops;
32
33 hset = tipc_hset_create();
34 if (IS_ERR(hset)) {
35 TLOGE("failed (%d) to create handle set\n", PTR_ERR(hset));
36 return PTR_ERR(hset);
37 }
38
39 ops.init = swbcc_init;
40 ops.close = swbcc_close;
41 ops.sign_key = swbcc_sign_key;
42 ops.get_bcc = swbcc_get_bcc;
43 ops.get_dice_artifacts = swbcc_get_dice_artifacts;
44 ops.ns_deprivilege = swbcc_ns_deprivilege;
45
46 uint8_t FRS[DICE_HIDDEN_SIZE];
47 /* FRS, code hash and authority hash are set to all zeros in the sample
48 * hwbcc app. */
49 memset(FRS, 0, DICE_HIDDEN_SIZE);
50
51 uint8_t code_hash[DICE_HASH_SIZE];
52 memset(code_hash, 0, DICE_HASH_SIZE);
53
54 uint8_t authority_hash[DICE_HASH_SIZE];
55 memset(authority_hash, 0, DICE_HASH_SIZE);
56
57 /* Initialize DICE information of the child node in non-secure world. */
58 DiceAndroidConfigValues config_descriptor = {
59 /* TODO: add DICE_ANDROID_CONFIG_RESETTABLE when the FRS is reliable
60 */
61 .configs = DICE_ANDROID_CONFIG_COMPONENT_NAME |
62 DICE_ANDROID_CONFIG_COMPONENT_VERSION,
63 .component_name = "ABL",
64 .component_version = 1,
65 };
66
67 swbcc_glob_init(FRS, code_hash, authority_hash, &config_descriptor);
68 rc = add_hwbcc_service(hset, &ops);
69 if (rc != NO_ERROR) {
70 TLOGE("failed (%d) to initialize system state service\n", rc);
71 return rc;
72 }
73
74 return tipc_run_event_loop(hset);
75 }
76