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