AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Macros | Functions | Variables
Pkcs11Stubs.cpp File Reference
#include <cstring>
#include <memory>
#include <mutex>
#include <unordered_map>
#include <AVSCommon/Utils/Logger/Logger.h>
#include <pkcs11.h>
#include <acsdkCryptoInterfaces/CryptoFactoryInterface.h>
#include <acsdkCrypto/CryptoFactory.h>
Include dependency graph for Pkcs11Stubs.cpp:

Classes

struct  SessionStub
 Session state object. More...
 

Macros

#define LX(event)   alexaClientSDK::avsCommon::utils::logger::LogEntry(TAG, event)
 
#define CK_PTR   *
 
#define CK_DECLARE_FUNCTION(returnType, name)   returnType name
 
#define CK_DECLARE_FUNCTION_POINTER(returnType, name)   returnType(*name)
 
#define CK_CALLBACK_FUNCTION(returnType, name)   returnType(*name)
 
#define NULL_PTR   nullptr
 

Functions

static std::shared_ptr< SessionStubfindSession (CK_SESSION_HANDLE sessionHandle)
 Helper to find session by handle. More...
 
CK_RV C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR result)
 Provides function table. More...
 
static void initializeKey (AlgorithmType type, CryptoCodecInterface::Key &key, DigestInterface::DataBlock &checksum)
 
CK_RV C_Initialize (CK_VOID_PTR reserved)
 Initializes module. More...
 
CK_RV C_Finalize (CK_VOID_PTR reserved)
 Releases module data. More...
 
CK_RV C_GetSlotList (CK_BBOOL tokenPresent, CK_SLOT_ID_PTR slotList, CK_ULONG_PTR slotListSize)
 Provides slot list. More...
 
CK_RV C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR tokenInfo)
 Provide token info. More...
 
CK_RV C_OpenSession (CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR application, CK_NOTIFY notify, CK_SESSION_HANDLE_PTR sessionHandle)
 Opens a new session. More...
 
CK_RV C_CloseSession (CK_SESSION_HANDLE sessionHandle)
 Terminates session. More...
 
CK_RV C_Login (CK_SESSION_HANDLE sessionHandle, CK_USER_TYPE type, CK_UTF8CHAR_PTR pin, CK_ULONG pinLen)
 Performs login. More...
 
CK_RV C_Logout (CK_SESSION_HANDLE sessionHandle)
 
CK_RV C_GetAttributeValue (CK_SESSION_HANDLE sessionHandle, CK_OBJECT_HANDLE objectHandle, CK_ATTRIBUTE_PTR attributes, CK_ULONG attributeCount)
 
CK_RV C_FindObjectsInit (CK_SESSION_HANDLE sessionHandle, CK_ATTRIBUTE_PTR attributes, CK_ULONG attributeCount)
 Initializes object search. More...
 
CK_RV C_FindObjects (CK_SESSION_HANDLE sessionHandle, CK_OBJECT_HANDLE_PTR objectHandles, CK_ULONG maxObjectCount, CK_ULONG_PTR objectCount)
 Finds objects matching search criteria. More...
 
CK_RV C_FindObjectsFinal (CK_SESSION_HANDLE sessionHandle)
 Finishes object search. More...
 
CK_RV C_EncryptInit (CK_SESSION_HANDLE sessionHandle, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE keyHandle)
 Initializes encryption operation. More...
 
CK_RV C_Encrypt (CK_SESSION_HANDLE sessionHandle, CK_BYTE_PTR plaintext, CK_ULONG plaintextLen, CK_BYTE_PTR ciphertext, CK_ULONG_PTR ciphertextLen)
 Performs encryption. More...
 
CK_RV C_DecryptInit (CK_SESSION_HANDLE sessionHandle, CK_MECHANISM_PTR mechanism, CK_OBJECT_HANDLE keyHandle)
 Initializes decryption operation. More...
 
CK_RV C_Decrypt (CK_SESSION_HANDLE sessionHandle, CK_BYTE_PTR ciphertext, CK_ULONG ciphertextLen, CK_BYTE_PTR plaintext, CK_ULONG_PTR plaintextLen)
 Performs decryption. More...
 

Variables

static CK_FUNCTION_LIST FUNCTION_LIST
 PKCS11 function list table. More...
 
static constexpr CK_OBJECT_CLASS UNSPECIFIED_OBJECT_CLASS = (CK_OBJECT_CLASS)-1
 Constant to indicate unspecified value for object class attribute. More...
 
static constexpr CK_KEY_TYPE UNSPECIFIED_KEY_TYPE = (CK_KEY_TYPE)-1
 Constant to indicate unspecified value for key type attribute. More...
 
static constexpr CK_ULONG UNSPECIFIED_VALUE_LEN = (CK_ULONG)-1
 Constant to indicate unspecified value for value length attribute. More...
 
static constexpr CK_SLOT_ID DEFAULT_SLOT_ID = 1
 Default slot id. More...
 
static constexpr CK_OBJECT_HANDLE AES256_KEY_OBJECT_HANDLE = 2
 AES256 key object handle. More...
 
static constexpr CK_OBJECT_HANDLE AES128_KEY_OBJECT_HANDLE = 3
 AES128 key object handle. More...
 
static constexpr CK_ULONG AES_BLOCK_SIZE = 16
 AES block size in bytes. More...
 
static constexpr int AES_GCM_TAG_SIZE = 16
 AES GCM tag size in bytes. More...
 
static constexpr CK_ULONG AES256_KEY_SIZE = 32
 Key size in bytes for AES 256. More...
 
static constexpr CK_ULONG AES128_KEY_SIZE = 16
 Key size in bytes for AES 128. More...
 
static std::shared_ptr< CryptoFactoryInterface > c_cryptoFactory
 Crypto factory to HSM function simulations. More...
 
static KeyFactoryInterface::Key c_aes256Key
 AES 256 key value. This stub generates key value on initialization. More...
 
static KeyFactoryInterface::Key c_aes128Key
 AES 128 key value. This stub generates key value on initialization. More...
 
static DigestInterface::DataBlock c_aes256Checksum
 
static DigestInterface::DataBlock c_aes128Checksum
 AES 128 key checksum. More...
 
static CK_ULONG c_sessionCounter
 Counter to generate unique session handle values. More...
 
static std::unordered_map< CK_ULONG, std::shared_ptr< SessionStub > > c_sessions
 Session map. More...
 
static std::mutex c_sessionsMutex
 Session map mutex. More...
 

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