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