Skip to content
Permalink
Browse files

[auth] Moved the PEM/DER sniffing to a common private function

  • Loading branch information
elpaso committed Nov 14, 2017
1 parent c09c96b commit b1eb6c0bc6d6440108ec04bec4e7aafca4879305
Showing with 12 additions and 5 deletions.
  1. +10 −5 src/core/auth/qgsauthcertutils.cpp
  2. +2 −0 src/core/auth/qgsauthcertutils.h
@@ -125,8 +125,8 @@ QByteArray QgsAuthCertUtils::fileData( const QString &path )
QList<QSslCertificate> QgsAuthCertUtils::certsFromFile( const QString &certspath )
{
QList<QSslCertificate> certs;
bool pem = certspath.endsWith( QLatin1String( ".pem" ), Qt::CaseInsensitive );
certs = QSslCertificate::fromData( QgsAuthCertUtils::fileData( certspath ), pem ? QSsl::Pem : QSsl::Der );
const QByteArray payload( QgsAuthCertUtils::fileData( certspath ) );
certs = QSslCertificate::fromData( payload, sniffEncoding( payload ) );
if ( certs.isEmpty() )
{
QgsDebugMsg( QString( "Parsed cert(s) EMPTY for path: %1" ).arg( certspath ) );
@@ -193,9 +193,7 @@ QSslKey QgsAuthCertUtils::keyFromFile( const QString &keypath,
QByteArray keydata( QgsAuthCertUtils::fileData( keypath ) );
QSslKey clientkey;

QSsl::EncodingFormat keyEncoding( keydata.contains( QByteArrayLiteral( "-----BEGIN " ) ) ?
QSsl::Pem :
QSsl::Der );
QSsl::EncodingFormat keyEncoding( sniffEncoding( keydata ) );

const std::vector<QSsl::KeyAlgorithm> algs
{
@@ -652,6 +650,13 @@ void QgsAuthCertUtils::appendDirSegment_( QStringList &dirname,
}
}

QSsl::EncodingFormat QgsAuthCertUtils::sniffEncoding( const QByteArray &payload )
{
return payload.contains( QByteArrayLiteral( "-----BEGIN " ) ) ?
QSsl::Pem :
QSsl::Der;
}

QString QgsAuthCertUtils::getCertDistinguishedName( const QSslCertificate &qcert,
const QCA::Certificate &acert,
bool issuer )
@@ -373,6 +373,8 @@ class CORE_EXPORT QgsAuthCertUtils

private:
static void appendDirSegment_( QStringList &dirname, const QString &segment, QString value );

static QSsl::EncodingFormat sniffEncoding( const QByteArray &payload );
};

#endif // QGSAUTHCERTUTILS_H

0 comments on commit b1eb6c0

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