File indexing completed on 2025-01-18 10:00:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef GNUTLS_PKCS11_H
0025 #define GNUTLS_PKCS11_H
0026
0027 #include <stdarg.h>
0028 #include <gnutls/gnutls.h>
0029 #include <gnutls/x509.h>
0030
0031 #ifdef __cplusplus
0032 extern "C" {
0033 #endif
0034
0035 #define GNUTLS_PKCS11_MAX_PIN_LEN 256
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 typedef int (*gnutls_pkcs11_token_callback_t)(void *const userdata,
0056 const char *const label,
0057 unsigned retry);
0058
0059 struct gnutls_pkcs11_obj_st;
0060 typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t;
0061
0062 #define GNUTLS_PKCS11_FLAG_MANUAL 0
0063 #define GNUTLS_PKCS11_FLAG_AUTO \
0064 1
0065 #define GNUTLS_PKCS11_FLAG_AUTO_TRUSTED \
0066 (1 \
0067 << 1)
0068
0069
0070
0071
0072
0073
0074 int gnutls_pkcs11_init(unsigned int flags, const char *deprecated_config_file);
0075 int gnutls_pkcs11_reinit(void);
0076 void gnutls_pkcs11_deinit(void);
0077 void gnutls_pkcs11_set_token_function(gnutls_pkcs11_token_callback_t fn,
0078 void *userdata);
0079
0080 void gnutls_pkcs11_set_pin_function(gnutls_pin_callback_t fn, void *userdata);
0081
0082 gnutls_pin_callback_t gnutls_pkcs11_get_pin_function(void **userdata);
0083
0084 int gnutls_pkcs11_add_provider(const char *name, const char *params);
0085 int gnutls_pkcs11_obj_init(gnutls_pkcs11_obj_t *obj);
0086 void gnutls_pkcs11_obj_set_pin_function(gnutls_pkcs11_obj_t obj,
0087 gnutls_pin_callback_t fn,
0088 void *userdata);
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 typedef enum gnutls_pkcs11_obj_flags {
0123 GNUTLS_PKCS11_OBJ_FLAG_LOGIN = (1 << 0),
0124 GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED = (1 << 1),
0125 GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE = (1 << 2),
0126 GNUTLS_PKCS11_OBJ_FLAG_LOGIN_SO = (1 << 3),
0127 GNUTLS_PKCS11_OBJ_FLAG_MARK_PRIVATE = (1 << 4),
0128 GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_PRIVATE = (1 << 5),
0129 GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_ANY = (1 << 6),
0130 GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_TRUSTED =
0131 GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED,
0132 GNUTLS_PKCS11_OBJ_FLAG_MARK_DISTRUSTED = (1 << 8),
0133 GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED =
0134 GNUTLS_PKCS11_OBJ_FLAG_MARK_DISTRUSTED,
0135 GNUTLS_PKCS11_OBJ_FLAG_COMPARE = (1 << 9),
0136 GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE = (1 << 10),
0137 GNUTLS_PKCS11_OBJ_FLAG_MARK_CA = (1 << 11),
0138 GNUTLS_PKCS11_OBJ_FLAG_MARK_KEY_WRAP = (1 << 12),
0139 GNUTLS_PKCS11_OBJ_FLAG_COMPARE_KEY = (1 << 13),
0140 GNUTLS_PKCS11_OBJ_FLAG_OVERWRITE_TRUSTMOD_EXT = (1 << 14),
0141 GNUTLS_PKCS11_OBJ_FLAG_MARK_ALWAYS_AUTH = (1 << 15),
0142 GNUTLS_PKCS11_OBJ_FLAG_MARK_EXTRACTABLE = (1 << 16),
0143 GNUTLS_PKCS11_OBJ_FLAG_NEVER_EXTRACTABLE = (1 << 17),
0144 GNUTLS_PKCS11_OBJ_FLAG_CRT = (1 << 18),
0145 GNUTLS_PKCS11_OBJ_FLAG_WITH_PRIVKEY = (1 << 19),
0146 GNUTLS_PKCS11_OBJ_FLAG_PUBKEY = (1 << 20),
0147 GNUTLS_PKCS11_OBJ_FLAG_NO_STORE_PUBKEY = GNUTLS_PKCS11_OBJ_FLAG_PUBKEY,
0148 GNUTLS_PKCS11_OBJ_FLAG_PRIVKEY = (1 << 21),
0149 GNUTLS_PKCS11_OBJ_FLAG_MARK_NOT_SENSITIVE = (1 << 22),
0150
0151 } gnutls_pkcs11_obj_flags;
0152
0153 #define gnutls_pkcs11_obj_attr_t gnutls_pkcs11_obj_flags
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163 typedef enum {
0164 GNUTLS_PKCS11_URL_GENERIC,
0165 GNUTLS_PKCS11_URL_LIB,
0166 GNUTLS_PKCS11_URL_LIB_VERSION
0167 } gnutls_pkcs11_url_type_t;
0168
0169 int gnutls_pkcs11_obj_import_url(gnutls_pkcs11_obj_t obj, const char *url,
0170 unsigned int flags
0171 );
0172 int gnutls_pkcs11_obj_export_url(gnutls_pkcs11_obj_t obj,
0173 gnutls_pkcs11_url_type_t detailed, char **url);
0174 void gnutls_pkcs11_obj_deinit(gnutls_pkcs11_obj_t obj);
0175
0176 int gnutls_pkcs11_obj_export(gnutls_pkcs11_obj_t obj, void *output_data,
0177 size_t *output_data_size);
0178 int gnutls_pkcs11_obj_export2(gnutls_pkcs11_obj_t obj, gnutls_datum_t *out);
0179
0180 int gnutls_pkcs11_obj_export3(gnutls_pkcs11_obj_t obj,
0181 gnutls_x509_crt_fmt_t fmt, gnutls_datum_t *out);
0182
0183 int gnutls_pkcs11_get_raw_issuer(const char *url, gnutls_x509_crt_t cert,
0184 gnutls_datum_t *issuer,
0185 gnutls_x509_crt_fmt_t fmt, unsigned int flags);
0186
0187 int gnutls_pkcs11_get_raw_issuer_by_dn(const char *url,
0188 const gnutls_datum_t *dn,
0189 gnutls_datum_t *issuer,
0190 gnutls_x509_crt_fmt_t fmt,
0191 unsigned int flags);
0192
0193 int gnutls_pkcs11_get_raw_issuer_by_subject_key_id(
0194 const char *url, const gnutls_datum_t *dn, const gnutls_datum_t *spki,
0195 gnutls_datum_t *issuer, gnutls_x509_crt_fmt_t fmt, unsigned int flags);
0196
0197 unsigned gnutls_pkcs11_crt_is_known(const char *url, gnutls_x509_crt_t cert,
0198 unsigned int flags);
0199
0200 #if 0
0201
0202 int gnutls_pkcs11_copy_x509_crt(const char *token_url,
0203 gnutls_x509_crt_t crt,
0204 const char *label, unsigned int flags
0205 );
0206
0207 int gnutls_pkcs11_copy_x509_privkey(const char *token_url,
0208 gnutls_x509_privkey_t key,
0209 const char *label,
0210 unsigned int key_usage, unsigned int flags);
0211 int
0212 gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
0213 unsigned int bits, const char *label,
0214 gnutls_x509_crt_fmt_t fmt,
0215 gnutls_datum_t * pubkey, unsigned int flags);
0216 int
0217 gnutls_pkcs11_privkey_generate(const char *url, gnutls_pk_algorithm_t pk,
0218 unsigned int bits, const char *label,
0219 unsigned int flags);
0220 #endif
0221
0222 int gnutls_pkcs11_copy_pubkey(const char *token_url, gnutls_pubkey_t crt,
0223 const char *label, const gnutls_datum_t *cid,
0224 unsigned int key_usage, unsigned int flags);
0225
0226 #define gnutls_pkcs11_copy_x509_crt(url, crt, label, flags) \
0227 gnutls_pkcs11_copy_x509_crt2(url, crt, label, NULL, flags)
0228
0229 int gnutls_pkcs11_copy_x509_crt2(const char *token_url, gnutls_x509_crt_t crt,
0230 const char *label, const gnutls_datum_t *id,
0231 unsigned int flags
0232 );
0233
0234 #define gnutls_pkcs11_copy_x509_privkey(url, key, label, usage, flags) \
0235 gnutls_pkcs11_copy_x509_privkey2(url, key, label, NULL, usage, flags)
0236 int gnutls_pkcs11_copy_x509_privkey2(const char *token_url,
0237 gnutls_x509_privkey_t key,
0238 const char *label,
0239 const gnutls_datum_t *cid,
0240 unsigned int key_usage
0241 ,
0242 unsigned int flags
0243
0244 );
0245
0246 int gnutls_pkcs11_delete_url(const char *object_url, unsigned int flags
0247 );
0248
0249 int gnutls_pkcs11_copy_secret_key(const char *token_url, gnutls_datum_t *key,
0250 const char *label,
0251 unsigned int key_usage
0252 ,
0253 unsigned int flags
0254 );
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 typedef enum {
0272 GNUTLS_PKCS11_OBJ_ID_HEX = 1,
0273 GNUTLS_PKCS11_OBJ_LABEL,
0274 GNUTLS_PKCS11_OBJ_TOKEN_LABEL,
0275 GNUTLS_PKCS11_OBJ_TOKEN_SERIAL,
0276 GNUTLS_PKCS11_OBJ_TOKEN_MANUFACTURER,
0277 GNUTLS_PKCS11_OBJ_TOKEN_MODEL,
0278 GNUTLS_PKCS11_OBJ_ID,
0279
0280 GNUTLS_PKCS11_OBJ_LIBRARY_VERSION,
0281 GNUTLS_PKCS11_OBJ_LIBRARY_DESCRIPTION,
0282 GNUTLS_PKCS11_OBJ_LIBRARY_MANUFACTURER
0283 } gnutls_pkcs11_obj_info_t;
0284
0285 int gnutls_pkcs11_obj_get_ptr(gnutls_pkcs11_obj_t obj, void **ptr,
0286 void **session, void **ohandle,
0287 unsigned long *slot_id, unsigned int flags);
0288
0289 int gnutls_pkcs11_obj_get_info(gnutls_pkcs11_obj_t obj,
0290 gnutls_pkcs11_obj_info_t itype, void *output,
0291 size_t *output_size);
0292 int gnutls_pkcs11_obj_set_info(gnutls_pkcs11_obj_t obj,
0293 gnutls_pkcs11_obj_info_t itype, const void *data,
0294 size_t data_size, unsigned flags);
0295
0296 #define GNUTLS_PKCS11_OBJ_ATTR_CRT_ALL GNUTLS_PKCS11_OBJ_FLAG_CRT
0297 #define GNUTLS_PKCS11_OBJ_ATTR_MATCH 0
0298 #define GNUTLS_PKCS11_OBJ_ATTR_ALL 0
0299 #define GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED \
0300 (GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED)
0301 #define GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY \
0302 (GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_WITH_PRIVKEY)
0303 #define GNUTLS_PKCS11_OBJ_ATTR_CRT_TRUSTED_CA \
0304 (GNUTLS_PKCS11_OBJ_FLAG_CRT | GNUTLS_PKCS11_OBJ_FLAG_MARK_CA | \
0305 GNUTLS_PKCS11_OBJ_FLAG_MARK_TRUSTED)
0306 #define GNUTLS_PKCS11_OBJ_ATTR_PUBKEY GNUTLS_PKCS11_OBJ_FLAG_PUBKEY
0307 #define GNUTLS_PKCS11_OBJ_ATTR_PRIVKEY GNUTLS_PKCS11_OBJ_FLAG_PRIVKEY
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320 typedef enum {
0321 GNUTLS_PKCS11_TOKEN_LABEL,
0322 GNUTLS_PKCS11_TOKEN_SERIAL,
0323 GNUTLS_PKCS11_TOKEN_MANUFACTURER,
0324 GNUTLS_PKCS11_TOKEN_MODEL,
0325 GNUTLS_PKCS11_TOKEN_MODNAME
0326 } gnutls_pkcs11_token_info_t;
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340 typedef enum {
0341 GNUTLS_PKCS11_OBJ_UNKNOWN,
0342 GNUTLS_PKCS11_OBJ_X509_CRT,
0343 GNUTLS_PKCS11_OBJ_PUBKEY,
0344 GNUTLS_PKCS11_OBJ_PRIVKEY,
0345 GNUTLS_PKCS11_OBJ_SECRET_KEY,
0346 GNUTLS_PKCS11_OBJ_DATA,
0347 GNUTLS_PKCS11_OBJ_X509_CRT_EXTENSION
0348 } gnutls_pkcs11_obj_type_t;
0349
0350 int gnutls_pkcs11_token_init(const char *token_url, const char *so_pin,
0351 const char *label);
0352
0353 int gnutls_pkcs11_token_get_ptr(const char *url, void **ptr,
0354 unsigned long *slot_id, unsigned int flags);
0355
0356 int gnutls_pkcs11_token_get_mechanism(const char *url, unsigned int idx,
0357 unsigned long *mechanism);
0358
0359 unsigned gnutls_pkcs11_token_check_mechanism(const char *url,
0360 unsigned long mechanism, void *ptr,
0361 unsigned psize, unsigned flags);
0362
0363 int gnutls_pkcs11_token_set_pin(const char *token_url, const char *oldpin,
0364 const char *newpin,
0365 unsigned int flags );
0366
0367 int gnutls_pkcs11_token_get_url(unsigned int seq,
0368 gnutls_pkcs11_url_type_t detailed, char **url);
0369 int gnutls_pkcs11_token_get_info(const char *url,
0370 gnutls_pkcs11_token_info_t ttype, void *output,
0371 size_t *output_size);
0372
0373 #define GNUTLS_PKCS11_TOKEN_HW 1
0374 #define GNUTLS_PKCS11_TOKEN_TRUSTED (1 << 1)
0375 #define GNUTLS_PKCS11_TOKEN_RNG (1 << 2)
0376 #define GNUTLS_PKCS11_TOKEN_LOGIN_REQUIRED (1 << 3)
0377 #define GNUTLS_PKCS11_TOKEN_PROTECTED_AUTHENTICATION_PATH \
0378 (1 << 4)
0379 #define GNUTLS_PKCS11_TOKEN_INITIALIZED (1 << 5)
0380 #define GNUTLS_PKCS11_TOKEN_USER_PIN_COUNT_LOW \
0381 (1 << 6)
0382 #define GNUTLS_PKCS11_TOKEN_USER_PIN_FINAL_TRY \
0383 (1 << 7)
0384 #define GNUTLS_PKCS11_TOKEN_USER_PIN_LOCKED (1 << 8)
0385 #define GNUTLS_PKCS11_TOKEN_SO_PIN_COUNT_LOW (1 << 9)
0386 #define GNUTLS_PKCS11_TOKEN_SO_PIN_FINAL_TRY \
0387 (1 << 10)
0388 #define GNUTLS_PKCS11_TOKEN_SO_PIN_LOCKED (1 << 11)
0389 #define GNUTLS_PKCS11_TOKEN_USER_PIN_INITIALIZED \
0390 (1 << 12)
0391 #define GNUTLS_PKCS11_TOKEN_ERROR_STATE (1 << 13)
0392
0393 int gnutls_pkcs11_token_get_flags(const char *url, unsigned int *flags);
0394
0395 #define gnutls_pkcs11_obj_list_import_url(p_list, n_list, url, attrs, flags) \
0396 gnutls_pkcs11_obj_list_import_url3(p_list, n_list, url, attrs | flags)
0397 #define gnutls_pkcs11_obj_list_import_url2(p_list, n_list, url, attrs, flags) \
0398 gnutls_pkcs11_obj_list_import_url4(p_list, n_list, url, attrs | flags)
0399
0400 int gnutls_pkcs11_obj_list_import_url3(gnutls_pkcs11_obj_t *p_list,
0401 unsigned int *const n_list,
0402 const char *url, unsigned int flags
0403
0404 );
0405
0406 int gnutls_pkcs11_obj_list_import_url4(gnutls_pkcs11_obj_t **p_list,
0407 unsigned int *n_list, const char *url,
0408 unsigned int flags
0409
0410 );
0411
0412 int gnutls_x509_crt_import_pkcs11(gnutls_x509_crt_t crt,
0413 gnutls_pkcs11_obj_t pkcs11_crt);
0414
0415 gnutls_pkcs11_obj_type_t gnutls_pkcs11_obj_get_type(gnutls_pkcs11_obj_t obj);
0416 const char *gnutls_pkcs11_type_get_name(gnutls_pkcs11_obj_type_t type);
0417
0418 int gnutls_pkcs11_obj_get_exts(gnutls_pkcs11_obj_t obj,
0419 struct gnutls_x509_ext_st **exts,
0420 unsigned int *exts_size, unsigned int flags);
0421
0422 int gnutls_pkcs11_obj_get_flags(gnutls_pkcs11_obj_t obj, unsigned int *oflags);
0423 char *gnutls_pkcs11_obj_flags_get_str(unsigned int flags);
0424
0425 int gnutls_x509_crt_list_import_pkcs11(gnutls_x509_crt_t *certs,
0426 unsigned int cert_max,
0427 gnutls_pkcs11_obj_t *const objs,
0428 unsigned int flags
0429 );
0430
0431
0432 int gnutls_pkcs11_privkey_init(gnutls_pkcs11_privkey_t *key);
0433
0434 int gnutls_pkcs11_privkey_cpy(gnutls_pkcs11_privkey_t dst,
0435 gnutls_pkcs11_privkey_t src);
0436
0437 void gnutls_pkcs11_privkey_set_pin_function(gnutls_pkcs11_privkey_t key,
0438 gnutls_pin_callback_t fn,
0439 void *userdata);
0440 void gnutls_pkcs11_privkey_deinit(gnutls_pkcs11_privkey_t key);
0441 int gnutls_pkcs11_privkey_get_pk_algorithm(gnutls_pkcs11_privkey_t key,
0442 unsigned int *bits);
0443 int gnutls_pkcs11_privkey_get_info(gnutls_pkcs11_privkey_t pkey,
0444 gnutls_pkcs11_obj_info_t itype, void *output,
0445 size_t *output_size);
0446
0447 int gnutls_pkcs11_privkey_import_url(gnutls_pkcs11_privkey_t pkey,
0448 const char *url, unsigned int flags);
0449
0450 int gnutls_pkcs11_privkey_export_url(gnutls_pkcs11_privkey_t key,
0451 gnutls_pkcs11_url_type_t detailed,
0452 char **url);
0453 unsigned gnutls_pkcs11_privkey_status(gnutls_pkcs11_privkey_t key);
0454
0455 #define gnutls_pkcs11_privkey_generate(url, pk, bits, label, flags) \
0456 gnutls_pkcs11_privkey_generate3(url, pk, bits, label, NULL, 0, NULL, \
0457 0, flags)
0458
0459 #define gnutls_pkcs11_privkey_generate2(url, pk, bits, label, fmt, pubkey, \
0460 flags) \
0461 gnutls_pkcs11_privkey_generate3(url, pk, bits, label, NULL, fmt, \
0462 pubkey, 0, flags)
0463
0464 int gnutls_pkcs11_privkey_generate3(const char *url, gnutls_pk_algorithm_t pk,
0465 unsigned int bits, const char *label,
0466 const gnutls_datum_t *cid,
0467 gnutls_x509_crt_fmt_t fmt,
0468 gnutls_datum_t *pubkey,
0469 unsigned int key_usage, unsigned int flags);
0470
0471 int gnutls_pkcs11_privkey_export_pubkey(gnutls_pkcs11_privkey_t pkey,
0472 gnutls_x509_crt_fmt_t fmt,
0473 gnutls_datum_t *pubkey,
0474 unsigned int flags);
0475
0476 int gnutls_pkcs11_token_get_random(const char *token_url, void *data,
0477 size_t len);
0478
0479 int gnutls_pkcs11_copy_attached_extension(const char *token_url,
0480 gnutls_x509_crt_t crt,
0481 gnutls_datum_t *data,
0482 const char *label,
0483 unsigned int flags);
0484
0485 #define gnutls_x509_crt_import_pkcs11_url gnutls_x509_crt_import_url
0486
0487 #ifdef __cplusplus
0488 }
0489 #endif
0490
0491 #endif