27#include <openssl/evp.h>
33#ifndef DEFAULT_CONNECTOR_URL
34#define DEFAULT_CONNECTOR_URL "http://127.0.0.1:12345"
48 const char *connector_url;
50 connector_url = getenv(
"DEFAULT_CONNECTOR_URL");
51 if (connector_url == NULL) {
65 sizeof(password),
false, &
session);
75 printf(
"Successfully established session %02d\n", session_id);
76 printf(
"Flushing existing logs\n");
78 uint16_t unlogged_boot, unlogged_auth;
82 yh_log_entry *last_previous_log_ptr = &last_previous_log;
91 last_previous_log_ptr = NULL;
99 printf(
"Performing some operations\n");
108 printf(
"Getting logs\n");
117 fprintf(stdout,
"%d unlogged boots found\n", unlogged_boot);
118 fprintf(stdout,
"%d unlogged authentications found\n", unlogged_auth);
123 fprintf(stdout,
"No logs to extract\n");
125 }
else if (n_items == 1) {
126 fprintf(stdout,
"Found 1 item\n");
128 fprintf(stdout,
"Found %zu items\n", n_items);
131 for (
uint16_t i = 0; i < n_items; i++) {
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);
145 printf(
"Logs correctly verified\n");
150 option[0] = YHC_SET_OPTION;
157 option_len =
sizeof(
option);
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);
171 assert(option_found ==
true);
173 option[0] = YHC_SET_OPTION;
180 option_len =
sizeof(
option);
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);
194 assert(option_found ==
true);
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
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)