NAME
Crypt::PKCS11::XS - XS layer for PKCS #11 functions
SYNPOSIS
use Crypt::PKCS11;
my $pkcs11xs = Crypt::PKCS11::XS->new;
$pkcs11xs->C_...
DESCRIPTION
XS layer containing wrappers for all PKCS #11 functions that converts Perl data structures to/from PKCS #11 specific data structures.
RETURN VALUES AND ERROR HANDLING
This is the general return value and error handling for all methods unless otherwise stated.
Return values will be given in output arguments and if the output is an ARRAY or HASH reference then they need to be set prior of using the call.
my $output_hash = {};
$pkcs11xs->C_Call($input_arg1, $input_arg2, $output_hash);
print $output_hash->{output_field};
All functions will return a CKR value and the Perl XS intergration will croak if any argument are not the correct type.
METHODS
All methods that starts with C_ are in direct relation with the PKCS #11 v2.30 functions described in detail at http://www.cryptsoft.com/pkcs11doc/v230/ .
For documentation about what each of those method does please see the documentation for PKCS #11 v2.30, the only thing documented here is the structure of the input and output arguments which uses Perl arrays and hashes (conversion to/from PKCS #11 specific data structures are handled by the methods).
- $pkcs11xs = Crypt::PKCS11::XS->new
-
Create a new Crypt::PKCS11::XS object.
- $str = Crypt::PKCS11::XS::rv2str ($rv)
-
Return the textual name of a CKR return value.
- $rv = Crypt::PKCS11::XS::setCreateMutex ($pCreateMutex)
-
Set the global create mutex callback, for more information about mutex callbacks and how to use them please see Crypt::PKCS11::MutexCallbacks.
- Crypt::PKCS11::XS::clearCreateMutex
-
Clear the stored create mutex callback reference.
- $rv = Crypt::PKCS11::XS::setDestroyMutex ($pDestroyMutex)
-
Set the global destroy mutex callback, for more information about mutex callbacks and how to use them please see Crypt::PKCS11::MutexCallbacks.
- Crypt::PKCS11::XS::clearDestroyMutex
-
Clear the stored destroy mutex callback reference.
- $rv = Crypt::PKCS11::XS::setLockMutex ($pLockMutex)
-
Set the global lock mutex callback, for more information about mutex callbacks and how to use them please see Crypt::PKCS11::MutexCallbacks.
- Crypt::PKCS11::XS::clearLockMutex
-
Clear the stored lock mutex callback reference.
- $rv = Crypt::PKCS11::XS::setUnlockMutex ($pUnlockMutex)
-
Set the global unlock mutex callback, for more information about mutex callbacks and how to use them please see Crypt::PKCS11::MutexCallbacks.
- Crypt::PKCS11::XS::clearUnlockMutex
-
Clear the stored unlock mutex callback reference.
- $rv = $pkcs11xs->load ($path)
-
Load a PKCS #11 library.
- $rv = $pkcs11xs->unload
-
Unload the PKCS #11 library.
- $rv = $pkcs11xs->C_Initialize ($pInitArgs)
-
- $pInitArgs
-
A HASH reference with the fields listed below.
NOTE: For all Mutex CODE references the global callback will be set, there is no support for individual callbacks per Crypt::PKCS11::XS object.
All of the Mutex arguments needs to be set if any should be used.
For more information about mutex callbacks and how to use them please see Crypt::PKCS11::MutexCallbacks.
- CreateMutex
-
A CODE reference to a function to use for creating mutex objects. The global callback for CreateMutex will also be set.
- DestroyMutex
-
A CODE reference to a function to use for destroying mutex objects. The global callback for DestroyMutex will also be set.
- LockMutex
-
A CODE reference to a function to use for locking mutex objects. The global callback for LockMutex will also be set.
- UnlockMutex
-
A CODE reference to a function to use for unlocking mutex objects. The global callback for UnlockMutex will also be set.
- flags
-
A SCALAR.
- $rv = $pkcs11xs->C_Finalize
- $rv = $pkcs11xs->C_GetInfo ($pInfo)
-
- $pInfo
-
A HASH reference output argument that will get the following fields set:
- cryptokiVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- manufacturerID
-
A SCALAR.
- flags
-
A SCALAR.
- libraryDescription
-
A SCALAR.
- libraryVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- $rv = $pkcs11xs->C_GetSlotList ($tokenPresent, $pSlotList)
- $rv = $pkcs11xs->C_GetSlotInfo ($slotID, $pInfo)
-
- $slotID
-
A SCALAR.
- $pInfo
-
A HASH reference output argument that will get the following fields set:
- slotDescription
-
A SCALAR.
- manufacturerID
-
A SCALAR.
- flags
-
A SCALAR.
- hardwareVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- firmwareVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- $rv = $pkcs11xs->C_GetTokenInfo ($slotID, $pInfo)
-
- $slotID
-
A SCALAR.
- $pInfo
-
A HASH reference output argument that will get the following fields set:
- label
-
A SCALAR.
- manufacturerID
-
A SCALAR.
- model
-
A SCALAR.
- serialNumber
-
A SCALAR.
- flags
-
A SCALAR.
- ulMaxSessionCount
-
A SCALAR.
- ulSessionCount
-
A SCALAR.
- ulMaxRwSessionCount
-
A SCALAR.
- ulRwSessionCount
-
A SCALAR.
- ulMaxPinLen
-
A SCALAR.
- ulMinPinLen
-
A SCALAR.
- ulTotalPublicMemory
-
A SCALAR.
- ulFreePublicMemory
-
A SCALAR.
- ulTotalPrivateMemory
-
A SCALAR.
- ulFreePrivateMemory
-
A SCALAR.
- hardwareVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- firmwareVersion
-
A HASH reference with the following fields:
- major
-
A SCALAR.
- minor
-
A SCALAR.
- utcTime
-
A SCALAR.
- $rv = $pkcs11xs->C_GetMechanismList ($slotID, $pMechanismList)
- $rv = $pkcs11xs->C_GetMechanismInfo ($slotID, $type, $pInfo)
- $rv = $pkcs11xs->C_InitToken ($slotID, $pPin, $pLabel)
- $rv = $pkcs11xs->C_InitPIN ($hSession, $pPin)
- $rv = $pkcs11xs->C_SetPIN ($hSession, $pOldPin, $pNewPin)
- $rv = $pkcs11xs->C_OpenSession ($slotID, $flags, $Notify, $phSession)
- $rv = $pkcs11xs->C_CloseSession ($hSession)
- $rv = $pkcs11xs->C_CloseAllSessions ($slotID)
- $rv = $pkcs11xs->C_GetSessionInfo ($hSession, $pInfo)
- $rv = $pkcs11xs->C_GetOperationState ($hSession, $pOperationState)
- $rv = $pkcs11xs->C_SetOperationState ($hSession, $pOperationState, $hEncryptionKey, $hAuthenticationKey)
- $rv = $pkcs11xs->C_Login ($hSession, $userType, $pPin)
- $rv = $pkcs11xs->C_Logout ($hSession)
- $rv = $pkcs11xs->C_CreateObject ($hSession, $pTemplate, $phObject)
- $rv = $pkcs11xs->C_CopyObject ($hSession, $hObject, $pTemplate, $phNewObject)
- $rv = $pkcs11xs->C_DestroyObject ($hSession, $hObject)
- $rv = $pkcs11xs->C_GetObjectSize ($hSession, $hObject, $pulSize)
- $rv = $pkcs11xs->C_GetAttributeValue ($hSession, $hObject, $pTemplate)
- $rv = $pkcs11xs->C_SetAttributeValue ($hSession, $hObject, $pTemplate)
- $rv = $pkcs11xs->C_FindObjectsInit ($hSession, $pTemplate)
- $rv = $pkcs11xs->C_FindObjects ($hSession, $phObject, $ulMaxObjectCount)
- $rv = $pkcs11xs->C_FindObjectsFinal ($hSession)
- $rv = $pkcs11xs->C_EncryptInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_Encrypt ($hSession, $pData, $pEncryptedData)
- $rv = $pkcs11xs->C_EncryptUpdate ($hSession, $pPart, $pEncryptedPart)
- $rv = $pkcs11xs->C_EncryptFinal ($hSession, $pLastEncryptedPart)
- $rv = $pkcs11xs->C_DecryptInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_Decrypt ($hSession, $pEncryptedData, $pData)
- $rv = $pkcs11xs->C_DecryptUpdate ($hSession, $pEncryptedPart, $pPart)
- $rv = $pkcs11xs->C_DecryptFinal ($hSession, $pLastPart)
- $rv = $pkcs11xs->C_DigestInit ($hSession, $pMechanism)
- $rv = $pkcs11xs->C_Digest ($hSession, $pData, $pDigest)
- $rv = $pkcs11xs->C_DigestUpdate ($hSession, $pPart)
- $rv = $pkcs11xs->C_DigestKey ($hSession, $hKey)
- $rv = $pkcs11xs->C_DigestFinal ($hSession, $pDigest)
- $rv = $pkcs11xs->C_SignInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_Sign ($hSession, $pData, $pSignature)
- $rv = $pkcs11xs->C_SignUpdate ($hSession, $pPart)
- $rv = $pkcs11xs->C_SignFinal ($hSession, $pSignature)
- $rv = $pkcs11xs->C_SignRecoverInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_SignRecover ($hSession, $pData, $pSignature)
- $rv = $pkcs11xs->C_VerifyInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_Verify ($hSession, $pData, $pSignature)
- $rv = $pkcs11xs->C_VerifyUpdate ($hSession, $pPart)
- $rv = $pkcs11xs->C_VerifyFinal ($hSession, $pSignature)
- $rv = $pkcs11xs->C_VerifyRecoverInit ($hSession, $pMechanism, $hKey)
- $rv = $pkcs11xs->C_VerifyRecover ($hSession, $pSignature, $pData)
- $rv = $pkcs11xs->C_DigestEncryptUpdate ($hSession, $pPart, $pEncryptedPart)
- $rv = $pkcs11xs->C_DecryptDigestUpdate ($hSession, $pEncryptedPart, $pPart)
- $rv = $pkcs11xs->C_SignEncryptUpdate ($hSession, $pPart, $pEncryptedPart)
- $rv = $pkcs11xs->C_DecryptVerifyUpdate ($hSession, $pEncryptedPart, $pPart)
- $rv = $pkcs11xs->C_GenerateKey ($hSession, $pMechanism, $pTemplate, $phKey)
- $rv = $pkcs11xs->C_GenerateKeyPair ($hSession, $pMechanism, $pPublicKeyTemplate, $pPrivateKeyTemplate, $phPublicKey, $phPrivateKey)
- $rv = $pkcs11xs->C_WrapKey ($hSession, $pMechanism, $hWrappingKey, $hKey, $pWrappedKey)
- $rv = $pkcs11xs->C_UnwrapKey ($hSession, $pMechanism, $hUnwrappingKey, $pWrappedKey, $pTemplate, $phKey)
- $rv = $pkcs11xs->C_DeriveKey ($hSession, $pMechanism, $hBaseKey, $pTemplate, $phKey)
- $rv = $pkcs11xs->C_SeedRandom ($hSession, $pSeed)
- $rv = $pkcs11xs->C_GenerateRandom ($hSession, $RandomData, $ulRandomLen)
- $rv = $pkcs11xs->C_GetFunctionStatus ($hSession)
- $rv = $pkcs11xs->C_CancelFunction ($hSession)
- $rv = $pkcs11xs->C_WaitForSlotEvent ($flags, $pSlot)
PRIVATE METHODS
These are the private methods used within the module and should not be used elsewhere.
- Crypt::PKCS11::XS::SvUOK ($sv)
-
Returns true (1) if the given SV is considered an unsigned number by Perl otherwise return false (0/undef).
- Crypt::PKCS11::XS::SvIOK ($sv)
-
Returns true (1) if the given SV is considered an signed number by Perl otherwise return false (0/undef).
MECHANISM ARGUMENT
A HASH reference that represents a CK_MECHANISM struct that has the following fields:
- mechanism
-
A SCALAR.
- pParameter
-
A SCALAR.
TEMPLATE ARGUMENT
An ARRAY reference that contains HASH references which represents CK_ATTRIBUTE structs and the HASH reference has the following fields:
- type
-
A SCALAR.
- pValue
-
A SCALAR.
NOTE
Derived from the RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki)
AUTHOR
Jerry Lundström <lundstrom.jerry@gmail.com>
REPORTING BUGS
Report bugs at https://github.com/dotse/p5-Crypt-PKCS11/issues .
LICENSE
Copyright (c) 2015 Jerry Lundström <lundstrom.jerry@gmail.com>
Copyright (c) 2015 .SE (The Internet Infrastructure Foundation)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.