Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

p11_session.h
Go to the documentation of this file.
1 /*
2 * PKCS#11 Session
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 #ifndef BOTAN_P11_SESSION_H_
10 #define BOTAN_P11_SESSION_H_
11
12 #include <botan/p11_slot.h>
13
14 #include <utility>
15
16 namespace Botan {
17 namespace PKCS11 {
18 class Module;
19
20 /// Represents a PKCS#11 session
21 class BOTAN_PUBLIC_API(2,0) Session final
22 {
23 public:
24 /**
25 * @param slot the slot to use
26 * @param read_only true if the session should be read only, false to create a read-write session
27 */
28 Session(Slot& slot, bool read_only);
29
30 /**
31 * @param slot the slot to use
32 * @param flags the flags to use for the session. Remark: Flag::SerialSession is mandatory
33 * @param callback_data application-defined pointer to be passed to the notification callback
34 * @param notify_callback address of the notification callback function
35 */
36 Session(Slot& slot, Flags flags, VoidPtr callback_data, Notify notify_callback);
37
38 /// Takes ownership of a session
39 Session(Slot& slot, SessionHandle handle);
40
41 Session(Session&& other) = default;
42 Session& operator=(Session&& other) = delete;
43
44 // Dtor calls C_CloseSession() and eventually C_Logout. A copy could close the session while the origin still exists
45 Session(const Session& other) = delete;
46 Session& operator=(const Session& other) = delete;
47
48 /// Logout user and close the session on destruction
49 ~Session() noexcept;
50
51 /// @return a reference to the slot
52 inline const Slot& slot() const
53 {
54 return m_slot;
55 }
56
57 /// @return the session handle of this session
58 inline SessionHandle handle() const
59 {
60 return m_handle;
61 }
62
63 /// @return a reference to the used module
64 inline Module& module() const
65 {
66 return m_slot.module();
67 }
68
69 /// @return the released session handle
70 SessionHandle release();
71
72 /**
73 * Login to this session
74 * @param userType the user type to use for the login
75 * @param pin the PIN of the user
76 */
77 void login(UserType userType, const secure_string& pin);
78
79 /// Logout from this session
80 void logoff();
81
82 /// @return information about this session
83 SessionInfo get_info() const;
84
85 /// Calls `C_SetPIN` to change the PIN using the old PIN (requires a logged in session)
86 void set_pin(const secure_string& old_pin, const secure_string& new_pin) const;
87
88 /// Calls `C_InitPIN` to change or initialize the PIN using the SO_PIN (requires a logged in session)
89 void init_pin(const secure_string& new_pin);
90
91 private:
92 const Slot& m_slot;
93 SessionHandle m_handle;
94 bool m_logged_in;
95 };
96
97 }
98 }
99
100 #endif
Botan::PKCS11::Notify
CK_NOTIFY Notify
Definition: p11.h:842
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:64
CK_SESSION_INFO
Definition: pkcs11t.h:279
Botan::PKCS11::set_pin
void set_pin(Slot &slot, const secure_string &so_pin, const secure_string &pin)
Definition: p11.cpp:66
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::PKCS11::VoidPtr
CK_VOID_PTR VoidPtr
Definition: p11.h:826
Botan::PKCS11::Module
Definition: p11_module.h:25
Botan::PKCS11::Session::handle
SessionHandle handle() const
Definition: p11_session.h:58
Botan::PKCS11::SessionHandle
CK_SESSION_HANDLE SessionHandle
Definition: p11.h:843
Botan
Definition: alg_id.cpp:13
Botan::PKCS11::Flags
CK_FLAGS Flags
Definition: p11.h:832
Botan::PKCS11::UserType
UserType
Definition: p11.h:812
Botan::PKCS11::secure_string
secure_vector< uint8_t > secure_string
Definition: p11.h:61
Botan::PKCS11::Session
Represents a PKCS#11 session.
Definition: p11_session.h:21
Botan::PKCS11::Slot
Represents a PKCS#11 Slot, i.e., a card reader.
Definition: p11_slot.h:22
Botan::PKCS11::Session::slot
const Slot & slot() const
Definition: p11_session.h:52