AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
PKCS11Functions.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ACSDKPKCS11_PRIVATE_PKCS11FUNCTIONS_H_
17 #define ACSDKPKCS11_PRIVATE_PKCS11FUNCTIONS_H_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #ifdef _WIN32
24 #ifndef WIN32_LEAN_AND_MEAN
25 #define WIN32_LEAN_AND_MEAN
26 #endif
27 #include <windows.h>
28 #endif
29 
31 
32 namespace alexaClientSDK {
33 namespace acsdkPkcs11 {
34 
35 class PKCS11Key;
36 class PKCS11Slot;
37 class PKCS11Session;
38 class PKCS11Token;
39 
47 class PKCS11Functions : public std::enable_shared_from_this<PKCS11Functions> {
48 public:
54  static std::shared_ptr<PKCS11Functions> create(const std::string& libpath) noexcept;
55 
59  virtual ~PKCS11Functions() noexcept;
60 
69  bool listSlots(bool tokenPresent, std::vector<std::shared_ptr<PKCS11Slot>>& slots) noexcept;
70 
79  bool findSlotByTokenName(const std::string& tokenName, std::shared_ptr<PKCS11Slot>& slot) noexcept;
80 
81 private:
82  friend class PKCS11Key;
83  friend class PKCS11Session;
84  friend class PKCS11Token;
85  friend class PKCS11Slot;
86 
88  PKCS11Functions() noexcept;
89 
95  bool initialize() noexcept;
103  bool loadLibraryAndGetFunctions(const std::string& libpath) noexcept;
104 
108  void finalizeOperations() noexcept;
109 
113  void unloadLibrary() noexcept;
114 
115 #ifdef _WIN32
116  HMODULE m_libraryHandle;
118 #else
119  void* m_libraryHandle;
121 #endif
122  CK_FUNCTION_LIST* m_pkcs11Functions;
124 };
125 
126 } // namespace acsdkPkcs11
127 } // namespace alexaClientSDK
128 
129 #endif // ACSDKPKCS11_PRIVATE_PKCS11FUNCTIONS_H_
alexaClientSDK::acsdkPkcs11::PKCS11Session
PKCS11 session wrapper.
Definition: PKCS11Session.h:38
alexaClientSDK::acsdkPkcs11::PKCS11Functions
PKCS11 API Wrapper.
Definition: PKCS11Functions.h:47
alexaClientSDK::acsdkPkcs11::PKCS11Slot
PKCS11 slot wrapper.
Definition: PKCS11Slot.h:36
alexaClientSDK::acsdkPkcs11::PKCS11Functions::listSlots
bool listSlots(bool tokenPresent, std::vector< std::shared_ptr< PKCS11Slot >> &slots) noexcept
Lists available PKCS11 slots by type.
Definition: PKCS11Functions.cpp:72
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
PKCS11API.h
std
Definition: CapabilityConfiguration.h:190
alexaClientSDK::acsdkPkcs11::PKCS11Key
PKCS11 key object wrapper.
Definition: PKCS11Key.h:38
alexaClientSDK::acsdkPkcs11::PKCS11Functions::PKCS11Token
friend class PKCS11Token
Definition: PKCS11Functions.h:84
alexaClientSDK::acsdkPkcs11::PKCS11Functions::create
static std::shared_ptr< PKCS11Functions > create(const std::string &libpath) noexcept
Definition: PKCS11Functions.cpp:27
alexaClientSDK::acsdkPkcs11::PKCS11Functions::~PKCS11Functions
virtual ~PKCS11Functions() noexcept
Releases library.
Definition: PKCS11Functions.cpp:44
alexaClientSDK::acsdkPkcs11::PKCS11Functions::findSlotByTokenName
bool findSlotByTokenName(const std::string &tokenName, std::shared_ptr< PKCS11Slot > &slot) noexcept
Finds PKCS11 slot by name.
Definition: PKCS11Functions.cpp:108

AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0