|
|
@ -55,6 +55,7 @@ class CryptokiEngine: public QObject, public openssl::Engine { |
|
|
|
sslConfig.setLocalCertificate(localcert); |
|
|
|
sslConfig.setLocalCertificate(localcert); |
|
|
|
assert(localcert.isValid()); |
|
|
|
assert(localcert.isValid()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//RSA_set_default_method(ENGINE_get_RSA(_e));
|
|
|
|
QByteArray pem // empty dummy key for qt object instantiation
|
|
|
|
QByteArray pem // empty dummy key for qt object instantiation
|
|
|
|
("-----BEGIN RSA PRIVATE KEY-----\n" |
|
|
|
("-----BEGIN RSA PRIVATE KEY-----\n" |
|
|
|
"MIIBOwIBAAJBAMH2yqAGeVNPdgeZ2GoHo31m9aUxZ7QfK2Go2qLTahLpQ3UL1C8G\n" |
|
|
|
"MIIBOwIBAAJBAMH2yqAGeVNPdgeZ2GoHo31m9aUxZ7QfK2Go2qLTahLpQ3UL1C8G\n" |
|
|
@ -67,21 +68,20 @@ class CryptokiEngine: public QObject, public openssl::Engine { |
|
|
|
"-----END RSA PRIVATE KEY-----\n"); |
|
|
|
"-----END RSA PRIVATE KEY-----\n"); |
|
|
|
QSslKey privkey(pem, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); |
|
|
|
QSslKey privkey(pem, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); |
|
|
|
RSA* rsa(0); |
|
|
|
RSA* rsa(0); |
|
|
|
do { |
|
|
|
rsa = (RSA*)privkey.handle(); |
|
|
|
rsa = ((RSA*)privkey.handle()); |
|
|
|
if (rsa) RSA_free(rsa); |
|
|
|
//! @todo call RSA_free(rsa); later, see #82
|
|
|
|
rsa = RSA_new_method(_e); |
|
|
|
rsa = RSA_new_method(_e); |
|
|
|
set(rsa->n, privateKey, CKA_MODULUS, "CKA_MODULUS"); |
|
|
|
set(rsa->n, privateKey, CKA_MODULUS, "CKA_MODULUS"); |
|
|
|
set(rsa->e, privateKey, CKA_PUBLIC_EXPONENT, "CKA_PUBLIC_EXPONENT"); |
|
|
|
set(rsa->e, privateKey, CKA_PUBLIC_EXPONENT, "CKA_PUBLIC_EXPONENT"); |
|
|
|
set(rsa->d, privateKey, CKA_PRIVATE_EXPONENT, "CKA_PRIVATE_EXPONENT"); |
|
|
|
set(rsa->d, privateKey, CKA_PRIVATE_EXPONENT, "CKA_PRIVATE_EXPONENT"); |
|
|
|
set(rsa->p, privateKey, CKA_PRIME_1, "CKA_PRIME_1"); |
|
|
|
set(rsa->p, privateKey, CKA_PRIME_1, "CKA_PRIME_1"); |
|
|
|
set(rsa->q, privateKey, CKA_PRIME_2, "CKA_PRIME_2"); |
|
|
|
set(rsa->q, privateKey, CKA_PRIME_2, "CKA_PRIME_2"); |
|
|
|
set(rsa->dmp1, privateKey, CKA_EXPONENT_1, "CKA_EXPONENT_1"); |
|
|
|
set(rsa->dmp1, privateKey, CKA_EXPONENT_1, "CKA_EXPONENT_1"); |
|
|
|
set(rsa->dmq1, privateKey, CKA_EXPONENT_2, "CKA_EXPONENT_2"); |
|
|
|
set(rsa->dmq1, privateKey, CKA_EXPONENT_2, "CKA_EXPONENT_2"); |
|
|
|
set(rsa->iqmp, privateKey, CKA_COEFFICIENT, "CKA_COEFFICIENT"); |
|
|
|
set(rsa->iqmp, privateKey, CKA_COEFFICIENT, "CKA_COEFFICIENT"); |
|
|
|
rsa->flags |= RSA_FLAG_SIGN_VER; // don't emulate with encrypt/decrypt
|
|
|
|
rsa->flags |= RSA_FLAG_SIGN_VER; // don't emulate with encrypt/decrypt
|
|
|
|
assert(!privkey.isNull()); |
|
|
|
assert(!privkey.isNull()); |
|
|
|
assert(rsa==(RSA*)privkey.handle()); |
|
|
|
} while (rsa!=(RSA*)privkey.handle()); |
|
|
|
|
|
|
|
sslConfig.setPrivateKey(privkey); |
|
|
|
sslConfig.setPrivateKey(privkey); |
|
|
|
QSslConfiguration::setDefaultConfiguration(sslConfig); |
|
|
|
QSslConfiguration::setDefaultConfiguration(sslConfig); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
} catch (const std::exception& e) { |
|
|
|