21#include <QMutexLocker>
24#include <QSqlDatabase>
33#include <QDomDocument>
34#include <QRegularExpression>
35#include <QCoreApplication>
36#include <QRandomGenerator>
41#include <QSslConfiguration>
54#include "moc_qgsauthmanager.cpp"
63const QString QgsAuthManager::AUTH_CONFIG_TABLE = QStringLiteral(
"auth_configs" );
64const QString QgsAuthManager::AUTH_SERVERS_TABLE = QStringLiteral(
"auth_servers" );
66const QString QgsAuthManager::AUTH_CFG_REGEX = QStringLiteral(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
69const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_KEY_NAME_BASE(
"QGIS-Master-Password" );
70const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_FOLDER_NAME(
"QGIS" );
76#elif defined(Q_OS_WIN)
78#elif defined(Q_OS_LINUX)
87 QMutexLocker locker( &sMutex );
98 mMutex = std::make_unique<QRecursiveMutex>();
99 mMasterPasswordMutex = std::make_unique<QRecursiveMutex>();
101 this, &QgsAuthManager::writeToConsole );
115 QMutexLocker locker( mMutex.get() );
120 return storage->authDatabaseConnection();
134 const QList<QgsAuthConfigurationStorage *> storages { storageRegistry->
readyStorages() };
137 if (
auto dbStorage = qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
141 return dbStorage->quotedQualifiedIdentifier( dbStorage->methodConfigTableName() );
154 const auto drivers { QSqlDatabase::drivers() };
155 for (
const QString &driver : std::as_const( drivers ) )
157 if ( driver != ( QStringLiteral(
"QSQLITE" ) ) && driver != ( QStringLiteral(
"QSPATIALITE" ) ) && uri.startsWith( driver ) )
167 return mAuthDatabaseConnectionUri;
172 QRegularExpression re( QStringLiteral(
"password=(.*)" ) );
173 QString uri = mAuthDatabaseConnectionUri;
174 return uri.replace( re, QStringLiteral(
"password=*****" ) );
180 mAuthDatabaseConnectionUri = authDatabasePath.startsWith( QLatin1String(
"QSQLITE://" ) ) ? authDatabasePath : QStringLiteral(
"QSQLITE://" ) + authDatabasePath;
181 return initPrivate( pluginPath );
186 static QRecursiveMutex sInitializationMutex;
187 static bool sInitialized =
false;
189 sInitializationMutex.lock();
192 sInitializationMutex.unlock();
193 return mLazyInitResult;
196 mLazyInitResult =
const_cast< QgsAuthManager *
>( this )->initPrivate( mPluginPath );
198 sInitializationMutex.unlock();
200 return mLazyInitResult;
203static char *sPassFileEnv =
nullptr;
205bool QgsAuthManager::initPrivate(
const QString &pluginPath )
214 mQcaInitializer = std::make_unique<QCA::Initializer>( QCA::Practical, 256 );
217 QCA::scanForPlugins();
219 QgsDebugMsgLevel( QStringLiteral(
"QCA Plugin Diagnostics Context: %1" ).arg( QCA::pluginDiagnosticText() ), 2 );
220 QStringList capabilities;
222 capabilities = QCA::supportedFeatures();
223 QgsDebugMsgLevel( QStringLiteral(
"QCA supports: %1" ).arg( capabilities.join(
"," ) ), 2 );
226 if ( !QCA::isSupported(
"cert", QStringLiteral(
"qca-ossl" ) ) )
228 mAuthDisabled =
true;
229 mAuthDisabledMessage = tr(
"QCA's OpenSSL plugin (qca-ossl) is missing" );
233 QgsDebugMsgLevel( QStringLiteral(
"Prioritizing qca-ossl over all other QCA providers..." ), 2 );
234 const QCA::ProviderList provds = QCA::providers();
236 for ( QCA::Provider *p : provds )
238 QString pn = p->name();
240 if ( pn != QLatin1String(
"qca-ossl" ) )
242 pr = QCA::providerPriority( pn ) + 1;
244 QCA::setProviderPriority( pn, pr );
245 prlist << QStringLiteral(
"%1:%2" ).arg( pn ).arg( QCA::providerPriority( pn ) );
247 QgsDebugMsgLevel( QStringLiteral(
"QCA provider priorities: %1" ).arg( prlist.join(
", " ) ), 2 );
254 QgsDebugMsgLevel( QStringLiteral(
"Authentication methods found: %1" ).arg( methods.join(
", " ) ), 2 );
256 if ( methods.isEmpty() )
258 mAuthDisabled =
true;
259 mAuthDisabledMessage = tr(
"No authentication method plugins found" );
265 mAuthDisabled =
true;
266 mAuthDisabledMessage = tr(
"No authentication method plugins could be loaded" );
270 QgsDebugMsgLevel( QStringLiteral(
"Auth database URI: %1" ).arg( mAuthDatabaseConnectionUri ), 2 );
273 const QString sqliteDbPath { sqliteDatabasePath() };
274 if ( ! sqliteDbPath.isEmpty() )
278 else if ( ! mAuthDatabaseConnectionUri.isEmpty() )
301 const QString err = tr(
"Failed to initialize storage %1: %2" ).arg( storage->
name(), storage->
lastError() );
321 QString passpath( sPassFileEnv );
322 free( sPassFileEnv );
323 sPassFileEnv =
nullptr;
326 QFile passfile( passpath );
327 if ( passfile.exists() && passfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
329 QTextStream passin( &passfile );
330 while ( !passin.atEnd() )
332 masterpass = passin.readLine();
337 if ( !masterpass.isEmpty() )
341 QgsDebugMsgLevel( QStringLiteral(
"Authentication master password set from QGIS_AUTH_PASSWORD_FILE" ), 2 );
345 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to set password using: " + passpath );
351 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to read password from: " + passpath );
365 mPluginPath = pluginPath;
366 mAuthDatabaseConnectionUri = authDatabasePath;
368 const char *p = getenv(
"QGIS_AUTH_PASSWORD_FILE" );
371 sPassFileEnv = qstrdup( p );
376 putenv(
"QGIS_AUTH_PASSWORD_FILE" );
378 unsetenv(
"QGIS_AUTH_PASSWORD_FILE" );
389 QgsDebugError( QStringLiteral(
"Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing" ) );
391 return mAuthDisabled;
398 return tr(
"Authentication system is DISABLED:\n%1" ).arg( mAuthDisabledMessage );
402const QString QgsAuthManager::sqliteDatabasePath()
const
410 QString path = mAuthDatabaseConnectionUri;
411 if ( path.startsWith( QStringLiteral(
"QSQLITE://" ), Qt::CaseSensitivity::CaseInsensitive ) )
413 path = path.mid( 10 );
415 else if ( path.startsWith( QStringLiteral(
"QSPATIALITE://" ), Qt::CaseSensitivity::CaseInsensitive ) )
417 path = path.mid( 14 );
420 return QDir::cleanPath( path );
425 return sqliteDatabasePath();
432 QMutexLocker locker( mMasterPasswordMutex.get() );
436 if ( mScheduledDbErase )
439 if ( mMasterPass.isEmpty() )
441 QgsDebugMsgLevel( QStringLiteral(
"Master password is not yet set by user" ), 2 );
442 if ( !masterPasswordInput() )
444 QgsDebugMsgLevel( QStringLiteral(
"Master password input canceled by user" ), 2 );
458 QgsDebugMsgLevel( QStringLiteral(
"Master password is set and verified" ), 2 );
466 QMutexLocker locker( mMutex.get() );
470 if ( mScheduledDbErase )
474 QString prevpass = QString( mMasterPass );
478 mMasterPass = prevpass;
479 const char *err = QT_TR_NOOP(
"Master password set: FAILED to verify, reset to previous" );
485 QgsDebugMsgLevel( QStringLiteral(
"Master password set: SUCCESS%1" ).arg( verify ?
" and verified" :
"" ), 2 );
497 if ( !masterPasswordRowsInDb( &rows ) )
499 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
507 QgsDebugMsgLevel( QStringLiteral(
"Master password: %1 rows in database" ).arg( rows ), 2 );
511 const char *err = QT_TR_NOOP(
"Master password: FAILED to find just one master password record in database" );
518 else if ( rows == 1 )
520 if ( !masterPasswordCheckAgainstDb( compare ) )
522 if ( compare.isNull() )
524 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
533 if ( mPassTries >= 5 )
535 mAuthDisabled =
true;
536 const char *err = QT_TR_NOOP(
"Master password: failed 5 times authentication system DISABLED" );
544 QgsDebugMsgLevel( QStringLiteral(
"Master password: verified against hash in database" ), 2 );
545 if ( compare.isNull() )
549 else if ( compare.isNull() )
551 if ( !masterPasswordStoreInDb() )
553 const char *err = QT_TR_NOOP(
"Master password: hash FAILED to be stored in database" );
562 QgsDebugMsgLevel( QStringLiteral(
"Master password: hash stored in database" ), 2 );
565 if ( !masterPasswordCheckAgainstDb() )
567 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
577 QgsDebugMsgLevel( QStringLiteral(
"Master password: verified against hash in database" ), 2 );
589 return !mMasterPass.isEmpty();
596 return mMasterPass == pass;
600 bool keepbackup, QString *backuppath )
616 QgsDebugMsgLevel( QStringLiteral(
"Master password reset: backed up current database" ), 2 );
619 QString prevpass = QString( mMasterPass );
620 QString prevciv = QString( masterPasswordCiv() );
626 if ( ok && !masterPasswordClearDb() )
629 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not clear current password from database" );
635 QgsDebugMsgLevel( QStringLiteral(
"Master password reset: cleared current password from database" ), 2 );
642 if ( ok && !masterPasswordStoreInDb() )
645 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not store new password in database" );
651 QgsDebugMsgLevel( QStringLiteral(
"Master password reset: stored new password in database" ), 2 );
658 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify new password in database" );
664 if ( ok && !reencryptAllAuthenticationConfigs( prevpass, prevciv ) )
667 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt configs in database" );
673 QgsDebugMsgLevel( QStringLiteral(
"Master password reset: re-encrypted configs in database" ), 2 );
677 if ( ok && !verifyPasswordCanDecryptConfigs() )
680 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify password can decrypt re-encrypted configs" );
685 if ( ok && !reencryptAllAuthenticationSettings( prevpass, prevciv ) )
688 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt settings in database" );
693 if ( ok && !reencryptAllAuthenticationIdentities( prevpass, prevciv ) )
696 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt identities in database" );
705 QString errdbbackup( dbbackup );
706 errdbbackup.replace( QLatin1String(
".db" ), QLatin1String(
"_ERROR.db" ) );
707 QFile::rename( sqliteDatabasePath(), errdbbackup );
708 QgsDebugError( QStringLiteral(
"Master password reset FAILED: backed up failed db at %1" ).arg( errdbbackup ) );
710 QFile::rename( dbbackup, sqliteDatabasePath() );
711 mMasterPass = prevpass;
712 QgsDebugError( QStringLiteral(
"Master password reset FAILED: reinstated previous password and database" ) );
716 *backuppath = errdbbackup;
722 if ( !keepbackup && !QFile::remove( dbbackup ) )
724 const char *err = QT_TR_NOOP(
"Master password reset: could not remove old database backup" );
732 QgsDebugMsgLevel( QStringLiteral(
"Master password reset: backed up previous db at %1" ).arg( dbbackup ), 2 );
734 *backuppath = dbbackup;
746 mScheduledDbErase = scheduleErase;
748 mScheduledDbEraseRequestEmitted =
false;
749 mScheduledDbEraseRequestCount = 0;
753 if ( !mScheduledDbEraseTimer )
755 mScheduledDbEraseTimer =
new QTimer(
this );
756 connect( mScheduledDbEraseTimer, &QTimer::timeout,
this, &QgsAuthManager::tryToStartDbErase );
757 mScheduledDbEraseTimer->start( mScheduledDbEraseRequestWait * 1000 );
759 else if ( !mScheduledDbEraseTimer->isActive() )
761 mScheduledDbEraseTimer->start();
766 if ( mScheduledDbEraseTimer && mScheduledDbEraseTimer->isActive() )
767 mScheduledDbEraseTimer->stop();
776 qDeleteAll( mAuthMethods );
777 mAuthMethods.clear();
779 for (
const auto &authMethodKey : methods )
784 return !mAuthMethods.isEmpty();
796#ifndef __clang_analyzer__
799 QTimer::singleShot( 3, &loop, &QEventLoop::quit );
806 for (
int i = 0; i < len; i++ )
808 switch ( QRandomGenerator::system()->generate() % 2 )
811 id +=
static_cast<char>(
'0' + QRandomGenerator::system()->generate() % 10 );
814 id +=
static_cast<char>(
'a' + QRandomGenerator::system()->generate() % 26 );
818 if ( !configids.contains(
id ) )
823 QgsDebugMsgLevel( QStringLiteral(
"Generated unique ID: %1" ).arg(
id ), 2 );
836 const char *err = QT_TR_NOOP(
"Config ID is empty" );
842 return !configids.contains(
id );
847 const thread_local QRegularExpression authCfgRegExp( AUTH_CFG_REGEX );
848 return txt.indexOf( authCfgRegExp ) != -1;
855 QMutexLocker locker( mMutex.get() );
856 QStringList providerAuthMethodsKeys;
857 if ( !dataprovider.isEmpty() )
874 if ( providerAuthMethodsKeys.isEmpty() || providerAuthMethodsKeys.contains( config.method() ) )
877 if ( baseConfigs.contains( config.id() ) )
884 baseConfigs.insert( config.id(), config );
890 if ( storages.empty() )
893 QgsDebugError( QStringLiteral(
"No credentials storages found" ) );
912 if ( !
configIds.contains( config.id() ) )
914 mConfigAuthMethods.insert( config.id(), config.method() );
915 QgsDebugMsgLevel( QStringLiteral(
"Stored auth config/methods:\n%1 %2" ).arg( config.id(), config.method() ), 2 );
921 QgsDebugMsgLevel( QStringLiteral(
"A config with same id %1 was already added, skipping from %2" ).arg( config.id(), storage->
name() ), 2 );
934 if ( !mConfigAuthMethods.contains( authcfg ) )
936 QgsDebugError( QStringLiteral(
"No config auth method found in database for authcfg: %1" ).arg( authcfg ) );
940 QString authMethodKey = mConfigAuthMethods.value( authcfg );
952 return mConfigAuthMethods.value( authcfg, QString() );
967 if ( !mAuthMethods.contains( authMethodKey ) )
969 QgsDebugError( QStringLiteral(
"No auth method registered for auth method key: %1" ).arg( authMethodKey ) );
973 return mAuthMethods.value( authMethodKey );
980 if ( !mAuthMethods.contains( authMethodKey ) )
982 QgsDebugError( QStringLiteral(
"No auth method registered for auth method key: %1" ).arg( authMethodKey ) );
994 if ( dataprovider.isEmpty() )
1000 QgsAuthMethodsMap::const_iterator i = mAuthMethods.constBegin();
1001 while ( i != mAuthMethods.constEnd() )
1004 && ( i.value()->supportedDataProviders().contains( QStringLiteral(
"all" ) )
1005 || i.value()->supportedDataProviders().contains( dataprovider ) ) )
1007 filteredmap.insert( i.key(), i.value() );
1015QWidget *QgsAuthManager::authMethodEditWidget(
const QString &authMethodKey, QWidget *parent )
1021 return method->editWidget( parent );
1046 QMutexLocker locker( mMutex.get() );
1053 const char *err = QT_TR_NOOP(
"Store config: FAILED because config is invalid" );
1059 QString uid = config.
id();
1060 bool passedinID = !uid.isEmpty();
1061 if ( uid.isEmpty() )
1069 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 is not unique" );
1077 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 could not be removed" );
1086 if ( configstring.isEmpty() )
1088 const char *err = QT_TR_NOOP(
"Store config: FAILED because config string is empty" );
1096 if ( defaultStorage->isEncrypted() )
1103 configCopy.
setId( uid );
1104 if ( !defaultStorage->storeMethodConfig( configCopy, configstring ) )
1118 config.
setId( uid );
1122 QgsDebugMsgLevel( QStringLiteral(
"Store config SUCCESS for authcfg: %1" ).arg( uid ), 2 );
1130 QMutexLocker locker( mMutex.get() );
1135 if ( !config.
isValid(
true ) )
1137 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is invalid" );
1144 if ( configstring.isEmpty() )
1146 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is empty" );
1177 if ( storages.empty() )
1188 QgsDebugMsgLevel( QStringLiteral(
"Update config SUCCESS for authcfg: %1" ).arg( config.
id() ), 2 );
1203 QMutexLocker locker( mMutex.get() );
1215 if ( ! config.
isValid(
true ) || ( full && payload.isEmpty() ) )
1238 QgsDebugError( QStringLiteral(
"Update of authcfg %1 FAILED for auth method %2" ).arg( authcfg, authMethodKey ) );
1241 QgsDebugMsgLevel( QStringLiteral(
"Load %1 config SUCCESS for authcfg: %2" ).arg( full ?
"full" :
"base", authcfg ), 2 );
1246 if ( storages.empty() )
1262 QMutexLocker locker( mMutex.get() );
1266 if ( authcfg.isEmpty() )
1285 QgsDebugMsgLevel( QStringLiteral(
"REMOVED config for authcfg: %1" ).arg( authcfg ), 2 );
1292 if ( storages.empty() )
1309 if ( filename.isEmpty() )
1312 QDomDocument document( QStringLiteral(
"qgis_authentication" ) );
1313 QDomElement root = document.createElement( QStringLiteral(
"qgis_authentication" ) );
1314 document.appendChild( root );
1317 if ( !password.isEmpty() )
1322 root.setAttribute( QStringLiteral(
"salt" ), salt );
1323 root.setAttribute( QStringLiteral(
"hash" ), hash );
1324 root.setAttribute( QStringLiteral(
"civ" ), civ );
1327 QDomElement configurations = document.createElement( QStringLiteral(
"configurations" ) );
1328 for (
const QString &authcfg : authcfgs )
1335 authMethodConfig.
writeXml( configurations, document );
1338 if ( !password.isEmpty() )
1340 QString configurationsString;
1341 QTextStream ts( &configurationsString );
1342#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1343 ts.setCodec(
"UTF-8" );
1345 configurations.save( ts, 2 );
1346 root.appendChild( document.createTextNode(
QgsAuthCrypto::encrypt( password, civ, configurationsString ) ) );
1350 root.appendChild( configurations );
1353 QFile file( filename );
1354 if ( !file.open( QFile::WriteOnly | QIODevice::Truncate ) )
1357 QTextStream ts( &file );
1358#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1359 ts.setCodec(
"UTF-8" );
1361 document.save( ts, 2 );
1370 QFile file( filename );
1371 if ( !file.open( QFile::ReadOnly ) )
1376 QDomDocument document( QStringLiteral(
"qgis_authentication" ) );
1377 if ( !document.setContent( &file ) )
1384 QDomElement root = document.documentElement();
1385 if ( root.tagName() != QLatin1String(
"qgis_authentication" ) )
1390 QDomElement configurations;
1391 if ( root.hasAttribute( QStringLiteral(
"salt" ) ) )
1393 QString salt = root.attribute( QStringLiteral(
"salt" ) );
1394 QString hash = root.attribute( QStringLiteral(
"hash" ) );
1395 QString civ = root.attribute( QStringLiteral(
"civ" ) );
1400 configurations = document.firstChild().toElement();
1404 configurations = root.firstChildElement( QStringLiteral(
"configurations" ) );
1407 QDomElement configuration = configurations.firstChildElement();
1408 while ( !configuration.isNull() )
1411 authMethodConfig.
readXml( configuration );
1414 configuration = configuration.nextSiblingElement();
1423 QMutexLocker locker( mMutex.get() );
1429 if ( defaultStorage->clearMethodConfigs() )
1433 QgsDebugMsgLevel( QStringLiteral(
"REMOVED all configs from the default storage" ), 2 );
1438 QgsDebugMsgLevel( QStringLiteral(
"FAILED to remove all configs from the default storage" ), 2 );
1454 QMutexLocker locker( mMutex.get() );
1456 if ( sqliteDatabasePath().isEmpty() )
1458 const char *err = QT_TR_NOOP(
"The authentication database is not filesystem-based" );
1464 if ( !QFile::exists( sqliteDatabasePath() ) )
1466 const char *err = QT_TR_NOOP(
"No authentication database found" );
1476 if ( authConn.isValid() && authConn.isOpen() )
1480 QString datestamp( QDateTime::currentDateTime().toString( QStringLiteral(
"yyyy-MM-dd-hhmmss" ) ) );
1481 QString dbbackup( sqliteDatabasePath() );
1482 dbbackup.replace( QLatin1String(
".db" ), QStringLiteral(
"_%1.db" ).arg( datestamp ) );
1484 if ( !QFile::copy( sqliteDatabasePath(), dbbackup ) )
1486 const char *err = QT_TR_NOOP(
"Could not back up authentication database" );
1493 *backuppath = dbbackup;
1495 QgsDebugMsgLevel( QStringLiteral(
"Backed up auth database at %1" ).arg( dbbackup ), 2 );
1503 QMutexLocker locker( mMutex.get() );
1514 if ( backuppath && !dbbackup.isEmpty() )
1515 *backuppath = dbbackup;
1519 if ( defaultStorage->erase() )
1521 mMasterPass = QString();
1549 const QString &dataprovider )
1561 QgsDebugError( QStringLiteral(
"Network request updating not supported by authcfg: %1" ).arg( authcfg ) );
1576 const QString &dataprovider )
1588 QgsDebugMsgLevel( QStringLiteral(
"Network reply updating not supported by authcfg: %1" ).arg( authcfg ), 3 );
1604 const QString &dataprovider )
1616 QgsDebugError( QStringLiteral(
"Data source URI updating not supported by authcfg: %1" ).arg( authcfg ) );
1643 QgsDebugError( QStringLiteral(
"Proxy updating not supported by authcfg: %1" ).arg( authcfg ) );
1652 QgsDebugMsgLevel( QStringLiteral(
"Proxy updated successfully from authcfg: %1" ).arg( authcfg ), 2 );
1663 QMutexLocker locker( mMutex.get() );
1664 if ( key.isEmpty() )
1667 QString storeval( value.toString() );
1690 if ( !defaultStorage->storeAuthSetting( key, storeval ) )
1708 QMutexLocker locker( mMutex.get() );
1709 if ( key.isEmpty() )
1715 QVariant value = defaultValue;
1723 if ( !storeval.isEmpty() )
1734 if ( storages.empty() )
1746 QMutexLocker locker( mMutex.get() );
1747 if ( key.isEmpty() )
1761 if ( storages.empty() )
1773 QMutexLocker locker( mMutex.get() );
1774 if ( key.isEmpty() )
1801 if ( storages.empty() )
1816 QMutexLocker locker( mMutex.get() );
1822 mCustomConfigByHostCache.clear();
1823 mHasCheckedIfCustomConfigByHostExists =
false;
1826 QgsDebugError( QStringLiteral(
"Init of SSL caches FAILED" ) );
1834 QMutexLocker locker( mMutex.get() );
1835 if ( cert.isNull() )
1837 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
1842 QgsDebugError( QStringLiteral(
"Passed private key is null" ) );
1854 QgsDebugError( QStringLiteral(
"Store certificate identity: FAILED to remove pre-existing certificate identity %1" ).arg(
id ) );
1862 if ( !defaultStorage->storeCertIdentity( cert, keypem ) )
1880 QMutexLocker locker( mMutex.get() );
1882 QSslCertificate cert;
1893 if ( !cert.isNull() )
1899 if ( storages.empty() )
1911 QMutexLocker locker( mMutex.get() );
1912 QPair<QSslCertificate, QSslKey> bundle;
1927 if ( encryptedBundle.first.isNull() )
1929 QgsDebugError( QStringLiteral(
"Certificate identity bundle is null for id: %1" ).arg(
id ) );
1932 QSslKey key(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), encryptedBundle.second ).toLatin1(),
1933 QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey );
1936 QgsDebugError( QStringLiteral(
"Certificate identity bundle: FAILED to create private key" ) );
1939 bundle = qMakePair( encryptedBundle.first, key );
1944 if ( storages.empty() )
1957 QMutexLocker locker( mMutex.get() );
1961 return QStringList() << QString( bundle.first.toPem() ) << QString( bundle.second.toPem() );
1963 return QStringList();
1970 QMutexLocker locker( mMutex.get() );
1971 QList<QSslCertificate> certs;
1978 const QList<QSslCertificate> storageCerts = storage->
certIdentities();
1980 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
1982 if ( !certs.contains( cert ) )
1984 certs.append( cert );
1993 if ( storages.empty() )
2005 QMutexLocker locker( mMutex.get() );
2019 for (
const QString &
id : std::as_const( storageIds ) )
2021 if ( !ids.contains(
id ) )
2039 QMutexLocker locker( mMutex.get() );
2054 if ( storages.empty() )
2066 QMutexLocker locker( mMutex.get() );
2069 QgsDebugError( QStringLiteral(
"Passed bundle ID is empty" ) );
2089 if ( storages.empty() )
2102 QMutexLocker locker( mMutex.get() );
2114 QgsDebugError( QStringLiteral(
"Store SSL certificate custom config: FAILED to remove pre-existing config %1" ).arg(
id ) );
2120 if ( !defaultStorage->storeSslCertCustomConfig( config ) )
2133 mCustomConfigByHostCache.clear();
2142 QMutexLocker locker( mMutex.get() );
2145 if (
id.isEmpty() || hostport.isEmpty() )
2147 QgsDebugError( QStringLiteral(
"Passed config ID or host:port is empty" ) );
2171 if ( storages.empty() )
2185 if ( hostport.isEmpty() )
2190 QMutexLocker locker( mMutex.get() );
2192 if ( mCustomConfigByHostCache.contains( hostport ) )
2193 return mCustomConfigByHostCache.value( hostport );
2203 mCustomConfigByHostCache.insert( hostport, config );
2208 if ( storages.empty() )
2220 QMutexLocker locker( mMutex.get() );
2221 QList<QgsAuthConfigSslServer> configs;
2232 for (
const auto &config : std::as_const( storageConfigs ) )
2235 const QString hostPort = config.sslHostPort();
2236 const QString shaHostPort( QStringLiteral(
"%1:%2" ).arg(
id, hostPort ) );
2237 if ( ! ids.contains( shaHostPort ) )
2239 ids.append( shaHostPort );
2240 configs.append( config );
2249 if ( storages.empty() )
2261 QMutexLocker locker( mMutex.get() );
2262 if (
id.isEmpty() || hostPort.isEmpty() )
2264 QgsDebugError( QStringLiteral(
"Passed config ID or host:port is empty" ) );
2279 if ( storages.empty() )
2291 QMutexLocker locker( mMutex.get() );
2292 if (
id.isEmpty() || hostport.isEmpty() )
2294 QgsDebugError( QStringLiteral(
"Passed config ID or host:port is empty" ) );
2298 mCustomConfigByHostCache.clear();
2312 const QString shaHostPort( QStringLiteral(
"%1:%2" ).arg(
id, hostport ) );
2313 if ( mIgnoredSslErrorsCache.contains( shaHostPort ) )
2315 mIgnoredSslErrorsCache.remove( shaHostPort );
2321 if ( storages.empty() )
2334 QMutexLocker locker( mMutex.get() );
2335 if ( !mIgnoredSslErrorsCache.isEmpty() )
2337 QgsDebugMsgLevel( QStringLiteral(
"Ignored SSL errors cache items:" ), 1 );
2338 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = mIgnoredSslErrorsCache.constBegin();
2339 while ( i != mIgnoredSslErrorsCache.constEnd() )
2342 for (
auto err : i.value() )
2346 QgsDebugMsgLevel( QStringLiteral(
"%1 = %2" ).arg( i.key(), errs.join(
", " ) ), 1 );
2360 QMutexLocker locker( mMutex.get() );
2367 QString shahostport( QStringLiteral(
"%1:%2" )
2370 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2372 mIgnoredSslErrorsCache.remove( shahostport );
2375 if ( !errenums.isEmpty() )
2377 mIgnoredSslErrorsCache.insert( shahostport, QSet<QSslError::SslError>( errenums.begin(), errenums.end() ) );
2378 QgsDebugMsgLevel( QStringLiteral(
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1" ).arg( shahostport ), 2 );
2383 QgsDebugMsgLevel( QStringLiteral(
"No ignored SSL errors to cache for sha:host:port = %1" ).arg( shahostport ), 2 );
2391 QMutexLocker locker( mMutex.get() );
2392 const thread_local QRegularExpression rx( QRegularExpression::anchoredPattern(
"\\S+:\\S+:\\d+" ) );
2393 if ( !rx.match( shahostport ).hasMatch() )
2395 QgsDebugError(
"Passed shahostport does not match \\S+:\\S+:\\d+, "
2396 "e.g. 74a4ef5ea94512a43769b744cda0ca5049a72491:www.example.com:443" );
2400 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2402 mIgnoredSslErrorsCache.remove( shahostport );
2405 if ( errors.isEmpty() )
2407 QgsDebugError( QStringLiteral(
"Passed errors list empty" ) );
2411 QSet<QSslError::SslError> errs;
2412 for (
const auto &error : errors )
2414 if ( error.error() == QSslError::NoError )
2417 errs.insert( error.error() );
2420 if ( errs.isEmpty() )
2422 QgsDebugError( QStringLiteral(
"Passed errors list does not contain errors" ) );
2426 mIgnoredSslErrorsCache.insert( shahostport, errs );
2428 QgsDebugMsgLevel( QStringLiteral(
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1" ).arg( shahostport ), 2 );
2437 QMutexLocker locker( mMutex.get() );
2438 QHash<QString, QSet<QSslError::SslError> > prevcache( mIgnoredSslErrorsCache );
2439 QHash<QString, QSet<QSslError::SslError> > nextcache;
2449 for (
const auto &config : std::as_const( customConfigs ) )
2452 if ( ! ids.contains( shaHostPort ) )
2454 ids.append( shaHostPort );
2455 if ( !config.sslIgnoredErrorEnums().isEmpty() )
2457 nextcache.insert( shaHostPort, QSet<QSslError::SslError>( config.sslIgnoredErrorEnums().cbegin(), config.sslIgnoredErrorEnums().cend() ) );
2459 if ( prevcache.contains( shaHostPort ) )
2461 prevcache.remove( shaHostPort );
2471 if ( !prevcache.isEmpty() )
2474 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = prevcache.constBegin();
2475 while ( i != prevcache.constEnd() )
2477 nextcache.insert( i.key(), i.value() );
2482 if ( nextcache != mIgnoredSslErrorsCache )
2484 mIgnoredSslErrorsCache.clear();
2485 mIgnoredSslErrorsCache = nextcache;
2486 QgsDebugMsgLevel( QStringLiteral(
"Rebuild of ignored SSL errors cache SUCCEEDED" ), 2 );
2491 QgsDebugMsgLevel( QStringLiteral(
"Rebuild of ignored SSL errors cache SAME AS BEFORE" ), 2 );
2500 QMutexLocker locker( mMutex.get() );
2501 if ( certs.isEmpty() )
2503 QgsDebugError( QStringLiteral(
"Passed certificate list has no certs" ) );
2507 for (
const auto &cert : certs )
2519 QMutexLocker locker( mMutex.get() );
2522 if ( cert.isNull() )
2524 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
2530 QgsDebugError( QStringLiteral(
"Store certificate authority: FAILED to remove pre-existing certificate authority" ) );
2536 return defaultStorage->storeCertAuthority( cert );
2551 QMutexLocker locker( mMutex.get() );
2552 QSslCertificate emptycert;
2553 QSslCertificate cert;
2563 if ( !cert.isNull() )
2569 if ( storages.empty() )
2582 QMutexLocker locker( mMutex.get() );
2583 if ( cert.isNull() )
2585 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
2600 if ( storages.empty() )
2612 QMutexLocker locker( mMutex.get() );
2613 if ( cert.isNull() )
2615 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
2642 if ( storages.empty() )
2652 return QSslConfiguration::systemCaCertificates();
2659 QMutexLocker locker( mMutex.get() );
2660 QList<QSslCertificate> certs;
2661 QList<QSslCertificate> filecerts;
2670 QString cafile( cafileval.toString() );
2671 if ( !cafile.isEmpty() && QFile::exists( cafile ) )
2676 for (
const auto &cert : std::as_const( filecerts ) )
2678 if ( !allowinvalid.toBool() && ( cert.isBlacklisted()
2680 || cert.expiryDate() <= QDateTime::currentDateTime()
2681 || cert.effectiveDate() > QDateTime::currentDateTime() ) )
2698 QMutexLocker locker( mMutex.get() );
2703 QList<QSslCertificate> certs;
2707 const QList<QSslCertificate> storageCerts = storage->
caCerts();
2709 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
2711 if ( !certs.contains( cert ) )
2713 certs.append( cert );
2722 if ( storages.empty() )
2734 QMutexLocker locker( mMutex.get() );
2742 QMutexLocker locker( mMutex.get() );
2743 mCaCertsCache.clear();
2749 bool res = !mCaCertsCache.isEmpty();
2751 QgsDebugError( QStringLiteral(
"Rebuild of CA certs cache FAILED" ) );
2759 QMutexLocker locker( mMutex.get() );
2760 if ( cert.isNull() )
2762 QgsDebugError( QStringLiteral(
"Passed certificate is null." ) );
2779 return defaultStorage->storeCertTrustPolicy( cert, policy );
2792 QMutexLocker locker( mMutex.get() );
2793 if ( cert.isNull() )
2795 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
2811 if ( storages.empty() )
2823 QMutexLocker locker( mMutex.get() );
2824 if ( certs.empty() )
2826 QgsDebugError( QStringLiteral(
"Passed certificate list has no certs" ) );
2830 for (
const auto &cert : certs )
2842 QMutexLocker locker( mMutex.get() );
2843 if ( cert.isNull() )
2845 QgsDebugError( QStringLiteral(
"Passed certificate is null" ) );
2871 if ( storages.empty() )
2883 QMutexLocker locker( mMutex.get() );
2884 if ( cert.isNull() )
2894 if ( trustedids.contains(
id ) )
2898 else if ( untrustedids.contains(
id ) )
2914 return storeAuthSetting( QStringLiteral(
"certdefaulttrust" ),
static_cast< int >( policy ) );
2921 QMutexLocker locker( mMutex.get() );
2922 QVariant policy(
authSetting( QStringLiteral(
"certdefaulttrust" ) ) );
2934 QMutexLocker locker( mMutex.get() );
2935 mCertTrustCache.clear();
2946 for (
auto it = trustedCerts.cbegin(); it != trustedCerts.cend(); ++it )
2948 const QString
id { it.key( )};
2949 if ( ! ids.contains(
id ) )
2970 if ( ! storages.empty() )
2972 QgsDebugMsgLevel( QStringLiteral(
"Rebuild of cert trust policy cache SUCCEEDED" ), 2 );
2986 QMutexLocker locker( mMutex.get() );
2990 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
2992 QList<QSslCertificate> trustedcerts;
2993 for (
int i = 0; i < certpairs.size(); ++i )
2995 QSslCertificate cert( certpairs.at( i ).second );
2997 if ( trustedids.contains( certid ) )
3000 trustedcerts.append( cert );
3006 trustedcerts.append( cert );
3011 QSslConfiguration sslconfig( QSslConfiguration::defaultConfiguration() );
3012 sslconfig.setCaCertificates( trustedcerts );
3013 QSslConfiguration::setDefaultConfiguration( sslconfig );
3015 return trustedcerts;
3022 QMutexLocker locker( mMutex.get() );
3023 if ( trustedCAs.isEmpty() )
3025 if ( mTrustedCaCertsCache.isEmpty() )
3032 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
3034 QList<QSslCertificate> untrustedCAs;
3035 for (
int i = 0; i < certpairs.size(); ++i )
3037 QSslCertificate cert( certpairs.at( i ).second );
3038 if ( !trustedCAs.contains( cert ) )
3040 untrustedCAs.append( cert );
3043 return untrustedCAs;
3050 QMutexLocker locker( mMutex.get() );
3052 QgsDebugMsgLevel( QStringLiteral(
"Rebuilt trusted cert authorities cache" ), 2 );
3061 QMutexLocker locker( mMutex.get() );
3069 QMutexLocker locker( mMutex.get() );
3072 return passwordHelperWrite( mMasterPass );
3090 for (
const auto &authcfg : ids )
3110void QgsAuthManager::writeToConsole(
const QString &message,
3126 msg += QLatin1String(
"WARNING: " );
3129 msg += QLatin1String(
"ERROR: " );
3136 QTextStream out( stdout, QIODevice::WriteOnly );
3137 out << msg << Qt::endl;
3140void QgsAuthManager::tryToStartDbErase()
3144 ++mScheduledDbEraseRequestCount;
3146 int trycutoff = 90 / ( mScheduledDbEraseRequestWait ? mScheduledDbEraseRequestWait : 3 );
3147 if ( mScheduledDbEraseRequestCount >= trycutoff )
3150 QgsDebugMsgLevel( QStringLiteral(
"authDatabaseEraseRequest emitting/scheduling canceled" ), 2 );
3155 QgsDebugMsgLevel( QStringLiteral(
"authDatabaseEraseRequest attempt (%1 of %2)" )
3156 .arg( mScheduledDbEraseRequestCount ).arg( trycutoff ), 2 );
3162 mScheduledDbEraseRequestEmitted =
true;
3167 QgsDebugMsgLevel( QStringLiteral(
"authDatabaseEraseRequest emitted" ), 2 );
3170 QgsDebugMsgLevel( QStringLiteral(
"authDatabaseEraseRequest emit skipped" ), 2 );
3176 QMutexLocker locker( mMutex.get() );
3178 QMapIterator<QThread *, QMetaObject::Connection> iterator( mConnectedThreads );
3179 while ( iterator.hasNext() )
3182 QThread::disconnect( iterator.value() );
3193 qDeleteAll( mAuthMethods );
3198 if ( authConn.isValid() && authConn.isOpen() )
3201 delete mScheduledDbEraseTimer;
3202 mScheduledDbEraseTimer =
nullptr;
3203 QSqlDatabase::removeDatabase( QStringLiteral(
"authentication.configs" ) );
3208 QMutexLocker locker( mMutex.get() );
3209 if ( ! mAuthConfigurationStorageRegistry )
3211 mAuthConfigurationStorageRegistry = std::make_unique<QgsAuthConfigurationStorageRegistry>();
3213 return mAuthConfigurationStorageRegistry.get();
3217QString QgsAuthManager::passwordHelperName()
const
3219 return tr(
"Password Helper" );
3223void QgsAuthManager::passwordHelperLog(
const QString &msg )
const
3239 QKeychain::DeletePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3242 job.setAutoDelete(
false );
3243 job.setKey( authPasswordHelperKeyName() );
3245 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3250 mPasswordHelperErrorCode = job.error();
3251 mPasswordHelperErrorMessage = tr(
"Delete password failed: %1." ).arg( job.errorString() );
3262 passwordHelperProcessError();
3266QString QgsAuthManager::passwordHelperRead()
3273 QKeychain::ReadPasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3276 job.setAutoDelete(
false );
3277 job.setKey( authPasswordHelperKeyName() );
3279 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3284 mPasswordHelperErrorCode = job.error();
3291 password = job.textData();
3293 if ( password.isEmpty() )
3295 mPasswordHelperErrorCode = QKeychain::EntryNotFound;
3306 passwordHelperProcessError();
3310bool QgsAuthManager::passwordHelperWrite(
const QString &password )
3314 Q_ASSERT( !password.isEmpty() );
3317 QKeychain::WritePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3320 job.setAutoDelete(
false );
3321 job.setKey( authPasswordHelperKeyName() );
3322 job.setTextData( password );
3324 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3329 mPasswordHelperErrorCode = job.error();
3337 passwordHelperClearErrors();
3342 passwordHelperProcessError();
3357 emit
messageLog( enabled ? tr(
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
3359 tr(
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
3376void QgsAuthManager::passwordHelperClearErrors()
3378 mPasswordHelperErrorCode = QKeychain::NoError;
3379 mPasswordHelperErrorMessage.clear();
3382void QgsAuthManager::passwordHelperProcessError()
3386 if ( mPasswordHelperErrorCode == QKeychain::AccessDenied ||
3387 mPasswordHelperErrorCode == QKeychain::AccessDeniedByUser ||
3388 mPasswordHelperErrorCode == QKeychain::NoBackendAvailable ||
3389 mPasswordHelperErrorCode == QKeychain::NotImplemented )
3395 mPasswordHelperErrorMessage = tr(
"There was an error and integration with your %1 system has been disabled. "
3396 "You can re-enable it at any time through the \"Utilities\" menu "
3397 "in the Authentication pane of the options dialog. %2" )
3400 if ( mPasswordHelperErrorCode != QKeychain::NoError )
3406 passwordHelperClearErrors();
3410bool QgsAuthManager::masterPasswordInput()
3418 bool storedPasswordIsValid =
false;
3424 pass = passwordHelperRead();
3425 if ( ! pass.isEmpty() && ( mPasswordHelperErrorCode == QKeychain::NoError ) )
3431 storedPasswordIsValid =
true;
3447 if ( ok && !pass.isEmpty() && mMasterPass != pass )
3452 if ( passwordHelperWrite( pass ) )
3466bool QgsAuthManager::masterPasswordRowsInDb(
int *rows )
const
3475 QMutexLocker locker( mMutex.get() );
3493 if ( storages.empty() )
3510 if ( !masterPasswordRowsInDb( &rows ) )
3512 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
3518 return ( rows == 1 );
3521bool QgsAuthManager::masterPasswordCheckAgainstDb(
const QString &compare )
const
3533 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords( ) };
3534 if ( passwords.size() == 0 )
3557bool QgsAuthManager::masterPasswordStoreInDb()
const
3564 QString salt, hash, civ;
3572 return defaultStorage->storeMasterPassword( { salt, civ, hash } );
3588bool QgsAuthManager::masterPasswordClearDb()
3600 return defaultStorage->clearMasterPasswords();
3617const QString QgsAuthManager::masterPasswordCiv()
const
3628 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords( ) };
3629 if ( passwords.size() == 0 )
3634 return passwords.first().civ;
3654 QStringList configKeys = QStringList();
3668 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
3670 if ( !configKeys.contains( it.key() ) )
3672 configKeys.append( it.key() );
3690bool QgsAuthManager::verifyPasswordCanDecryptConfigs()
const
3713 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
3715 QString configstring(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), it.value().config( QStringLiteral(
"encrypted_payload" ) ) ) );
3716 if ( configstring.isEmpty() )
3718 QgsDebugError( QStringLiteral(
"Verify password can decrypt configs FAILED, could not decrypt a config (id: %1) from storage %2" )
3719 .arg( it.key(), storage->
name() ) );
3733 if ( storages.empty() )
3742bool QgsAuthManager::reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv )
3751 for (
const auto &configid : ids )
3753 res = res && reencryptAuthenticationConfig( configid, prevpass, prevciv );
3758bool QgsAuthManager::reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv )
3783 if ( payload.isEmpty() || ! config.
isValid(
true ) )
3785 QgsDebugError( QStringLiteral(
"Reencrypt FAILED, could not find config (id: %1)" ).arg( authcfg ) );
3790 if ( configstring.isEmpty() )
3792 QgsDebugError( QStringLiteral(
"Reencrypt FAILED, could not decrypt config (id: %1)" ).arg( authcfg ) );
3814 if ( storages.empty() )
3826bool QgsAuthManager::reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv )
3831 Q_UNUSED( prevpass )
3844 QStringList encryptedsettings;
3845 encryptedsettings <<
"";
3847 for (
const auto & sett, std::as_const( encryptedsettings ) )
3854 QSqlQuery query( authDbConnection() );
3856 query.prepare( QStringLiteral(
"SELECT value FROM %1 "
3857 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
3859 query.bindValue(
":setting", sett );
3861 if ( !authDbQuery( &query ) )
3864 if ( !query.isActive() || !query.isSelect() )
3866 QgsDebugError( QStringLiteral(
"Reencrypt FAILED, query not active or a select operation for setting: %2" ).arg( sett ) );
3870 if ( query.first() )
3876 query.prepare( QStringLiteral(
"UPDATE %1 "
3877 "SET value = :value "
3878 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
3880 query.bindValue(
":setting", sett );
3883 if ( !authDbStartTransaction() )
3886 if ( !authDbQuery( &query ) )
3889 if ( !authDbCommit() )
3892 QgsDebugMsgLevel( QStringLiteral(
"Reencrypt SUCCESS for setting: %2" ).arg( sett ), 2 );
3897 QgsDebugError( QStringLiteral(
"Reencrypt FAILED, could not find in db setting: %2" ).arg( sett ) );
3903 QgsDebugError( QStringLiteral(
"Select contains more than one for setting: %1" ).arg( sett ) );
3914bool QgsAuthManager::reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv )
3923 for (
const auto &identid : ids )
3925 res = res && reencryptAuthenticationIdentity( identid, prevpass, prevciv );
3930bool QgsAuthManager::reencryptAuthenticationIdentity(
3931 const QString &identid,
3932 const QString &prevpass,
3933 const QString &prevciv )
3961 if ( keystring.isEmpty() )
3963 QgsDebugError( QStringLiteral(
"Reencrypt FAILED, could not decrypt identity id: %1" ).arg( identid ) );
3979 if ( storages.empty() )
3995 for (
const auto &cert : certs )
3998 QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>( source, cert ) );
4002QString QgsAuthManager::authPasswordHelperKeyName()
const
4006 QString dbProfilePath;
4012 const QFileInfo info( mAuthDatabaseConnectionUri );
4013 dbProfilePath = info.dir().dirName();
4017 dbProfilePath = QCryptographicHash::hash( ( mAuthDatabaseConnectionUri.toUtf8() ), QCryptographicHash::Md5 ).toHex();
4021 return AUTH_PASSWORD_HELPER_KEY_NAME_BASE + ( dbProfilePath.compare( QLatin1String(
"default" ), Qt::CaseInsensitive ) == 0 ? QString() : dbProfilePath );
4030 if ( qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
@ CreateSetting
Can create a new authentication setting.
@ CreateConfiguration
Can create a new authentication configuration.
@ ClearStorage
Can clear all configurations from storage.
@ DeleteCertificateAuthority
Can delete a certificate authority.
@ DeleteSslCertificateCustomConfig
Can delete a SSL certificate custom config.
@ DeleteSetting
Can delete the authentication setting.
@ ReadSslCertificateCustomConfig
Can read a SSL certificate custom config.
@ DeleteMasterPassword
Can delete the master password.
@ CreateSslCertificateCustomConfig
Can create a new SSL certificate custom config.
@ ReadCertificateTrustPolicy
Can read a certificate trust policy.
@ ReadConfiguration
Can read an authentication configuration.
@ UpdateConfiguration
Can update an authentication configuration.
@ ReadCertificateAuthority
Can read a certificate authority.
@ CreateCertificateAuthority
Can create a new certificate authority.
@ DeleteConfiguration
Can deleet an authentication configuration.
@ ReadSetting
Can read the authentication settings.
@ CreateCertificateIdentity
Can create a new certificate identity.
@ ReadCertificateIdentity
Can read a certificate identity.
@ CreateCertificateTrustPolicy
Can create a new certificate trust policy.
@ ReadMasterPassword
Can read the master password.
@ CreateMasterPassword
Can create a new master password.
@ DeleteCertificateTrustPolicy
Can delete a certificate trust policy.
static QString sslErrorEnumString(QSslError::SslError errenum)
Gets short strings describing an SSL error.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
CertTrustPolicy
Type of certificate trust policy.
static QMap< QString, QSslCertificate > mapDigestToCerts(const QList< QSslCertificate > &certs)
Map certificate sha1 to certificate as simple cache.
static QByteArray certsToPemText(const QList< QSslCertificate > &certs)
certsToPemText dump a list of QSslCertificates to PEM text
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
static QList< QSslCertificate > certsFromFile(const QString &certspath)
Returns a list of concatenated certs from a PEM or DER formatted file.
static bool certificateIsAuthorityOrIssuer(const QSslCertificate &cert)
Gets whether a certificate is an Authority or can at least sign other certificates.
CaCertSource
Type of CA certificate source.
Configuration container for SSL server connection exceptions or overrides.
bool isNull() const
Whether configuration is null (missing components)
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.
const QSslCertificate sslCertificate() const
Server certificate object.
const QString sslHostPort() const
Server host:port string.
QSqlDatabase based implementation of QgsAuthConfigurationStorage.
bool removeCertTrustPolicy(const QSslCertificate &cert) override
Remove certificate trust policy.
const QgsAuthConfigSslServer loadSslCertCustomConfigByHost(const QString &hostport) const override
Loads an SSL certificate custom config by hostport (host:port)
QString loadAuthSetting(const QString &key) const override
Load an authentication setting from the storage.
bool removeAuthSetting(const QString &key) override
Remove an authentication setting from the storage.
const QMap< QString, QgsAuthCertUtils::CertTrustPolicy > caCertsPolicy() const override
Returns the map of CA certificates hashes in the storages and their trust policy.
QgsAuthCertUtils::CertTrustPolicy loadCertTrustPolicy(const QSslCertificate &cert) const override
Load certificate trust policy.
bool sslCertCustomConfigExists(const QString &id, const QString &hostport) override
Check if SSL certificate custom config exists.
bool removeCertIdentity(const QSslCertificate &cert) override
Remove a certificate identity from the storage.
const QPair< QSslCertificate, QString > loadCertIdentityBundle(const QString &id) const override
Returns a certificate identity bundle by id (sha hash).
const QList< QgsAuthConfigurationStorage::MasterPasswordConfig > masterPasswords() const override
Returns the list of (encrypted) master passwords stored in the database.
bool methodConfigExists(const QString &id) const override
Check if an authentication configuration exists in the storage.
QStringList certIdentityIds() const override
certIdentityIds get list of certificate identity ids from database
bool initialize() override
Initializes the storage.
bool storeMethodConfig(const QgsAuthMethodConfig &mconfig, const QString &payload) override
Store an authentication config in the database.
bool removeCertAuthority(const QSslCertificate &cert) override
Remove a certificate authority.
const QSslCertificate loadCertIdentity(const QString &id) const override
certIdentity get a certificate identity by id (sha hash)
const QList< QgsAuthConfigSslServer > sslCertCustomConfigs() const override
sslCertCustomConfigs get SSL certificate custom configs
QgsAuthMethodConfigsMap authMethodConfigs(const QStringList &allowedMethods=QStringList()) const override
Returns a mapping of authentication configurations available from this storage.
const QList< QSslCertificate > caCerts() const override
Returns the list of CA certificates in the storage.
bool certTrustPolicyExists(const QSslCertificate &cert) const override
Check if certificate trust policy exists.
const QSslCertificate loadCertAuthority(const QString &id) const override
certAuthority get a certificate authority by id (sha hash)
bool removeMethodConfig(const QString &id) override
Removes the authentication configuration with the specified id.
QgsAuthMethodConfigsMap authMethodConfigsWithPayload() const override
Returns a mapping of authentication configurations available from this storage.
bool certIdentityExists(const QString &id) const override
Check if the certificate identity exists.
bool certAuthorityExists(const QSslCertificate &cert) const override
Check if a certificate authority exists.
QgsAuthMethodConfig loadMethodConfig(const QString &id, QString &payload, bool full=false) const override
Load an authentication configuration from the database.
bool storeCertIdentity(const QSslCertificate &cert, const QString &keyPem) override
Store a certificate identity in the storage.
bool removeSslCertCustomConfig(const QString &id, const QString &hostport) override
Remove an SSL certificate custom config.
const QList< QSslCertificate > certIdentities() const override
certIdentities get certificate identities
QString name() const override
Returns a human readable localized short name of the storage implementation (e.g "SQLite").
bool authSettingExists(const QString &key) const override
Check if an authentication setting exists in the storage.
const QgsAuthConfigSslServer loadSslCertCustomConfig(const QString &id, const QString &hostport) const override
Loads an SSL certificate custom config by id (sha hash) and hostport (host:port)
Registry for authentication configuration storages.
QgsAuthConfigurationStorage * firstReadyStorageWithCapability(Qgis::AuthConfigurationStorageCapability capability) const
Returns the first ready (and enabled) authentication configuration storage which has the required cap...
QList< QgsAuthConfigurationStorage * > storages() const
Returns the list of all registered authentication configuration storages.
QList< QgsAuthConfigurationStorage * > readyStoragesWithCapability(Qgis::AuthConfigurationStorageCapability capability) const
Returns the list of all ready (and enabled) authentication configuration storage with the required ca...
QList< QgsAuthConfigurationStorage * > readyStorages() const
Returns the list of all ready (and enabled) authentication configuration storage.
bool addStorage(QgsAuthConfigurationStorage *storage)
Add an authentication configuration storage to the registry.
Abstract class that defines the interface for all authentication configuration storage implementation...
virtual void setReadOnly(bool readOnly)
Utility method to unset all editing capabilities.
void methodConfigChanged()
Emitted when the storage method config table was changed.
Qgis::AuthConfigurationStorageCapabilities capabilities() const
Returns the capabilities of the storage.
bool isEnabled() const
Returns true if the storage is enabled.
bool isEncrypted() const
Returns true if the storage is encrypted.
void messageLog(const QString &message, const QString &tag=QStringLiteral("Authentication"), Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Custom logging signal to relay to console output and QgsMessageLog.
virtual QString lastError() const
Returns the last error message.
static void passwordKeyHash(const QString &pass, QString *salt, QString *hash, QString *cipheriv=nullptr)
Generate SHA256 hash for master password, with iterations and salt.
static const QString encrypt(const QString &pass, const QString &cipheriv, const QString &text)
Encrypt data using master password.
static bool verifyPasswordKeyHash(const QString &pass, const QString &salt, const QString &hash, QString *hashderived=nullptr)
Verify existing master password hash to a re-generated one.
static const QString decrypt(const QString &pass, const QString &cipheriv, const QString &text)
Decrypt data using master password.
Singleton offering an interface to manage the authentication configuration database and to utilize co...
bool storeAuthSetting(const QString &key, const QVariant &value, bool encrypt=false)
Store an authentication setting (stored as string via QVariant( value ).toString() )
bool setDefaultCertTrustPolicy(QgsAuthCertUtils::CertTrustPolicy policy)
Sets the default certificate trust policy preferred by user.
void clearAllCachedConfigs()
Clear all authentication configs from authentication method caches.
const QSslCertificate certIdentity(const QString &id)
certIdentity get a certificate identity by id (sha hash)
const QStringList certIdentityBundleToPem(const QString &id)
certIdentityBundleToPem get a certificate identity bundle by id (sha hash) returned as PEM text
bool updateIgnoredSslErrorsCache(const QString &shahostport, const QList< QSslError > &errors)
Update ignored SSL error cache with possible ignored SSL errors, using sha:host:port key.
bool verifyMasterPassword(const QString &compare=QString())
Verify the supplied master password against any existing hash in authentication database.
bool updateIgnoredSslErrorsCacheFromConfig(const QgsAuthConfigSslServer &config)
Update ignored SSL error cache with possible ignored SSL errors, using server config.
const QString disabledMessage() const
Standard message for when QCA's qca-ossl plugin is missing and system is disabled.
const QList< QSslCertificate > trustedCaCertsCache()
trustedCaCertsCache cache of trusted certificate authorities, ready for network connections
QgsAuthMethod * configAuthMethod(const QString &authcfg)
Gets authentication method from the config/provider cache.
static bool isFilesystemBasedDatabase(const QString &uri)
Returns the true if the uri is a filesystem-based database (SQLite).
bool storeCertIdentity(const QSslCertificate &cert, const QSslKey &key)
Store a certificate identity.
QgsAuthMethodsMap authMethodsMap(const QString &dataprovider=QString())
Gets available authentication methods mapped to their key.
bool rebuildIgnoredSslErrorCache()
Rebuild ignoredSSL error cache.
bool initSslCaches()
Initialize various SSL authentication caches.
const QList< QSslCertificate > extraFileCAs()
extraFileCAs extra file-based certificate authorities
bool removeAuthSetting(const QString &key)
Remove an authentication setting.
bool storeCertTrustPolicy(const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy)
Store user trust value for a certificate.
bool rebuildCaCertsCache()
Rebuild certificate authority cache.
bool scheduledAuthDatabaseErase()
Whether there is a scheduled opitonal erase of authentication database.
bool eraseAuthenticationDatabase(bool backup, QString *backuppath=nullptr)
Erase all rows from all tables in authentication database.
static bool passwordHelperEnabled()
Password helper enabled getter.
void passwordHelperMessageLog(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Custom logging signal to inform the user about master password <-> password manager interactions.
bool exportAuthenticationConfigsToXml(const QString &filename, const QStringList &authcfgs, const QString &password=QString())
Export authentication configurations to an XML file.
Q_DECL_DEPRECATED bool init(const QString &pluginPath=QString(), const QString &authDatabasePath=QString())
init initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database
void authDatabaseChanged()
Emitted when the authentication db is significantly changed, e.g. large record removal,...
void setPasswordHelperEnabled(bool enabled)
Password helper enabled setter.
void setScheduledAuthDatabaseErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
const QList< QgsAuthConfigSslServer > sslCertCustomConfigs()
sslCertCustomConfigs get SSL certificate custom configs
const QList< QSslCertificate > untrustedCaCerts(QList< QSslCertificate > trustedCAs=QList< QSslCertificate >())
untrustedCaCerts get list of untrusted certificate authorities
const QString uniqueConfigId() const
Gets a unique generated 7-character string to assign to as config id.
const QPair< QSslCertificate, QSslKey > certIdentityBundle(const QString &id)
Gets a certificate identity bundle by id (sha hash).
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
QVariant authSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
authSetting get an authentication setting (retrieved as string and returned as QVariant( QString ))
static const QString AUTH_MAN_TAG
The display name of the Authentication Manager.
QgsAuthCertUtils::CertTrustPolicy defaultCertTrustPolicy()
Gets the default certificate trust policy preferred by user.
const QByteArray trustedCaCertsPemText()
trustedCaCertsPemText get concatenated string of all trusted CA certificates
static bool hasConfigId(const QString &txt)
Returns whether a string includes an authcfg ID token.
bool removeAllAuthenticationConfigs()
Clear all authentication configs from table in database and from provider caches.
QgsAuthCertUtils::CertTrustPolicy certificateTrustPolicy(const QSslCertificate &cert)
certificateTrustPolicy get trust policy for a particular certificate cert
static bool passwordHelperLoggingEnabled()
Password helper logging enabled getter.
QgsAuthConfigurationStorageRegistry * authConfigurationStorageRegistry() const
Returns the authentication configuration storage registry.
bool rebuildCertTrustCache()
Rebuild certificate authority cache.
Q_DECL_DEPRECATED const QString authenticationDatabasePath() const
The standard authentication database file in ~/.qgis3/ or defined location.
static const QList< QSslCertificate > systemRootCAs()
systemRootCAs get root system certificate authorities
bool removeCertAuthority(const QSslCertificate &cert)
Remove a certificate authority.
const QList< QSslCertificate > trustedCaCerts(bool includeinvalid=false)
trustedCaCerts get list of all trusted CA certificates
bool existsCertAuthority(const QSslCertificate &cert)
Check if a certificate authority exists.
const QMap< QString, QSslCertificate > mappedDatabaseCAs()
mappedDatabaseCAs get sha1-mapped database-stored certificate authorities
bool importAuthenticationConfigsFromXml(const QString &filename, const QString &password=QString(), bool overwrite=false)
Import authentication configurations from an XML file.
bool configIdUnique(const QString &id) const
Verify if provided authentication id is unique.
QStringList configIds() const
Gets list of authentication ids from database.
QString authManTag() const
Simple text tag describing authentication system for message logs.
bool loadAuthenticationConfig(const QString &authcfg, QgsAuthMethodConfig &mconfig, bool full=false)
Load an authentication config from the database into subclass.
QgsAuthCertUtils::CertTrustPolicy certTrustPolicy(const QSslCertificate &cert)
certTrustPolicy get whether certificate cert is trusted by user
bool masterPasswordHashInDatabase() const
Verify a password hash existing in authentication database.
Q_DECL_DEPRECATED void messageOut(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level=QgsAuthManager::INFO) const
Custom logging signal to relay to console output and QgsMessageLog.
QgsAuthConfigurationStorageDb * defaultDbStorage() const
Transitional proxy to the first ready storage of database type.
bool updateNetworkProxy(QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkProxy with an authentication config.
const QSslCertificate certAuthority(const QString &id)
Gets a certificate authority by id (sha hash)
void passwordHelperSuccess()
Signals emitted on password helper success, mainly used in the tests to exit main application loop.
bool registerCoreAuthMethods()
Instantiate and register existing C++ core authentication methods from plugins.
bool passwordHelperDelete()
Delete master password from wallet.
~QgsAuthManager() override
void dumpIgnoredSslErrorsCache_()
Utility function to dump the cache for debug purposes.
const QList< QSslCertificate > databaseCAs()
databaseCAs get database-stored certificate authorities
void messageLog(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Custom logging signal to relay to console output and QgsMessageLog.
bool backupAuthenticationDatabase(QString *backuppath=nullptr)
Close connection to current authentication database and back it up.
void authDatabaseEraseRequested()
Emitted when a user has indicated they may want to erase the authentication db.
void passwordHelperFailure()
Signals emitted on password helper failure, mainly used in the tests to exit main application loop.
bool existsSslCertCustomConfig(const QString &id, const QString &hostport)
Check if SSL certificate custom config exists.
bool existsAuthSetting(const QString &key)
Check if an authentication setting exists.
void clearCachedConfig(const QString &authcfg)
Clear an authentication config from its associated authentication method cache.
void clearMasterPassword()
Clear supplied master password.
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
const QList< QSslCertificate > certIdentities()
certIdentities get certificate identities
bool storeCertAuthority(const QSslCertificate &cert)
Store a certificate authority.
QStringList certIdentityIds() const
certIdentityIds get list of certificate identity ids from database
bool removeCertTrustPolicies(const QList< QSslCertificate > &certs)
Remove a group certificate authorities.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Gets authentication method from the config/provider cache via its key.
bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QgsDataSourceUri with an authentication config.
void setup(const QString &pluginPath=QString(), const QString &authDatabasePath=QString())
Sets up the authentication manager configuration.
static QgsAuthManager * instance()
Enforce singleton pattern.
Q_DECL_DEPRECATED QSqlDatabase authDatabaseConnection() const
Sets up the application instance of the authentication database connection.
void updateConfigAuthMethods()
Sync the confg/authentication method cache with what is in database.
bool storeSslCertCustomConfig(const QgsAuthConfigSslServer &config)
Store an SSL certificate custom config.
static void setPasswordHelperLoggingEnabled(bool enabled)
Password helper logging enabled setter.
bool ensureInitialized() const
Performs lazy initialization of the authentication framework, if it has not already been done.
const QgsAuthConfigSslServer sslCertCustomConfigByHost(const QString &hostport)
sslCertCustomConfigByHost get an SSL certificate custom config by hostport (host:port)
bool updateAuthenticationConfig(const QgsAuthMethodConfig &config)
Update an authentication config in the database.
bool existsCertIdentity(const QString &id)
Check if a certificate identity exists.
const QString authenticationDatabaseUri() const
Returns the authentication database connection URI.
bool resetMasterPassword(const QString &newpass, const QString &oldpass, bool keepbackup, QString *backuppath=nullptr)
Reset the master password to a new one, then re-encrypt all previous configs in a new database file,...
QStringList authMethodsKeys(const QString &dataprovider=QString())
Gets keys of supported authentication methods.
bool passwordHelperSync()
Store the password manager into the wallet.
bool masterPasswordIsSet() const
Whether master password has be input and verified, i.e. authentication database is accessible.
const QString methodConfigTableName() const
Returns the database table from the first ready storage that stores authentication configs,...
void masterPasswordVerified(bool verified)
Emitted when a password has been verify (or not)
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
bool storeCertAuthorities(const QList< QSslCertificate > &certs)
Store multiple certificate authorities.
bool removeSslCertCustomConfig(const QString &id, const QString &hostport)
Remove an SSL certificate custom config.
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME
The display name of the password helper (platform dependent)
bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkReply with an authentication config (used to skip known SSL errors,...
bool rebuildTrustedCaCertsCache()
Rebuild trusted certificate authorities cache.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
bool removeAuthenticationConfig(const QString &authcfg)
Remove an authentication config in the database.
bool removeCertTrustPolicy(const QSslCertificate &cert)
Remove a certificate authority.
const QString authenticationDatabaseUriStripped() const
Returns the authentication database connection URI with the password stripped.
QgsAuthMethod::Expansions supportedAuthMethodExpansions(const QString &authcfg)
Gets supported authentication method expansion(s), e.g.
const QgsAuthConfigSslServer sslCertCustomConfig(const QString &id, const QString &hostport)
sslCertCustomConfig get an SSL certificate custom config by id (sha hash) and hostport (host:port)
QgsAuthMethodConfigsMap availableAuthMethodConfigs(const QString &dataprovider=QString())
Gets mapping of authentication config ids and their base configs (not decrypted data)
bool masterPasswordSame(const QString &password) const
Check whether supplied password is the same as the one already set.
bool storeAuthenticationConfig(QgsAuthMethodConfig &mconfig, bool overwrite=false)
Store an authentication config in the database.
bool removeCertIdentity(const QString &id)
Remove a certificate identity.
QString configAuthMethodKey(const QString &authcfg) const
Gets key of authentication method associated with config ID.
Configuration storage class for authentication method configurations.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
bool readXml(const QDomElement &element)
from a DOM element.
const QString configString() const
The extended configuration, as stored and retrieved from the authentication database.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
void loadConfigString(const QString &configstr)
Load existing extended configuration.
bool writeXml(QDomElement &parentElement, QDomDocument &document)
Stores the configuration in a DOM.
void setId(const QString &id)
Sets auth config ID.
A registry / canonical manager of authentication methods.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey) const
Returns metadata of the auth method or nullptr if not found.
static QgsAuthMethodRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QStringList authMethodList() const
Returns list of available auth methods by their keys.
QgsAuthMethod * createAuthMethod(const QString &authMethodKey)
Create an instance of the auth method.
Abstract base class for authentication method plugins.
virtual bool updateNetworkProxy(QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider=QString())
Update proxy settings with authentication components.
virtual bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Update a network request with authentication components.
QgsAuthMethod::Expansions supportedExpansions() const
Flags that represent the update points (where authentication configurations are expanded) supported b...
virtual void clearCachedConfig(const QString &authcfg)=0
Clear any cached configuration.
virtual void updateMethodConfig(QgsAuthMethodConfig &mconfig)=0
Update an authentication configuration in place.
virtual bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Update a network reply with authentication components.
virtual bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Update data source connection items with authentication components.
QFlags< Expansion > Expansions
static QgsCredentials * instance()
retrieves instance
bool getMasterPassword(QString &password, bool stored=false)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Custom exception class which is raised when an operation is not supported.
Scoped object for logging of the runtime for a single operation or group of operations.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
QHash< QString, QgsAuthMethod * > QgsAuthMethodsMap
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
Structure that holds the (encrypted) master password elements.