Lines Matching refs:key
104 static void u2f_emulated_reset(U2FEmulatedState *key) in u2f_emulated_reset() argument
106 key->pending_out_start = 0; in u2f_emulated_reset()
107 key->pending_out_end = 0; in u2f_emulated_reset()
108 key->pending_out_num = 0; in u2f_emulated_reset()
111 static void u2f_pending_out_add(U2FEmulatedState *key, in u2f_pending_out_add() argument
116 if (key->pending_out_num >= PENDING_OUT_NUM) { in u2f_pending_out_add()
120 index = key->pending_out_end; in u2f_pending_out_add()
121 key->pending_out_end = (index + 1) % PENDING_OUT_NUM; in u2f_pending_out_add()
122 ++key->pending_out_num; in u2f_pending_out_add()
124 memcpy(&key->pending_out[index], packet, U2FHID_PACKET_SIZE); in u2f_pending_out_add()
127 static uint8_t *u2f_pending_out_get(U2FEmulatedState *key) in u2f_pending_out_get() argument
131 if (key->pending_out_num == 0) { in u2f_pending_out_get()
135 index = key->pending_out_start; in u2f_pending_out_get()
136 key->pending_out_start = (index + 1) % PENDING_OUT_NUM; in u2f_pending_out_get()
137 --key->pending_out_num; in u2f_pending_out_get()
139 return key->pending_out[index]; in u2f_pending_out_get()
145 U2FEmulatedState *key = EMULATED_U2F_KEY(base); in u2f_emulated_recv_from_guest() local
147 qemu_mutex_lock(&key->pending_out_mutex); in u2f_emulated_recv_from_guest()
148 u2f_pending_out_add(key, packet); in u2f_emulated_recv_from_guest()
149 qemu_mutex_unlock(&key->pending_out_mutex); in u2f_emulated_recv_from_guest()
151 qemu_mutex_lock(&key->key_mutex); in u2f_emulated_recv_from_guest()
152 qemu_cond_signal(&key->key_cond); in u2f_emulated_recv_from_guest()
153 qemu_mutex_unlock(&key->key_mutex); in u2f_emulated_recv_from_guest()
158 U2FEmulatedState *key = arg; in u2f_emulated_thread() local
165 qemu_mutex_lock(&key->key_mutex); in u2f_emulated_thread()
166 qemu_cond_wait(&key->key_cond, &key->key_mutex); in u2f_emulated_thread()
167 qemu_mutex_unlock(&key->key_mutex); in u2f_emulated_thread()
170 if (key->stop_thread) { in u2f_emulated_thread()
171 key->stop_thread = false; in u2f_emulated_thread()
175 qemu_mutex_lock(&key->pending_out_mutex); in u2f_emulated_thread()
176 packet_out = u2f_pending_out_get(key); in u2f_emulated_thread()
178 qemu_mutex_unlock(&key->pending_out_mutex); in u2f_emulated_thread()
182 qemu_mutex_unlock(&key->pending_out_mutex); in u2f_emulated_thread()
184 qemu_mutex_lock(&key->vdev_mutex); in u2f_emulated_thread()
185 u2f_emu_vdev_send(key->vdev, U2F_EMU_USB, packet, in u2f_emulated_thread()
189 if (u2f_emu_vdev_has_response(key->vdev, U2F_EMU_USB)) { in u2f_emulated_thread()
190 event_notifier_set(&key->notifier); in u2f_emulated_thread()
192 qemu_mutex_unlock(&key->vdev_mutex); in u2f_emulated_thread()
241 static u2f_emu_rc u2f_emulated_setup_vdev_manualy(U2FEmulatedState *key) in u2f_emulated_setup_vdev_manualy() argument
248 ret = u2f_emulated_read(key->cert, cert_pem, sizeof(cert_pem)); in u2f_emulated_setup_vdev_manualy()
254 ret = u2f_emulated_read(key->privkey, privkey_pem, sizeof(privkey_pem)); in u2f_emulated_setup_vdev_manualy()
260 ret = u2f_emulated_read(key->entropy, (char *)&setup_info.entropy, in u2f_emulated_setup_vdev_manualy()
267 if (!u2f_emulated_setup_counter(key->counter, &key->synced_counter)) { in u2f_emulated_setup_vdev_manualy()
274 setup_info.counter = (struct u2f_emu_vdev_counter *)&key->synced_counter; in u2f_emulated_setup_vdev_manualy()
276 return u2f_emu_vdev_new(&key->vdev, &setup_info); in u2f_emulated_setup_vdev_manualy()
281 U2FEmulatedState *key = container_of(notifier, U2FEmulatedState, notifier); in u2f_emulated_event_handler() local
285 event_notifier_test_and_clear(&key->notifier); in u2f_emulated_event_handler()
286 qemu_mutex_lock(&key->vdev_mutex); in u2f_emulated_event_handler()
287 while (u2f_emu_vdev_has_response(key->vdev, U2F_EMU_USB)) { in u2f_emulated_event_handler()
288 packet_size = u2f_emu_vdev_get_response(key->vdev, U2F_EMU_USB, in u2f_emulated_event_handler()
291 u2f_send_to_guest(&key->base, packet_in); in u2f_emulated_event_handler()
295 qemu_mutex_unlock(&key->vdev_mutex); in u2f_emulated_event_handler()
300 U2FEmulatedState *key = EMULATED_U2F_KEY(base); in u2f_emulated_realize() local
303 if (key->cert != NULL || key->privkey != NULL || key->entropy != NULL in u2f_emulated_realize()
304 || key->counter != NULL) { in u2f_emulated_realize()
305 if (key->cert != NULL && key->privkey != NULL in u2f_emulated_realize()
306 && key->entropy != NULL && key->counter != NULL) { in u2f_emulated_realize()
307 rc = u2f_emulated_setup_vdev_manualy(key); in u2f_emulated_realize()
314 } else if (key->dir != NULL) { in u2f_emulated_realize()
315 rc = u2f_emu_vdev_new_from_dir(&key->vdev, key->dir); in u2f_emulated_realize()
317 rc = u2f_emu_vdev_new_ephemeral(&key->vdev); in u2f_emulated_realize()
325 if (event_notifier_init(&key->notifier, false) < 0) { in u2f_emulated_realize()
331 event_notifier_set_handler(&key->notifier, u2f_emulated_event_handler); in u2f_emulated_realize()
334 qemu_cond_init(&key->key_cond); in u2f_emulated_realize()
335 qemu_mutex_init(&key->vdev_mutex); in u2f_emulated_realize()
336 qemu_mutex_init(&key->pending_out_mutex); in u2f_emulated_realize()
337 qemu_mutex_init(&key->key_mutex); in u2f_emulated_realize()
338 u2f_emulated_reset(key); in u2f_emulated_realize()
341 key->stop_thread = false; in u2f_emulated_realize()
342 qemu_thread_create(&key->key_thread, "u2f-key", u2f_emulated_thread, in u2f_emulated_realize()
343 key, QEMU_THREAD_JOINABLE); in u2f_emulated_realize()
348 U2FEmulatedState *key = EMULATED_U2F_KEY(base); in u2f_emulated_unrealize() local
351 key->stop_thread = true; in u2f_emulated_unrealize()
352 qemu_cond_signal(&key->key_cond); in u2f_emulated_unrealize()
353 qemu_thread_join(&key->key_thread); in u2f_emulated_unrealize()
356 event_notifier_set_handler(&key->notifier, NULL); in u2f_emulated_unrealize()
357 event_notifier_cleanup(&key->notifier); in u2f_emulated_unrealize()
360 qemu_cond_destroy(&key->key_cond); in u2f_emulated_unrealize()
361 qemu_mutex_destroy(&key->vdev_mutex); in u2f_emulated_unrealize()
362 qemu_mutex_destroy(&key->key_mutex); in u2f_emulated_unrealize()
363 qemu_mutex_destroy(&key->pending_out_mutex); in u2f_emulated_unrealize()
366 u2f_emu_vdev_free(key->vdev); in u2f_emulated_unrealize()
367 if (key->synced_counter.fp != NULL) { in u2f_emulated_unrealize()
368 fclose(key->synced_counter.fp); in u2f_emulated_unrealize()