#ifndef CRYPTOTOKEN_H #define CRYPTOTOKEN_H #include #include #include "include/pkcs11.h" class CryptoToken { public: /** * @brief Constructor de la clase CryptoToken */ explicit CryptoToken(); /** * @brief Destructor de la clase */ virtual ~CryptoToken(); /** * @brief Inicializa el Criptoki * @return retorna si inicializa el Criptoki */ bool initializeCriptoki(); /** * @brief Finaliza el criptoki */ void finalize(); /** * @brief Abre una sesion en el dispositivo criptografico * @param Pin PIN del dispositivo * @param slotID slot asociado a la sesión en el dispositivo * @param requiredlogin si se requiere el login, por defecto si * @return handle de la sesión */ CK_SESSION_HANDLE openSession(char * Pin, CK_SLOT_ID & slotID, bool requiredlogin = true); void closeSession(CK_SESSION_HANDLE hSession); /** * @brief Retorna un handle a la clave privada encontrada dentro del dispositivo * @param hSession handle de la sesión abierta en el dispositivo * @param slotID identificador de slot * @param id etiqueta de la clave dentro del dispositivo * @return */ CK_OBJECT_HANDLE getPrivateKey(CK_SESSION_HANDLE hSession, CK_SLOT_ID slotID, QString id); /** * @brief Retorna un handle a la clave privada encontrada dentro del dispositivo * @param hSession handle de la sesión abierta en el dispositivo * @param slotID identificador de slot * @param id indice del certificado asociado a la clave privada * @return handle de la clave privada encontrada */ CK_OBJECT_HANDLE getPrivateKey(CK_SESSION_HANDLE hSession, CK_SLOT_ID slotID, int certificateIndex); /** * @brief firma digitalmente unos datos con la tarjeta inteligente * @param hSession handle a la sesion abierta en la tarjeta * @param privateKey handle a la clave privada de la tarjeta * @param someData datos a firmar (CK_BYTE_PTR: unsigned char *) * @param someDataLen longitud de los datos a firmar * @param sign firma de los datos * @param signLen longitud de la firma de los datos * @return firma electronica de los datos pasados en someData */ bool signSomeData(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE privateKey, CK_BYTE_PTR someData, CK_ULONG someDataLen, CK_BYTE_PTR sign, CK_ULONG_PTR signLen ); /** * @brief Sign a hash. * * @param hashToSign hash to be signed * @param pin pin of the cryptographic device * @param label label of the private key stored in the cryptographic device * @return signed hash */ std::vector signHash(QString hashToSign, QString pin, QString label); /** * @brief Sign a hash. * * @param hashToSign hash a ser firmado * @param pin PIN del dispositivo * @param certificateIndex indice del certificado seleccionado para firmar * @return signed hash */ std::vector signHash(QString hashToSign, QString pin, int certificateIndex); //std::vector findObject(CK_OBJECT_CLASS objectClass, CK_ULONG max) const; /** * @brief Returns a list of private key labels * * @param pin pin of the cryptographic device * @return QStringList of labels */ QStringList getPrivateKeyLabels(QString pin); QStringList getLabel(); /** * @brief get label of the key * @param hSession session handle * @param key key handle * @return key label as QString */ QString getKeyLabel(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE key); /** * @brief get certificate information bound to the key * @param hSession session handle * @param key key handle * @return QStringList with commonName and expiration date */ QStringList getCertificateInformation(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE certificate); /** * @brief Get information of commonName and expiration date of certificates inside the device * @return list of QStringList with */ QList getCertificateCNandExpirationDate(); /** * @brief Returns information about device's certificates. * * @return QList of information about certificate: */ QList getDeviceCertificates(); void getCertificateAttributes(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hCert); /** * @brief Retorna información del modulo PKCS11 * @return cadena con informacion del modulo PKCS11 */ QString getInfoCryptoki(); /** * @brief Retorna error de pkcs11 en formato de cadena QString * @param rv * @return cadena con el error */ QString returnErrorToQString(CK_RV rv); QByteArray toHex(const std::vector &data); std::vector fromHex(const QString &data); }; #endif // CRYPTOTOKEN_H