Skip to content
Permalink
Browse files

Qt5 compatibility patch for QSsl

> QSslCertificate::subjectInfo() and QSslCertificate::issuerInfo() return a
> QStringList instead of a QString in Qt5. It's pretty common for a certificate
> to contain more than entry of a specific type, but in Qt 4 the API only let
> you access the first one.

[Source](https://blogs.kde.org/2012/04/14/whats-new-qt-5-ssl)

This fix adds macros to apply the Qt4 behavior on Qt5 code. Obviously it would
be better the other way round.
  • Loading branch information
m-kuhn committed Oct 6, 2015
1 parent ca697db commit 3960da124b54b84d93f61030d353759f4ac09447
@@ -86,7 +86,7 @@ void QgsAuthIdentCertEdit::populateIdentityComboBox()
QgsStringMap idents;
Q_FOREACH ( const QSslCertificate& cert, certs )
{
QString org( cert.subjectInfo( QSslCertificate::Organization ) );
QString org( SSL_SUBJECT_INFO( cert, QSslCertificate::Organization ) );
if ( org.isEmpty() )
org = tr( "Organization not defined" );
idents.insert( QString( "%1 (%2)" ).arg( QgsAuthCertUtils::resolvedCertName( cert ) ).arg( org ),
@@ -24,7 +24,6 @@
#include "qgsauthmanager.h"
#include "qgslogger.h"


QString QgsAuthCertUtils::getSslProtocolName( QSsl::SslProtocol protocol )
{
switch ( protocol )
@@ -61,7 +60,7 @@ QMap<QString, QList<QSslCertificate> > QgsAuthCertUtils::certsGroupedByOrg( QLis
QMap< QString, QList<QSslCertificate> > orgcerts;
Q_FOREACH ( const QSslCertificate& cert, certs )
{
QString org( cert.subjectInfo( QSslCertificate::Organization ) );
QString org( SSL_SUBJECT_INFO( cert, QSslCertificate::Organization ) );
if ( org.isEmpty() )
org = "(Organization not defined)";
QList<QSslCertificate> valist = orgcerts.contains( org ) ? orgcerts.value( org ) : QList<QSslCertificate>();
@@ -85,7 +84,8 @@ QMap<QString, QList<QgsAuthConfigSslServer> > QgsAuthCertUtils::sslConfigsGroupe
QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs;
Q_FOREACH ( const QgsAuthConfigSslServer& config, configs )
{
QString org( config.sslCertificate().subjectInfo( QSslCertificate::Organization ) );
QString org( SSL_SUBJECT_INFO( config.sslCertificate(), QSslCertificate::Organization ) );

if ( org.isEmpty() )
org = QObject::tr( "(Organization not defined)" );
QList<QgsAuthConfigSslServer> valist = orgconfigs.contains( org ) ? orgconfigs.value( org ) : QList<QgsAuthConfigSslServer>();
@@ -265,28 +265,28 @@ QString QgsAuthCertUtils::getCaSourceName( QgsAuthCertUtils::CaCertSource source

QString QgsAuthCertUtils::resolvedCertName( const QSslCertificate &cert, bool issuer )
{
QString name( issuer ? cert.issuerInfo( QSslCertificate::CommonName )
: cert.subjectInfo( QSslCertificate::CommonName ) );
QString name( issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::CommonName )
: SSL_SUBJECT_INFO( cert, QSslCertificate::CommonName ) );

if ( name.isEmpty() )
name = issuer ? cert.issuerInfo( QSslCertificate::OrganizationalUnitName )
: cert.subjectInfo( QSslCertificate::OrganizationalUnitName );
name = issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::OrganizationalUnitName )
: SSL_SUBJECT_INFO( cert, QSslCertificate::OrganizationalUnitName );

if ( name.isEmpty() )
name = issuer ? cert.issuerInfo( QSslCertificate::Organization )
: cert.subjectInfo( QSslCertificate::Organization );
name = issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::Organization )
: SSL_SUBJECT_INFO( cert, QSslCertificate::Organization );

if ( name.isEmpty() )
name = issuer ? cert.issuerInfo( QSslCertificate::LocalityName )
: cert.subjectInfo( QSslCertificate::LocalityName );
name = issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::LocalityName )
: SSL_SUBJECT_INFO( cert, QSslCertificate::LocalityName );

if ( name.isEmpty() )
name = issuer ? cert.issuerInfo( QSslCertificate::StateOrProvinceName )
: cert.subjectInfo( QSslCertificate::StateOrProvinceName );
name = issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::StateOrProvinceName )
: SSL_SUBJECT_INFO( cert, QSslCertificate::StateOrProvinceName );

if ( name.isEmpty() )
name = issuer ? cert.issuerInfo( QSslCertificate::CountryName )
: cert.subjectInfo( QSslCertificate::CountryName );
name = issuer ? SSL_ISSUER_INFO( cert, QSslCertificate::CountryName )
: SSL_SUBJECT_INFO( cert, QSslCertificate::CountryName );

return name;
}
@@ -330,23 +330,23 @@ QString QgsAuthCertUtils::getCertDistinguishedName( const QSslCertificate &qcert
dirname, "E", issuer ? acert.issuerInfo().value( QCA::Email )
: acert.subjectInfo().value( QCA::Email ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "CN", issuer ? qcert.issuerInfo( QSslCertificate::CommonName )
: qcert.subjectInfo( QSslCertificate::CommonName ) );
dirname, "CN", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::CommonName )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::CommonName ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "OU", issuer ? qcert.issuerInfo( QSslCertificate::OrganizationalUnitName )
: qcert.subjectInfo( QSslCertificate::OrganizationalUnitName ) );
dirname, "OU", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::OrganizationalUnitName )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::OrganizationalUnitName ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "O", issuer ? qcert.issuerInfo( QSslCertificate::Organization )
: qcert.subjectInfo( QSslCertificate::Organization ) );
dirname, "O", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::Organization )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::Organization ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "L", issuer ? qcert.issuerInfo( QSslCertificate::LocalityName )
: qcert.subjectInfo( QSslCertificate::LocalityName ) );
dirname, "L", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::LocalityName )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::LocalityName ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "ST", issuer ? qcert.issuerInfo( QSslCertificate::StateOrProvinceName )
: qcert.subjectInfo( QSslCertificate::StateOrProvinceName ) );
dirname, "ST", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::StateOrProvinceName )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::StateOrProvinceName ) );
QgsAuthCertUtils::appendDirSegment_(
dirname, "C", issuer ? qcert.issuerInfo( QSslCertificate::CountryName )
: qcert.subjectInfo( QSslCertificate::CountryName ) );
dirname, "C", issuer ? SSL_ISSUER_INFO( qcert, QSslCertificate::CountryName )
: SSL_SUBJECT_INFO( qcert, QSslCertificate::CountryName ) );

