-
Notifications
You must be signed in to change notification settings - Fork 9
/
duo.h
168 lines (140 loc) · 4.5 KB
/
duo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* duo.h
*
* Copyright (c) 2013 Duo Security
* All rights reserved, all wrongs reversed.
*/
#ifndef DUO_H
#define DUO_H
/* API status codes */
typedef enum {
DUO_OK = 0, /* API success */
DUO_FAIL, /* API error */
DUO_LIB_ERROR, /* library error */
DUO_CONN_ERROR, /* connection error */
DUO_CLIENT_ERROR, /* client HTTP error */
DUO_SERVER_ERROR, /* server HTTP error */
} duocode_t;
struct duo_param {
const char *key;
const char *value;
};
typedef struct duo_ctx duo_t;
/* Initialize Duo API handle */
duo_t *duo_init(const char *apihost, const char *ikey, const char *skey,
const char *progname, const char *cafile, const char *proxy);
/* Configure a timeout on appropriate network operations.
* Set seconds to the number of seconds to wait for network operations,
* or 0 to disable timeouts. The timeout is capped at 5 minutes.
*/
duocode_t duo_set_timeout(duo_t * const d, unsigned int seconds);
/* Execute low-level API call */
duocode_t duo_call(duo_t *d, const char *method, const char *uri,
struct duo_param *params, int param_cnt);
/* Retrieve the raw response body from the last API call */
const char *duo_get_response(duo_t *d);
/* Retrieve the error message from the last API call */
const char *duo_get_error(duo_t *d);
/* Retrieve the status code from the last API call */
duocode_t duo_get_code(duo_t *d);
/* Close Duo API handle */
duo_t *duo_close(duo_t *d);
/*
* Duo Auth API
*/
struct duo_device {
int capabilities; // bitmask of DUO_DEVCAP_*
const char *device;
const char *display_name;
const char *name;
const char *next_sms_passcode;
const char *number;
const char *type;
};
#define DUO_DEVCAP_PUSH (1 << 0)
#define DUO_DEVCAP_PHONE (1 << 1)
#define DUO_DEVCAP_SMS (1 << 2)
struct duo_factor {
const char *option;
const char *label;
};
struct duo_push_params {
const char *device;
const char *type;
const char *display_username;
const char *pushinfo;
};
#define DUO_MAX_CODES 10
#define DUO_MAX_DEVICES 10
#define DUO_MAX_FACTORS 30
union duo_auth_ok {
/* ping */
struct {
int time;
} ping;
/* check */
struct {
int time;
} check;
/* enroll_status */
struct {
const char *response;
} enroll_status;
/* enroll */
struct {
const char *activation_barcode;
const char *activation_code;
int expiration;
const char *user_id;
const char *username;
} enroll;
/* bypass_codes */
struct {
const char *codes[DUO_MAX_CODES];
int codes_cnt;
int expiration;
} bypass_codes;
/* preauth */
struct {
const char *result;
const char *status_msg;
struct duo_device devices[DUO_MAX_DEVICES];
int devices_cnt;
struct {
const char *text;
struct duo_factor factors[DUO_MAX_FACTORS];
int factors_cnt;
} prompt;
} preauth;
/* auth */
struct {
const char *result;
const char *status;
const char *status_msg;
} auth;
/* XXX skip async, auth_status */
};
struct duo_auth_fail {
int code;
const char *message;
const char *message_detail;
};
struct duo_auth {
duocode_t stat;
void *__private;
struct duo_auth_fail fail;
union duo_auth_ok ok;
};
struct duo_auth *duo_auth_ping(duo_t *d);
struct duo_auth *duo_auth_check(duo_t *d);
struct duo_auth *duo_auth_enroll(duo_t *d, const char *username,
const char *valid_secs);
struct duo_auth *duo_auth_enroll_status(duo_t *d, const char *user_id,
const char *activation_code);
struct duo_auth *duo_auth_bypass_codes(duo_t *d, const char *username,
const char *count, const char *valid_secs);
struct duo_auth *duo_auth_preauth(duo_t *d, const char *username);
struct duo_auth *duo_auth_auth(duo_t *d, const char *username,
const char *factor, const char *ipaddr, const void *factor_arg);
struct duo_auth *duo_auth_free(struct duo_auth *res);
#endif /* DUO_H */