35 {
39
41
42 const char *connector_url;
43
44 connector_url = getenv("DEFAULT_CONNECTOR_URL");
45 if (connector_url == NULL) {
47 }
48
51
54
57
59 sizeof(password),
false, &
session);
61
64
68
69 printf(
"Successfully established session %02d\n", session_id);
70
75
79
80
81
82
83
85
89
96
97 printf(
"Generated wrapping key with ID %04x\n", wrapping_key_id);
98
103
108
109 printf(
"Generated ec key with ID %04x\n", key_id_before);
110
111 uint8_t public_key_before[512];
112 size_t public_key_before_len = sizeof(public_key_before);
114 &public_key_before_len, NULL);
116
117 printf(
"Public key before (%zu bytes) is:", public_key_before_len);
118 for (unsigned int i = 0; i < public_key_before_len; i++) {
119 printf(
" %02x", public_key_before[i]);
120 }
122
124 size_t wrapped_object_len = sizeof(wrapped_object);
128 key_id_before, wrapped_object, &wrapped_object_len);
130
131 printf(
"Wrapped object (%zu bytes) is:", wrapped_object_len);
132 for (unsigned int i = 0; i < wrapped_object_len; i++) {
133 printf(
" %02x", wrapped_object[i]);
134 }
136
139
140 printf(
"Successfully deleted ec key with ID %04x\n", key_id_before);
141
143 size_t public_key_after_len = sizeof(public_key_after);
145 &public_key_after_len, NULL);
147
148 printf(
"Unable to get public key for ec key with ID %04x\n", key_id_before);
149
152 wrapped_object_len, &object_type_after,
153 &key_id_after);
155
156 printf(
"Successfully imported wrapped object with ID %04x\n", key_id_after);
157
159 printf(
"Unexpected odbject type\n");
160 exit(EXIT_FAILURE);
161 }
162
163 if (key_id_before != key_id_after) {
164 printf(
"ID %04x and %04x do not match\n", key_id_before, key_id_after);
165 exit(EXIT_FAILURE);
166 } else {
167 printf(
"ID %04x and %04x match\n", key_id_before, key_id_after);
168 }
169
171 &public_key_after_len, NULL);
173
174 printf(
"Public key after (%zu bytes) is:", public_key_after_len);
175 for (unsigned int i = 0; i < public_key_after_len; i++) {
176 printf(
" %02x", public_key_after[i]);
177 }
179
180 if (public_key_before_len != public_key_after_len ||
181 memcmp(public_key_before, public_key_after, public_key_before_len) != 0) {
182 printf(
"Public key before and after do not match\n");
183 exit(EXIT_FAILURE);
184 } else {
185 printf(
"Public key before and after match\n");
186 }
187
189
193
196
199
202
205
206 return 0;
207}
CK_SESSION_HANDLE session
LOGGING_API void printf(Category category, const char *format,...)
Capabilities representation.
uint8_t capabilities[YH_CAPABILITIES_LEN]
Capabilities is represented as an 8 byte uint8_t array.
#define DEFAULT_CONNECTOR_URL
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_util_generate_wrap_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm, const yh_capabilities *delegated_capabilities)
yh_rc yh_util_generate_ec_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm)
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_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_string_to_domains(const char *domains, uint16_t *result)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_connect(yh_connector *connector, int timeout)
yh_rc yh_util_export_wrapped(yh_session *session, uint16_t wrapping_key_id, yh_object_type target_type, uint16_t target_id, uint8_t *out, size_t *out_len)
yh_rc yh_util_get_public_key(yh_session *session, uint16_t id, uint8_t *data, size_t *data_len, yh_algorithm *algorithm)
yh_rc yh_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_util_import_wrapped(yh_session *session, uint16_t wrapping_key_id, const uint8_t *in, size_t in_len, yh_object_type *target_type, uint16_t *target_id)
yh_rc yh_util_delete_object(yh_session *session, uint16_t id, yh_object_type type)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YH_ASYMMETRIC_KEY
Asymmetric Key is the private key of an asymmetric key-pair.
@ YH_ALGO_AES256_CCM_WRAP
aes256-ccm-wrap
#define YH_CAPABILITIES_LEN
Length of capabilities array.
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
@ YHR_DEVICE_OBJECT_NOT_FOUND
Return value when the object not found on the device.
yh_capabilities capabilities
yh_object_descriptor object
memset(pInfo->slotDescription, ' ', 64)
yh_capabilities delegated_capabilities