Botan 3.6.1
Crypto and TLS for C&
p11.cpp
Go to the documentation of this file.
1/*
2* PKCS#11
3* (C) 2016 Daniel Neus, Sirrix AG
4* (C) 2016 Philipp Weber, Sirrix AG
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/p11.h>
10
11#include <botan/p11_types.h>
12#include <botan/internal/dyn_load.h>
13
14#include <cstdint>
15#include <functional>
16#include <string>
17
18namespace Botan::PKCS11 {
19
20// NOLINTNEXTLINE(*-no-int-to-ptr,*-avoid-non-const-global-variables)
21ReturnValue* ThrowException = reinterpret_cast<ReturnValue*>(-1);
22
23/// @param function_result Return value of the PKCS11 module function
24/// @param return_value if (`ThrowException`) is passed the function throws an exception, otherwise if a non-NULL pointer is passed:
25/// return_value receives the return value of the PKCS#11 function and no exception is thrown.
26/// @return true if function call was successful, false otherwise
27bool LowLevel::handle_return_value(const CK_RV function_result, ReturnValue* return_value) {
28 if(return_value == ThrowException) {
29 if(static_cast<ReturnValue>(function_result) != ReturnValue::OK) {
30 // caller wants exception
31 throw PKCS11_ReturnError(static_cast<ReturnValue>(function_result));
32 }
33 } else if(return_value != nullptr) {
34 // caller wants return value
35 *return_value = static_cast<ReturnValue>(function_result);
36 }
37
38 return static_cast<ReturnValue>(function_result) == ReturnValue::OK;
39}
40
41void initialize_token(Slot& slot, std::string_view label, const secure_string& so_pin, const secure_string& pin) {
42 slot.initialize(label, so_pin);
43 set_pin(slot, so_pin, pin);
44}
45
46void change_pin(Slot& slot, const secure_string& old_pin, const secure_string& new_pin) {
47 Session session(slot, false);
48 session.login(UserType::User, old_pin);
49 session.set_pin(old_pin, new_pin);
50}
51
52void change_so_pin(Slot& slot, const secure_string& old_so_pin, const secure_string& new_so_pin) {
53 Session session(slot, false);
54 session.login(UserType::SO, old_so_pin);
55 session.set_pin(old_so_pin, new_so_pin);
56}
57
58void set_pin(Slot& slot, const secure_string& so_pin, const secure_string& pin) {
59 Session session(slot, false);
60 session.login(UserType::SO, so_pin);
61 session.init_pin(pin);
62}
63
64LowLevel::LowLevel(FunctionListPtr ptr) : m_func_list_ptr(ptr) {
65 if(m_func_list_ptr == nullptr) {
66 throw Invalid_Argument("Invalid PKCS#11 function list ptr");
67 }
68}
69
70/****************************** General purpose functions ******************************/
71
72bool LowLevel::C_Initialize(VoidPtr init_args, ReturnValue* return_value) const {
73 return handle_return_value(m_func_list_ptr->C_Initialize(init_args), return_value);
74}
75
76bool LowLevel::C_Finalize(VoidPtr reserved, ReturnValue* return_value) const {
77 return handle_return_value(m_func_list_ptr->C_Finalize(reserved), return_value);
78}
79
80bool LowLevel::C_GetInfo(Info* info_ptr, ReturnValue* return_value) const {
81 return handle_return_value(m_func_list_ptr->C_GetInfo(info_ptr), return_value);
82}
83
85 FunctionListPtr* function_list_ptr_ptr,
86 ReturnValue* return_value) {
87 using get_function_list = CK_RV (*)(FunctionListPtr*);
88
89 get_function_list get_function_list_ptr = pkcs11_module.resolve<get_function_list>("C_GetFunctionList");
90
91 return handle_return_value(get_function_list_ptr(function_list_ptr_ptr), return_value);
92}
93
94/****************************** Slot and token management functions ******************************/
95
96bool LowLevel::C_GetSlotList(Bbool token_present,
97 SlotId* slot_list_ptr,
98 Ulong* count_ptr,
99 ReturnValue* return_value) const {
100 return handle_return_value(m_func_list_ptr->C_GetSlotList(token_present, slot_list_ptr, count_ptr), return_value);
101}
102
103bool LowLevel::C_GetSlotList(bool token_present, std::vector<SlotId>& slot_ids, ReturnValue* return_value) const {
104 slot_ids.clear();
105
106 // first get available slots
107 Ulong number_slots = 0;
108
109 bool success = C_GetSlotList(token_present, nullptr, &number_slots, return_value);
110
111 if(!success || !number_slots) {
112 return success;
113 }
114
115 // get actual slot ids
116 slot_ids.resize(number_slots);
117 return C_GetSlotList(token_present, slot_ids.data(), &number_slots, return_value);
118}
119
120bool LowLevel::C_GetSlotInfo(SlotId slot_id, SlotInfo* info_ptr, ReturnValue* return_value) const {
121 return handle_return_value(m_func_list_ptr->C_GetSlotInfo(slot_id, info_ptr), return_value);
122}
123
124bool LowLevel::C_GetTokenInfo(SlotId slot_id, TokenInfo* info_ptr, ReturnValue* return_value) const {
125 return handle_return_value(m_func_list_ptr->C_GetTokenInfo(slot_id, info_ptr), return_value);
126}
127
128bool LowLevel::C_WaitForSlotEvent(Flags flags, SlotId* slot_ptr, VoidPtr reserved, ReturnValue* return_value) const {
129 return handle_return_value(m_func_list_ptr->C_WaitForSlotEvent(flags, slot_ptr, reserved), return_value);
130}
131
133 MechanismType* mechanism_list_ptr,
134 Ulong* count_ptr,
135 ReturnValue* return_value) const {
136 return handle_return_value(m_func_list_ptr->C_GetMechanismList(
137 slot_id, reinterpret_cast<CK_MECHANISM_TYPE_PTR>(mechanism_list_ptr), count_ptr),
138 return_value);
139}
140
142 std::vector<MechanismType>& mechanisms,
143 ReturnValue* return_value) const {
144 mechanisms.clear();
145
146 // first get number of mechanisms
147 Ulong number_mechanisms = 0;
148
149 bool success = C_GetMechanismList(slot_id, nullptr, &number_mechanisms, return_value);
150
151 if(!success || !number_mechanisms) {
152 return success;
153 }
154
155 // get actual mechanisms
156 mechanisms.resize(number_mechanisms);
157 return C_GetMechanismList(
158 slot_id, reinterpret_cast<MechanismType*>(mechanisms.data()), &number_mechanisms, return_value);
159}
160
162 MechanismType type,
163 MechanismInfo* info_ptr,
164 ReturnValue* return_value) const {
165 return handle_return_value(
166 m_func_list_ptr->C_GetMechanismInfo(slot_id, static_cast<CK_MECHANISM_TYPE>(type), info_ptr), return_value);
167}
168
170 SlotId slot_id, Utf8Char* so_pin_ptr, Ulong so_pin_len, Utf8Char* label_ptr, ReturnValue* return_value) const {
171 return handle_return_value(m_func_list_ptr->C_InitToken(slot_id, so_pin_ptr, so_pin_len, label_ptr), return_value);
172}
173
174bool LowLevel::C_InitPIN(SessionHandle session, Utf8Char* pin_ptr, Ulong pin_len, ReturnValue* return_value) const {
175 return handle_return_value(m_func_list_ptr->C_InitPIN(session, pin_ptr, pin_len), return_value);
176}
177
179 Utf8Char* old_pin_ptr,
180 Ulong old_len,
181 Utf8Char* new_pin_ptr,
182 Ulong new_len,
183 ReturnValue* return_value) const {
184 return handle_return_value(m_func_list_ptr->C_SetPIN(session, old_pin_ptr, old_len, new_pin_ptr, new_len),
185 return_value);
186}
187
188/****************************** Session management ******************************/
189
191 Flags flags,
192 VoidPtr application,
193 Notify notify,
194 SessionHandle* session_ptr,
195 ReturnValue* return_value) const {
196 return handle_return_value(m_func_list_ptr->C_OpenSession(slot_id, flags, application, notify, session_ptr),
197 return_value);
198}
199
200bool LowLevel::C_CloseSession(SessionHandle session, ReturnValue* return_value) const {
201 return handle_return_value(m_func_list_ptr->C_CloseSession(session), return_value);
202}
203
204bool LowLevel::C_CloseAllSessions(SlotId slot_id, ReturnValue* return_value) const {
205 return handle_return_value(m_func_list_ptr->C_CloseAllSessions(slot_id), return_value);
206}
207
208bool LowLevel::C_GetSessionInfo(SessionHandle session, SessionInfo* info_ptr, ReturnValue* return_value) const {
209 return handle_return_value(m_func_list_ptr->C_GetSessionInfo(session, info_ptr), return_value);
210}
211
213 Byte* operation_state_ptr,
214 Ulong* operation_state_len_ptr,
215 ReturnValue* return_value) const {
216 return handle_return_value(
217 m_func_list_ptr->C_GetOperationState(session, operation_state_ptr, operation_state_len_ptr), return_value);
218}
219
221 Byte* operation_state_ptr,
222 Ulong operation_state_len,
223 ObjectHandle encryption_key,
224 ObjectHandle authentication_key,
225 ReturnValue* return_value) const {
226 return handle_return_value(m_func_list_ptr->C_SetOperationState(
227 session, operation_state_ptr, operation_state_len, encryption_key, authentication_key),
228 return_value);
229}
230
232 SessionHandle session, UserType user_type, Utf8Char* pin_ptr, Ulong pin_len, ReturnValue* return_value) const {
233 return handle_return_value(m_func_list_ptr->C_Login(session, static_cast<CK_USER_TYPE>(user_type), pin_ptr, pin_len),
234 return_value);
235}
236
237bool LowLevel::C_Logout(SessionHandle session, ReturnValue* return_value) const {
238 return handle_return_value(m_func_list_ptr->C_Logout(session), return_value);
239}
240
241/****************************** Object management functions ******************************/
242
244 Attribute* attribute_template_ptr,
245 Ulong count,
246 ObjectHandle* object_ptr,
247 ReturnValue* return_value) const {
248 return handle_return_value(m_func_list_ptr->C_CreateObject(session, attribute_template_ptr, count, object_ptr),
249 return_value);
250}
251
253 ObjectHandle object,
254 Attribute* attribute_template_ptr,
255 Ulong count,
256 ObjectHandle* new_object_ptr,
257 ReturnValue* return_value) const {
258 return handle_return_value(
259 m_func_list_ptr->C_CopyObject(session, object, attribute_template_ptr, count, new_object_ptr), return_value);
260}
261
262bool LowLevel::C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue* return_value) const {
263 return handle_return_value(m_func_list_ptr->C_DestroyObject(session, object), return_value);
264}
265
267 ObjectHandle object,
268 Ulong* size_ptr,
269 ReturnValue* return_value) const {
270 return handle_return_value(m_func_list_ptr->C_GetObjectSize(session, object, size_ptr), return_value);
271}
272
274 ObjectHandle object,
275 Attribute* attribute_template_ptr,
276 Ulong count,
277 ReturnValue* return_value) const {
278 return handle_return_value(m_func_list_ptr->C_GetAttributeValue(session, object, attribute_template_ptr, count),
279 return_value);
280}
281
283 ObjectHandle object,
284 Attribute* attribute_template_ptr,
285 Ulong count,
286 ReturnValue* return_value) const {
287 return handle_return_value(m_func_list_ptr->C_SetAttributeValue(session, object, attribute_template_ptr, count),
288 return_value);
289}
290
292 Attribute* attribute_template_ptr,
293 Ulong count,
294 ReturnValue* return_value) const {
295 return handle_return_value(m_func_list_ptr->C_FindObjectsInit(session, attribute_template_ptr, count), return_value);
296}
297
299 ObjectHandle* object_ptr,
300 Ulong max_object_count,
301 Ulong* object_count_ptr,
302 ReturnValue* return_value) const {
303 return handle_return_value(m_func_list_ptr->C_FindObjects(session, object_ptr, max_object_count, object_count_ptr),
304 return_value);
305}
306
307bool LowLevel::C_FindObjectsFinal(SessionHandle session, ReturnValue* return_value) const {
308 return handle_return_value(m_func_list_ptr->C_FindObjectsFinal(session), return_value);
309}
310
311/****************************** Encryption functions ******************************/
312
314 Mechanism* mechanism_ptr,
315 ObjectHandle key,
316 ReturnValue* return_value) const {
317 return handle_return_value(m_func_list_ptr->C_EncryptInit(session, mechanism_ptr, key), return_value);
318}
319
321 Byte* data_ptr,
322 Ulong data_len,
323 Byte* encrypted_data_ptr,
324 Ulong* encrypted_data_len_ptr,
325 ReturnValue* return_value) const {
326 return handle_return_value(
327 m_func_list_ptr->C_Encrypt(session, data_ptr, data_len, encrypted_data_ptr, encrypted_data_len_ptr),
328 return_value);
329}
330
332 Byte* part_ptr,
333 Ulong part_len,
334 Byte* encrypted_part_ptr,
335 Ulong* encrypted_part_len_ptr,
336 ReturnValue* return_value) const {
337 return handle_return_value(
338 m_func_list_ptr->C_EncryptUpdate(session, part_ptr, part_len, encrypted_part_ptr, encrypted_part_len_ptr),
339 return_value);
340}
341
343 Byte* last_encrypted_part_ptr,
344 Ulong* last_encrypted_part_len_ptr,
345 ReturnValue* return_value) const {
346 return handle_return_value(
347 m_func_list_ptr->C_EncryptFinal(session, last_encrypted_part_ptr, last_encrypted_part_len_ptr), return_value);
348}
349
350/****************************** Decryption functions ******************************/
351
353 Mechanism* mechanism_ptr,
354 ObjectHandle key,
355 ReturnValue* return_value) const {
356 return handle_return_value(m_func_list_ptr->C_DecryptInit(session, mechanism_ptr, key), return_value);
357}
358
360 Byte* encrypted_data_ptr,
361 Ulong encrypted_data_len,
362 Byte* data_ptr,
363 Ulong* data_len_ptr,
364 ReturnValue* return_value) const {
365 return handle_return_value(
366 m_func_list_ptr->C_Decrypt(session, encrypted_data_ptr, encrypted_data_len, data_ptr, data_len_ptr),
367 return_value);
368}
369
371 Byte* encrypted_part_ptr,
372 Ulong encrypted_part_len,
373 Byte* part_ptr,
374 Ulong* part_len_ptr,
375 ReturnValue* return_value) const {
376 return handle_return_value(
377 m_func_list_ptr->C_DecryptUpdate(session, encrypted_part_ptr, encrypted_part_len, part_ptr, part_len_ptr),
378 return_value);
379}
380
382 Byte* last_part_ptr,
383 Ulong* last_part_len_ptr,
384 ReturnValue* return_value) const {
385 return handle_return_value(m_func_list_ptr->C_DecryptFinal(session, last_part_ptr, last_part_len_ptr), return_value);
386}
387
388/****************************** Message digesting functions ******************************/
389
390bool LowLevel::C_DigestInit(SessionHandle session, Mechanism* mechanism, ReturnValue* return_value) const {
391 return handle_return_value(m_func_list_ptr->C_DigestInit(session, mechanism), return_value);
392}
393
395 Byte* data_ptr,
396 Ulong data_len,
397 Byte* digest_ptr,
398 Ulong* digest_len_ptr,
399 ReturnValue* return_value) const {
400 return handle_return_value(m_func_list_ptr->C_Digest(session, data_ptr, data_len, digest_ptr, digest_len_ptr),
401 return_value);
402}
403
404bool LowLevel::C_DigestUpdate(SessionHandle session, Byte* part_ptr, Ulong part_len, ReturnValue* return_value) const {
405 return handle_return_value(m_func_list_ptr->C_DigestUpdate(session, part_ptr, part_len), return_value);
406}
407
408bool LowLevel::C_DigestKey(SessionHandle session, ObjectHandle key, ReturnValue* return_value) const {
409 return handle_return_value(m_func_list_ptr->C_DigestKey(session, key), return_value);
410}
411
413 Byte* digest_ptr,
414 Ulong* digest_len_ptr,
415 ReturnValue* return_value) const {
416 return handle_return_value(m_func_list_ptr->C_DigestFinal(session, digest_ptr, digest_len_ptr), return_value);
417}
418
419/****************************** Signing and MACing functions ******************************/
420
422 Mechanism* mechanism_ptr,
423 ObjectHandle key,
424 ReturnValue* return_value) const {
425 return handle_return_value(m_func_list_ptr->C_SignInit(session, mechanism_ptr, key), return_value);
426}
427
429 const Byte* data_ptr,
430 Ulong data_len,
431 Byte* signature_ptr,
432 Ulong* signature_len_ptr,
433 ReturnValue* return_value) const {
434 return handle_return_value(
435 m_func_list_ptr->C_Sign(session, const_cast<Byte*>(data_ptr), data_len, signature_ptr, signature_len_ptr),
436 return_value);
437}
438
440 const Byte* part_ptr,
441 Ulong part_len,
442 ReturnValue* return_value) const {
443 return handle_return_value(m_func_list_ptr->C_SignUpdate(session, const_cast<Byte*>(part_ptr), part_len),
444 return_value);
445}
446
448 Byte* signature_ptr,
449 Ulong* signature_len_ptr,
450 ReturnValue* return_value) const {
451 return handle_return_value(m_func_list_ptr->C_SignFinal(session, signature_ptr, signature_len_ptr), return_value);
452}
453
455 Mechanism* mechanism_ptr,
456 ObjectHandle key,
457 ReturnValue* return_value) const {
458 return handle_return_value(m_func_list_ptr->C_SignRecoverInit(session, mechanism_ptr, key), return_value);
459}
460
462 Byte* data,
463 Ulong data_len,
464 Byte* signature,
465 Ulong* signature_len,
466 ReturnValue* return_value) const {
467 return handle_return_value(m_func_list_ptr->C_SignRecover(session, data, data_len, signature, signature_len),
468 return_value);
469}
470
471/****************************** Functions for verifying signatures and MACs ******************************/
472
474 Mechanism* mechanism_ptr,
475 ObjectHandle key,
476 ReturnValue* return_value) const {
477 return handle_return_value(m_func_list_ptr->C_VerifyInit(session, mechanism_ptr, key), return_value);
478}
479
481 const Byte* data_ptr,
482 Ulong data_len,
483 const Byte* signature_ptr,
484 Ulong signature_len,
485 ReturnValue* return_value) const {
486 return handle_return_value(
487 m_func_list_ptr->C_Verify(
488 session, const_cast<Byte*>(data_ptr), data_len, const_cast<Byte*>(signature_ptr), signature_len),
489 return_value);
490}
491
493 const Byte* part_ptr,
494 Ulong part_len,
495 ReturnValue* return_value) const {
496 return handle_return_value(m_func_list_ptr->C_VerifyUpdate(session, const_cast<Byte*>(part_ptr), part_len),
497 return_value);
498}
499
501 const Byte* signature_ptr,
502 Ulong signature_len,
503 ReturnValue* return_value) const {
504 return handle_return_value(m_func_list_ptr->C_VerifyFinal(session, const_cast<Byte*>(signature_ptr), signature_len),
505 return_value);
506}
507
509 Mechanism* mechanism_ptr,
510 ObjectHandle key,
511 ReturnValue* return_value) const {
512 return handle_return_value(m_func_list_ptr->C_VerifyRecoverInit(session, mechanism_ptr, key), return_value);
513}
514
516 Byte* signature_ptr,
517 Ulong signature_len,
518 Byte* data_ptr,
519 Ulong* data_len_ptr,
520 ReturnValue* return_value) const {
521 return handle_return_value(
522 m_func_list_ptr->C_VerifyRecover(session, signature_ptr, signature_len, data_ptr, data_len_ptr), return_value);
523}
524
525/****************************** Dual-purpose cryptographic functions ******************************/
526
528 Byte* part_ptr,
529 Ulong part_len,
530 Byte* encrypted_part_ptr,
531 Ulong* encrypted_part_len_ptr,
532 ReturnValue* return_value) const {
533 return handle_return_value(
534 m_func_list_ptr->C_DigestEncryptUpdate(session, part_ptr, part_len, encrypted_part_ptr, encrypted_part_len_ptr),
535 return_value);
536}
537
539 Byte* encrypted_part_ptr,
540 Ulong encrypted_part_len,
541 Byte* part_ptr,
542 Ulong* part_len_ptr,
543 ReturnValue* return_value) const {
544 return handle_return_value(
545 m_func_list_ptr->C_DecryptDigestUpdate(session, encrypted_part_ptr, encrypted_part_len, part_ptr, part_len_ptr),
546 return_value);
547}
548
550 Byte* part_ptr,
551 Ulong part_len,
552 Byte* encrypted_part_ptr,
553 Ulong* encrypted_part_len_ptr,
554 ReturnValue* return_value) const {
555 return handle_return_value(
556 m_func_list_ptr->C_SignEncryptUpdate(session, part_ptr, part_len, encrypted_part_ptr, encrypted_part_len_ptr),
557 return_value);
558}
559
561 Byte* encrypted_part_ptr,
562 Ulong encrypted_part_len,
563 Byte* part_ptr,
564 Ulong* part_len_ptr,
565 ReturnValue* return_value) const {
566 return handle_return_value(
567 m_func_list_ptr->C_DecryptVerifyUpdate(session, encrypted_part_ptr, encrypted_part_len, part_ptr, part_len_ptr),
568 return_value);
569}
570
571/****************************** Key management functions ******************************/
572
574 Mechanism* mechanism_ptr,
575 Attribute* attribute_template_ptr,
576 Ulong count,
577 ObjectHandle* key_ptr,
578 ReturnValue* return_value) const {
579 return handle_return_value(
580 m_func_list_ptr->C_GenerateKey(session, mechanism_ptr, attribute_template_ptr, count, key_ptr), return_value);
581}
582
584 Mechanism* mechanism_ptr,
585 Attribute* public_key_template_ptr,
586 Ulong public_key_attribute_count,
587 Attribute* private_key_template_ptr,
588 Ulong private_key_attribute_count,
589 ObjectHandle* public_key_ptr,
590 ObjectHandle* private_key_ptr,
591 ReturnValue* return_value) const {
592 return handle_return_value(m_func_list_ptr->C_GenerateKeyPair(session,
593 mechanism_ptr,
594 public_key_template_ptr,
595 public_key_attribute_count,
596 private_key_template_ptr,
597 private_key_attribute_count,
598 public_key_ptr,
599 private_key_ptr),
600 return_value);
601}
602
604 Mechanism* mechanism_ptr,
605 ObjectHandle wrapping_key,
606 ObjectHandle key,
607 Byte* wrapped_key_ptr,
608 Ulong* wrapped_key_len_ptr,
609 ReturnValue* return_value) const {
610 return handle_return_value(
611 m_func_list_ptr->C_WrapKey(session, mechanism_ptr, wrapping_key, key, wrapped_key_ptr, wrapped_key_len_ptr),
612 return_value);
613}
614
616 Mechanism* mechanism_ptr,
617 ObjectHandle unwrapping_key,
618 Byte* wrapped_key_ptr,
619 Ulong wrapped_key_len,
620 Attribute* attribute_template_ptr,
621 Ulong attribute_count,
622 ObjectHandle* key_ptr,
623 ReturnValue* return_value) const {
624 return handle_return_value(m_func_list_ptr->C_UnwrapKey(session,
625 mechanism_ptr,
626 unwrapping_key,
627 wrapped_key_ptr,
628 wrapped_key_len,
629 attribute_template_ptr,
630 attribute_count,
631 key_ptr),
632 return_value);
633}
634
636 Mechanism* mechanism_ptr,
637 ObjectHandle base_key,
638 Attribute* attribute_template_ptr,
639 Ulong attribute_count,
640 ObjectHandle* key_ptr,
641 ReturnValue* return_value) const {
642 return handle_return_value(
643 m_func_list_ptr->C_DeriveKey(session, mechanism_ptr, base_key, attribute_template_ptr, attribute_count, key_ptr),
644 return_value);
645}
646
647/****************************** Random number generation functions ******************************/
648
650 const Byte* seed_ptr,
651 Ulong seed_len,
652 ReturnValue* return_value) const {
653 return handle_return_value(m_func_list_ptr->C_SeedRandom(session, const_cast<Byte*>(seed_ptr), seed_len),
654 return_value);
655}
656
658 Byte* random_data_ptr,
659 Ulong random_len,
660 ReturnValue* return_value) const {
661 return handle_return_value(m_func_list_ptr->C_GenerateRandom(session, random_data_ptr, random_len), return_value);
662}
663
664/****************************** Parallel function management functions ******************************/
665
666bool LowLevel::C_GetFunctionStatus(SessionHandle session, ReturnValue* return_value) const {
667 return handle_return_value(m_func_list_ptr->C_GetFunctionStatus(session), return_value);
668}
669
670bool LowLevel::C_CancelFunction(SessionHandle session, ReturnValue* return_value) const {
671 return handle_return_value(m_func_list_ptr->C_CancelFunction(session), return_value);
672}
673
674} // namespace Botan::PKCS11
T resolve(const std::string &symbol)
Definition dyn_load.h:52
bool C_CancelFunction(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:670
bool C_Finalize(VoidPtr reserved, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:76
bool C_GetSessionInfo(SessionHandle session, SessionInfo *info_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:208
bool C_DecryptUpdate(SessionHandle session, Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:370
bool C_Logout(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:237
bool C_GetOperationState(SessionHandle session, Byte *operation_state_ptr, Ulong *operation_state_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:212
bool C_DigestKey(SessionHandle session, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:408
bool C_EncryptInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:313
bool C_WaitForSlotEvent(Flags flags, SlotId *slot_ptr, VoidPtr reserved, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:128
bool C_GetTokenInfo(SlotId slot_id, TokenInfo *info_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:124
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:282
static bool C_GetFunctionList(Dynamically_Loaded_Library &pkcs11_module, FunctionListPtr *function_list_ptr_ptr, ReturnValue *return_value=ThrowException)
Definition p11.cpp:84
bool C_DecryptFinal(SessionHandle session, Byte *last_part_ptr, Ulong *last_part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:381
bool C_SignInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:421
LowLevel(FunctionListPtr ptr)
Definition p11.cpp:64
bool C_GetSlotInfo(SlotId slot_id, SlotInfo *info_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:120
bool C_EncryptFinal(SessionHandle session, Byte *last_encrypted_part_ptr, Ulong *last_encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:342
bool C_DecryptInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:352
bool C_FindObjectsInit(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:291
bool C_VerifyUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:492
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:273
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:262
bool C_Digest(SessionHandle session, Byte *data_ptr, Ulong data_len, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:394
bool C_OpenSession(SlotId slot_id, Flags flags, VoidPtr application, Notify notify, SessionHandle *session_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:190
bool C_DeriveKey(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle base_key, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:635
bool C_VerifyRecoverInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:508
bool C_InitPIN(SessionHandle session, Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:174
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:252
bool C_SignEncryptUpdate(SessionHandle session, Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:549
bool C_Initialize(VoidPtr init_args, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:72
bool C_GenerateRandom(SessionHandle session, Byte *random_data_ptr, Ulong random_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:657
bool C_DigestEncryptUpdate(SessionHandle session, Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:527
bool C_VerifyInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:473
bool C_Sign(SessionHandle session, const Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:428
bool C_GetFunctionStatus(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:666
bool C_CloseSession(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:200
bool C_DigestInit(SessionHandle session, Mechanism *mechanism_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:390
bool C_GenerateKeyPair(SessionHandle session, Mechanism *mechanism_ptr, Attribute *public_key_template_ptr, Ulong public_key_attribute_count, Attribute *private_key_template_ptr, Ulong private_key_attribute_count, ObjectHandle *public_key_ptr, ObjectHandle *private_key_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:583
bool C_SignUpdate(SessionHandle session, const Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:439
bool C_SignRecoverInit(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:454
bool C_GetInfo(Info *info_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:80
bool C_WrapKey(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle wrapping_key, ObjectHandle key, Byte *wrapped_key_ptr, Ulong *wrapped_key_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:603
bool C_SignRecover(SessionHandle session, Byte *data_ptr, Ulong data_len, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:461
bool C_GetMechanismList(SlotId slot_id, MechanismType *mechanism_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:132
bool C_DigestUpdate(SessionHandle session, Byte *part_ptr, Ulong part_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:404
bool C_FindObjectsFinal(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:307
static bool handle_return_value(CK_RV function_result, ReturnValue *return_value)
Definition p11.cpp:27
bool C_Decrypt(SessionHandle session, Byte *encrypted_data_ptr, Ulong encrypted_data_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:359
bool C_SetOperationState(SessionHandle session, Byte *operation_state_ptr, Ulong operation_state_len, ObjectHandle encryption_key, ObjectHandle authentication_key, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:220
bool C_CloseAllSessions(SlotId slot_id, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:204
bool C_DecryptVerifyUpdate(SessionHandle session, Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:560
bool C_SeedRandom(SessionHandle session, const Byte *seed_ptr, Ulong seed_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:649
bool C_CreateObject(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *object_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:243
bool C_VerifyRecover(SessionHandle session, Byte *signature_ptr, Ulong signature_len, Byte *data_ptr, Ulong *data_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:515
bool C_DecryptDigestUpdate(SessionHandle session, Byte *encrypted_part_ptr, Ulong encrypted_part_len, Byte *part_ptr, Ulong *part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:538
bool C_GenerateKey(SessionHandle session, Mechanism *mechanism_ptr, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:573
bool C_FindObjects(SessionHandle session, ObjectHandle *object_ptr, Ulong max_object_count, Ulong *object_count_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:298
bool C_Encrypt(SessionHandle session, Byte *data_ptr, Ulong data_len, Byte *encrypted_data, Ulong *encrypted_data_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:320
bool C_GetSlotList(Bbool token_present, SlotId *slot_list_ptr, Ulong *count_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:96
bool C_GetMechanismInfo(SlotId slot_id, MechanismType type, MechanismInfo *info_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:161
bool C_VerifyFinal(SessionHandle session, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:500
bool C_Login(SessionHandle session, UserType user_type, Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:231
bool C_SignFinal(SessionHandle session, Byte *signature_ptr, Ulong *signature_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:447
bool C_InitToken(SlotId slot_id, Utf8Char *so_pin_ptr, Ulong so_pin_len, Utf8Char *label_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:169
bool C_DigestFinal(SessionHandle session, Byte *digest_ptr, Ulong *digest_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:412
bool C_Verify(SessionHandle session, const Byte *data_ptr, Ulong data_len, const Byte *signature_ptr, Ulong signature_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:480
bool C_GetObjectSize(SessionHandle session, ObjectHandle object, Ulong *size_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:266
bool C_SetPIN(SessionHandle session, Utf8Char *old_pin_ptr, Ulong old_len, Utf8Char *new_pin_ptr, Ulong new_len, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:178
bool C_UnwrapKey(SessionHandle session, Mechanism *mechanism_ptr, ObjectHandle unwrapping_key, Byte *wrapped_key_ptr, Ulong wrapped_key_len, Attribute *attribute_template_ptr, Ulong attribute_count, ObjectHandle *key_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:615
bool C_EncryptUpdate(SessionHandle session, Byte *part_ptr, Ulong part_len, Byte *encrypted_part_ptr, Ulong *encrypted_part_len_ptr, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:331
Represents a PKCS#11 session.
Definition p11_types.h:121
void set_pin(const secure_string &old_pin, const secure_string &new_pin)
Calls C_SetPIN to change the PIN using the old PIN (requires a logged in session)
void init_pin(const secure_string &new_pin)
Calls C_InitPIN to change or initialize the PIN using the SO_PIN (requires a logged in session)
void login(UserType userType, const secure_string &pin)
Represents a PKCS#11 Slot, i.e., a card reader.
Definition p11_types.h:74
void initialize(std::string_view label, const secure_string &so_pin) const
Definition p11_slot.cpp:45
CK_SLOT_ID SlotId
Definition p11.h:815
ReturnValue * ThrowException
Definition p11.cpp:21
secure_vector< uint8_t > secure_string
Definition p11.h:59
CK_NOTIFY Notify
Definition p11.h:822
void change_pin(Slot &slot, const secure_string &old_pin, const secure_string &new_pin)
Definition p11.cpp:46
CK_OBJECT_HANDLE ObjectHandle
Definition p11.h:826
void change_so_pin(Slot &slot, const secure_string &old_so_pin, const secure_string &new_so_pin)
Definition p11.cpp:52
CK_FUNCTION_LIST_PTR FunctionListPtr
Definition p11.h:805
CK_BYTE Byte
Definition p11.h:827
CK_VOID_PTR VoidPtr
Definition p11.h:806
CK_FLAGS Flags
Definition p11.h:812
CK_UTF8CHAR Utf8Char
Definition p11.h:821
CK_ULONG Ulong
Definition p11.h:816
CK_BBOOL Bbool
Definition p11.h:814
void set_pin(Slot &slot, const secure_string &so_pin, const secure_string &pin)
Definition p11.cpp:58
Flags flags(Flag flags)
Definition p11.h:838
void initialize_token(Slot &slot, std::string_view label, const secure_string &so_pin, const secure_string &pin)
Definition p11.cpp:41
CK_SESSION_HANDLE SessionHandle
Definition p11.h:823
CK_ULONG CK_RV
Definition pkcs11t.h:1036
CK_MECHANISM_TYPE CK_PTR CK_MECHANISM_TYPE_PTR
Definition pkcs11t.h:977
CK_ULONG CK_USER_TYPE
Definition pkcs11t.h:262
CK_ULONG CK_MECHANISM_TYPE
Definition pkcs11t.h:583