Libu2f-emu  0.0.0
Universal 2nd Factor (U2F) Emulation C Library
Macros | Functions | Variables
authenticate.c File Reference
#include <stdlib.h>
#include <string.h>
#include "counter.h"
#include "crypto.h"
#include "raw.h"
#include "u2f-vdev.h"
Include dependency graph for authenticate.c:

Macros

#define U2F_AUTH_CHECK   0x07
 
#define U2F_AUTH_ENFORCE   0x03
 
#define U2F_AUTH_NO_ENFORCE   0x08
 
#define U2F_CHA_PARAM_SIZE   32
 
#define U2F_APP_PARAM_SIZE   32
 

Functions

struct authentification_params __attribute__ ((__packed__))
 
static void authenticate_response_user_pre (struct payload *payload, uint8_t presence)
 Add user precense to the authentification response payload. More...
 
static void authenticate_response_counter (struct payload *payload, uint32_t counter)
 Add counter to the authentification response payload. More...
 
static void authenticate_response_signature (struct payload *payload, EC_KEY *key, const struct authentification_params *params, uint8_t presence, uint32_t counter)
 Add the signature to the authentification response payload. More...
 
static void authenticate_response_sw (struct payload *payload, uint32_t status)
 Add status code to the authentification response payload. More...
 
static uint8_t * authenticate_get_key_handle_cipher (const uint8_t *apdu, size_t apdu_size, const struct authentification_params *params, uint8_t *size)
 Get the ciphered key handle from the request. More...
 
static uint8_t * authenticate_decrypt_key_handle_cipher (struct crypto_core *crypto_core, const uint8_t *key_handle_cipher, size_t key_handle_cipher_size, size_t *size)
 Decrypt ciphered key handle. More...
 
static EC_KEY * authenticate_get_pubkey_from_key_handle (const uint8_t *key_handle, size_t key_handle_size)
 Get the pubkey from the key handle. More...
 
static struct payloadraw_authenticate_check (u2f_emu_vdev *vdev, const uint8_t *apdu, size_t size)
 Handle check authentification request. More...
 
static struct payloadraw_authenticate_enforce (u2f_emu_vdev *vdev, const uint8_t *apdu, size_t size)
 Handle enforce authentification request. More...
 
static struct payloadraw_authenticate_no_enforce (u2f_emu_vdev *vdev, const uint8_t *apdu, size_t size)
 Handle no enforce authentification request. More...
 
struct payloadraw_authenticate (u2f_emu_vdev *vdev, const uint8_t *apdu, size_t size)
 Handle authentification request. More...
 

Variables

uint8_t challenge_param [32]
 
uint8_t application_param [32]
 
uint8_t key_handle_size
 
uint8_t key_handle []
 

Macro Definition Documentation

#define U2F_APP_PARAM_SIZE   32
#define U2F_AUTH_CHECK   0x07
#define U2F_AUTH_ENFORCE   0x03
#define U2F_AUTH_NO_ENFORCE   0x08
#define U2F_CHA_PARAM_SIZE   32

Function Documentation

struct authentification_params __attribute__ ( (__packed__)  )
static uint8_t* authenticate_decrypt_key_handle_cipher ( struct crypto_core crypto_core,
const uint8_t *  key_handle_cipher,
size_t  key_handle_cipher_size,
size_t *  size 
)
static

Decrypt ciphered key handle.

Parameters
crypto_coreThe crypto core.
key_handle_cipherThe ciphered key handle.
key_handle_cipher_sizeThe ciphered key handle size.
sizeThe ref size of the plain key handle.
Returns
The plain key handle.
static uint8_t* authenticate_get_key_handle_cipher ( const uint8_t *  apdu,
size_t  apdu_size,
const struct authentification_params *  params,
uint8_t *  size 
)
static

Get the ciphered key handle from the request.

Parameters
apduThe apdu data.
apdu_sizeThe apdu data size.
paramsThe authentification response.
sizeThe ref size of the ciphered key handle.
Returns
The ciphered key handle.
static EC_KEY* authenticate_get_pubkey_from_key_handle ( const uint8_t *  key_handle,
size_t  key_handle_size 
)
static

Get the pubkey from the key handle.

Parameters
key_handleThe plain key handle
key_handle_sizeThe plain key handle size
Returns
The pubkey
static void authenticate_response_counter ( struct payload payload,
uint32_t  counter 
)
static

Add counter to the authentification response payload.

Parameters
payloadThe response payload.
counterThe counter.
static void authenticate_response_signature ( struct payload payload,
EC_KEY *  key,
const struct authentification_params *  params,
uint8_t  presence,
uint32_t  counter 
)
static

Add the signature to the authentification response payload.

Parameters
payloadThe response payload.
keyThe key used to sign.
paramsThe authentification params.
presenceThe user presence.
counterThe counter.
static void authenticate_response_sw ( struct payload payload,
uint32_t  status 
)
static

Add status code to the authentification response payload.

Parameters
payloadThe response payload.
statusThe status code.
static void authenticate_response_user_pre ( struct payload payload,
uint8_t  presence 
)
static

Add user precense to the authentification response payload.

Parameters
payloadThe response payload.
presenceThe presence.
struct payload* raw_authenticate ( u2f_emu_vdev vdev,
const uint8_t *  apdu,
size_t  size 
)

Handle authentification request.

Parameters
vdevThe virtual device.
apduThe apdu data.
sizeThe apdu data size.
Returns
The response payload.
static struct payload* raw_authenticate_check ( u2f_emu_vdev vdev,
const uint8_t *  apdu,
size_t  size 
)
static

Handle check authentification request.

Parameters
vdevThe virtual device.
apduThe apdu data.
sizeThe apdu data size.
Returns
The response payload.
static struct payload* raw_authenticate_enforce ( u2f_emu_vdev vdev,
const uint8_t *  apdu,
size_t  size 
)
static

Handle enforce authentification request.

Parameters
vdevThe virtual device.
apduThe apdu data.
sizeThe apdu data size.
Returns
The response payload.
static struct payload* raw_authenticate_no_enforce ( u2f_emu_vdev vdev,
const uint8_t *  apdu,
size_t  size 
)
static

Handle no enforce authentification request.

Parameters
vdevThe virtual device.
apduThe apdu data.
sizeThe apdu data size.
Returns
The response payload.

Variable Documentation

uint8_t application_param[32]

SHA-256 App Id

uint8_t challenge_param[32]

SHA-256 client data

uint8_t key_handle[]
uint8_t key_handle_size