]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/pkcs11-util.h
959e7c3e0d9c90f63760ab1898aae978beb81dcc
[thirdparty/systemd.git] / src / shared / pkcs11-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <stdbool.h>
5
6 #if HAVE_P11KIT
7 # include <p11-kit/p11-kit.h>
8 # include <p11-kit/uri.h>
9 #endif
10
11 #include "macro.h"
12 #include "openssl-util.h"
13 #include "time-util.h"
14
15 bool pkcs11_uri_valid(const char *uri);
16
17 #if HAVE_P11KIT
18 int uri_from_string(const char *p, P11KitUri **ret);
19
20 P11KitUri *uri_from_module_info(const CK_INFO *info);
21 P11KitUri *uri_from_slot_info(const CK_SLOT_INFO *slot_info);
22 P11KitUri *uri_from_token_info(const CK_TOKEN_INFO *token_info);
23
24 DEFINE_TRIVIAL_CLEANUP_FUNC(P11KitUri*, p11_kit_uri_free);
25 DEFINE_TRIVIAL_CLEANUP_FUNC(CK_FUNCTION_LIST**, p11_kit_modules_finalize_and_release);
26
27 CK_RV pkcs11_get_slot_list_malloc(CK_FUNCTION_LIST *m, CK_SLOT_ID **ret_slotids, CK_ULONG *ret_n_slotids);
28
29 char *pkcs11_token_label(const CK_TOKEN_INFO *token_info);
30 char *pkcs11_token_manufacturer_id(const CK_TOKEN_INFO *token_info);
31 char *pkcs11_token_model(const CK_TOKEN_INFO *token_info);
32
33 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 *keyname, usec_t until, char **ret_used_pin);
34
35 int pkcs11_token_find_x509_certificate(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, P11KitUri *search_uri, CK_OBJECT_HANDLE *ret_object);
36 #if HAVE_OPENSSL
37 int pkcs11_token_read_x509_certificate(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object, X509 **ret_cert);
38 #endif
39
40 int pkcs11_token_find_private_key(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session, P11KitUri *search_uri, CK_OBJECT_HANDLE *ret_object);
41 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);
42
43 int pkcs11_token_acquire_rng(CK_FUNCTION_LIST *m, CK_SESSION_HANDLE session);
44
45 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);
46 int pkcs11_find_token(const char *pkcs11_uri, pkcs11_find_token_callback_t callback, void *userdata);
47 #endif