return dirname.join( "," );
}
@@ -24,6 +24,18 @@

#include "qgsauthconfig.h"

#if QT_VERSION >= 0x050000
#define SSL_ISSUER_INFO( var, prop ) var.issuerInfo( prop ).first()
#else
#define SSL_ISSUER_INFO( var, prop ) var.issuerInfo( prop )
#endif

#if QT_VERSION >= 0x050000
#define SSL_SUBJECT_INFO( var, prop ) var.subjectInfo( prop ).first()
#else
#define SSL_SUBJECT_INFO( var, prop ) var.subjectInfo( prop )
#endif

/** \ingroup core
* \brief Utilities for working with certificates and keys
*/
@@ -78,7 +78,7 @@ QgsAuthCertInfo::QgsAuthCertInfo( QSslCertificate cert,

setUpCertDetailsTree();

grpbxTrust->setShown( mManageTrust );
grpbxTrust->setVisible( mManageTrust );

// trust policy is still queried, even if not managing the policy, so public getter will work
mDefaultTrustPolicy = QgsAuthManager::instance()->defaultCertTrustPolicy();
@@ -103,7 +103,7 @@ QgsAuthCertInfo::~QgsAuthCertInfo()

void QgsAuthCertInfo::setupError( const QString &msg )
{
lblError->setShown( true );
lblError->setVisible( true );
QString out = tr( "<b>Setup ERROR:</b>\n\n" );
out += msg;
lblError->setText( out );
@@ -526,22 +526,22 @@ void QgsAuthCertInfo::populateInfoDetailsSection()

// Subject Info
addFieldItem( mGrpSubj, tr( "Country (C)" ),
mCurrentQCert.subjectInfo( QSslCertificate::CountryName ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::CountryName ),
LineEdit );
addFieldItem( mGrpSubj, tr( "State/Province (ST)" ),
mCurrentQCert.subjectInfo( QSslCertificate::StateOrProvinceName ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::StateOrProvinceName ),
LineEdit );
addFieldItem( mGrpSubj, tr( "Locality (L)" ),
mCurrentQCert.subjectInfo( QSslCertificate::LocalityName ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::LocalityName ),
LineEdit );
addFieldItem( mGrpSubj, tr( "Organization (O)" ),
mCurrentQCert.subjectInfo( QSslCertificate::Organization ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::Organization ),
LineEdit );
addFieldItem( mGrpSubj, tr( "Organizational unit (OU)" ),
mCurrentQCert.subjectInfo( QSslCertificate::OrganizationalUnitName ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::OrganizationalUnitName ),
LineEdit );
addFieldItem( mGrpSubj, tr( "Common name (CN)" ),
mCurrentQCert.subjectInfo( QSslCertificate::CommonName ),
SSL_SUBJECT_INFO( mCurrentQCert, QSslCertificate::CommonName ),
LineEdit );
addFieldItem( mGrpSubj, tr( "Email address (E)" ),
mCurrentACert.subjectInfo().value( QCA::Email ),
@@ -594,22 +594,22 @@ void QgsAuthCertInfo::populateInfoDetailsSection()

// Issuer Info
addFieldItem( mGrpIssu, tr( "Country (C)" ),
mCurrentQCert.issuerInfo( QSslCertificate::CountryName ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::CountryName ),
LineEdit );
addFieldItem( mGrpIssu, tr( "State/Province (ST)" ),
mCurrentQCert.issuerInfo( QSslCertificate::StateOrProvinceName ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::StateOrProvinceName ),
LineEdit );
addFieldItem( mGrpIssu, tr( "Locality (L)" ),
mCurrentQCert.issuerInfo( QSslCertificate::LocalityName ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::LocalityName ),
LineEdit );
addFieldItem( mGrpIssu, tr( "Organization (O)" ),
mCurrentQCert.issuerInfo( QSslCertificate::Organization ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::Organization ),
LineEdit );
addFieldItem( mGrpIssu, tr( "Organizational unit (OU)" ),
mCurrentQCert.issuerInfo( QSslCertificate::OrganizationalUnitName ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::OrganizationalUnitName ),
LineEdit );
addFieldItem( mGrpIssu, tr( "Common name (CN)" ),
mCurrentQCert.issuerInfo( QSslCertificate::CommonName ),
SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::CommonName ),
LineEdit );
addFieldItem( mGrpIssu, tr( "Email address (E)" ),
mCurrentACert.issuerInfo().value( QCA::Email ),
@@ -71,7 +71,7 @@ void QgsAuthImportIdentityDialog::populateIdentityType()
{
if ( mIdentityType == CertIdentity )
{
stkwBundleType->setShown( true );
stkwBundleType->setVisible( true );

cmbIdentityTypes->addItem( tr( "PKI PEM/DER Certificate Paths" ),
QVariant( QgsAuthImportIdentityDialog::PkiPaths ) );
@@ -62,7 +62,7 @@ QgsAuthSslConfigWidget::QgsAuthSslConfigWidget( QWidget *parent,

setUpSslConfigTree();

lblLoadedConfig->setShown( false );
lblLoadedConfig->setVisible( false );
lblLoadedConfig->setText( "" );

connect( leHost, SIGNAL( textChanged( QString ) ),
@@ -207,7 +207,7 @@ void QgsAuthSslConfigWidget::setSslCertificate( const QSslCertificate &cert, con

emit certFoundInAuthDatabase( !config.isNull() );

lblLoadedConfig->setShown( true );
lblLoadedConfig->setVisible( true );
if ( !config.isNull() )
{
loadSslCustomConfig( config );
@@ -246,7 +246,7 @@ void QgsAuthSslConfigWidget::loadSslCustomConfig( const QgsAuthConfigSslServer &
setSslProtocol( config.sslProtocol() );
setSslPeerVerify( config.sslPeerVerifyMode(), config.sslPeerVerifyDepth() );

lblLoadedConfig->setShown( true );
lblLoadedConfig->setVisible( true );
lblLoadedConfig->setText( configFoundText_() );
}

@@ -266,7 +266,7 @@ void QgsAuthSslConfigWidget::resetSslCertConfig()
leCommonName->setStyleSheet( "" );
leHost->clear();

lblLoadedConfig->setShown( false );
lblLoadedConfig->setVisible( false );
lblLoadedConfig->setText( "" );
resetSslProtocol();
resetSslIgnoreErrors();

0 comments on commit 3960da1

Please sign in to comment.
You can’t perform that action at this time.