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