| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#if HAVE_P11KIT |
| 5 |
# include <p11-kit/p11-kit.h> /* IWYU pragma: export */ |
| 6 |
# include <p11-kit/uri.h> /* IWYU pragma: export */ |
| 7 |
#endif |
| 8 |
|
| 9 |
#include "ask-password-api.h" |
| 10 |
#include "dlfcn-util.h" |
| 11 |
#include "pkcs11-padding.h" |
| 12 |
#include "shared-forward.h" |
| 13 |
|
| 14 |
bool pkcs11_uri_valid(const char *uri); |
| 15 |
|
| 16 |
#if HAVE_P11KIT |
| 17 |
extern DLSYM_PROTOTYPE(p11_kit_module_get_name); |
| 18 |
extern DLSYM_PROTOTYPE(p11_kit_modules_finalize_and_release); |
| 19 |
extern DLSYM_PROTOTYPE(p11_kit_modules_load_and_initialize); |
| 20 |
extern DLSYM_PROTOTYPE(p11_kit_strerror); |
| 21 |
extern DLSYM_PROTOTYPE(p11_kit_uri_format); |
| 22 |
extern DLSYM_PROTOTYPE(p11_kit_uri_free); |
| 23 |
extern DLSYM_PROTOTYPE(p11_kit_uri_get_attributes); |
| 24 |
extern DLSYM_PROTOTYPE(p11_kit_uri_get_attribute); |
| 25 |
extern DLSYM_PROTOTYPE(p11_kit_uri_set_attribute); |
| 26 |
extern DLSYM_PROTOTYPE(p11_kit_uri_get_module_info); |
| 27 |
extern DLSYM_PROTOTYPE(p11_kit_uri_get_slot_info); |
| 28 |
extern DLSYM_PROTOTYPE(p11_kit_uri_get_token_info); |
| 29 |
extern DLSYM_PROTOTYPE(p11_kit_uri_match_token_info); |
| 30 |
extern DLSYM_PROTOTYPE(p11_kit_uri_message); |
| 31 |
extern DLSYM_PROTOTYPE(p11_kit_uri_new); |
| 32 |
extern DLSYM_PROTOTYPE(p11_kit_uri_parse); |
| 33 |
|
| 34 |
int uri_from_string(const char *p, P11KitUri **ret); |
| 35 |
|
| 36 |
P11KitUri *uri_from_module_info(const CK_INFO *info); |
| 37 |
P11KitUri *uri_from_slot_info(const CK_SLOT_INFO *slot_info); |
| 38 |
P11KitUri *uri_from_token_info(const CK_TOKEN_INFO *token_info); |
| 39 |
|
| 40 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(P11KitUri*, sym_p11_kit_uri_free, p11_kit_uri_freep, NULL); |
| 41 |
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(CK_FUNCTION_LIST**, sym_p11_kit_modules_finalize_and_release, p11_kit_modules_finalize_and_releasep, NULL); |
| 42 |
|
| 43 |
CK_RV pkcs11_get_slot_list_malloc(CK_FUNCTION_LIST *m, CK_SLOT_ID **ret_slotids, CK_ULONG *ret_n_slotids); |
| 44 |
|
| 45 |
char* pkcs11_token_label(const CK_TOKEN_INFO *token_info); |
| 46 |
char* pkcs11_token_manufacturer_id(const CK_TOKEN_INFO *token_info); |
| 47 |
char* pkcs11_token_model(const CK_TOKEN_INFO *token_info); |
| 48 |
|
| 49 |
int pkcs11_token_login_by_pin(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, const CK_TOKEN_INFO *token_info, const char *token_label, const void *pin, size_t pin_size); |
| 50 |
int pkcs11_token_login( |
| 51 |
CK_FUNCTION_LIST *m, |
| 52 |
CK_SESSION_HANDLE session, |
| 53 |
CK_SLOT_ID slotid, |
| 54 |
const CK_TOKEN_INFO *token_info, |
| 55 |
const char *friendly_name, |
| 56 |
const char *ask_password_icon, |
| 57 |
const char *ask_password_key, |
| 58 |
const char *ask_password_credential, |
| 59 |
usec_t until, |
| 60 |
AskPasswordFlags ask_password_flags, |
| 61 |
char **ret_used_pin); |
| 62 |
|
| 63 |
int pkcs11_token_find_related_object(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE prototype, CK_OBJECT_CLASS class, CK_OBJECT_HANDLE *ret_object); |
| 64 |
#if HAVE_OPENSSL |
| 65 |
int pkcs11_token_read_public_key(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, EVP_PKEY **ret_pkey); |
| 66 |
int pkcs11_token_read_x509_certificate(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, X509 **ret_cert); |
| 67 |
#endif |
| 68 |
|
| 69 |
int pkcs11_token_find_private_key(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, P11KitUri *search_uri, CK_OBJECT_HANDLE *ret_object); |
| 70 |
int pkcs11_token_decrypt_data(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, const void *encrypted_data, size_t encrypted_data_size, Pkcs11RsaPadding rsa_padding, void **ret_decrypted_data, size_t *ret_decrypted_data_size); |
| 71 |
|
| 72 |
int pkcs11_token_acquire_rng(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session); |
| 73 |
|
| 74 |
typedef int (*pkcs11_find_token_callback_t)(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_SLOT_ID slotid, const CK_SLOT_INFO *slot_info, const CK_TOKEN_INFO *token_info, P11KitUri *uri, void *userdata); |
| 75 |
int pkcs11_find_token(const char *pkcs11_uri, pkcs11_find_token_callback_t callback, void *userdata); |
| 76 |
|
| 77 |
#if HAVE_OPENSSL |
| 78 |
int pkcs11_acquire_public_key(const char *uri, const char *askpw_friendly_name, const char *askpw_icon, const char *askpw_credential, AskPasswordFlags askpw_flags, EVP_PKEY **ret_pkey, Pkcs11RsaPadding *ret_rsa_padding, char **ret_pin_used); |
| 79 |
#endif |
| 80 |
|
| 81 |
typedef struct { |
| 82 |
const char *friendly_name; |
| 83 |
usec_t until; |
| 84 |
void *encrypted_key; |
| 85 |
size_t encrypted_key_size; |
| 86 |
void *decrypted_key; |
| 87 |
size_t decrypted_key_size; |
| 88 |
bool free_encrypted_key; |
| 89 |
const char *askpw_credential; |
| 90 |
AskPasswordFlags askpw_flags; |
| 91 |
Pkcs11RsaPadding rsa_padding; |
| 92 |
} pkcs11_crypt_device_callback_data; |
| 93 |
|
| 94 |
void pkcs11_crypt_device_callback_data_release(pkcs11_crypt_device_callback_data *data); |
| 95 |
|
| 96 |
int pkcs11_crypt_device_callback( |
| 97 |
CK_FUNCTION_LIST *m, |
| 98 |
CK_SESSION_HANDLE session, |
| 99 |
CK_SLOT_ID slot_id, |
| 100 |
const CK_SLOT_INFO *slot_info, |
| 101 |
const CK_TOKEN_INFO *token_info, |
| 102 |
P11KitUri *uri, |
| 103 |
void *userdata); |
| 104 |
|
| 105 |
#endif |
| 106 |
|
| 107 |
int dlopen_p11kit(int log_level); |
| 108 |
|
| 109 |
typedef struct { |
| 110 |
const char *friendly_name; |
| 111 |
usec_t until; |
| 112 |
const char *askpw_credential; |
| 113 |
AskPasswordFlags askpw_flags; |
| 114 |
} systemd_pkcs11_plugin_params; |
| 115 |
|
| 116 |
int pkcs11_list_tokens(void); |
| 117 |
int pkcs11_find_token_auto(char **ret); |