34 {
37
38 const char *connector_url;
39
40 connector_url = getenv("DEFAULT_CONNECTOR_URL");
41 if (connector_url == NULL) {
43 }
44
47 fprintf(stderr,
"unable to initialize yubihsm: %s\n",
yh_strerror(
yrc));
48 exit(EXIT_FAILURE);
49 }
50
53
56
57 char *received_url;
60
62
63 printf(
"Send a plain (unencrypted, unauthenticated) echo command\n");
64
67 size_t response_len = sizeof(response);
70 response, &response_len);
72 fprintf(stderr,
"Failed to send ECHO command): %s\n",
yh_strerror(
yrc));
73 exit(EXIT_FAILURE);
74 }
75
77 fprintf(stderr, "Unable to get echo data: %s (%x)\n",
79 exit(EXIT_FAILURE);
80 }
81
82 printf(
"Response (%zu bytes): \"%s\"\n", response_len, response);
83
87 sizeof(password),
false, &
session);
89
92
96
97 printf(
"Successfully established session %02d\n", session_id);
98
99 printf(
"Send a secure echo command\n");
100
102 size_t response2_len = sizeof(response);
105 response2, &response2_len);
107 fprintf(stderr,
"Failed to send ECHO command: %s\n",
yh_strerror(
yrc));
108 exit(EXIT_FAILURE);
109 }
110
112 fprintf(stderr, "Unable to get echo data: %s (%x)\n",
114 exit(EXIT_FAILURE);
115 }
116
117 printf(
"Response (%zu bytes): \"%s\"\n", response_len, response);
118
119 assert(response_len == response2_len);
120 assert(memcmp(response, response2, response_len) == 0);
121
124
127
130
133
134 return 0;
135}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
const char * yh_strerror(yh_rc err)
LOGGING_API void printf(Category category, const char *format,...)
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_set_verbosity(yh_connector *connector, uint8_t verbosity)
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_send_secure_msg(yh_session *session, yh_cmd cmd, const uint8_t *data, size_t data_len, yh_cmd *response_cmd, uint8_t *response, size_t *response_len)
yh_rc yh_util_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
yh_rc yh_send_plain_msg(yh_connector *connector, yh_cmd cmd, const uint8_t *data, size_t data_len, yh_cmd *response_cmd, uint8_t *response, size_t *response_len)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_connect(yh_connector *connector, int timeout)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_get_connector_address(yh_connector *connector, char **const address)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
#define YH_VERB_ALL
Debug level all. All previous options enabled.
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.