util.h revision 1.3 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.3 christos #define DEFAULT_AUTHFILE_SSH "/id_ecdsa_sk"
20 1.3 christos #define DEFAULT_AUTHFILE_DIR "/.config"
21 1.3 christos #define DEFAULT_AUTHFILE_DIR_SSH "/.ssh"
22 1.1 christos #define DEFAULT_AUTHPENDING_FILE_PATH "/var/run/user/%d/pam-u2f-authpending"
23 1.1 christos #define DEFAULT_PROMPT "Insert your U2F device, then press ENTER."
24 1.1 christos #define DEFAULT_CUE "Please touch the device."
25 1.1 christos #define DEFAULT_ORIGIN_PREFIX "pam://"
26 1.3 christos #define SSH_ORIGIN "ssh:"
27 1.1 christos #define DEBUG_STR "debug(pam_u2f): %s:%d (%s): "
28 1.1 christos
29 1.1 christos #if defined(DEBUG_PAM)
30 1.1 christos #define D(file, ...) _debug(file, __FILE__, __LINE__, __func__, __VA_ARGS__)
31 1.1 christos #else
32 1.3 christos #define D(file, ...) ((void) 0)
33 1.1 christos #endif /* DEBUG_PAM */
34 1.1 christos
35 1.1 christos typedef struct {
36 1.1 christos unsigned max_devs;
37 1.1 christos int manual;
38 1.1 christos int debug;
39 1.1 christos int nouserok;
40 1.1 christos int openasuser;
41 1.1 christos int alwaysok;
42 1.1 christos int interactive;
43 1.1 christos int cue;
44 1.1 christos int nodetect;
45 1.1 christos int userpresence;
46 1.1 christos int userverification;
47 1.1 christos int pinverification;
48 1.3 christos int sshformat;
49 1.1 christos const char *auth_file;
50 1.1 christos const char *authpending_file;
51 1.1 christos const char *origin;
52 1.1 christos const char *appid;
53 1.1 christos const char *prompt;
54 1.1 christos const char *cue_prompt;
55 1.1 christos FILE *debug_file;
56 1.1 christos int is_custom_debug_file;
57 1.1 christos } cfg_t;
58 1.1 christos
59 1.1 christos typedef struct {
60 1.1 christos char *publicKey;
61 1.1 christos char *keyHandle;
62 1.1 christos char *coseType;
63 1.1 christos char *attributes;
64 1.1 christos int old_format;
65 1.1 christos } device_t;
66 1.1 christos
67 1.3 christos int get_devices_from_authfile(const cfg_t *cfg, const char *username,
68 1.1 christos device_t *devices, unsigned *n_devs);
69 1.1 christos void free_devices(device_t *devices, const unsigned n_devs);
70 1.1 christos
71 1.1 christos int do_authentication(const cfg_t *cfg, const device_t *devices,
72 1.1 christos const unsigned n_devs, pam_handle_t *pamh);
73 1.1 christos int do_manual_authentication(const cfg_t *cfg, const device_t *devices,
74 1.1 christos const unsigned n_devs, pam_handle_t *pamh);
75 1.1 christos char *converse(pam_handle_t *pamh, int echocode, const char *prompt);
76 1.3 christos int random_bytes(void *, size_t);
77 1.3 christos int cose_type(const char *, int *);
78 1.3 christos const char *cose_string(int);
79 1.3 christos
80 1.3 christos #ifdef __GNUC__
81 1.3 christos void _debug(FILE *, const char *, int, const char *, const char *, ...)
82 1.3 christos __attribute__((__format__(printf, 5, 6)));
83 1.3 christos #else
84 1.1 christos void _debug(FILE *, const char *, int, const char *, const char *, ...);
85 1.3 christos #endif /* __GNUC__ */
86 1.1 christos
87 1.1 christos #if !defined(HAVE_EXPLICIT_BZERO)
88 1.1 christos void explicit_bzero(void *, size_t);
89 1.1 christos #endif
90 1.1 christos
91 1.1 christos #endif /* UTIL_H */
92