1 /*
2 * stoken-internal.h - internal functions called within the stoken package
3 *
4 * Copyright 2012 Kevin Cernekee <cernekee@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef __STOKEN_INTERNAL_H__
22 #define __STOKEN_INTERNAL_H__
23
24 #include <stdint.h>
25 #include "stoken.h"
26
27 #define BUFLEN 2048
28 #define RC_NAME ".stokenrc"
29 #define RC_VER 1
30
31 struct stoken_cfg {
32 char *rc_ver;
33 char *rc_token;
34 char *rc_pin;
35 };
36
37 struct securid_token;
38
39 /* keep this in sync with stoken_errstr */
40 enum {
41 ERR_NONE = 0,
42 ERR_GENERAL,
43 ERR_BAD_LEN,
44 ERR_TOKEN_VERSION,
45 ERR_CHECKSUM_FAILED,
46 ERR_BAD_PASSWORD,
47 ERR_MISSING_PASSWORD,
48 ERR_DECRYPT_FAILED,
49 ERR_BAD_DEVID,
50 ERR_NO_MEMORY,
51 ERR_FILE_READ,
52 ERR_MULTIPLE_TOKENS,
53 };
54
55 typedef void (warn_fn_t)(const char *, ...);
__stoken_warn_empty(const char * fmt,...)56 static inline void __stoken_warn_empty(const char *fmt, ...) { }
57
58 STOKEN_EXPORT int __stoken_parse_and_decode_token(const char *str,
59 struct securid_token *t,
60 int interactive);
61
62 STOKEN_EXPORT int __stoken_read_rcfile(const char *override,
63 struct stoken_cfg *cfg,
64 warn_fn_t warn_fn);
65
66 STOKEN_EXPORT int __stoken_write_rcfile(const char *override,
67 const struct stoken_cfg *cfg,
68 warn_fn_t warn_fn);
69
70 STOKEN_EXPORT void __stoken_zap_rcfile_data(struct stoken_cfg *cfg);
71
72 #ifdef __ANDROID__
73 /* Sigh. This exists but it isn't in the Bionic headers. */
74 int mkstemps(char *path, int slen);
75 #elif !defined(HAVE_MKSTEMPS)
76 #define mkstemps stoken__mkstemps
77 STOKEN_EXPORT int stoken__mkstemps(char *path, int slen);
78 #endif
79
80 #ifndef HAVE_STRCASESTR
81 #define strcasestr stoken__strcasestr
82 STOKEN_EXPORT char *stoken__strcasestr(const char *haystack,
83 const char *needle);
84 #endif
85
86 #ifndef HAVE_GMTIME_R
87 #define gmtime_r stoken__gmtime_r
88 struct tm *stoken__gmtime_r(const time_t *timep, struct tm *result);
89 #endif
90
91 #ifndef HAVE_TIMEGM
92 #define timegm stoken__timegm
93 time_t stoken__timegm(struct tm *tm);
94 #endif
95
96 /* crypto wrappers */
97 STOKEN_EXPORT int stc_standalone_init(void);
98 void stc_aes128_ecb_decrypt(const uint8_t *key, const uint8_t *in, uint8_t *out);
99 void stc_aes128_ecb_encrypt(const uint8_t *key, const uint8_t *in, uint8_t *out);
100 void stc_aes256_cbc_decrypt(const uint8_t *key, const uint8_t *in, int in_len,
101 const uint8_t *iv, uint8_t *out);
102 void stc_aes256_cbc_encrypt(const uint8_t *key, const uint8_t *in, int in_len,
103 const uint8_t *iv, uint8_t *out);
104 void stc_sha1_hash(uint8_t *out, ...);
105 void stc_sha256_hash(uint8_t *out, ...);
106 int stc_b64_encode(const uint8_t *in, unsigned long len,
107 uint8_t *out, unsigned long *outlen);
108 int stc_b64_decode(const uint8_t *in, unsigned long len,
109 uint8_t *out, unsigned long *outlen);
110 int stc_rsa_sha1_sign_digest(const uint8_t *privkey_der, size_t privkey_len,
111 const uint8_t *digest,
112 uint8_t *out, unsigned long *outlen);
113
114 #endif /* !__STOKEN_INTERNAL_H__ */
115