Skip to content

Commit ee89bf5

Browse files
committedOct 11, 2017
[auth] Added mutex to protect cache for pkipkcs12 auth
1 parent afeaa7f commit ee89bf5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎src/auth/pkipkcs12/qgsauthpkcs12method.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QSslConfiguration>
2626
#include <QSslError>
2727
#endif
28+
#include <QMutexLocker>
2829

2930
#include "qgsauthcertutils.h"
3031
#include "qgsauthmanager.h"
@@ -52,8 +53,9 @@ QgsAuthPkcs12Method::QgsAuthPkcs12Method()
5253

5354
QgsAuthPkcs12Method::~QgsAuthPkcs12Method()
5455
{
55-
qDeleteAll( mPkiConfigBundleCache );
56-
mPkiConfigBundleCache.clear();
56+
QMutexLocker locker( &mConfigMutex );
57+
qDeleteAll( sPkiConfigBundleCache );
58+
sPkiConfigBundleCache.clear();
5759
}
5860

5961
QString QgsAuthPkcs12Method::key() const
@@ -222,7 +224,8 @@ void QgsAuthPkcs12Method::updateMethodConfig( QgsAuthMethodConfig &mconfig )
222224

223225
QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &authcfg )
224226
{
225-
QgsPkiConfigBundle * bundle = nullptr;
227+
QMutexLocker locker( &mConfigMutex );
228+
QgsPkiConfigBundle *bundle = nullptr;
226229

227230
// check if it is cached
228231
if ( mPkiConfigBundleCache.contains( authcfg ) )
@@ -272,6 +275,7 @@ QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &auth
272275

273276
bundle = new QgsPkiConfigBundle( mconfig, clientcert, clientkey );
274277

278+
locker.unlock();
275279
// cache bundle
276280
putPkiConfigBundle( authcfg, bundle );
277281

@@ -280,13 +284,15 @@ QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &auth
280284

281285
void QgsAuthPkcs12Method::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
282286
{
287+
QMutexLocker locker( &mConfigMutex );
283288
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
284289
mPkiConfigBundleCache.insert( authcfg, pkibundle );
285290
}
286291

287292
void QgsAuthPkcs12Method::removePkiConfigBundle( const QString &authcfg )
288293
{
289-
if ( mPkiConfigBundleCache.contains( authcfg ) )
294+
QMutexLocker locker( &mConfigMutex );
295+
if ( sPkiConfigBundleCache.contains( authcfg ) )
290296
{
291297
QgsPkiConfigBundle * pkibundle = mPkiConfigBundleCache.take( authcfg );
292298
delete pkibundle;

‎src/auth/pkipkcs12/qgsauthpkcs12method.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define QGSAUTHPKCS12METHOD_H
1919

2020
#include <QObject>
21+
#include <QMutex>
2122

2223
#include "qgsauthconfig.h"
2324
#include "qgsauthmethod.h"
@@ -57,7 +58,9 @@ class QgsAuthPkcs12Method : public QgsAuthMethod
5758

5859
void removePkiConfigBundle( const QString &authcfg );
5960

60-
static QMap<QString, QgsPkiConfigBundle *> mPkiConfigBundleCache;
61+
static QMap<QString, QgsPkiConfigBundle *> sPkiConfigBundleCache;
62+
63+
QMutex mConfigMutex;
6164
};
6265

6366
#endif // QGSAUTHPKCS12METHOD_H

0 commit comments

Comments
 (0)
Please sign in to comment.