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