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