Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::PKCS11::Session Class Referencefinal

Represents a PKCS#11 session. More...

`#include <p11_session.h>`

## Public Member Functions
SessionInfo | get_info () const
SessionHandle | handle () const
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) More...
void | login (UserType userType, const secure_string &pin)
void | logoff ()
| Logout from this session. More...
Module & | module () const
Session & | operator= (Session &&other)=default
Session & | operator= (const Session &other)=delete
SessionHandle | release ()
| Session (Slot &slot, bool read_only)
| Session (Slot &slot, Flags flags, VoidPtr callback_data, Notify notify_callback)
| Session (Slot &slot, SessionHandle handle)
| Takes ownership of a session. More...
| Session (Session &&other)=default
| Session (const Session &other)=delete
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) More...
const Slot & | slot () const
| ~Session () BOTAN_NOEXCEPT
| Logout user and close the session on destruction. More...

## Detailed Description

Represents a PKCS#11 session.

Definition at line 22 of file p11_session.h.

## Constructor & Destructor Documentation

Botan::PKCS11::Session::Session | ( | Slot & | slot,
|  | bool | read_only
| ) |  |

Parameters

  slot | the slot to use
  read_only | true if the session should be read only, false to create a read-write session

Definition at line 14 of file p11_session.cpp.

References Botan::PKCS11::None, Botan::PKCS11::RwSession, and Botan::PKCS11::SerialSession.

15 : Session(slot, PKCS11::flags(Flag::SerialSession | (read_only ? Flag::None : Flag::RwSession)), nullptr, nullptr)
16 {}
Botan::PKCS11::Flag::None
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
Botan::PKCS11::Session::Session
Session(Slot &slot, bool read_only)
Definition: p11_session.cpp:14
Botan::PKCS11::Flag::RwSession
Botan::PKCS11::Flag::SerialSession
Botan::PKCS11::Session::slot
const Slot & slot() const
Definition: p11_session.h:57

Botan::PKCS11::Session::Session | ( | Slot & | slot,
|  | Flags | flags,
|  | VoidPtr | callback_data,
|  | Notify | notify_callback
| ) |  |

Parameters

  slot | the slot to use
  flags | the flags to use for the session. Remark: Flag::SerialSession is mandatory
  callback_data | application-defined pointer to be passed to the notification callback
  notify_callback | address of the notification callback function

Definition at line 18 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_OpenSession(), Botan::PKCS11::flags(), module(), and Botan::PKCS11::Slot::slot_id().

