Skip to content

Commit

Permalink
[auth] Added mutex to protect cache for pkipkcs12 auth
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 11, 2017
1 parent afeaa7f commit ee89bf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/auth/pkipkcs12/qgsauthpkcs12method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QSslConfiguration>
#include <QSslError>
#endif
#include <QMutexLocker>

#include "qgsauthcertutils.h"
#include "qgsauthmanager.h"
Expand Down Expand Up @@ -52,8 +53,9 @@ QgsAuthPkcs12Method::QgsAuthPkcs12Method()

QgsAuthPkcs12Method::~QgsAuthPkcs12Method()
{
qDeleteAll( mPkiConfigBundleCache );
mPkiConfigBundleCache.clear();
QMutexLocker locker( &mConfigMutex );
qDeleteAll( sPkiConfigBundleCache );
sPkiConfigBundleCache.clear();
}

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

QgsPkiConfigBundle *QgsAuthPkcs12Method::getPkiConfigBundle( const QString &authcfg )
{
QgsPkiConfigBundle * bundle = nullptr;
QMutexLocker locker( &mConfigMutex );
QgsPkiConfigBundle *bundle = nullptr;

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

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

locker.unlock();
// cache bundle
putPkiConfigBundle( authcfg, bundle );

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

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

void QgsAuthPkcs12Method::removePkiConfigBundle( const QString &authcfg )
{
if ( mPkiConfigBundleCache.contains( authcfg ) )
QMutexLocker locker( &mConfigMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle * pkibundle = mPkiConfigBundleCache.take( authcfg );
delete pkibundle;
Expand Down
5 changes: 4 additions & 1 deletion src/auth/pkipkcs12/qgsauthpkcs12method.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define QGSAUTHPKCS12METHOD_H

#include <QObject>
#include <QMutex>

#include "qgsauthconfig.h"
#include "qgsauthmethod.h"
Expand Down Expand Up @@ -57,7 +58,9 @@ class QgsAuthPkcs12Method : public QgsAuthMethod

void removePkiConfigBundle( const QString &authcfg );

static QMap<QString, QgsPkiConfigBundle *> mPkiConfigBundleCache;
static QMap<QString, QgsPkiConfigBundle *> sPkiConfigBundleCache;

QMutex mConfigMutex;
};

#endif // QGSAUTHPKCS12METHOD_H

0 comments on commit ee89bf5

Please sign in to comment.