]> err.no Git - yubikey-personalization/blob - ykpers.h
Merge tag 'v1.15.1'
[yubikey-personalization] / ykpers.h
1 /* -*- mode:C; c-file-style: "bsd" -*- */
2 /*
3  * Copyright (c) 2008-2014 Yubico AB
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials provided
16  *       with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef __YKPERS_H_INCLUDED__
32 #define __YKPERS_H_INCLUDED__
33
34 #include <stddef.h>
35 #include <stdbool.h>
36 #include <ykstatus.h>
37 #include <ykdef.h>
38
39 # ifdef __cplusplus
40 extern "C" {
41 # endif
42
43 typedef struct ykp_config_t YKP_CONFIG;
44
45 /* This only works with Yubikey 1 unless it's fed with a YK_STATUS using
46    ykp_configure_for(). */
47 YKP_CONFIG *ykp_create_config(void);
48 int ykp_free_config(YKP_CONFIG *cfg);
49
50 /* allocate an empty YKP_CONFIG, use ykp_configure_version() to set
51    version information. */
52 YKP_CONFIG *ykp_alloc(void);
53
54 /* Set the version information in st in cfg. */
55 void ykp_configure_version(YKP_CONFIG *cfg, YK_STATUS *st);
56
57 /* This is used to tell what YubiKey version we're working with and what
58    command we want to send to it. If this isn't used YubiKey 1 only will
59    be assumed. */
60 int ykp_configure_command(YKP_CONFIG *cfg, uint8_t command);
61 /* wrapper function for ykp_configure_command */
62 int ykp_configure_for(YKP_CONFIG *cfg, int confnum, YK_STATUS *st);
63
64 int ykp_AES_key_from_hex(YKP_CONFIG *cfg, const char *hexkey);
65 int ykp_AES_key_from_raw(YKP_CONFIG *cfg, const char *key);
66 int ykp_AES_key_from_passphrase(YKP_CONFIG *cfg, const char *passphrase,
67                                 const char *salt);
68 int ykp_HMAC_key_from_hex(YKP_CONFIG *cfg, const char *hexkey);
69 int ykp_HMAC_key_from_raw(YKP_CONFIG *cfg, const char *key);
70
71 /* Functions for constructing the YK_NDEF struct before writing it to a neo */
72 YK_NDEF *ykp_alloc_ndef(void);
73 int ykp_free_ndef(YK_NDEF *ndef);
74 int ykp_construct_ndef_uri(YK_NDEF *ndef, const char *uri);
75 int ykp_construct_ndef_text(YK_NDEF *ndef, const char *text, const char *lang, bool isutf16);
76 int ykp_set_ndef_access_code(YK_NDEF *ndef, unsigned char *access_code);
77 int ykp_ndef_as_text(YK_NDEF *ndef, char *text, size_t len);
78
79 YK_DEVICE_CONFIG *ykp_alloc_device_config(void);
80 int ykp_free_device_config(YK_DEVICE_CONFIG *device_config);
81 int ykp_set_device_mode(YK_DEVICE_CONFIG *device_config, unsigned char mode);
82 int ykp_set_device_chalresp_timeout(YK_DEVICE_CONFIG *device_config, unsigned char timeout);
83 int ykp_set_device_autoeject_time(YK_DEVICE_CONFIG *device_config, unsigned short eject_time);
84
85 int ykp_set_access_code(YKP_CONFIG *cfg, unsigned char *access_code, size_t len);
86 int ykp_set_fixed(YKP_CONFIG *cfg, unsigned char *fixed, size_t len);
87 int ykp_set_uid(YKP_CONFIG *cfg, unsigned char *uid, size_t len);
88 int ykp_set_oath_imf(YKP_CONFIG *cfg, unsigned long imf);
89 unsigned long ykp_get_oath_imf(const YKP_CONFIG *cfg);
90
91 int ykp_set_tktflag_TAB_FIRST(YKP_CONFIG *cfg, bool state);
92 int ykp_set_tktflag_APPEND_TAB1(YKP_CONFIG *cfg, bool state);
93 int ykp_set_tktflag_APPEND_TAB2(YKP_CONFIG *cfg, bool state);
94 int ykp_set_tktflag_APPEND_DELAY1(YKP_CONFIG *cfg, bool state);
95 int ykp_set_tktflag_APPEND_DELAY2(YKP_CONFIG *cfg, bool state);
96 int ykp_set_tktflag_APPEND_CR(YKP_CONFIG *cfg, bool state);
97 int ykp_set_tktflag_PROTECT_CFG2(YKP_CONFIG *cfg, bool state);
98 int ykp_set_tktflag_OATH_HOTP(YKP_CONFIG *cfg, bool state);
99 int ykp_set_tktflag_CHAL_RESP(YKP_CONFIG *cfg, bool state);
100
101 int ykp_set_cfgflag_SEND_REF(YKP_CONFIG *cfg, bool state);
102 int ykp_set_cfgflag_TICKET_FIRST(YKP_CONFIG *cfg, bool state);
103 int ykp_set_cfgflag_PACING_10MS(YKP_CONFIG *cfg, bool state);
104 int ykp_set_cfgflag_PACING_20MS(YKP_CONFIG *cfg, bool state);
105 int ykp_set_cfgflag_ALLOW_HIDTRIG(YKP_CONFIG *cfg, bool state);
106 int ykp_set_cfgflag_STATIC_TICKET(YKP_CONFIG *cfg, bool state);
107 int ykp_set_cfgflag_SHORT_TICKET(YKP_CONFIG *cfg, bool state);
108 int ykp_set_cfgflag_STRONG_PW1(YKP_CONFIG *cfg, bool state);
109 int ykp_set_cfgflag_STRONG_PW2(YKP_CONFIG *cfg, bool state);
110 int ykp_set_cfgflag_MAN_UPDATE(YKP_CONFIG *cfg, bool state);
111 int ykp_set_cfgflag_OATH_HOTP8(YKP_CONFIG *cfg, bool state);
112 int ykp_set_cfgflag_OATH_FIXED_MODHEX1(YKP_CONFIG *cfg, bool state);
113 int ykp_set_cfgflag_OATH_FIXED_MODHEX2(YKP_CONFIG *cfg, bool state);
114 int ykp_set_cfgflag_OATH_FIXED_MODHEX(YKP_CONFIG *cfg, bool state);
115 int ykp_set_cfgflag_CHAL_YUBICO(YKP_CONFIG *cfg, bool state);
116 int ykp_set_cfgflag_CHAL_HMAC(YKP_CONFIG *cfg, bool state);
117 int ykp_set_cfgflag_HMAC_LT64(YKP_CONFIG *cfg, bool state);
118 int ykp_set_cfgflag_CHAL_BTN_TRIG(YKP_CONFIG *cfg, bool state);
119
120 int ykp_set_extflag_SERIAL_BTN_VISIBLE(YKP_CONFIG *cfg, bool state);
121 int ykp_set_extflag_SERIAL_USB_VISIBLE(YKP_CONFIG *cfg, bool state);
122 int ykp_set_extflag_SERIAL_API_VISIBLE (YKP_CONFIG *cfg, bool state);
123 int ykp_set_extflag_USE_NUMERIC_KEYPAD (YKP_CONFIG *cfg, bool state);
124 int ykp_set_extflag_FAST_TRIG (YKP_CONFIG *cfg, bool state);
125 int ykp_set_extflag_ALLOW_UPDATE (YKP_CONFIG *cfg, bool state);
126 int ykp_set_extflag_DORMANT (YKP_CONFIG *cfg, bool state);
127 int ykp_set_extflag_LED_INV (YKP_CONFIG *cfg, bool state);
128
129 bool ykp_get_tktflag_TAB_FIRST(const YKP_CONFIG *cfg);
130 bool ykp_get_tktflag_APPEND_TAB1(const YKP_CONFIG *cfg);
131 bool ykp_get_tktflag_APPEND_TAB2(const YKP_CONFIG *cfg);
132 bool ykp_get_tktflag_APPEND_DELAY1(const YKP_CONFIG *cfg);
133 bool ykp_get_tktflag_APPEND_DELAY2(const YKP_CONFIG *cfg);
134 bool ykp_get_tktflag_APPEND_CR(const YKP_CONFIG *cfg);
135 bool ykp_get_tktflag_PROTECT_CFG2(const YKP_CONFIG *cfg);
136 bool ykp_get_tktflag_OATH_HOTP(const YKP_CONFIG *cfg);
137 bool ykp_get_tktflag_CHAL_RESP(const YKP_CONFIG *cfg);
138
139 bool ykp_get_cfgflag_SEND_REF(const YKP_CONFIG *cfg);
140 bool ykp_get_cfgflag_TICKET_FIRST(const YKP_CONFIG *cfg);
141 bool ykp_get_cfgflag_PACING_10MS(const YKP_CONFIG *cfg);
142 bool ykp_get_cfgflag_PACING_20MS(const YKP_CONFIG *cfg);
143 bool ykp_get_cfgflag_ALLOW_HIDTRIG(const YKP_CONFIG *cfg);
144 bool ykp_get_cfgflag_STATIC_TICKET(const YKP_CONFIG *cfg);
145 bool ykp_get_cfgflag_SHORT_TICKET(const YKP_CONFIG *cfg);
146 bool ykp_get_cfgflag_STRONG_PW1(const YKP_CONFIG *cfg);
147 bool ykp_get_cfgflag_STRONG_PW2(const YKP_CONFIG *cfg);
148 bool ykp_get_cfgflag_MAN_UPDATE(const YKP_CONFIG *cfg);
149 bool ykp_get_cfgflag_OATH_HOTP8(const YKP_CONFIG *cfg);
150 bool ykp_get_cfgflag_OATH_FIXED_MODHEX1(const YKP_CONFIG *cfg);
151 bool ykp_get_cfgflag_OATH_FIXED_MODHEX2(const YKP_CONFIG *cfg);
152 bool ykp_get_cfgflag_OATH_FIXED_MODHEX(const YKP_CONFIG *cfg);
153 bool ykp_get_cfgflag_CHAL_YUBICO(const YKP_CONFIG *cfg);
154 bool ykp_get_cfgflag_CHAL_HMAC(const YKP_CONFIG *cfg);
155 bool ykp_get_cfgflag_HMAC_LT64(const YKP_CONFIG *cfg);
156 bool ykp_get_cfgflag_CHAL_BTN_TRIG(const YKP_CONFIG *cfg);
157
158 bool ykp_get_extflag_SERIAL_BTN_VISIBLE(const YKP_CONFIG *cfg);
159 bool ykp_get_extflag_SERIAL_USB_VISIBLE(const YKP_CONFIG *cfg);
160 bool ykp_get_extflag_SERIAL_API_VISIBLE (const YKP_CONFIG *cfg);
161 bool ykp_get_extflag_USE_NUMERIC_KEYPAD (const YKP_CONFIG *cfg);
162 bool ykp_get_extflag_FAST_TRIG (const YKP_CONFIG *cfg);
163 bool ykp_get_extflag_ALLOW_UPDATE (const YKP_CONFIG *cfg);
164 bool ykp_get_extflag_DORMANT (const YKP_CONFIG *cfg);
165 bool ykp_get_extflag_LED_INV (const YKP_CONFIG *cfg);
166
167 int ykp_clear_config(YKP_CONFIG *cfg);
168
169 int ykp_write_config(const YKP_CONFIG *cfg,
170                      int (*writer)(const char *buf, size_t count,
171                                    void *userdata),
172                      void *userdata);
173 int ykp_read_config(YKP_CONFIG *cfg,
174                     int (*reader)(char *buf, size_t count,
175                                   void *userdata),
176                     void *userdata);
177
178 YK_CONFIG *ykp_core_config(YKP_CONFIG *cfg);
179 int ykp_command(YKP_CONFIG *cfg);
180 int ykp_config_num(YKP_CONFIG *cfg);
181
182 int ykp_export_config(const YKP_CONFIG *cfg, char *buf, size_t len, int format);
183 int ykp_import_config(YKP_CONFIG *cfg, const char *buf, size_t len, int format);
184
185 #define YKP_FORMAT_LEGACY       0x01
186 #define YKP_FORMAT_YCFG         0x02
187
188 void ykp_set_acccode_type(YKP_CONFIG *cfg, unsigned int type);
189 unsigned int ykp_get_acccode_type(const YKP_CONFIG *cfg);
190
191 #define YKP_ACCCODE_NONE        0x01
192 #define YKP_ACCCODE_RANDOM      0x02
193 #define YKP_ACCCODE_SERIAL      0x03
194
195 int ykp_get_supported_key_length(const YKP_CONFIG *cfg);
196
197 extern int * _ykp_errno_location(void);
198 #define ykp_errno (*_ykp_errno_location())
199 const char *ykp_strerror(int errnum);
200
201 #define YKP_ENOTYETIMPL 0x01
202 #define YKP_ENOCFG      0x02
203 #define YKP_EYUBIKEYVER 0x03
204 #define YKP_EOLDYUBIKEY 0x04
205 #define YKP_EINVCONFNUM 0x05
206 #define YKP_EINVAL      0x06
207 #define YKP_ENORANDOM   0x07
208
209 # ifdef __cplusplus
210 }
211 # endif
212
213 #endif  /* __YKPERS_H_INCLUDED__ */