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