41 {
45
47
48 const char *connector_url;
49
50 connector_url = getenv("DEFAULT_CONNECTOR_URL");
51 if (connector_url == NULL) {
53 }
54
57
60
63
65 sizeof(password),
false, &
session);
67
70
74
75 printf(
"Successfully established session %02d\n", session_id);
76 printf(
"Flushing existing logs\n");
77
78 uint16_t unlogged_boot, unlogged_auth;
82 yh_log_entry *last_previous_log_ptr = &last_previous_log;
83
85 &n_items);
87
88 if (n_items != 0) {
90 } else {
91 last_previous_log_ptr = NULL;
92 }
93
95
98
99 printf(
"Performing some operations\n");
100
104 &descriptor);
106 }
107
109
112 &n_items);
114
116
117 fprintf(stdout, "%d unlogged boots found\n", unlogged_boot);
118 fprintf(stdout, "%d unlogged authentications found\n", unlogged_auth);
119
121
122 if (n_items == 0) {
123 fprintf(stdout, "No logs to extract\n");
124 return 0;
125 } else if (n_items == 1) {
126 fprintf(stdout, "Found 1 item\n");
127 } else {
128 fprintf(stdout, "Found %zu items\n", n_items);
129 }
130
131 for (
uint16_t i = 0; i < n_items; i++) {
133 fprintf(stdout,
134 "item: %5u -- cmd: 0x%02x -- length: %4u -- session key: "
135 "0x%04x -- target key: 0x%04x -- second key: 0x%04x -- "
136 "result: 0x%02x -- tick: %lu -- hash: %s\n",
137 logs[i].number, logs[i].command, logs[i].length,
138 logs[i].session_key, logs[i].target_key, logs[i].second_key,
139 logs[i].result, (unsigned long) logs[i].systick, digest_buf);
140 }
141
144
145 printf(
"Logs correctly verified\n");
146
148 size_t option_len;
149
150 option[0] = YHC_SET_OPTION;
152 option_len = 2;
156
157 option_len =
sizeof(
option);
161
162 assert(option_len % 2 == 0);
163 bool option_found = false;
164 for (size_t i = 0; i < option_len; i += 2) {
165 if (
option[i] == YHC_SET_OPTION) {
166 assert(
option[i + 1] == 0);
167 option_found = true;
168 break;
169 }
170 }
171 assert(option_found == true);
172
173 option[0] = YHC_SET_OPTION;
175 option_len = 2;
179
180 option_len =
sizeof(
option);
184
185 assert(option_len % 2 == 0);
186 option_found = false;
187 for (size_t i = 0; i < option_len; i += 2) {
188 if (
option[i] == YHC_SET_OPTION) {
189 assert(
option[i + 1] == 1);
190 option_found = true;
191 break;
192 }
193 }
194 assert(option_found == true);
195
198
201
204
207
208 return EXIT_SUCCESS;
209}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
LOGGING_API void printf(Category category, const char *format,...)
uint16_t number
Monotonically increasing index.
void format_digest(uint8_t *digest, char *str, uint16_t len)
bool yh_verify_logs(yh_log_entry *logs, size_t n_items, yh_log_entry *last_previous_log)
yh_rc yh_util_get_option(yh_session *session, yh_option option, uint8_t *out, size_t *out_len)
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_create_session_derived(yh_connector *connector, uint16_t authkey_id, const uint8_t *password, size_t password_len, bool recreate, yh_session **session)
yh_rc yh_util_get_log_entries(yh_session *session, uint16_t *unlogged_boot, uint16_t *unlogged_auth, yh_log_entry *out, size_t *n_items)
yh_rc yh_util_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
yh_rc yh_util_get_object_info(yh_session *session, uint16_t id, yh_object_type type, yh_object_descriptor *object)
yh_rc yh_util_set_option(yh_session *session, yh_option option, size_t len, uint8_t *val)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_util_set_log_index(yh_session *session, uint16_t index)
yh_rc yh_connect(yh_connector *connector, int timeout)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
#define YH_LOG_DIGEST_SIZE
Size that the log digest is truncated to.
@ YH_AUTHENTICATION_KEY
Authentication Key is used to establish Sessions with a device.
@ YH_OPTION_COMMAND_AUDIT
Enable/Disable logging of specific commands.
#define YH_MAX_LOG_ENTRIES
Max log entries the device may hold.
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
memcpy((char *) pInfo->slotDescription, s, l)