1 1.1 christos /* 2 1.1 christos * Copyright (C) 2014-2019 Yubico AB - See COPYING 3 1.1 christos */ 4 1.1 christos 5 1.1 christos #ifndef UTIL_H 6 1.1 christos #define UTIL_H 7 1.1 christos 8 1.1 christos #include <stdio.h> 9 1.1 christos #include <security/pam_appl.h> 10 1.1 christos 11 1.1 christos #define BUFSIZE 1024 12 1.1 christos #define MAX_DEVS 24 13 1.1 christos #define DEFAULT_AUTHFILE_DIR_VAR "XDG_CONFIG_HOME" 14 1.4 christos #define DEFAULT_AUTHFILE "Yubico/u2f_keys" 15 1.4 christos #define DEFAULT_AUTHFILE_SSH "id_ecdsa_sk" 16 1.4 christos #define DEFAULT_AUTHFILE_DIR ".config" 17 1.4 christos #define DEFAULT_AUTHFILE_DIR_SSH ".ssh" 18 1.1 christos #define DEFAULT_AUTHPENDING_FILE_PATH "/var/run/user/%d/pam-u2f-authpending" 19 1.1 christos #define DEFAULT_PROMPT "Insert your U2F device, then press ENTER." 20 1.1 christos #define DEFAULT_CUE "Please touch the device." 21 1.1 christos #define DEFAULT_ORIGIN_PREFIX "pam://" 22 1.3 christos #define SSH_ORIGIN "ssh:" 23 1.1 christos 24 1.4 christos #define DEVLIST_LEN 64 25 1.1 christos 26 1.1 christos typedef struct { 27 1.1 christos unsigned max_devs; 28 1.1 christos int manual; 29 1.1 christos int debug; 30 1.1 christos int nouserok; 31 1.1 christos int openasuser; 32 1.1 christos int alwaysok; 33 1.1 christos int interactive; 34 1.1 christos int cue; 35 1.1 christos int nodetect; 36 1.1 christos int userpresence; 37 1.1 christos int userverification; 38 1.1 christos int pinverification; 39 1.3 christos int sshformat; 40 1.4 christos int expand; 41 1.1 christos const char *auth_file; 42 1.1 christos const char *authpending_file; 43 1.1 christos const char *origin; 44 1.1 christos const char *appid; 45 1.1 christos const char *prompt; 46 1.1 christos const char *cue_prompt; 47 1.1 christos FILE *debug_file; 48 1.1 christos } cfg_t; 49 1.1 christos 50 1.1 christos typedef struct { 51 1.1 christos char *publicKey; 52 1.1 christos char *keyHandle; 53 1.1 christos char *coseType; 54 1.1 christos char *attributes; 55 1.1 christos int old_format; 56 1.1 christos } device_t; 57 1.1 christos 58 1.3 christos int get_devices_from_authfile(const cfg_t *cfg, const char *username, 59 1.1 christos device_t *devices, unsigned *n_devs); 60 1.1 christos void free_devices(device_t *devices, const unsigned n_devs); 61 1.1 christos 62 1.1 christos int do_authentication(const cfg_t *cfg, const device_t *devices, 63 1.1 christos const unsigned n_devs, pam_handle_t *pamh); 64 1.1 christos int do_manual_authentication(const cfg_t *cfg, const device_t *devices, 65 1.1 christos const unsigned n_devs, pam_handle_t *pamh); 66 1.1 christos char *converse(pam_handle_t *pamh, int echocode, const char *prompt); 67 1.3 christos int random_bytes(void *, size_t); 68 1.3 christos int cose_type(const char *, int *); 69 1.3 christos const char *cose_string(int); 70 1.4 christos char *expand_variables(const char *, const char *); 71 1.1 christos 72 1.1 christos #if !defined(HAVE_EXPLICIT_BZERO) 73 1.1 christos void explicit_bzero(void *, size_t); 74 1.1 christos #endif 75 1.1 christos 76 1.1 christos #endif /* UTIL_H */ 77