]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
839fddbe LP |
2 | #pragma once |
3 | ||
4 | #include <stdbool.h> | |
5 | ||
6 | #if HAVE_P11KIT | |
b012a1f4 ZJS |
7 | # include <p11-kit/p11-kit.h> |
8 | # include <p11-kit/uri.h> | |
839fddbe LP |
9 | #endif |
10 | ||
11 | #include "macro.h" | |
b012a1f4 | 12 | #include "openssl-util.h" |
839fddbe LP |
13 | #include "time-util.h" |
14 | ||
15 | bool pkcs11_uri_valid(const char *uri); | |
16 | ||
17 | #if HAVE_P11KIT | |
da035a3a LB |
18 | |
19 | extern char *(*sym_p11_kit_module_get_name)(CK_FUNCTION_LIST *module); | |
20 | extern void (*sym_p11_kit_modules_finalize_and_release)(CK_FUNCTION_LIST **modules); | |
21 | extern CK_FUNCTION_LIST **(*sym_p11_kit_modules_load_and_initialize)(int flags); | |
22 | extern const char *(*sym_p11_kit_strerror)(CK_RV rv); | |
23 | extern int (*sym_p11_kit_uri_format)(P11KitUri *uri, P11KitUriType uri_type, char **string); | |
24 | extern void (*sym_p11_kit_uri_free)(P11KitUri *uri); | |
25 | extern CK_ATTRIBUTE_PTR (*sym_p11_kit_uri_get_attributes)(P11KitUri *uri, CK_ULONG *n_attrs); | |
26 | extern CK_INFO_PTR (*sym_p11_kit_uri_get_module_info)(P11KitUri *uri); | |
27 | extern CK_SLOT_INFO_PTR (*sym_p11_kit_uri_get_slot_info)(P11KitUri *uri); | |
28 | extern CK_TOKEN_INFO_PTR (*sym_p11_kit_uri_get_token_info)(P11KitUri *uri); | |
29 | extern int (*sym_p11_kit_uri_match_token_info)(const P11KitUri *uri, const CK_TOKEN_INFO *token_info); | |
30 | extern const char *(*sym_p11_kit_uri_message)(int code); | |
31 | extern P11KitUri *(*sym_p11_kit_uri_new)(void); | |
32 | extern int (*sym_p11_kit_uri_parse)(const char *string, P11KitUriType uri_type, P11KitUri *uri); | |
33 | ||
839fddbe LP |
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 | ||
da035a3a LB |
40 | DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(P11KitUri*, sym_p11_kit_uri_free, NULL); |
41 | DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(CK_FUNCTION_LIST**, sym_p11_kit_modules_finalize_and_release, NULL); | |
839fddbe LP |
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); | |
0eb3be46 LP |
46 | char *pkcs11_token_manufacturer_id(const CK_TOKEN_INFO *token_info); |
47 | char *pkcs11_token_model(const CK_TOKEN_INFO *token_info); | |
839fddbe | 48 | |
0ff60566 | 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); |
cd5f57bd | 50 | int pkcs11_token_login(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_SLOT_ID slotid, const CK_TOKEN_INFO *token_info, const char *friendly_name, const char *icon_name, const char *key_name, const char *credential_name, usec_t until, bool headless, char **ret_used_pin); |
839fddbe LP |
51 | |
52 | int pkcs11_token_find_x509_certificate(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, P11KitUri *search_uri, CK_OBJECT_HANDLE *ret_object); | |
53 | #if HAVE_OPENSSL | |
54 | int pkcs11_token_read_x509_certificate(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, X509 **ret_cert); | |
55 | #endif | |
56 | ||
57 | int pkcs11_token_find_private_key(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, P11KitUri *search_uri, CK_OBJECT_HANDLE *ret_object); | |
58 | 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, void **ret_decrypted_data, size_t *ret_decrypted_data_size); | |
59 | ||
60 | int pkcs11_token_acquire_rng(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session); | |
61 | ||
62 | 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); | |
63 | int pkcs11_find_token(const char *pkcs11_uri, pkcs11_find_token_callback_t callback, void *userdata); | |
2289a784 LP |
64 | |
65 | #if HAVE_OPENSSL | |
66 | int pkcs11_acquire_certificate(const char *uri, const char *askpw_friendly_name, const char *askpw_icon_name, X509 **ret_cert, char **ret_pin_used); | |
67 | #endif | |
68 | ||
ed3d3af1 OK |
69 | typedef struct { |
70 | const char *friendly_name; | |
71 | usec_t until; | |
72 | void *encrypted_key; | |
73 | size_t encrypted_key_size; | |
74 | void *decrypted_key; | |
75 | size_t decrypted_key_size; | |
76 | bool free_encrypted_key; | |
77 | bool headless; | |
78 | } pkcs11_crypt_device_callback_data; | |
79 | ||
80 | void pkcs11_crypt_device_callback_data_release(pkcs11_crypt_device_callback_data *data); | |
81 | ||
82 | int pkcs11_crypt_device_callback( | |
83 | CK_FUNCTION_LIST *m, | |
84 | CK_SESSION_HANDLE session, | |
85 | CK_SLOT_ID slot_id, | |
86 | const CK_SLOT_INFO *slot_info, | |
87 | const CK_TOKEN_INFO *token_info, | |
88 | P11KitUri *uri, | |
89 | void *userdata); | |
90 | ||
da035a3a LB |
91 | int dlopen_p11kit(void); |
92 | ||
93 | #else | |
94 | ||
95 | static inline int dlopen_p11kit(void) { | |
96 | return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "p11kit support is not compiled in."); | |
97 | } | |
98 | ||
839fddbe | 99 | #endif |
f240cbb6 | 100 | |
8186022c OK |
101 | typedef struct { |
102 | const char *friendly_name; | |
103 | usec_t until; | |
104 | bool headless; | |
105 | } systemd_pkcs11_plugin_params; | |
106 | ||
f240cbb6 LP |
107 | int pkcs11_list_tokens(void); |
108 | int pkcs11_find_token_auto(char **ret); |