mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[auth] Moved the PEM/DER sniffing to a common private function
This commit is contained in:
parent
c09c96b03e
commit
b1eb6c0bc6
@ -125,8 +125,8 @@ QByteArray QgsAuthCertUtils::fileData( const QString &path )
|
|||||||
QList<QSslCertificate> QgsAuthCertUtils::certsFromFile( const QString &certspath )
|
QList<QSslCertificate> QgsAuthCertUtils::certsFromFile( const QString &certspath )
|
||||||
{
|
{
|
||||||
QList<QSslCertificate> certs;
|
QList<QSslCertificate> certs;
|
||||||
bool pem = certspath.endsWith( QLatin1String( ".pem" ), Qt::CaseInsensitive );
|
const QByteArray payload( QgsAuthCertUtils::fileData( certspath ) );
|
||||||
certs = QSslCertificate::fromData( QgsAuthCertUtils::fileData( certspath ), pem ? QSsl::Pem : QSsl::Der );
|
certs = QSslCertificate::fromData( payload, sniffEncoding( payload ) );
|
||||||
if ( certs.isEmpty() )
|
if ( certs.isEmpty() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString( "Parsed cert(s) EMPTY for path: %1" ).arg( certspath ) );
|
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 ) );
|
QByteArray keydata( QgsAuthCertUtils::fileData( keypath ) );
|
||||||
QSslKey clientkey;
|
QSslKey clientkey;
|
||||||
|
|
||||||
QSsl::EncodingFormat keyEncoding( keydata.contains( QByteArrayLiteral( "-----BEGIN " ) ) ?
|
QSsl::EncodingFormat keyEncoding( sniffEncoding( keydata ) );
|
||||||
QSsl::Pem :
|
|
||||||
QSsl::Der );
|
|
||||||
|
|
||||||
const std::vector<QSsl::KeyAlgorithm> algs
|
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,
|
QString QgsAuthCertUtils::getCertDistinguishedName( const QSslCertificate &qcert,
|
||||||
const QCA::Certificate &acert,
|
const QCA::Certificate &acert,
|
||||||
bool issuer )
|
bool issuer )
|
||||||
|
@ -373,6 +373,8 @@ class CORE_EXPORT QgsAuthCertUtils
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void appendDirSegment_( QStringList &dirname, const QString &segment, QString value );
|
static void appendDirSegment_( QStringList &dirname, const QString &segment, QString value );
|
||||||
|
|
||||||
|
static QSsl::EncodingFormat sniffEncoding( const QByteArray &payload );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSAUTHCERTUTILS_H
|
#endif // QGSAUTHCERTUTILS_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user