util.h revision 1.1.1.1 1 /*
2 * Copyright (C) 2014-2019 Yubico AB - See COPYING
3 */
4
5 #ifndef UTIL_H
6 #define UTIL_H
7
8 #include <stdio.h>
9 #include <security/pam_appl.h>
10
11 #define BUFSIZE 1024
12 #define MAX_DEVS 24
13 #define PK_LEN 130 // Public key
14 #define KH_LEN 86 // Key handle
15 #define RD_LEN 40 // Rounding
16 #define DEVSIZE (((PK_LEN) + (KH_LEN) + (RD_LEN)))
17 #define DEFAULT_AUTHFILE_DIR_VAR "XDG_CONFIG_HOME"
18 #define DEFAULT_AUTHFILE "/Yubico/u2f_keys"
19 #define DEFAULT_AUTHPENDING_FILE_PATH "/var/run/user/%d/pam-u2f-authpending"
20 #define DEFAULT_PROMPT "Insert your U2F device, then press ENTER."
21 #define DEFAULT_CUE "Please touch the device."
22 #define DEFAULT_ORIGIN_PREFIX "pam://"
23 #define DEBUG_STR "debug(pam_u2f): %s:%d (%s): "
24
25 #if defined(DEBUG_PAM)
26 #define D(file, ...) _debug(file, __FILE__, __LINE__, __func__, __VA_ARGS__)
27 #else
28 #define D(file, ...)
29 #endif /* DEBUG_PAM */
30
31 typedef struct {
32 unsigned max_devs;
33 const char *client_key;
34 int manual;
35 int debug;
36 int nouserok;
37 int openasuser;
38 int alwaysok;
39 int interactive;
40 int cue;
41 int nodetect;
42 int userpresence;
43 int userverification;
44 int pinverification;
45 const char *auth_file;
46 const char *authpending_file;
47 const char *origin;
48 const char *appid;
49 const char *prompt;
50 const char *cue_prompt;
51 FILE *debug_file;
52 int is_custom_debug_file;
53 } cfg_t;
54
55 typedef struct {
56 char *publicKey;
57 char *keyHandle;
58 char *coseType;
59 char *attributes;
60 int old_format;
61 } device_t;
62
63 int get_devices_from_authfile(const char *authfile, const char *username,
64 unsigned max_devs, int verbose, FILE *debug_file,
65 device_t *devices, unsigned *n_devs);
66 void free_devices(device_t *devices, const unsigned n_devs);
67
68 int do_authentication(const cfg_t *cfg, const device_t *devices,
69 const unsigned n_devs, pam_handle_t *pamh);
70 int do_manual_authentication(const cfg_t *cfg, const device_t *devices,
71 const unsigned n_devs, pam_handle_t *pamh);
72 char *converse(pam_handle_t *pamh, int echocode, const char *prompt);
73 void _debug(FILE *, const char *, int, const char *, const char *, ...);
74 int random_bytes(void *, size_t);
75
76 #if !defined(HAVE_EXPLICIT_BZERO)
77 void explicit_bzero(void *, size_t);
78 #endif
79
80 #endif /* UTIL_H */
81