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