-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix up SSL client certificates #5213 #69 #5289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,13 @@ | |
#include <QMessageBox> | ||
#include <QSsl> | ||
#include <QSslCertificate> | ||
#include <QNetworkAccessManager> | ||
|
||
#include "QProgressIndicator.h" | ||
|
||
#include "wizard/owncloudwizardcommon.h" | ||
#include "wizard/owncloudsetuppage.h" | ||
#include "wizard/owncloudconnectionmethoddialog.h" | ||
#include "../3rdparty/certificates/p12topem.h" | ||
#include "theme.h" | ||
#include "account.h" | ||
|
||
|
@@ -71,7 +71,6 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent) | |
connect(_ui.leUrl, SIGNAL(editingFinished()), SLOT(slotUrlEditFinished())); | ||
|
||
addCertDial = new AddCertificateDialog(this); | ||
connect(_ocWizard,SIGNAL(needCertificate()),this,SLOT(slotAskSSLClientCertificate())); | ||
} | ||
|
||
void OwncloudSetupPage::setServerUrl( const QString& newUrl ) | ||
|
@@ -269,7 +268,10 @@ void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly ) | |
} | ||
break; | ||
case OwncloudConnectionMethodDialog::Client_Side_TLS: | ||
slotAskSSLClientCertificate(); | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) | ||
addCertDial->show(); | ||
connect(addCertDial, SIGNAL(accepted()),this,SLOT(slotCertificateAccepted())); | ||
#endif | ||
break; | ||
case OwncloudConnectionMethodDialog::Closed: | ||
case OwncloudConnectionMethodDialog::Back: | ||
|
@@ -302,12 +304,6 @@ void OwncloudSetupPage::stopSpinner() | |
_progressIndi->stopAnimation(); | ||
} | ||
|
||
void OwncloudSetupPage::slotAskSSLClientCertificate() | ||
{ | ||
addCertDial->show(); | ||
connect(addCertDial, SIGNAL(accepted()),this,SLOT(slotCertificateAccepted())); | ||
} | ||
|
||
QString subjectInfoHelper(const QSslCertificate& cert, const QByteArray &qa) | ||
{ | ||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0) | ||
|
@@ -320,36 +316,40 @@ QString subjectInfoHelper(const QSslCertificate& cert, const QByteArray &qa) | |
//called during the validation of the client certificate. | ||
void OwncloudSetupPage::slotCertificateAccepted() | ||
{ | ||
QSslCertificate sslCertificate; | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) | ||
QList<QSslCertificate> clientCaCertificates; | ||
QFile certFile(addCertDial->getCertificatePath()); | ||
certFile.open(QFile::ReadOnly); | ||
if(QSslCertificate::importPkcs12(&certFile, | ||
&_ocWizard->_clientSslKey, &_ocWizard->_clientSslCertificate, | ||
&clientCaCertificates, | ||
addCertDial->getCertificatePasswd().toLocal8Bit())){ | ||
AccountPtr acc = _ocWizard->account(); | ||
|
||
resultP12ToPem certif = p12ToPem(addCertDial->getCertificatePath().toStdString() , addCertDial->getCertificatePasswd().toStdString()); | ||
if(certif.ReturnCode){ | ||
QString s = QString::fromStdString(certif.Certificate); | ||
QByteArray ba = s.toLocal8Bit(); | ||
// to re-create the session ticket because we added a key/cert | ||
acc->setSslConfiguration(QSslConfiguration()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this line do anything? In particular, shouldn't the SslConfiguration returned from the next line be exactly the empty configuration passed in here?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, setting a null configuration should make getOrCreateSslConfig return a new configuration filled in with some stuff already. The goal is also to clear any ssl session ticket etc out so we start with a new configuration state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ckamm Do you agree/understand? Then I can merge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guruz Yes, right. Setting a null configuration will cause |
||
QSslConfiguration sslConfiguration = acc->getOrCreateSslConfig(); | ||
|
||
QList<QSslCertificate> sslCertificateList = QSslCertificate::fromData(ba, QSsl::Pem); | ||
sslCertificate = sslCertificateList.takeAt(0); | ||
// We're stuffing the certificate into the configuration form here. Later the | ||
// cert will come via the HttpCredentials | ||
sslConfiguration.setLocalCertificate(_ocWizard->_clientSslCertificate); | ||
sslConfiguration.setPrivateKey(_ocWizard->_clientSslKey); | ||
acc->setSslConfiguration(sslConfiguration); | ||
|
||
_ocWizard->ownCloudCertificate = ba; | ||
_ocWizard->ownCloudPrivateKey = certif.PrivateKey.c_str(); | ||
_ocWizard->ownCloudCertificatePath = addCertDial->getCertificatePath(); | ||
_ocWizard->ownCloudCertificatePasswd = addCertDial->getCertificatePasswd(); | ||
// Make sure TCP connections get re-established | ||
acc->networkAccessManager()->clearAccessCache(); | ||
|
||
AccountPtr acc = _ocWizard->account(); | ||
acc->setCertificate(_ocWizard->ownCloudCertificate, _ocWizard->ownCloudPrivateKey); | ||
addCertDial->reinit(); | ||
addCertDial->reinit(); // FIXME: Why not just have this only created on use? | ||
validatePage(); | ||
} else { | ||
QString message; | ||
message = certif.Comment.c_str(); | ||
addCertDial->showErrorMessage(message); | ||
addCertDial->showErrorMessage("Could not load certificate"); | ||
addCertDial->show(); | ||
} | ||
#endif | ||
} | ||
|
||
OwncloudSetupPage::~OwncloudSetupPage() | ||
{ | ||
delete addCertDial; | ||
} | ||
|
||
} // namespace OCC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be >= 5.4.0?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, for old versions we want to hide this button to not allow the user to configure anything.
This is based on 3dd6bcc