Skip to content

Commit

Permalink
Merge branch 'jb50947' into 'sailfishos-esr60'
Browse files Browse the repository at this point in the history
Use nsISSLStatus deserialisation from libxul

See merge request mer-core/qtmozembed!68
  • Loading branch information
llewelld committed Sep 17, 2020
2 parents d8958ea + 655cc5f commit 666f7ca
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 54 deletions.
89 changes: 39 additions & 50 deletions src/qmozsecurity.cpp
Expand Up @@ -13,9 +13,12 @@
#include <nsServiceManagerUtils.h>
#include <nsISSLStatus.h>
#include <nsIX509Cert.h>
#include <mozilla/embedlite/EmbedLiteApp.h>
#include <mozilla/embedlite/EmbedLiteSecurity.h>
#include <systemsettings/certificatemodel.h>

#include "qmozembedlog.h"
#include "qmozcontext.h"
#include "qmozsecurity.h"

// Ensure the enum values in QMozSecurity match the enum values in nsISSLStatus
Expand All @@ -41,13 +44,15 @@ static_assert((uint16_t)QMozSecurity::TLS_VERSION_1_2 == (uint16_t)nsISSLStatus:
emissions << &QMozSecurity:: METHODNAME ## Changed; \
}

QMozSecurity::QMozSecurity(QObject *parent) : QObject(parent)
QMozSecurity::QMozSecurity(QObject *parent)
: QObject(parent)
{
resetState(nullptr);
resetStatus(nullptr);
}

