source: terepaima/terepaima-0.4.16/sources/cryptotokenOld.h

stretch
Last change on this file was 35bdadc, checked in by pbuitrago@…>, 6 years ago

Se agregaron las librerias necesarias para la gestion de dispositivos criptograficos y se modifico mainwindow.cpp y mainwindow.h para la gestion de los dispositivos criptograficos

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#ifndef CRYPTOTOKEN_H
2#define CRYPTOTOKEN_H
3
4#include <QObject>
5#include <QStringList>
6
7#include "include/pkcs11.h"
8
9class CryptoToken
10{
11
12public:
13
14    /**
15     * @brief Constructor de la clase CryptoToken
16     */
17    explicit CryptoToken();
18
19    /**
20     * @brief Destructor de la clase
21     */
22    virtual ~CryptoToken();
23
24    /**
25     * @brief Inicializa el Criptoki
26     * @return retorna si inicializa el Criptoki
27     */
28    bool initializeCriptoki();
29
30    /**
31     * @brief Finaliza el criptoki
32     */
33    void finalize();
34
35    /**
36     * @brief Abre una sesion en el dispositivo criptografico
37     * @param Pin PIN del dispositivo
38     * @param slotID slot asociado a la sesión en el dispositivo
39     * @param requiredlogin si se requiere el login, por defecto si
40     * @return handle de la sesión
41     */
42    CK_SESSION_HANDLE openSession(char * Pin, CK_SLOT_ID & slotID, bool requiredlogin = true);
43
44    void closeSession(CK_SESSION_HANDLE hSession);
45
46    /**
47     * @brief Retorna un handle a la clave privada encontrada dentro del dispositivo
48     * @param hSession handle de la sesión abierta en el dispositivo
49     * @param slotID identificador de slot
50     * @param id etiqueta de la clave dentro del dispositivo
51     * @return
52     */
53    CK_OBJECT_HANDLE getPrivateKey(CK_SESSION_HANDLE hSession, CK_SLOT_ID slotID, QString id);
54
55    /**
56     * @brief firma digitalmente unos datos con la tarjeta inteligente
57     * @param hSession handle a la sesion abierta en la tarjeta
58     * @param privateKey handle a la clave privada de la tarjeta
59     * @param someData datos a firmar (CK_BYTE_PTR: unsigned char *)
60     * @param someDataLen longitud de los datos a firmar
61     * @param sign firma de los datos
62     * @param signLen longitud de la firma de los datos
63     * @return firma electronica de los datos pasados en someData
64     */
65    bool signSomeData(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE privateKey, CK_BYTE_PTR someData,
66            CK_ULONG someDataLen, CK_BYTE_PTR sign, CK_ULONG_PTR signLen );
67
68
69    /**
70     * @brief Sign a hash.
71     *
72     * @param hashToSign hash to be signed
73     * @param pin pin of the cryptographic device
74     * @param label label of the private key stored in the cryptographic device
75     * @return signed hash
76     */
77    std::vector<unsigned char> signHash(QString hashToSign, QString pin, QString label);
78
79
80    //std::vector<CK_OBJECT_HANDLE> findObject(CK_OBJECT_CLASS objectClass, CK_ULONG max) const;
81
82    /**
83     * @brief Returns a list of private key labels
84     *
85     * @param pin pin of the cryptographic device
86     * @return QStringList of labels
87     */
88    QStringList getPrivateKeyLabels(QString pin);
89
90    /**
91     * @brief get label of the key
92     * @param hSession session handle
93     * @param key key handle
94     * @return key label as QString
95     */
96    QString getKeyLabel(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE key);
97
98    /**
99     * @brief get certificate information bound to the key
100     * @param hSession session handle
101     * @param key key handle
102     * @return QStringList with commonName and expiration date
103     */
104    QStringList getCertificateInformation(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE certificate);
105
106    /**
107     * @brief Get information of commonName and expiration date of certificates inside the device
108     * @param pin pin of the device
109     * @return list of QStringList with <commnonName,expirationDate>
110     */
111    QList<QStringList> getCertificateCNandExpirationDate(QString pin);
112
113    /**
114     * @brief Returns information about device's certificates.
115     *
116     * @param pin pin of the device
117     * @return QList<QStringList> of information about certificate: <key label, commonName, expiration date>
118     */
119    QList<QStringList> getDeviceCertificates(QString pin);
120
121
122    void getCertificateAttributes(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hCert);
123
124
125
126
127    /**
128     * @brief Retorna información del modulo PKCS11
129     * @return cadena con informacion del modulo PKCS11
130     */
131    QString getInfoCryptoki();
132
133    /**
134     * @brief Retorna error de pkcs11 en formato de cadena QString
135     * @param rv
136     * @return cadena con el error
137     */
138    QString returnErrorToQString(CK_RV rv);
139
140
141    QByteArray toHex(const std::vector<unsigned char> &data);
142
143    std::vector<unsigned char> fromHex(const QString &data);
144};
145
146#endif // CRYPTOTOKEN_H
Note: See TracBrowser for help on using the repository browser.