/usr/include/stoken.h is in libstoken-dev 0.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 169 170 171 172 173 174 175 176 177 178 179 180 181 | /*
* stoken.h - public libstoken library interface
*
* Copyright 2012 Kevin Cernekee <cernekee@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __STOKEN_H__
#define __STOKEN_H__
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define STOKEN_API_VER_MAJOR 1
#define STOKEN_API_VER_MINOR 2
#define STOKEN_MAX_TOKENCODE 8
struct stoken_ctx;
struct stoken_info {
char serial[16];
time_t exp_date;
int interval;
};
/*
* Create/destroy library context.
* stoken_new() returns NULL on error.
*/
struct stoken_ctx *stoken_new(void);
void stoken_destroy(struct stoken_ctx *ctx);
/*
* Load a token from an existing .stokenrc file (PATH can be NULL to use
* $HOME/.stokenrc).
*
* Return values:
*
* 0: success; token is now stored in CTX
* -ENOENT: missing input file
* -EINVAL: invalid input file format
* -EIO: any other failure (e.g. ran out of memory)
*/
int stoken_import_rcfile(struct stoken_ctx *ctx, const char *path);
/*
* Parse a token string (nominally a string of ~71 digits, starting with
* '1' or '2').
*
* Return values:
*
* 0: success; token is now stored in CTX
* -EINVAL: invalid input string format
* -EIO: any other failure (e.g. ran out of memory)
*/
int stoken_import_string(struct stoken_ctx *ctx, const char *token_string);
/*
* Retrieve metadata for the currently imported token. This returns a
* callee-allocated, caller-freed struct, which may grow larger in the future.
*
* Return values:
*
* ptr: success
* NULL: any failure (e.g. ran out of memory)
*/
struct stoken_info *stoken_get_info(struct stoken_ctx *ctx);
/*
* Set *MIN_PIN and *MAX_PIN to reflect the valid range of PIN lengths
* (e.g. 4-8).
*/
void stoken_pin_range(struct stoken_ctx *ctx, int *min_pin, int *max_pin);
/* returns nonzero if the token in CTX requires a PIN */
int stoken_pin_required(struct stoken_ctx *ctx);
/* returns nonzero if the token in CTX needs a password to decrypt the seed */
int stoken_pass_required(struct stoken_ctx *ctx);
/* returns nonzero if the token in CTX needs a device ID to decrypt the seed */
int stoken_devid_required(struct stoken_ctx *ctx);
/*
* Check the PIN for proper format. This does not validate whether the PIN
* matches the PIN on file for the user's account; only the server knows that.
*
* Return values:
*
* 0: success
* -EINVAL: invalid format
*/
int stoken_check_pin(struct stoken_ctx *ctx, const char *pin);
/*
* Check the device ID by performing a partial seed decrypt. This helps
* callers provide better user feedback after a stoken_decrypt_seed() failure.
*
* Return values:
*
* 0: success
* -EINVAL: DEVID MAC failed
* -EIO: any other failure (e.g. ran out of memory)
*/
int stoken_check_devid(struct stoken_ctx *ctx, const char *devid);
/*
* Try to decrypt the seed stored in CTX, and compare the MAC to see if
* decryption was successful.
*
* PASS may be NULL if stoken_needs_pass() == 0
* DEVID may be NULL if stoken_needs_devid() == 0
*
* Return values:
*
* 0: success
* -EINVAL: MAC failed (PASS or DEVID is probably incorrect)
* -EIO: any other failure (e.g. ran out of memory)
*/
int stoken_decrypt_seed(struct stoken_ctx *ctx, const char *pass,
const char *devid);
/*
* Generate a new token string for the previously-decrypted seed stored
* in CTX. PASS and DEVID may be NULL. The returned string must be freed
* by the caller.
*
* Return values:
*
* ptr: on success, a pointer to a new string
* NULL: on failure
*/
char *stoken_encrypt_seed(struct stoken_ctx *ctx, const char *pass,
const char *devid);
/*
* Generate a tokencode from the decrypted seed, for UNIX time WHEN.
* OUT is allocated by the caller, and must be able to store at least
* (STOKEN_MAX_TOKENCODE + 1) bytes.
*
* This can be called over and over again, as needed.
*
* If stoken_pin_required() returns 0, PIN may be NULL. If PIN is not
* NULL and the user stored a PIN in ~/.stokenrc, the PIN string passed
* into this function will override the stored PIN. This will affect
* subsequent calls to stoken_compute_tokencode() but the change will not
* be stored on disk.
*
* Return values:
*
* 0: success
* -EINVAL: invalid PIN format
* -EIO: general failure
*/
int stoken_compute_tokencode(struct stoken_ctx *ctx, time_t when,
const char *pin, char *out);
#ifdef __cplusplus
}
#endif
#endif /* !__STOKEN_H__ */
|