From c743f47c8576f56561e87eb7a836e9db4997fdba Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Tue, 25 Oct 2016 16:09:40 -0400 Subject: [PATCH 1/9] Added support for ssl client certificates --- AUTHORS | 1 + include/wkhtmltox/loadsettings.hh | 15 +++++++++ src/lib/loadsettings.hh | 15 +++++++++ src/lib/pdfconverter.cc | 52 +++++++++++++++++++++++++++++++ src/lib/reflect.cc | 5 +++ src/shared/commonarguments.cc | 5 +++ 6 files changed, 93 insertions(+) diff --git a/AUTHORS b/AUTHORS index 62f43f49c..96f9b82b5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -38,3 +38,4 @@ Mehdi Abbad Lyes Amazouz Pascal Bach Mário Silva +JasonParallel diff --git a/include/wkhtmltox/loadsettings.hh b/include/wkhtmltox/loadsettings.hh index 5b9565f79..a15a5cb7c 100644 --- a/include/wkhtmltox/loadsettings.hh +++ b/include/wkhtmltox/loadsettings.hh @@ -50,6 +50,21 @@ struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file QString cookieJar; + + //! String containing the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyString; + + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; + + //! Password to ssl client cert private key + QString clientSslKeyPassword; + + //! String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtString; + + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; }; struct DLL_PUBLIC LoadPage { diff --git a/src/lib/loadsettings.hh b/src/lib/loadsettings.hh index 20a5da295..2290bc05a 100644 --- a/src/lib/loadsettings.hh +++ b/src/lib/loadsettings.hh @@ -53,6 +53,21 @@ struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file QString cookieJar; + + //! String containing the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyString; + + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; + + //! Password to ssl client cert private key + QString clientSslKeyPassword; + + //! String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtString; + + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; }; struct DLL_PUBLIC LoadPage { diff --git a/src/lib/pdfconverter.cc b/src/lib/pdfconverter.cc index 7a14e25c3..a6b264ba7 100644 --- a/src/lib/pdfconverter.cc +++ b/src/lib/pdfconverter.cc @@ -31,6 +31,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -45,6 +50,7 @@ using namespace wkhtmltopdf::settings; #define STRINGIZE_(x) #x #define STRINGIZE(x) STRINGIZE_(x) +#define S(t) ((t).toLocal8Bit().constData()) const qreal PdfConverter::millimeterToPointMultiplier = 2.83464567; @@ -131,6 +137,52 @@ PdfConverterPrivate::PdfConverterPrivate(PdfGlobal & s, PdfConverter & o) : int height = viewportSizeList.last().toInt(); viewportSize = QSize(width,height); } + + if(settings.load.clientSslKeyString != NULL || settings.load.clientSslKeyPath != NULL){ + bool success = true; + QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); + if(settings.load.clientSslKeyPassword == NULL){ + fprintf(stderr, "Client ssl key can not be loaded without password. Skipping ssl config."); + }else if(settings.load.clientSslKeyString != NULL){ + QSslKey key(settings.load.clientSslKeyString.toUtf8(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.load.clientSslKeyPassword.toUtf8()); + sslConfig.setPrivateKey(key); + }else{ + //key not supplied as string use path + QFile keyFile(settings.load.clientSslKeyPath); + success = keyFile.open(QFile::ReadOnly); + if(!success){ + fprintf(stderr, "Client ssl key file coult not be loaded. Skipping ssl config."); + } + QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.load.clientSslKeyPassword.toUtf8()); + sslConfig.setPrivateKey(key); + keyFile.close(); + } + if(success){ + if(settings.load.clientSslCrtString == NULL && settings.load.clientSslCrtPath == NULL){ + success = false; + fprintf(stderr, "Client ssl cert is required when a ssl client key has been supplied. Skipping ssl config."); + }else if(settings.load.clientSslCrtString != NULL){ + QList chainCerts = + QSslCertificate::fromData(settings.load.clientSslCrtString.toUtf8(), QSsl::Pem); + QList cas = sslConfig.caCertificates(); + cas.append(chainCerts); + sslConfig.setLocalCertificate(chainCerts.first()); + sslConfig.setCaCertificates(cas); + }else{ + //key not supplied as string use path + QList chainCerts = + QSslCertificate::fromPath(settings.load.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); + QList cas = sslConfig.caCertificates(); + cas.append(chainCerts); + sslConfig.setLocalCertificate(chainCerts.first()); + sslConfig.setCaCertificates(cas); + } + + if(success){ + QSslConfiguration::setDefaultConfiguration(sslConfig); + } + } + } } PdfConverterPrivate::~PdfConverterPrivate() { diff --git a/src/lib/reflect.cc b/src/lib/reflect.cc index 32fc8190f..eb72efe8a 100644 --- a/src/lib/reflect.cc +++ b/src/lib/reflect.cc @@ -52,6 +52,11 @@ ReflectClass::~ReflectClass() { ReflectImpl::ReflectImpl(LoadGlobal & c) { WKHTMLTOPDF_REFLECT(cookieJar); + WKHTMLTOPDF_REFLECT(clientSslKeyString); + WKHTMLTOPDF_REFLECT(clientSslKeyPath); + WKHTMLTOPDF_REFLECT(clientSslKeyPassword); + WKHTMLTOPDF_REFLECT(clientSslCrtString); + WKHTMLTOPDF_REFLECT(clientSslCrtPath); } ReflectImpl::ReflectImpl(LoadPage & c) { diff --git a/src/shared/commonarguments.cc b/src/shared/commonarguments.cc index 3d45aaf35..2e36bc7d5 100644 --- a/src/shared/commonarguments.cc +++ b/src/shared/commonarguments.cc @@ -174,6 +174,11 @@ void CommandLineParserBase::addGlobalLoadArgs(LoadGlobal & s) { qthack(false); addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path") ); + addarg("ssl-key-string",0,"String containing the ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyString, "PEM String")); + addarg("ssl-key-path",0,"Path to ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyPath, "path")); + addarg("ssl-key-password",0,"Password to ssl client cert private key", new QStrSetter(s.clientSslKeyPassword, "password")); + addarg("ssl-crt-string",0,"String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtString, "PEM String")); + addarg("ssl-crt-path",0,"Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtPath, "path")); } void CommandLineParserBase::addWebArgs(Web & s) { From b138dfd533afdd06db89dd97229de8b2189ce896 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Thu, 1 Dec 2016 22:46:16 -0500 Subject: [PATCH 2/9] Removed key and cert string params & moved client ssl code Removed key and cert string params. Moved client ssl code to MyNetworkAccessManager::createRequest --- include/wkhtmltox/loadsettings.hh | 26 ++++++---------- src/lib/loadsettings.hh | 26 ++++++---------- src/lib/multipageloader.cc | 34 ++++++++++++++++++++ src/lib/pdfconverter.cc | 52 +------------------------------ src/lib/reflect.cc | 10 +++--- src/shared/commonarguments.cc | 8 ++--- 6 files changed, 62 insertions(+), 94 deletions(-) diff --git a/include/wkhtmltox/loadsettings.hh b/include/wkhtmltox/loadsettings.hh index a15a5cb7c..0ab126ca3 100644 --- a/include/wkhtmltox/loadsettings.hh +++ b/include/wkhtmltox/loadsettings.hh @@ -49,22 +49,7 @@ struct DLL_PUBLIC PostItem { struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file - QString cookieJar; - - //! String containing the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyString; - - //! Path to the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyPath; - - //! Password to ssl client cert private key - QString clientSslKeyPassword; - - //! String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtString; - - //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtPath; + QString cookieJar; }; struct DLL_PUBLIC LoadPage { @@ -82,6 +67,15 @@ struct DLL_PUBLIC LoadPage { //! Password used for http auth login QString password; + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; + + //! Password to ssl client cert private key + QString clientSslKeyPassword; + + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; + //! How many milliseconds should we wait for a Javascript redirect int jsdelay; diff --git a/src/lib/loadsettings.hh b/src/lib/loadsettings.hh index 2290bc05a..6682c08e7 100644 --- a/src/lib/loadsettings.hh +++ b/src/lib/loadsettings.hh @@ -52,22 +52,7 @@ struct DLL_PUBLIC PostItem { struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file - QString cookieJar; - - //! String containing the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyString; - - //! Path to the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyPath; - - //! Password to ssl client cert private key - QString clientSslKeyPassword; - - //! String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtString; - - //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtPath; + QString cookieJar; }; struct DLL_PUBLIC LoadPage { @@ -85,6 +70,15 @@ struct DLL_PUBLIC LoadPage { //! Password used for http auth login QString password; + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; + + //! Password to ssl client cert private key + QString clientSslKeyPassword; + + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; + //! How many milliseconds should we wait for a Javascript redirect int jsdelay; diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc index 7e6148509..136097daa 100644 --- a/src/lib/multipageloader.cc +++ b/src/lib/multipageloader.cc @@ -26,6 +26,11 @@ #include #include #include +#include +#include +#include +#include +#include #if QT_VERSION >= 0x050000 #include #endif @@ -104,6 +109,35 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo foreach (const HT & j, settings.customHeaders) r3.setRawHeader(j.first.toLatin1(), j.second.toLatin1()); } + + if(settings.clientSslKeyPath != NULL && settings.clientSslKeyPassword != NULL + && settings.clientSslCrtPath != NULL){ + bool success = true; + QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); + + //key not supplied as string use path + QFile keyFile(settings.clientSslKeyPath); + success = keyFile.open(QFile::ReadOnly); + QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.clientSslKeyPassword.toUtf8()); + sslConfig.setPrivateKey(key); + keyFile.close(); + + if(success){ + + //key not supplied as string use path + QList chainCerts = + QSslCertificate::fromPath(settings.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); + QList cas = sslConfig.caCertificates(); + cas.append(chainCerts); + sslConfig.setLocalCertificate(chainCerts.first()); + sslConfig.setCaCertificates(cas); + + if(success){ + r3.setSslConfiguration(sslConfig); + } + } + } + return QNetworkAccessManager::createRequest(op, r3, outgoingData); } diff --git a/src/lib/pdfconverter.cc b/src/lib/pdfconverter.cc index a6b264ba7..5c81a3e0c 100644 --- a/src/lib/pdfconverter.cc +++ b/src/lib/pdfconverter.cc @@ -31,11 +31,6 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include @@ -50,7 +45,6 @@ using namespace wkhtmltopdf::settings; #define STRINGIZE_(x) #x #define STRINGIZE(x) STRINGIZE_(x) -#define S(t) ((t).toLocal8Bit().constData()) const qreal PdfConverter::millimeterToPointMultiplier = 2.83464567; @@ -138,51 +132,7 @@ PdfConverterPrivate::PdfConverterPrivate(PdfGlobal & s, PdfConverter & o) : viewportSize = QSize(width,height); } - if(settings.load.clientSslKeyString != NULL || settings.load.clientSslKeyPath != NULL){ - bool success = true; - QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); - if(settings.load.clientSslKeyPassword == NULL){ - fprintf(stderr, "Client ssl key can not be loaded without password. Skipping ssl config."); - }else if(settings.load.clientSslKeyString != NULL){ - QSslKey key(settings.load.clientSslKeyString.toUtf8(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.load.clientSslKeyPassword.toUtf8()); - sslConfig.setPrivateKey(key); - }else{ - //key not supplied as string use path - QFile keyFile(settings.load.clientSslKeyPath); - success = keyFile.open(QFile::ReadOnly); - if(!success){ - fprintf(stderr, "Client ssl key file coult not be loaded. Skipping ssl config."); - } - QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.load.clientSslKeyPassword.toUtf8()); - sslConfig.setPrivateKey(key); - keyFile.close(); - } - if(success){ - if(settings.load.clientSslCrtString == NULL && settings.load.clientSslCrtPath == NULL){ - success = false; - fprintf(stderr, "Client ssl cert is required when a ssl client key has been supplied. Skipping ssl config."); - }else if(settings.load.clientSslCrtString != NULL){ - QList chainCerts = - QSslCertificate::fromData(settings.load.clientSslCrtString.toUtf8(), QSsl::Pem); - QList cas = sslConfig.caCertificates(); - cas.append(chainCerts); - sslConfig.setLocalCertificate(chainCerts.first()); - sslConfig.setCaCertificates(cas); - }else{ - //key not supplied as string use path - QList chainCerts = - QSslCertificate::fromPath(settings.load.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); - QList cas = sslConfig.caCertificates(); - cas.append(chainCerts); - sslConfig.setLocalCertificate(chainCerts.first()); - sslConfig.setCaCertificates(cas); - } - - if(success){ - QSslConfiguration::setDefaultConfiguration(sslConfig); - } - } - } + } PdfConverterPrivate::~PdfConverterPrivate() { diff --git a/src/lib/reflect.cc b/src/lib/reflect.cc index eb72efe8a..0d10a1e89 100644 --- a/src/lib/reflect.cc +++ b/src/lib/reflect.cc @@ -51,17 +51,15 @@ ReflectClass::~ReflectClass() { } ReflectImpl::ReflectImpl(LoadGlobal & c) { - WKHTMLTOPDF_REFLECT(cookieJar); - WKHTMLTOPDF_REFLECT(clientSslKeyString); - WKHTMLTOPDF_REFLECT(clientSslKeyPath); - WKHTMLTOPDF_REFLECT(clientSslKeyPassword); - WKHTMLTOPDF_REFLECT(clientSslCrtString); - WKHTMLTOPDF_REFLECT(clientSslCrtPath); + WKHTMLTOPDF_REFLECT(cookieJar); } ReflectImpl::ReflectImpl(LoadPage & c) { WKHTMLTOPDF_REFLECT(username); WKHTMLTOPDF_REFLECT(password); + WKHTMLTOPDF_REFLECT(clientSslKeyPath); + WKHTMLTOPDF_REFLECT(clientSslKeyPassword); + WKHTMLTOPDF_REFLECT(clientSslCrtPath); WKHTMLTOPDF_REFLECT(jsdelay); WKHTMLTOPDF_REFLECT(windowStatus); WKHTMLTOPDF_REFLECT(zoomFactor); diff --git a/src/shared/commonarguments.cc b/src/shared/commonarguments.cc index 2e36bc7d5..34e416663 100644 --- a/src/shared/commonarguments.cc +++ b/src/shared/commonarguments.cc @@ -174,11 +174,6 @@ void CommandLineParserBase::addGlobalLoadArgs(LoadGlobal & s) { qthack(false); addarg("cookie-jar", 0, "Read and write cookies from and to the supplied cookie jar file", new QStrSetter(s.cookieJar, "path") ); - addarg("ssl-key-string",0,"String containing the ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyString, "PEM String")); - addarg("ssl-key-path",0,"Path to ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyPath, "path")); - addarg("ssl-key-password",0,"Password to ssl client cert private key", new QStrSetter(s.clientSslKeyPassword, "password")); - addarg("ssl-crt-string",0,"String containing the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtString, "PEM String")); - addarg("ssl-crt-path",0,"Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtPath, "path")); } void CommandLineParserBase::addWebArgs(Web & s) { @@ -211,6 +206,9 @@ void CommandLineParserBase::addPageLoadArgs(LoadPage & s) { addarg("bypass-proxy-for", 0, "Bypass proxy for host (repeatable)", new StringListSetter(s.bypassProxyForHosts, "value")); addarg("username",0,"HTTP Authentication username", new QStrSetter(s.username, "username")); addarg("password",0,"HTTP Authentication password", new QStrSetter(s.password, "password")); + addarg("ssl-key-path",0,"Path to ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyPath, "path")); + addarg("ssl-key-password",0,"Password to ssl client cert private key", new QStrSetter(s.clientSslKeyPassword, "password")); + addarg("ssl-crt-path",0,"Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtPath, "path")); addarg("load-error-handling", 0, "Specify how to handle pages that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.loadErrorHandling, "handler")); addarg("load-media-error-handling", 0, "Specify how to handle media files that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.mediaLoadErrorHandling, "handler")); addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(s.customHeaders, "name", "value")); From 8064b082c1a1e9216b01238c9b44b86c123dd9e9 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Fri, 9 Dec 2016 17:24:00 -0500 Subject: [PATCH 3/9] Code Review Updates Code Review Updates --- include/wkhtmltox/loadsettings.hh | 2 +- src/lib/loadsettings.hh | 2 +- src/lib/multipageloader.cc | 46 ++++++++++++++----------------- src/lib/pdfconverter.cc | 1 - 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/include/wkhtmltox/loadsettings.hh b/include/wkhtmltox/loadsettings.hh index 0ab126ca3..43a7826f7 100644 --- a/include/wkhtmltox/loadsettings.hh +++ b/include/wkhtmltox/loadsettings.hh @@ -49,7 +49,7 @@ struct DLL_PUBLIC PostItem { struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file - QString cookieJar; + QString cookieJar; }; struct DLL_PUBLIC LoadPage { diff --git a/src/lib/loadsettings.hh b/src/lib/loadsettings.hh index 6682c08e7..1ecae1d2b 100644 --- a/src/lib/loadsettings.hh +++ b/src/lib/loadsettings.hh @@ -52,7 +52,7 @@ struct DLL_PUBLIC PostItem { struct DLL_PUBLIC LoadGlobal { LoadGlobal(); //! Path of the cookie jar file - QString cookieJar; + QString cookieJar; }; struct DLL_PUBLIC LoadPage { diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc index 136097daa..802a74be1 100644 --- a/src/lib/multipageloader.cc +++ b/src/lib/multipageloader.cc @@ -110,32 +110,26 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo r3.setRawHeader(j.first.toLatin1(), j.second.toLatin1()); } - if(settings.clientSslKeyPath != NULL && settings.clientSslKeyPassword != NULL - && settings.clientSslCrtPath != NULL){ - bool success = true; - QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); - - //key not supplied as string use path - QFile keyFile(settings.clientSslKeyPath); - success = keyFile.open(QFile::ReadOnly); - QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.clientSslKeyPassword.toUtf8()); - sslConfig.setPrivateKey(key); - keyFile.close(); - - if(success){ - - //key not supplied as string use path - QList chainCerts = - QSslCertificate::fromPath(settings.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); - QList cas = sslConfig.caCertificates(); - cas.append(chainCerts); - sslConfig.setLocalCertificate(chainCerts.first()); - sslConfig.setCaCertificates(cas); - - if(success){ - r3.setSslConfiguration(sslConfig); - } - } + if(!settings.clientSslKeyPath.isEmpty() && !settings.clientSslKeyPassword.isEmpty() + && !settings.clientSslCrtPath.isEmpty()){ + bool success = true; + QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); + + QFile keyFile(settings.clientSslKeyPath); + if(keyFile.open(QFile::ReadOnly)){ + QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, settings.clientSslKeyPassword.toUtf8()); + sslConfig.setPrivateKey(key); + keyFile.close(); + + QList chainCerts = + QSslCertificate::fromPath(settings.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); + QList cas = sslConfig.caCertificates(); + cas.append(chainCerts); + sslConfig.setLocalCertificate(chainCerts.first()); + sslConfig.setCaCertificates(cas); + + r3.setSslConfiguration(sslConfig); + } } return QNetworkAccessManager::createRequest(op, r3, outgoingData); diff --git a/src/lib/pdfconverter.cc b/src/lib/pdfconverter.cc index 5c81a3e0c..0b789b47e 100644 --- a/src/lib/pdfconverter.cc +++ b/src/lib/pdfconverter.cc @@ -132,7 +132,6 @@ PdfConverterPrivate::PdfConverterPrivate(PdfGlobal & s, PdfConverter & o) : viewportSize = QSize(width,height); } - } PdfConverterPrivate::~PdfConverterPrivate() { From 9152ab2d12fbbed452ff5b3b13a5d99f16967507 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Fri, 9 Dec 2016 17:31:01 -0500 Subject: [PATCH 4/9] Code Review Updates Code Review Updates --- src/lib/pdfconverter.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/pdfconverter.cc b/src/lib/pdfconverter.cc index 0b789b47e..7a14e25c3 100644 --- a/src/lib/pdfconverter.cc +++ b/src/lib/pdfconverter.cc @@ -131,7 +131,6 @@ PdfConverterPrivate::PdfConverterPrivate(PdfGlobal & s, PdfConverter & o) : int height = viewportSizeList.last().toInt(); viewportSize = QSize(width,height); } - } PdfConverterPrivate::~PdfConverterPrivate() { From b6646f1e528284faa4fe7f79f8330f6f388967b6 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Fri, 9 Dec 2016 17:38:15 -0500 Subject: [PATCH 5/9] Code Review Formatting Correction Code Review Formatting Correction --- include/wkhtmltox/loadsettings.hh | 12 ++++++------ src/lib/loadsettings.hh | 12 ++++++------ src/lib/reflect.cc | 8 ++++---- src/shared/commonarguments.cc | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/wkhtmltox/loadsettings.hh b/include/wkhtmltox/loadsettings.hh index 43a7826f7..3b9c76519 100644 --- a/include/wkhtmltox/loadsettings.hh +++ b/include/wkhtmltox/loadsettings.hh @@ -67,14 +67,14 @@ struct DLL_PUBLIC LoadPage { //! Password used for http auth login QString password; - //! Path to the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyPath; + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; - //! Password to ssl client cert private key - QString clientSslKeyPassword; + //! Password to ssl client cert private key + QString clientSslKeyPassword; - //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtPath; + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; //! How many milliseconds should we wait for a Javascript redirect int jsdelay; diff --git a/src/lib/loadsettings.hh b/src/lib/loadsettings.hh index 1ecae1d2b..bdd273957 100644 --- a/src/lib/loadsettings.hh +++ b/src/lib/loadsettings.hh @@ -70,14 +70,14 @@ struct DLL_PUBLIC LoadPage { //! Password used for http auth login QString password; - //! Path to the ssl client cert private key in OpenSSL PEM format - QString clientSslKeyPath; + //! Path to the ssl client cert private key in OpenSSL PEM format + QString clientSslKeyPath; - //! Password to ssl client cert private key - QString clientSslKeyPassword; + //! Password to ssl client cert private key + QString clientSslKeyPassword; - //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs - QString clientSslCrtPath; + //! Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs + QString clientSslCrtPath; //! How many milliseconds should we wait for a Javascript redirect int jsdelay; diff --git a/src/lib/reflect.cc b/src/lib/reflect.cc index 0d10a1e89..46e884c09 100644 --- a/src/lib/reflect.cc +++ b/src/lib/reflect.cc @@ -51,15 +51,15 @@ ReflectClass::~ReflectClass() { } ReflectImpl::ReflectImpl(LoadGlobal & c) { - WKHTMLTOPDF_REFLECT(cookieJar); + WKHTMLTOPDF_REFLECT(cookieJar); } ReflectImpl::ReflectImpl(LoadPage & c) { WKHTMLTOPDF_REFLECT(username); WKHTMLTOPDF_REFLECT(password); - WKHTMLTOPDF_REFLECT(clientSslKeyPath); - WKHTMLTOPDF_REFLECT(clientSslKeyPassword); - WKHTMLTOPDF_REFLECT(clientSslCrtPath); + WKHTMLTOPDF_REFLECT(clientSslKeyPath); + WKHTMLTOPDF_REFLECT(clientSslKeyPassword); + WKHTMLTOPDF_REFLECT(clientSslCrtPath); WKHTMLTOPDF_REFLECT(jsdelay); WKHTMLTOPDF_REFLECT(windowStatus); WKHTMLTOPDF_REFLECT(zoomFactor); diff --git a/src/shared/commonarguments.cc b/src/shared/commonarguments.cc index 34e416663..812f7b86a 100644 --- a/src/shared/commonarguments.cc +++ b/src/shared/commonarguments.cc @@ -206,9 +206,9 @@ void CommandLineParserBase::addPageLoadArgs(LoadPage & s) { addarg("bypass-proxy-for", 0, "Bypass proxy for host (repeatable)", new StringListSetter(s.bypassProxyForHosts, "value")); addarg("username",0,"HTTP Authentication username", new QStrSetter(s.username, "username")); addarg("password",0,"HTTP Authentication password", new QStrSetter(s.password, "password")); - addarg("ssl-key-path",0,"Path to ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyPath, "path")); - addarg("ssl-key-password",0,"Password to ssl client cert private key", new QStrSetter(s.clientSslKeyPassword, "password")); - addarg("ssl-crt-path",0,"Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtPath, "path")); + addarg("ssl-key-path",0,"Path to ssl client cert private key in OpenSSL PEM format", new QStrSetter(s.clientSslKeyPath, "path")); + addarg("ssl-key-password",0,"Password to ssl client cert private key", new QStrSetter(s.clientSslKeyPassword, "password")); + addarg("ssl-crt-path",0,"Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs", new QStrSetter(s.clientSslCrtPath, "path")); addarg("load-error-handling", 0, "Specify how to handle pages that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.loadErrorHandling, "handler")); addarg("load-media-error-handling", 0, "Specify how to handle media files that fail to load: abort, ignore or skip", new LoadErrorHandlingSetting(s.mediaLoadErrorHandling, "handler")); addarg("custom-header",0,"Set an additional HTTP header (repeatable)", new MapSetter<>(s.customHeaders, "name", "value")); From cd91ee14d84ea1912c1238b969cbd1b525d7de8c Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Fri, 9 Dec 2016 17:43:26 -0500 Subject: [PATCH 6/9] Code Review Formating Update Code Review Formating Update --- src/lib/multipageloader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc index 802a74be1..04d7e7892 100644 --- a/src/lib/multipageloader.cc +++ b/src/lib/multipageloader.cc @@ -130,7 +130,7 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo r3.setSslConfiguration(sslConfig); } - } + } return QNetworkAccessManager::createRequest(op, r3, outgoingData); } From 385c5e0fa7aec819696f8cdbd66dcfb3df4de694 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Fri, 9 Dec 2016 17:45:10 -0500 Subject: [PATCH 7/9] Updating contact info Updating contact info --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 96f9b82b5..1067b9b92 100644 --- a/AUTHORS +++ b/AUTHORS @@ -38,4 +38,4 @@ Mehdi Abbad Lyes Amazouz Pascal Bach Mário Silva -JasonParallel +Jason Smith From b6a98786bf08b146fb67b8a928e0b9b511a08a5f Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Wed, 4 Jan 2017 12:50:04 -0500 Subject: [PATCH 8/9] Added check for empty or missing ssl ctr file Added check for empty or missing ssl ctr file --- src/lib/multipageloader.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc index 04d7e7892..b26b987b1 100644 --- a/src/lib/multipageloader.cc +++ b/src/lib/multipageloader.cc @@ -125,10 +125,12 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo QSslCertificate::fromPath(settings.clientSslCrtPath.toLatin1(), QSsl::Pem, QRegExp::FixedString); QList cas = sslConfig.caCertificates(); cas.append(chainCerts); - sslConfig.setLocalCertificate(chainCerts.first()); - sslConfig.setCaCertificates(cas); + if(!chainCerts.isEmpty()){ + sslConfig.setLocalCertificate(chainCerts.first()); + sslConfig.setCaCertificates(cas); - r3.setSslConfiguration(sslConfig); + r3.setSslConfiguration(sslConfig); + } } } From e36d7e679186fe1b0209e9d0a2beff3dbfc7e683 Mon Sep 17 00:00:00 2001 From: JasonParallel Date: Wed, 4 Jan 2017 15:35:46 -0500 Subject: [PATCH 9/9] Added check for building without ssl support --- src/lib/multipageloader.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc index b26b987b1..841dd6e78 100644 --- a/src/lib/multipageloader.cc +++ b/src/lib/multipageloader.cc @@ -26,11 +26,13 @@ #include #include #include -#include -#include #include #include +#if (QT_VERSION >= 0x050000 && !defined QT_NO_SSL) || !defined QT_NO_OPENSSL +#include +#include #include +#endif #if QT_VERSION >= 0x050000 #include #endif @@ -110,6 +112,7 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo r3.setRawHeader(j.first.toLatin1(), j.second.toLatin1()); } + #if (QT_VERSION >= 0x050000 && !defined QT_NO_SSL) || !defined QT_NO_OPENSSL if(!settings.clientSslKeyPath.isEmpty() && !settings.clientSslKeyPassword.isEmpty() && !settings.clientSslCrtPath.isEmpty()){ bool success = true; @@ -133,6 +136,7 @@ QNetworkReply * MyNetworkAccessManager::createRequest(Operation op, const QNetwo } } } + #endif return QNetworkAccessManager::createRequest(op, r3, outgoingData); }