+
+bool SslServer::setCertificate(const QString &path)
+{
+ _isCertValid = false;
+
+ if (path.isEmpty())
+ return false;
+
+ QFile certFile(path);
+ if (!certFile.exists()) {
+ quWarning() << "SslServer: Certificate file" << qPrintable(path) << "does not exist";
+ return false;
+ }
+
+ if (!certFile.open(QIODevice::ReadOnly)) {
+ quWarning()
+ << "SslServer: Failed to open certificate file" << qPrintable(path)
+ << "error:" << certFile.error();
+ return false;
+ }
+
+ QList<QSslCertificate> certList = QSslCertificate::fromDevice(&certFile);
+
+ if (certList.isEmpty()) {
+ quWarning() << "SslServer: Certificate file doesn't contain a certificate";
+ return false;
+ }
+
+ _cert = certList[0];
+ certList.removeFirst(); // remove server cert
+
+ // store CA and intermediates certs
+ _ca = certList;
+
+ if (!certFile.reset()) {
+ quWarning() << "SslServer: IO error reading certificate file";
+ return false;
+ }
+
+ _key = QSslKey(&certFile, QSsl::Rsa);
+ certFile.close();
+
+ if (_cert.isNull()) {
+ quWarning() << "SslServer:" << qPrintable(path) << "contains no certificate data";
+ return false;
+ }
+ if (!_cert.isValid()) {
+ quWarning() << "SslServer: Invalid certificate (most likely expired)";
+ }
+ if (_key.isNull()) {
+ quWarning() << "SslServer:" << qPrintable(path) << "contains no key data";
+ return false;
+ }
+
+ _isCertValid = true;
+
+ return _isCertValid;
+}
+
+
+#endif // HAVE_SSL