88 {
92
94
95 const char *connector_url;
96
97 connector_url = getenv("DEFAULT_CONNECTOR_URL");
98 if (connector_url == NULL) {
100 }
101
104
107
110
112 sizeof(password),
false, &
session);
114
117
121
122 printf(
"Successfully established session %02d\n", session_id);
123
129
135 nonce_id);
137
139
142
147
148 for (size_t i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); i++) {
150 size_t aead_len = sizeof(aead);
152 test_vectors[i].id, aead, &aead_len);
154
159
160 printf(
"Checking test vector %zu ... ", i);
166
171
173 }
174
176
178 size_t otp_data_len = sizeof(otp_data);
179 size_t tag_len = 8;
180 size_t nonce_len = 13;
186
187 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
188
189
190 assert(EVP_DecryptInit_ex(ctx, EVP_aes_128_ccm(), NULL, NULL, NULL) == 1);
191
192
193 assert(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, nonce_len, NULL) ==
194 1);
195
196
197 assert(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tag_len,
198 otp_data + otp_data_len - tag_len) == 1);
199
200
201 memcpy(nonce, &nonce_id, 4);
202 memcpy(nonce + 4, otp_data, 6);
203 assert(EVP_DecryptInit_ex(ctx, NULL, NULL,
otp_key, nonce) == 1);
204
205
206 assert(EVP_DecryptUpdate(ctx, out_buf, &
out_len, otp_data + 6,
207 otp_data_len - 6 - tag_len) == 1);
208
209 EVP_CIPHER_CTX_free(ctx);
210
211 struct {
212 union {
213 struct {
221 };
223 };
224 } token = {.raw = {0}};
225
227
228 memcpy(token.id, out_buf + 16, 6);
229 token.use_counter = 0xabcd;
230 token.timestamp_low = 0xdcba;
231 token.timestamp_high = 0xff;
232 token.session_counter = 0x00;
233 token.crc = ~yubikey_crc16(token.raw, 14);
234
235 AES_KEY k;
236 AES_set_encrypt_key(out_buf, 128, &k);
237 AES_ecb_encrypt(token.raw,
otp, &k, AES_ENCRYPT);
238
243
248
253
256
259
262
265
266 return 0;
267}
CK_SESSION_HANDLE session
LOGGING_API void printf(Category category, const char *format,...)
Capabilities representation.
#define DEFAULT_CONNECTOR_URL
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_util_decrypt_otp(yh_session *session, uint16_t key_id, const uint8_t *aead, size_t aead_len, const uint8_t *otp, uint16_t *useCtr, uint8_t *sessionCtr, uint8_t *tstph, uint16_t *tstpl)
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_randomize_otp_aead(yh_session *session, uint16_t key_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_util_create_otp_aead(yh_session *session, uint16_t key_id, const uint8_t *key, const uint8_t *private_id, uint8_t *out, size_t *out_len)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_util_generate_otp_aead_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm, uint32_t nonce_id)
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_util_import_otp_aead_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, uint32_t nonce_id, const uint8_t *in, size_t in_len)
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_OTP_AEAD_KEY
OTP AEAD Key is a secret key used to decrypt Yubico OTP values.
@ YH_ALGO_AES128_YUBICO_OTP
aes128-yubico-otp
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities
memcpy((char *) pInfo->slotDescription, s, l)