19 : m_slot(slot), m_handle(0), m_logged_in(false)
20 {
21 module()->C_OpenSession(m_slot.slot_id(), flags, callback_data, notify_callback, &m_handle);
22 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::Slot::slot_id
SlotId slot_id() const
Definition: p11_slot.h:39
Botan::PKCS11::LowLevel::C_OpenSession
bool C_OpenSession(SlotId slot_id, Flags flags, VoidPtr application, Notify notify, SessionHandle *session_ptr, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:235
Botan::PKCS11::Session::slot
const Slot & slot() const
Definition: p11_session.h:57

Botan::PKCS11::Session::Session | ( | Slot & | slot,
|  | SessionHandle | handle
| ) |  |

Takes ownership of a session.

Definition at line 24 of file p11_session.cpp.

References get_info(), Botan::PKCS11::RoPublicSession, Botan::PKCS11::RwPublicSession, and CK_SESSION_INFO::state.

25 : m_slot(slot), m_handle(handle)
26 {
27 SessionInfo info = get_info();
28 if(info.state == static_cast<CK_STATE>(SessionState::RoPublicSession)
29 || info.state == static_cast<CK_STATE>(SessionState::RwPublicSession))
30 {
31 m_logged_in = false;
32 }
33 else
34 {
35 m_logged_in = true;
36 }
37 }
Botan::PKCS11::SessionState::RwPublicSession
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::SessionInfo
CK_SESSION_INFO SessionInfo
Definition: p11.h:844
Botan::PKCS11::Session::handle
SessionHandle handle() const
Definition: p11_session.h:63
Botan::PKCS11::Session::get_info
SessionInfo get_info() const
Definition: p11_session.cpp:78
Botan::PKCS11::SessionState::RoPublicSession
Botan::PKCS11::Session::slot
const Slot & slot() const
Definition: p11_session.h:57

Botan::PKCS11::Session::Session | ( | Session && | other | ) |
| default

Botan::PKCS11::Session::Session | ( | const Session & | other | ) |
| delete

Botan::PKCS11::Session::~Session | ( |  | ) |

Logout user and close the session on destruction.

Definition at line 39 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_CloseSession(), Botan::PKCS11::LowLevel::C_Logout(), and module().

40 {
41 try
42 {
43 if(m_handle)
44 {
45 if(m_logged_in)
46 {
47 module()->C_Logout(m_handle, nullptr);
48 }
49 module()->C_CloseSession(m_handle, nullptr);
50 m_handle = 0;
51 }
52 }
53 catch(...)
54 {
55 // exception during noexcept destructor is ignored
56 }
57 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::LowLevel::C_CloseSession
bool C_CloseSession(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:246
Botan::PKCS11::LowLevel::C_Logout
bool C_Logout(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:295

## Member Function Documentation

SessionInfo Botan::PKCS11::Session::get_info | ( |  | ) | const

Returns
  information about this session

Definition at line 78 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_GetSessionInfo(), and module().

Referenced by Session().

79 {
80 SessionInfo info;
81 module()->C_GetSessionInfo(m_handle, &info);
82 return info;
83 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::SessionInfo
CK_SESSION_INFO SessionInfo
Definition: p11.h:844
Botan::PKCS11::LowLevel::C_GetSessionInfo
bool C_GetSessionInfo(SessionHandle session, SessionInfo *info_ptr, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:258

SessionHandle Botan::PKCS11::Session::handle | ( |  | ) | const
| inline

Returns
  the session handle of this session

Definition at line 63 of file p11_session.h.

References m_handle.

Referenced by release().

64 {
65 return m_handle;
66 }
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45

void Botan::PKCS11::Session::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 at line 90 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_InitPIN(), and module().

Referenced by Botan::PKCS11::set_pin().

91 {
92 module()->C_InitPIN(m_handle, new_pin);
93 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
Botan::PKCS11::LowLevel::C_InitPIN
bool C_InitPIN(SessionHandle session, Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:214
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45

void Botan::PKCS11::Session::login | ( | UserType | userType,
|  | const secure_string & | pin
| ) |  |

Login to this session

Parameters

  userType | the user type to use for the login
  pin | the PIN of the user

Definition at line 66 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_Login(), and module().

Referenced by Botan::PKCS11::change_pin(), Botan::PKCS11::change_so_pin(), and Botan::PKCS11::set_pin().

67 {
68 module()->C_Login(m_handle, user_type, pin);
69 m_logged_in = true;
70 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::LowLevel::C_Login
bool C_Login(SessionHandle session, UserType user_type, Utf8Char *pin_ptr, Ulong pin_len, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:285

void Botan::PKCS11::Session::logoff | ( |  | ) |

Logout from this session.

Definition at line 72 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_Logout(), and module().

73 {
74 module()->C_Logout(m_handle);
75 m_logged_in = false;
76 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::LowLevel::C_Logout
bool C_Logout(SessionHandle session, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:295

Module& Botan::PKCS11::Session::module | ( |  | ) | const
| inline

Returns
  a reference to the used module

Definition at line 69 of file p11_session.h.

Referenced by get_info(), init_pin(), login(), logoff(), Session(), set_pin(), and ~Session().

70 {
71 return m_slot.module();
72 }
Botan::PKCS11::Slot::module
Module & module() const
Definition: p11_slot.h:33

Session& Botan::PKCS11::Session::operator= | ( | Session && | other | ) |
| default

Session& Botan::PKCS11::Session::operator= | ( | const Session & | other | ) |
| delete

SessionHandle Botan::PKCS11::Session::release | ( |  | ) |

Returns
  the released session handle

Definition at line 59 of file p11_session.cpp.

References handle().

60 {
61 SessionHandle handle = 0;
62 std::swap(handle, m_handle);
63 return handle;
64 }
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45
Botan::PKCS11::Session::handle
SessionHandle handle() const
Definition: p11_session.h:63
Botan::PKCS11::SessionHandle
CK_SESSION_HANDLE SessionHandle
Definition: p11.h:843

void Botan::PKCS11::Session::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 at line 85 of file p11_session.cpp.

References Botan::PKCS11::LowLevel::C_SetPIN(), and module().

Referenced by Botan::PKCS11::change_pin(), and Botan::PKCS11::change_so_pin().

86 {
87 module()->C_SetPIN(m_handle, old_pin, new_pin);
88 }
Botan::PKCS11::Session::module
Module & module() const
Definition: p11_session.h:69
Botan::PKCS11::LowLevel::C_SetPIN
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
m_handle
HCRYPTPROV m_handle
Definition: es_capi.cpp:45

const Slot& Botan::PKCS11::Session::slot | ( |  | ) | const
| inline

Returns
  a reference to the slot

Definition at line 57 of file p11_session.h.

58 {
59 return m_slot;
60 }

The documentation for this class was generated from the following files:

- src/lib/prov/pkcs11/p11_session.h
- src/lib/prov/pkcs11/p11_session.cpp