107 {
111
113
114 const char *connector_url;
115
116 connector_url = getenv("DEFAULT_CONNECTOR_URL");
117 if (connector_url == NULL) {
119 }
120
123
126
129
131 sizeof(password),
false, &
session);
133
136
140
141 printf(
"Successfully established session %02d\n", session_id);
142
147
151
153
157
158 printf(
"Generated attesting key with ID %04x\n", attesting_key_id);
159
161 assert(fp != NULL);
162
163 X509 *attestation_template = PEM_read_X509(fp, NULL, NULL, NULL);
164 assert(attestation_template != NULL);
165 fclose(fp);
166
167 uint8_t attestation_template_buffer[3072];
168 uint16_t attestation_template_buffer_len =
169 i2d_X509(attestation_template, NULL);
170 assert(sizeof(attestation_template_buffer) >=
171 attestation_template_buffer_len);
172
173 unsigned char *certptr = attestation_template_buffer;
174
175 i2d_X509(attestation_template, &certptr);
176 X509_free(attestation_template);
177
182 attestation_template_buffer,
183 attestation_template_buffer_len);
185
187 size_t tmpbuf_len = sizeof(tmpbuf);
190 assert(tmpbuf_len == attestation_template_buffer_len);
191 assert(memcmp(attestation_template_buffer, tmpbuf, tmpbuf_len) == 0);
192
196
201
202 printf(
"Generated attested key with ID %04x\n", attested_key_id);
203
205 size_t attestation_len = sizeof(attestation);
206
208 attesting_key_id, attestation,
209 &attestation_len);
211
212 const unsigned char *ptr = attestation;
213
214 X509 *x509 = d2i_X509(NULL, &ptr, attestation_len);
215 assert(x509 != NULL);
216
217 BIO *STDout = BIO_new_fp(stdout, BIO_NOCLOSE);
218
219 X509_print_ex(STDout, x509, 0, 0);
220
221 BIO_free(STDout);
222
223 const STACK_OF(X509_EXTENSION) *extensions_list = X509_get0_extensions(x509);
224 assert(sk_X509_EXTENSION_num(extensions_list) >= 6);
225
226 for (int i = 0; i < sk_X509_EXTENSION_num(extensions_list); i++) {
227 X509_EXTENSION *extension;
228
229 extension = sk_X509_EXTENSION_value(extensions_list, i);
230
231 print_extension(extension);
232 }
233
234 X509_free(x509);
235
238
241
244
247
248 return 0;
249}
#define DEFAULT_CONNECTOR_URL
const char attestation_template_file[]
CK_SESSION_HANDLE session
LOGGING_API void printf(Category category, const char *format,...)
const STACK_OF(X509_EXTENSION)
Capabilities representation.
uint8_t capabilities[YH_CAPABILITIES_LEN]
Capabilities is represented as an 8 byte uint8_t array.
yh_rc yh_util_import_opaque(yh_session *session, uint16_t *object_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm, const uint8_t *in, size_t in_len)
yh_rc yh_destroy_session(yh_session **session)
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_get_opaque(yh_session *session, uint16_t object_id, uint8_t *out, size_t *out_len)
yh_rc yh_util_sign_attestation_certificate(yh_session *session, uint16_t key_id, uint16_t attest_id, uint8_t *out, size_t *out_len)
yh_rc yh_util_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
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_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YH_ALGO_OPAQUE_X509_CERTIFICATE
opaque-x509-certificate
#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.
yh_capabilities capabilities
memset(pInfo->slotDescription, ' ', 64)