@@ -195,28 +195,31 @@ void WebServer::handleSettingsUpdate(settings::type type, QJsonDocument config)
195195 crtPath = WEBSERVER_DEFAULT_CRT_PATH;
196196
197197 // load and verify crt
198- QFile cfile (crtPath);
199- cfile.open (QIODevice::ReadOnly);
200- QList<QSslCertificate> validList;
201- QList<QSslCertificate> cList = QSslCertificate::fromDevice (&cfile, QSsl::Pem);
202- cfile.close ();
203-
204- // Filter for valid certs
205- for (const auto & entry : cList)
206- {
207- if (!entry.isNull () && QDateTime::currentDateTime ().daysTo (entry.expiryDate ()) > 0 )
208- validList.append (entry);
209- else
210- Error (_log, " The provided SSL certificate is invalid/not supported/reached expiry date ('{:s}')" , (crtPath));
211- }
212-
213- if (!validList.isEmpty ())
214- {
215- Info (_log, " Setup SSL certificate" );
216- _server->setCertificates (validList);
198+ if (QFile cfile (crtPath); !cfile.open (QIODevice::ReadOnly)) {
199+ Error (_log, " Cannot open cert file using path: '{:s}'" , (crtPath));
217200 }
218201 else {
219- Error (_log, " No valid SSL certificate has been found ('{:s}'). Did you install OpenSSL?" , (crtPath));
202+ QList<QSslCertificate> validList;
203+ QList<QSslCertificate> cList = QSslCertificate::fromDevice (&cfile, QSsl::Pem);
204+ cfile.close ();
205+
206+ // Filter for valid certs
207+ for (const auto & entry : cList)
208+ {
209+ if (!entry.isNull () && QDateTime::currentDateTime ().daysTo (entry.expiryDate ()) > 0 )
210+ validList.append (entry);
211+ else
212+ Error (_log, " The provided SSL certificate is invalid/not supported/reached expiry date ('{:s}')" , (crtPath));
213+ }
214+
215+ if (!validList.isEmpty ())
216+ {
217+ Info (_log, " Setup SSL certificate" );
218+ _server->setCertificates (validList);
219+ }
220+ else {
221+ Error (_log, " No valid SSL certificate has been found ('{:s}'). Did you install OpenSSL?" , (crtPath));
222+ }
220223 }
221224
222225 // load and verify key
0 commit comments