summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Neves2012-02-02 22:01:53 +0100
committerMichael Neves2012-02-02 22:01:53 +0100
commit955edaa2409b5177bebf94ae36b932daef0f6648 (patch)
treed783e4d71dc05cc65efee7608fa7a34bd7faa3d3
parentignore SelfSignedCertificateInChain-Error fot OpenSLX-Cert (diff)
downloadfbgui-955edaa2409b5177bebf94ae36b932daef0f6648.tar.gz
fbgui-955edaa2409b5177bebf94ae36b932daef0f6648.tar.xz
fbgui-955edaa2409b5177bebf94ae36b932daef0f6648.zip
User Private Key, Certificate und Server Certificate gesetzt
-rw-r--r--src/fbgui/fbgui.cpp46
-rw-r--r--src/fbgui/fbgui.h10
2 files changed, 35 insertions, 21 deletions
diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp
index 989b2c1..2adcca3 100644
--- a/src/fbgui/fbgui.cpp
+++ b/src/fbgui/fbgui.cpp
@@ -243,12 +243,28 @@ void fbgui::loadURL() {
// Generate POST identification data needed by PBS.
QByteArray postData = generatePOSTData();
+ // Generate a Network Request Object
_qnr = new QNetworkRequest(baseURL);
+ //Add OpenSLX Certificate to SSLConfiguration
QList<QSslCertificate> certList = QSslCertificate::fromPath(QLatin1String("/usr/lib/ssl/openslx/CA/certs/openslx-cert.pem"));
+ setCACertificates(certList);
+
+ //Ignore the SelfSignedCertificateInChain-error for the OpenSLX-Certificate
QSslError error(QSslError::SelfSignedCertificateInChain, certList.at(0));
_expectedSslErrors.append(error);
- registerCACertificates(certList);
+
+ //Add User Certificate to SSLConfiguration
+ QList<QSslCertificate> userCertList = QSslCertificate::fromPath(QLatin1String("/usr/lib/ssl/openslx/CA/certs/guest-cert.pem"));
+ setLocalCertificate(userCertList.at(0));
+
+ //Add User PrivateKey to SSLConfiguration
+ QFile keyFile("/usr/lib/ssl/openslx/CA/private/guest.pem");
+ Q_ASSERT(keyFile.open(QIODevice::ReadOnly));
+ QByteArray keyContent = keyFile.readAll();
+ setPrivateKey(QSslKey(keyContent, QSsl::Rsa));
+
+
//Connect webViews NetworkAccessManager to SSLErrorHandler SLOT
QObject::connect(_webView->page()->networkAccessManager(),
@@ -279,7 +295,6 @@ void fbgui::loadURLDone(bool success) {
// TODO handle failure properly...
} else {
LOG4CXX_DEBUG(coreLogger, "Loaded URL: " << _webView->url().toString());
- //dumpCACertificates();
}
}
@@ -303,16 +318,6 @@ void fbgui::httpErrorHandler(QNetworkReply* reply) {
LOG4CXX_DEBUG(coreLogger, "HTTP Error: " << reply->errorString());
}
-//test function to read Certificates
-QSslCertificate fbgui::readCertificate(const QString& fileName){
- QFile certFile(fileName);
- Q_ASSERT(certFile.open(QIODevice::ReadOnly));
- QByteArray certContent = certFile.readAll();
- LOG4CXX_DEBUG(coreLogger,"Is cert valid: " << certContent);
- QSslCertificate cert(certContent, QSsl::Pem);
- return cert;
-}
-
//Dump all Certificates in SSLConfiguration
void fbgui::dumpCACertificates(){
QSslConfiguration sslConfig = _qnr->sslConfiguration();
@@ -324,7 +329,7 @@ void fbgui::dumpCACertificates(){
}
//Saves CACertificates to SslConfiguration
-void fbgui::registerCACertificates(const QList<QSslCertificate> & certificates){
+void fbgui::setCACertificates(const QList<QSslCertificate> & certificates){
foreach (QSslCertificate cert, certificates){
LOG4CXX_DEBUG(coreLogger,"Is cert valid: " << cert.isValid());
@@ -341,17 +346,26 @@ void fbgui::registerCACertificates(const QList<QSslCertificate> & certificates){
}
-//Saves PrivateKey to SslConfiguration
-void fbgui::setLocalCertificate(QSslCertificate& cert){
+//Saves User Certificate to SslConfiguration
+void fbgui::setLocalCertificate(const QSslCertificate& cert){
LOG4CXX_DEBUG(coreLogger,"Is cert valid: " << cert.isValid());
- LOG4CXX_DEBUG(coreLogger,"Cert info: " << cert.issuerInfo(QSslCertificate::Organization));
+ LOG4CXX_DEBUG(coreLogger,"Cert Issuer: " << cert.issuerInfo(QSslCertificate::CommonName));
+ LOG4CXX_DEBUG(coreLogger,"Cert Subject: " << cert.subjectInfo(QSslCertificate::CommonName));
QSslConfiguration sslConfig = _qnr->sslConfiguration();
sslConfig.setLocalCertificate(cert);
_qnr->setSslConfiguration(sslConfig);
+}
+//Saves PrivateKey to SslConfiguration
+void fbgui::setPrivateKey(const QSslKey & key){
+ LOG4CXX_DEBUG(coreLogger,"Is key valid: " << key.isNull());
+ QSslConfiguration sslConfig = _qnr->sslConfiguration();
+ sslConfig.setPrivateKey(key);
+ _qnr->setSslConfiguration(sslConfig);
}
+
//-------------------------------------------------------------------------------------------
/**
* This method generates the POST data body.
diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h
index 1c9d8ae..0c8d7d6 100644
--- a/src/fbgui/fbgui.h
+++ b/src/fbgui/fbgui.h
@@ -82,9 +82,6 @@ private:
bool checkHost() const;
void loadURL();
- //test function to read and save CACertificates
- QSslCertificate readCertificate(const QString&);
-
//Dump all Certificates in SSLConfiguration
void dumpCACertificates();
@@ -134,10 +131,13 @@ private slots:
void httpErrorHandler(QNetworkReply*);
//Sets CaCertificates in QSslConfiguration
- void registerCACertificates(const QList<QSslCertificate> & );
+ void setCACertificates(const QList<QSslCertificate> & );
//Sets LocalCertificate in QSslConfiguration
- void setLocalCertificate(QSslCertificate& cert);
+ void setLocalCertificate(const QSslCertificate & );
+
+ //Sets PrivateKey in QSslConfiguration
+ void setPrivateKey(const QSslKey &);
// shut off the system
void performShutDown();