QMozSecurity::QMozSecurity(const char *aStatus, unsigned int aState, QObject *parent) : QObject(parent)
QMozSecurity::QMozSecurity(const char *aStatus, unsigned int aState, QObject *parent)
: QObject(parent)
{
resetState(nullptr);
resetStatus(nullptr);
Expand Down Expand Up @@ -198,13 +203,11 @@ void QMozSecurity::setSecurity(QString status, uint state)
void QMozSecurity::importState(const char *aStatus, unsigned int aState)
{
QQueue<void(QMozSecurity::*)()> emissions;
bool booleanResult;
bool allGood;
nsresult rv;
nsCOMPtr<nsISupports> infoObj;
mozilla::embedlite::EmbedLiteSecurity *embedSecurity = nullptr;
QMozContext *context = QMozContext::instance();

allGood = this->allGood();
rv = NS_ERROR_NOT_INITIALIZED;

if (m_state != aState) {
STATUS_EMISSION(isInsecure, STATE_IS_INSECURE)
Expand All @@ -231,86 +234,72 @@ void QMozSecurity::importState(const char *aStatus, unsigned int aState)
}

// Move implementation to the embedlite (JB#50947)
#if 0
// If the status is empty, leave it as it was
if (aStatus && *aStatus) {
nsCOMPtr<nsISerializationHelper> serialHelper = do_GetService("@mozilla.org/network/serialization-helper;1");

nsCString serSSLStatus(aStatus);
rv = serialHelper->DeserializeObject(serSSLStatus, getter_AddRefs(infoObj));

if (!NS_SUCCEEDED(rv)) {
qCDebug(lcEmbedLiteExt) << "Security state change: deserialisation failed";
if (aStatus && *aStatus && context) {
embedSecurity = context->GetApp()->CreateSecurity(aStatus, aState);
}
else {
if (!aStatus || !*aStatus) {
qDebug() << "Security state could not be imported: empty status";
}
if (!context) {
qDebug() << "Security state could not be imported: no app context";
}
}

if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsISSLStatus> sslStatus = do_QueryInterface(infoObj);

sslStatus->GetIsDomainMismatch(&booleanResult);
if (m_domainMismatch != booleanResult) {
m_domainMismatch = booleanResult;
if (embedSecurity && embedSecurity->populated()) {
if (m_domainMismatch != embedSecurity->domainMismatch()) {
m_domainMismatch = embedSecurity->domainMismatch();
emissions << &QMozSecurity::domainMismatchChanged;
}

nsCString resultCString;
sslStatus->GetCipherName(resultCString);
QString cipherName(resultCString.get());
QString cipherName = QString::fromStdString(embedSecurity->cipherName());
if (m_cipherName != cipherName) {
m_cipherName = cipherName;
emissions << &QMozSecurity::cipherNameChanged;
}

sslStatus->GetIsNotValidAtThisTime(&booleanResult);
if (m_notValidAtThisTime != booleanResult) {
m_notValidAtThisTime = booleanResult;
if (m_notValidAtThisTime != embedSecurity->notValidAtThisTime()) {
m_notValidAtThisTime = embedSecurity->notValidAtThisTime();
emissions << &QMozSecurity::notValidAtThisTimeChanged;
}

sslStatus->GetIsUntrusted(&booleanResult);
if (m_untrusted != booleanResult) {
m_untrusted = booleanResult;
if (m_untrusted != embedSecurity->untrusted()) {
m_untrusted = embedSecurity->untrusted();
emissions << &QMozSecurity::untrustedChanged;
}

sslStatus->GetIsExtendedValidation(&booleanResult);
if (m_extendedValidation != booleanResult) {
m_extendedValidation = booleanResult;
if (m_extendedValidation != embedSecurity->extendedValidation()) {
m_extendedValidation = embedSecurity->extendedValidation();
emissions << &QMozSecurity::extendedValidationChanged;
}

nsIX509Cert * aServerCert;
sslStatus->GetServerCert(&aServerCert);

uint16_t protocolVersion;
sslStatus->GetProtocolVersion(&protocolVersion);
if (m_protocolVersion != static_cast<TLS_VERSION>(protocolVersion)) {
m_protocolVersion = static_cast<TLS_VERSION>(protocolVersion);
if (m_protocolVersion != static_cast<TLS_VERSION>(embedSecurity->protocolVersion())) {
m_protocolVersion = static_cast<TLS_VERSION>(embedSecurity->protocolVersion());
emissions << &QMozSecurity::protocolVersionChanged;
}

QSslCertificate serverCertificate;
uint32_t length;
char *data;
nsresult rv = aServerCert->GetRawDER(&length, (uint8_t **)&data);
if (rv == NS_OK && data) {
serverCertificate = QSslCertificate(QByteArray(data, length), QSsl::EncodingFormat::Der);
}
QByteArray const rawDER(embedSecurity->rawDER().c_str(), embedSecurity->rawDER().length());
QSslCertificate serverCertificate = QSslCertificate(rawDER, QSsl::EncodingFormat::Der);

if (m_serverCertificate != serverCertificate) {
m_serverCertificate = serverCertificate;
emissions << &QMozSecurity::serverCertificateChanged;
}
}

if (aStatus && *aStatus && !NS_SUCCEEDED(rv)) {
else {
// There was a deserialisation error
resetStatus(&emissions);
qCDebug(lcEmbedLiteExt) << "Security state change: deserialisation failed";
}

if (allGood != this->allGood()) {
emissions << &QMozSecurity::allGoodChanged;
}
#endif

if (embedSecurity) {
context->GetApp()->DestroySecurity(embedSecurity);
}

sendEmissions(emissions);
}
Expand Down
15 changes: 11 additions & 4 deletions src/qmozsecurity.h
Expand Up @@ -19,6 +19,13 @@
#define CERT_SLOT(TYPE, NAME) \
TYPE NAME () const;

namespace mozilla {
namespace embedlite {
class EmbedLiteApp;
} // namespace embedlite
} // namespace mozilla

class QMozContext;

class QMozSecurity : public QObject
{
Expand Down Expand Up @@ -73,6 +80,10 @@ class QMozSecurity : public QObject
};
Q_ENUM(TLS_VERSION)

void setSecurityRaw(const char *aStatus, unsigned int aState);
void setSecurity(QString status, uint state);
void reset();

Q_SIGNALS:
void allGoodChanged();
void domainMismatchChanged();
Expand Down Expand Up @@ -104,10 +115,6 @@ class QMozSecurity : public QObject
void serverCertificateChanged();

public Q_SLOTS:
void setSecurityRaw(const char *aStatus, unsigned int aState);
void setSecurity(QString status, uint state);
void reset();

bool allGood() const;
const QSslCertificate serverCertificate() const;
bool domainMismatch() const;
Expand Down

0 comments on commit 666f7ca

Please sign in to comment.