it works, first cleanup; refs #49
This commit is contained in:
@@ -77,12 +77,12 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
|||||||
_url->addItems(urls);
|
_url->addItems(urls);
|
||||||
assert(connect(_url, SIGNAL(currentIndexChanged(const QString&)),
|
assert(connect(_url, SIGNAL(currentIndexChanged(const QString&)),
|
||||||
SLOT(load(QString))));
|
SLOT(load(QString))));
|
||||||
assert(connect(&_networkManager,
|
// assert(connect(&_networkManager,
|
||||||
SIGNAL(extendedContextInitialization(ssl_ctx_st*,
|
// SIGNAL(extendedContextInitialization(ssl_ctx_st*,
|
||||||
QSslSocket*)),
|
// QSslSocket*)),
|
||||||
&_scAuth,
|
// &_scAuth,
|
||||||
SLOT(extendedContextInitialization(ssl_ctx_st*,
|
// SLOT(extendedContextInitialization(ssl_ctx_st*,
|
||||||
QSslSocket*))));
|
// QSslSocket*))));
|
||||||
assert(connect(&_networkManager, SIGNAL(created(QNetworkReply*)),
|
assert(connect(&_networkManager, SIGNAL(created(QNetworkReply*)),
|
||||||
&_downloadManager, SLOT(add(QNetworkReply*))));
|
&_downloadManager, SLOT(add(QNetworkReply*))));
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// extern const QByteArray SWISSSIGN_GOLD_CA_G2;
|
|
||||||
|
|
||||||
class CryptokiEngine: public QObject, public openssl::Engine {
|
class CryptokiEngine: public QObject, public openssl::Engine {
|
||||||
|
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
@@ -58,45 +56,9 @@ class CryptokiEngine: public QObject, public openssl::Engine {
|
|||||||
return *_cert;
|
return *_cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual EVP_PKEY* privkey() {
|
|
||||||
// OPENSSL_LOG("log");
|
|
||||||
// EVP_PKEY* k(EVP_PKEY_new());
|
|
||||||
// RSA* r(RSA_new_method(_e));
|
|
||||||
// r->n = BN_bin2bn((const unsigned char*)_modulus.data(),
|
|
||||||
// _modulus.size(), r->n);
|
|
||||||
// r->e = BN_bin2bn((const unsigned char*)_exponent.data(),
|
|
||||||
// _exponent.size(), r->e);
|
|
||||||
// // otherwise OpenSSL emulates sign/verify with encrypt/decrypt
|
|
||||||
// r->flags |= RSA_FLAG_SIGN_VER;
|
|
||||||
// EVP_PKEY_set1_RSA(k, r);
|
|
||||||
// OPENSSL_LOG("RSA_free");
|
|
||||||
// RSA_free(r);
|
|
||||||
// return k;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// virtual RSA* rsaKey() {
|
|
||||||
// //EVP_PKEY* k(EVP_PKEY_new());
|
|
||||||
// RSA* r(RSA_new_method(_e));
|
|
||||||
// // RSA* r(RSA_new());
|
|
||||||
// r->n = BN_bin2bn((const unsigned char*)_modulus.data(),
|
|
||||||
// _modulus.size(), r->n);
|
|
||||||
// r->e = BN_bin2bn((const unsigned char*)_exponent.data(),
|
|
||||||
// _exponent.size(), r->e);
|
|
||||||
// // otherwise OpenSSL emulates sign/verify with encrypt/decrypt
|
|
||||||
// r->flags |= RSA_FLAG_SIGN_VER;
|
|
||||||
// //EVP_PKEY_set1_RSA(k, r);
|
|
||||||
// r->d = BN_bin2bn(0, 0, r->d);
|
|
||||||
// r->p = BN_bin2bn(0, 0, r->p);
|
|
||||||
// r->q = BN_bin2bn(0, 0, r->q);
|
|
||||||
// r->dmp1 = BN_bin2bn(0, 0, r->dmp1);
|
|
||||||
// r->dmp1 = BN_bin2bn(0, 0, r->dmq1);
|
|
||||||
// r->iqmp = r->n;/*BN_bin2bn(0, 0, r->iqmp);*/
|
|
||||||
// return r;
|
|
||||||
// }
|
|
||||||
|
|
||||||
virtual RSA* setupRsa(RSA* r) {
|
virtual RSA* setupRsa(RSA* r) {
|
||||||
RSA_set_method(r, ENGINE_get_RSA(_e));
|
RSA_free(r);
|
||||||
r->engine=_e;
|
r = RSA_new_method(_e);
|
||||||
r->n = BN_bin2bn((const unsigned char*)_modulus.data(),
|
r->n = BN_bin2bn((const unsigned char*)_modulus.data(),
|
||||||
_modulus.size(), r->n);
|
_modulus.size(), r->n);
|
||||||
r->e = BN_bin2bn((const unsigned char*)_exponent.data(),
|
r->e = BN_bin2bn((const unsigned char*)_exponent.data(),
|
||||||
@@ -106,11 +68,6 @@ class CryptokiEngine: public QObject, public openssl::Engine {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// const RSA_METHOD* rsaMethod() {
|
|
||||||
// return ENGINE_get_RSA(_e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual const char* id() {
|
virtual const char* id() {
|
||||||
@@ -153,38 +110,6 @@ class SmartCardAuth: public QObject {
|
|||||||
//assert(connect(e(), SIGNAL(certRequired()), SLOT(login())));
|
//assert(connect(e(), SIGNAL(certRequired()), SLOT(login())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
|
|
||||||
void extendedContextInitialization(ssl_ctx_st* ctx, QSslSocket* socket) {
|
|
||||||
// qDebug()<<__PRETTY_FUNCTION__;
|
|
||||||
// QList<QSslError> expectedSslErrors;
|
|
||||||
// for (std::list<std::string>::iterator cert(_cacerts.begin());
|
|
||||||
// cert!=_cacerts.end(); ++cert) {
|
|
||||||
// SSL_CTX_add_extra_chain_cert(ctx, openssl::X509(*cert).lowLevelCopy());
|
|
||||||
// expectedSslErrors.push_back(QSslError(QSslError::SelfSignedCertificateInChain,
|
|
||||||
// QSslCertificate::fromData
|
|
||||||
// (QByteArray(cert->data(),
|
|
||||||
// cert->size()),
|
|
||||||
// QSsl::Der).at(0)));
|
|
||||||
// //qDebug()<<"Added:\n"<<QSslCertificate(QByteArray(cert->data(), cert->size()), QSsl::Der).toPem();
|
|
||||||
// }
|
|
||||||
// //socket->ignoreSslErrors(expectedSslErrors);
|
|
||||||
// SSL_CTX_set_client_cert_cb(ctx, &SmartCardAuth::clientCert);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// static int clientCert(SSL* ssl, X509 **x509, EVP_PKEY **pkey) {
|
|
||||||
// qDebug()<<__PRETTY_FUNCTION__;
|
|
||||||
// if (!e() || !*e()) return 0; // no certificate found
|
|
||||||
// qDebug()<<"*** A "<<__PRETTY_FUNCTION__;
|
|
||||||
// *x509 = e()->cert().lowLevelCopy();
|
|
||||||
// qDebug()<<"*** B "<<__PRETTY_FUNCTION__;
|
|
||||||
// *pkey = e()->privkey();
|
|
||||||
// qDebug()<<"*** C "<<__PRETTY_FUNCTION__;
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
static CryptokiEngine* e(const QString& lib = QString()) try {
|
static CryptokiEngine* e(const QString& lib = QString()) try {
|
||||||
static CryptokiEngine* _e(new CryptokiEngine(lib.toStdString()));
|
static CryptokiEngine* _e(new CryptokiEngine(lib.toStdString()));
|
||||||
return _e;
|
return _e;
|
||||||
@@ -205,7 +130,6 @@ class SmartCardAuth: public QObject {
|
|||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
if (!e() || (!force && *e())) return; // no smartcard or already logged in
|
if (!e() || (!force && *e())) return; // no smartcard or already logged in
|
||||||
try {
|
try {
|
||||||
// _cacerts.clear();
|
|
||||||
QList<CertInfo> authcerts;
|
QList<CertInfo> authcerts;
|
||||||
QList<CertInfo> allcerts;
|
QList<CertInfo> allcerts;
|
||||||
QSslConfiguration sslConfig(QSslConfiguration::defaultConfiguration());
|
QSslConfiguration sslConfig(QSslConfiguration::defaultConfiguration());
|
||||||
@@ -230,7 +154,6 @@ class SmartCardAuth: public QObject {
|
|||||||
std::string data(cert->attribute(CKA_VALUE).value);
|
std::string data(cert->attribute(CKA_VALUE).value);
|
||||||
if (!keys.size()) { // add CA-certificate
|
if (!keys.size()) { // add CA-certificate
|
||||||
OPENSSL_LOG("**** add to CA-certificates");
|
OPENSSL_LOG("**** add to CA-certificates");
|
||||||
// _cacerts.push_back(data);
|
|
||||||
} else {
|
} else {
|
||||||
OPENSSL_LOG("**** user cert, check for authentictaion");
|
OPENSSL_LOG("**** user cert, check for authentictaion");
|
||||||
if (label.value.find("auth")==0 ||
|
if (label.value.find("auth")==0 ||
|
||||||
@@ -272,47 +195,25 @@ class SmartCardAuth: public QObject {
|
|||||||
sslConfig.setLocalCertificate(localcert);
|
sslConfig.setLocalCertificate(localcert);
|
||||||
assert(localcert.isValid());
|
assert(localcert.isValid());
|
||||||
|
|
||||||
EVP_PKEY* pk(e()->privkey());
|
QByteArray pem
|
||||||
|
("-----BEGIN RSA PRIVATE KEY-----\n"
|
||||||
// QByteArray secret("That's my Secret");
|
"MIIBOwIBAAJBAMH2yqAGeVNPdgeZ2GoHo31m9aUxZ7QfK2"
|
||||||
RSA* rsa(e()->rsaKey());
|
"Go2qLTahLpQ3UL1C8G\n"
|
||||||
BIO *bio = BIO_new(BIO_s_mem());
|
"LkuMS8SNK0ZGfRMalIpIhv6bW5l3kjogOncCAwEAAQJABV"
|
||||||
assert(bio);
|
"GECtFCoGMsZFb2lSmy\n"
|
||||||
OPENSSL_CHECK(PEM_write_bio_RSAPrivateKey
|
"dOzOzYHGSy0TnnDn1dEgNnZ8sIljElPtUzm9dyXs2P3ICL"
|
||||||
(bio, rsa,
|
"1sOd7qjpzfJeyxknDL\n"
|
||||||
0, 0,0,0,0));
|
"AQIhAO5iKdLmhyuW+EDEH19vDs1Pmqs3/ZnT5UgUiJnTJq"
|
||||||
// EVP_des_ede3_cbc(),(unsigned char*)secret.data(), secret.size(),
|
"z3AiEA0ExIfUOCnxq2\n"
|
||||||
// 0, 0));
|
"a3Z46KEivcr8JB2P9VqouBbVryiq/oECIQDj8bPCejMoiE"
|
||||||
char *data(0);
|
"zMSX0iWWTTB9qC/KAg\n"
|
||||||
long size(BIO_get_mem_data(bio, &data));
|
"FtF4skHIrXKfEwIgPCs86Uo+Ch2aQjKHvJMHSRHAgeI0Om"
|
||||||
assert(size);
|
"iEwiB+e0lhE4ECIQDd\n"
|
||||||
assert(data);
|
|
||||||
QByteArray pem(data, size);
|
|
||||||
BIO_free(bio);
|
|
||||||
OPENSSL_LOG(pem.data());
|
|
||||||
|
|
||||||
pem = "-----BEGIN RSA PRIVATE KEY-----\n"
|
|
||||||
"MIIBOwIBAAJBAMH2yqAGeVNPdgeZ2GoHo31m9aUxZ7QfK2Go2qLTahLpQ3UL1C8G\n"
|
|
||||||
"LkuMS8SNK0ZGfRMalIpIhv6bW5l3kjogOncCAwEAAQJABVGECtFCoGMsZFb2lSmy\n"
|
|
||||||
"dOzOzYHGSy0TnnDn1dEgNnZ8sIljElPtUzm9dyXs2P3ICL1sOd7qjpzfJeyxknDL\n"
|
|
||||||
"AQIhAO5iKdLmhyuW+EDEH19vDs1Pmqs3/ZnT5UgUiJnTJqz3AiEA0ExIfUOCnxq2\n"
|
|
||||||
"a3Z46KEivcr8JB2P9VqouBbVryiq/oECIQDj8bPCejMoiEzMSX0iWWTTB9qC/KAg\n"
|
|
||||||
"FtF4skHIrXKfEwIgPCs86Uo+Ch2aQjKHvJMHSRHAgeI0OmiEwiB+e0lhE4ECIQDd\n"
|
|
||||||
"IbUmHIXt6oHLJmoGFX46bCcfil5eE5FXfiaw7Q9iPw==\n"
|
"IbUmHIXt6oHLJmoGFX46bCcfil5eE5FXfiaw7Q9iPw==\n"
|
||||||
"-----END RSA PRIVATE KEY-----\n";
|
"-----END RSA PRIVATE KEY-----\n");
|
||||||
|
|
||||||
bio = BIO_new_mem_buf(const_cast<char *>(pem.data()), pem.size());
|
|
||||||
rsa = 0;
|
|
||||||
OPENSSL_CHECK(PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, 0));
|
|
||||||
assert(rsa);
|
|
||||||
BIO_free(bio);
|
|
||||||
|
|
||||||
QSslKey privkey(pem, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
QSslKey privkey(pem, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||||
// ,
|
|
||||||
// secret);
|
|
||||||
e()->setupRsa((RSA*)privkey.handle());
|
e()->setupRsa((RSA*)privkey.handle());
|
||||||
OPENSSL_LOG("Got Key");
|
|
||||||
OPENSSL_LOG(privkey.toPem().data());
|
|
||||||
assert(!privkey.isNull());
|
assert(!privkey.isNull());
|
||||||
sslConfig.setPrivateKey(privkey);
|
sslConfig.setPrivateKey(privkey);
|
||||||
QSslConfiguration::setDefaultConfiguration(sslConfig);
|
QSslConfiguration::setDefaultConfiguration(sslConfig);
|
||||||
@@ -329,8 +230,6 @@ class SmartCardAuth: public QObject {
|
|||||||
" please try again."));
|
" please try again."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// QByteArray ca(QSslCertificate(SWISSSIGN_GOLD_CA_G2, QSsl::Pem).toDer());
|
|
||||||
// _cacerts.push_back(std::string(ca.data(), ca.size()));
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,12 +541,12 @@ p, li { white-space: pre-wrap; }
|
|||||||
<context>
|
<context>
|
||||||
<name>QMessageBox</name>
|
<name>QMessageBox</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="327"/>
|
<location filename="smartcardauth.hxx" line="228"/>
|
||||||
<source>Wrong PIN</source>
|
<source>Wrong PIN</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="328"/>
|
<location filename="smartcardauth.hxx" line="229"/>
|
||||||
<source>Authentication failed, please try again.</source>
|
<source>Authentication failed, please try again.</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@@ -541,12 +541,12 @@ p, li { white-space: pre-wrap; }
|
|||||||
<context>
|
<context>
|
||||||
<name>QMessageBox</name>
|
<name>QMessageBox</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="327"/>
|
<location filename="smartcardauth.hxx" line="228"/>
|
||||||
<source>Wrong PIN</source>
|
<source>Wrong PIN</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="328"/>
|
<location filename="smartcardauth.hxx" line="229"/>
|
||||||
<source>Authentication failed, please try again.</source>
|
<source>Authentication failed, please try again.</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@@ -541,12 +541,12 @@ p, li { white-space: pre-wrap; }
|
|||||||
<context>
|
<context>
|
||||||
<name>QMessageBox</name>
|
<name>QMessageBox</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="327"/>
|
<location filename="smartcardauth.hxx" line="228"/>
|
||||||
<source>Wrong PIN</source>
|
<source>Wrong PIN</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="328"/>
|
<location filename="smartcardauth.hxx" line="229"/>
|
||||||
<source>Authentication failed, please try again.</source>
|
<source>Authentication failed, please try again.</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@@ -541,12 +541,12 @@ p, li { white-space: pre-wrap; }
|
|||||||
<context>
|
<context>
|
||||||
<name>QMessageBox</name>
|
<name>QMessageBox</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="327"/>
|
<location filename="smartcardauth.hxx" line="228"/>
|
||||||
<source>Wrong PIN</source>
|
<source>Wrong PIN</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="smartcardauth.hxx" line="328"/>
|
<location filename="smartcardauth.hxx" line="229"/>
|
||||||
<source>Authentication failed, please try again.</source>
|
<source>Authentication failed, please try again.</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
Reference in New Issue
Block a user