17#include <QCoreApplication>
19#include <QDomDocument>
24#include <QMutexLocker>
26#include <QRandomGenerator>
27#include <QRegularExpression>
29#include <QSqlDatabase>
43#include <QSslConfiguration>
58#include "moc_qgsauthmanager.cpp"
69const QString QgsAuthManager::AUTH_CONFIG_TABLE = u
"auth_configs"_s;
70const QString QgsAuthManager::AUTH_SERVERS_TABLE = u
"auth_servers"_s;
72const QString QgsAuthManager::AUTH_CFG_REGEX = u
"authcfg=([a-z]|[A-Z]|[0-9]){7}"_s;
75const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_KEY_NAME_BASE(
"QGIS-Master-Password" );
76const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_FOLDER_NAME(
"QGIS" );
84#elif defined(Q_OS_WIN)
86#elif defined(Q_OS_LINUX)
97 QMutexLocker locker( &sMutex );
112 mMutex = std::make_unique<QRecursiveMutex>();
113 mMasterPasswordMutex = std::make_unique<QRecursiveMutex>();
115 this, &QgsAuthManager::writeToConsole );
131 QMutexLocker locker( mMutex.get() );
136 return storage->authDatabaseConnection();
141 return QSqlDatabase();
154 const QList<QgsAuthConfigurationStorage *> storages { storageRegistry->
readyStorages() };
157 if (
auto dbStorage = qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
161 return dbStorage->quotedQualifiedIdentifier( dbStorage->methodConfigTableName() );
178 const auto drivers { QSqlDatabase::drivers() };
179 for (
const QString &driver : std::as_const( drivers ) )
181 if ( driver != ( u
"QSQLITE"_s ) && driver != ( u
"QSPATIALITE"_s ) && uri.startsWith( driver ) )
196 return mAuthDatabaseConnectionUri;
205 QRegularExpression re( u
"password=(.*)"_s );
206 QString uri = mAuthDatabaseConnectionUri;
207 return uri.replace( re, u
"password=*****"_s );
217 mAuthDatabaseConnectionUri = authDatabasePath.startsWith(
"QSQLITE://"_L1 ) ? authDatabasePath : u
"QSQLITE://"_s + authDatabasePath;
218 return initPrivate( pluginPath );
220 Q_UNUSED( pluginPath )
221 Q_UNUSED( authDatabasePath )
229 static QRecursiveMutex sInitializationMutex;
230 static bool sInitialized =
false;
232 sInitializationMutex.lock();
235 sInitializationMutex.unlock();
236 return mLazyInitResult;
239 mLazyInitResult =
const_cast< QgsAuthManager *
>( this )->initPrivate( mPluginPath );
241 sInitializationMutex.unlock();
243 return mLazyInitResult;
249static char *sPassFileEnv =
nullptr;
251bool QgsAuthManager::initPrivate(
const QString &pluginPath )
261 mQcaInitializer = std::make_unique<QCA::Initializer>( QCA::Practical, 256 );
264 QCA::scanForPlugins();
266 QgsDebugMsgLevel( u
"QCA Plugin Diagnostics Context: %1"_s.arg( QCA::pluginDiagnosticText() ), 2 );
267 QStringList capabilities;
269 capabilities = QCA::supportedFeatures();
270 QgsDebugMsgLevel( u
"QCA supports: %1"_s.arg( capabilities.join(
"," ) ), 2 );
273 if ( !QCA::isSupported(
"cert", u
"qca-ossl"_s ) )
275 mAuthDisabled =
true;
276 mAuthDisabledMessage = tr(
"QCA's OpenSSL plugin (qca-ossl) is missing" );
280 QgsDebugMsgLevel( u
"Prioritizing qca-ossl over all other QCA providers..."_s, 2 );
281 const QCA::ProviderList provds = QCA::providers();
283 for ( QCA::Provider *p : provds )
285 QString pn = p->name();
287 if ( pn !=
"qca-ossl"_L1 )
289 pr = QCA::providerPriority( pn ) + 1;
291 QCA::setProviderPriority( pn, pr );
292 prlist << u
"%1:%2"_s.arg( pn ).arg( QCA::providerPriority( pn ) );
294 QgsDebugMsgLevel( u
"QCA provider priorities: %1"_s.arg( prlist.join(
", " ) ), 2 );
301 QgsDebugMsgLevel( u
"Authentication methods found: %1"_s.arg( methods.join(
", " ) ), 2 );
303 if ( methods.isEmpty() )
305 mAuthDisabled =
true;
306 mAuthDisabledMessage = tr(
"No authentication method plugins found" );
312 mAuthDisabled =
true;
313 mAuthDisabledMessage = tr(
"No authentication method plugins could be loaded" );
317 QgsDebugMsgLevel( u
"Auth database URI: %1"_s.arg( mAuthDatabaseConnectionUri ), 2 );
321 if ( ! sqliteDbPath.isEmpty() )
325 else if ( ! mAuthDatabaseConnectionUri.isEmpty() )
329 QgsAuthConfigurationStorageDb *storage =
new QgsAuthConfigurationStorageDb( mAuthDatabaseConnectionUri );
339 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
348 const QString err = tr(
"Failed to initialize storage %1: %2" ).arg( storage->
name(), storage->
lastError() );
368 QString passpath( sPassFileEnv );
369 free( sPassFileEnv );
370 sPassFileEnv =
nullptr;
373 QFile passfile( passpath );
374 if ( passfile.exists() && passfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
376 QTextStream passin( &passfile );
377 while ( !passin.atEnd() )
379 masterpass = passin.readLine();
384 if ( !masterpass.isEmpty() )
388 QgsDebugMsgLevel( u
"Authentication master password set from QGIS_AUTH_PASSWORD_FILE"_s, 2 );
392 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to set password using: " + passpath );
398 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to read password from: " + passpath );
409 Q_UNUSED( pluginPath )
417 mPluginPath = pluginPath;
418 mAuthDatabaseConnectionUri = authDatabasePath;
420 const char *p = getenv(
"QGIS_AUTH_PASSWORD_FILE" );
423 sPassFileEnv = qstrdup( p );
428 putenv(
"QGIS_AUTH_PASSWORD_FILE" );
430 unsetenv(
"QGIS_AUTH_PASSWORD_FILE" );
434 Q_UNUSED( pluginPath )
435 Q_UNUSED( authDatabasePath )
439QString QgsAuthManager::generatePassword()
442 QRandomGenerator generator = QRandomGenerator::securelySeeded();
445 static const QString sPwChars = u
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-{}[]"_s;
446 for (
int i = 0; i < pw.size(); ++i )
448 pw[i] = sPwChars.at( generator.bounded( 0, sPwChars.length() ) );
463 QgsDebugError( u
"Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing"_s );
465 return mAuthDisabled;
476 return tr(
"Authentication system is DISABLED:\n%1" ).arg( mAuthDisabledMessage );
485 QMutexLocker locker( mMasterPasswordMutex.get() );
489 if ( mScheduledDbErase )
495 if ( !mMasterPass.isEmpty() )
501 const QString newPassword = generatePassword();
502 if ( passwordHelperWrite( newPassword ) )
504 mMasterPass = newPassword;
536 QString path = mAuthDatabaseConnectionUri;
537 if ( path.startsWith( u
"QSQLITE://"_s, Qt::CaseSensitivity::CaseInsensitive ) )
539 path = path.mid( 10 );
541 else if ( path.startsWith( u
"QSPATIALITE://"_s, Qt::CaseSensitivity::CaseInsensitive ) )
543 path = path.mid( 14 );
546 return QDir::cleanPath( path );
566 QMutexLocker locker( mMasterPasswordMutex.get() );
570 if ( mScheduledDbErase )
573 if ( mMasterPass.isEmpty() )
576 if ( !masterPasswordInput() )
605 QMutexLocker locker( mMutex.get() );
609 if ( mScheduledDbErase )
613 QString prevpass = QString( mMasterPass );
617 mMasterPass = prevpass;
618 const char *err = QT_TR_NOOP(
"Master password set: FAILED to verify, reset to previous" );
624 QgsDebugMsgLevel( u
"Master password set: SUCCESS%1"_s.arg( verify ?
" and verified" :
"" ), 2 );
642 if ( !masterPasswordRowsInDb( rows ) )
644 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
652 QgsDebugMsgLevel( u
"Master password: %1 rows in database"_s.arg( rows ), 2 );
656 const char *err = QT_TR_NOOP(
"Master password: FAILED to find just one master password record in database" );
663 else if ( rows == 1 )
665 if ( !masterPasswordCheckAgainstDb( compare ) )
667 if ( compare.isNull() )
669 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
678 if ( mPassTries >= 5 )
680 mAuthDisabled =
true;
681 const char *err = QT_TR_NOOP(
"Master password: failed 5 times authentication system DISABLED" );
689 QgsDebugMsgLevel( u
"Master password: verified against hash in database"_s, 2 );
690 if ( compare.isNull() )
694 else if ( compare.isNull() )
696 if ( !masterPasswordStoreInDb() )
698 const char *err = QT_TR_NOOP(
"Master password: hash FAILED to be stored in database" );
710 if ( !masterPasswordCheckAgainstDb() )
712 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
722 QgsDebugMsgLevel( u
"Master password: verified against hash in database"_s, 2 );
739 return !mMasterPass.isEmpty();
750 return mMasterPass == pass;
758 bool keepbackup, QString *backuppath )
775 QgsDebugMsgLevel( u
"Master password reset: backed up current database"_s, 2 );
778 QString prevpass = QString( mMasterPass );
779 QString prevciv = QString( masterPasswordCiv() );
785 if ( ok && !masterPasswordClearDb() )
788 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not clear current password from database" );
794 QgsDebugMsgLevel( u
"Master password reset: cleared current password from database"_s, 2 );
801 if ( ok && !masterPasswordStoreInDb() )
804 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not store new password in database" );
810 QgsDebugMsgLevel( u
"Master password reset: stored new password in database"_s, 2 );
817 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify new password in database" );
823 if ( ok && !reencryptAllAuthenticationConfigs( prevpass, prevciv ) )
826 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt configs in database" );
832 QgsDebugMsgLevel( u
"Master password reset: re-encrypted configs in database"_s, 2 );
836 if ( ok && !verifyPasswordCanDecryptConfigs() )
839 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify password can decrypt re-encrypted configs" );
844 if ( ok && !reencryptAllAuthenticationSettings( prevpass, prevciv ) )
847 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt settings in database" );
852 if ( ok && !reencryptAllAuthenticationIdentities( prevpass, prevciv ) )
855 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt identities in database" );
863 const QString err = tr(
"Master password reset FAILED: could not sync password helper: %1" ).arg(
passwordHelperErrorMessage() );
872 QString errdbbackup( dbbackup );
873 errdbbackup.replace(
".db"_L1,
"_ERROR.db"_L1 );
875 QgsDebugError( u
"Master password reset FAILED: backed up failed db at %1"_s.arg( errdbbackup ) );
878 mMasterPass = prevpass;
879 QgsDebugError( u
"Master password reset FAILED: reinstated previous password and database"_s );
883 *backuppath = errdbbackup;
888 if ( !keepbackup && !QFile::remove( dbbackup ) )
890 const char *err = QT_TR_NOOP(
"Master password reset: could not remove old database backup" );
898 QgsDebugMsgLevel( u
"Master password reset: backed up previous db at %1"_s.arg( dbbackup ), 2 );
900 *backuppath = dbbackup;
911 Q_UNUSED( keepbackup )
912 Q_UNUSED( backuppath )
927 const QString existingPassword = passwordHelperRead( readOk );
936 Q_UNUSED( newPassword )
937 Q_UNUSED( keepBackup )
938 Q_UNUSED( backupPath )
948 mScheduledDbErase = scheduleErase;
950 mScheduledDbEraseRequestEmitted =
false;
951 mScheduledDbEraseRequestCount = 0;
955 if ( !mScheduledDbEraseTimer )
957 mScheduledDbEraseTimer = std::make_unique<QTimer>(
this );
958 connect( mScheduledDbEraseTimer.get(), &QTimer::timeout,
this, &QgsAuthManager::tryToStartDbErase );
959 mScheduledDbEraseTimer->start( mScheduledDbEraseRequestWait * 1000 );
961 else if ( !mScheduledDbEraseTimer->isActive() )
963 mScheduledDbEraseTimer->start();
968 if ( mScheduledDbEraseTimer && mScheduledDbEraseTimer->isActive() )
969 mScheduledDbEraseTimer->stop();
972 Q_UNUSED( scheduleErase )
982 qDeleteAll( mAuthMethods );
983 mAuthMethods.clear();
985 for (
const auto &authMethodKey : methods )
990 return !mAuthMethods.isEmpty();
1006#ifndef __clang_analyzer__
1009 QTimer::singleShot( 3, &loop, &QEventLoop::quit );
1016 for (
int i = 0; i < len; i++ )
1018 switch ( QRandomGenerator::system()->generate() % 2 )
1021 id +=
static_cast<char>(
'0' + QRandomGenerator::system()->generate() % 10 );
1024 id +=
static_cast<char>(
'a' + QRandomGenerator::system()->generate() % 26 );
1028 if ( !configids.contains(
id ) )
1050 const char *err = QT_TR_NOOP(
"Config ID is empty" );
1056 return !configids.contains(
id );
1066 const thread_local QRegularExpression authCfgRegExp( AUTH_CFG_REGEX );
1067 return txt.indexOf( authCfgRegExp ) != -1;
1079 QMutexLocker locker( mMutex.get() );
1080 QStringList providerAuthMethodsKeys;
1081 if ( !dataprovider.isEmpty() )
1098 if ( providerAuthMethodsKeys.isEmpty() || providerAuthMethodsKeys.contains( config.method() ) )
1101 if ( baseConfigs.contains( config.id() ) )
1108 baseConfigs.insert( config.id(), config );
1114 if ( storages.empty() )
1123 Q_UNUSED( dataprovider )
1141 if ( !
configIds.contains( config.id() ) )
1143 mConfigAuthMethods.insert( config.id(), config.method() );
1144 QgsDebugMsgLevel( u
"Stored auth config/methods:\n%1 %2"_s.arg( config.id(), config.method() ), 2 );
1150 QgsDebugMsgLevel( u
"A config with same id %1 was already added, skipping from %2"_s.arg( config.id(), storage->
name() ), 2 );
1165 if ( !mConfigAuthMethods.contains( authcfg ) )
1167 QgsDebugError( u
"No config auth method found in database for authcfg: %1"_s.arg( authcfg ) );
1171 QString authMethodKey = mConfigAuthMethods.value( authcfg );
1188 return mConfigAuthMethods.value( authcfg, QString() );
1203 Q_UNUSED( dataprovider )
1204 return QStringList();
1213 if ( !mAuthMethods.contains( authMethodKey ) )
1215 QgsDebugError( u
"No auth method registered for auth method key: %1"_s.arg( authMethodKey ) );
1219 return mAuthMethods.value( authMethodKey );
1221 Q_UNUSED( authMethodKey )
1231 if ( !mAuthMethods.contains( authMethodKey ) )
1233 QgsDebugError( u
"No auth method registered for auth method key: %1"_s.arg( authMethodKey ) );
1239 Q_UNUSED( authMethodKey )
1250 if ( dataprovider.isEmpty() )
1252 return mAuthMethods;
1256 QgsAuthMethodsMap::const_iterator i = mAuthMethods.constBegin();
1257 while ( i != mAuthMethods.constEnd() )
1260 && ( i.value()->supportedDataProviders().contains( u
"all"_s )
1261 || i.value()->supportedDataProviders().contains( dataprovider ) ) )
1263 filteredmap.insert( i.key(), i.value() );
1269 Q_UNUSED( dataprovider )
1275QWidget *QgsAuthManager::authMethodEditWidget(
const QString &authMethodKey, QWidget *parent )
1281 return method->editWidget( parent );
1313 QMutexLocker locker( mMutex.get() );
1320 const char *err = QT_TR_NOOP(
"Store config: FAILED because config is invalid" );
1326 QString uid = config.
id();
1327 bool passedinID = !uid.isEmpty();
1328 if ( uid.isEmpty() )
1336 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 is not unique" );
1344 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 could not be removed" );
1353 if ( configstring.isEmpty() )
1355 const char *err = QT_TR_NOOP(
"Store config: FAILED because config string is empty" );
1363 if ( defaultStorage->isEncrypted() )
1370 configCopy.
setId( uid );
1371 if ( !defaultStorage->storeMethodConfig( configCopy, configstring ) )
1385 config.
setId( uid );
1389 QgsDebugMsgLevel( u
"Store config SUCCESS for authcfg: %1"_s.arg( uid ), 2 );
1393 Q_UNUSED( overwrite )
1403 QMutexLocker locker( mMutex.get() );
1408 if ( !config.
isValid(
true ) )
1410 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is invalid" );
1417 if ( configstring.isEmpty() )
1419 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is empty" );
1450 if ( storages.empty() )
1461 QgsDebugMsgLevel( u
"Update config SUCCESS for authcfg: %1"_s.arg( config.
id() ), 2 );
1481 QMutexLocker locker( mMutex.get() );
1493 if ( ! config.
isValid(
true ) || ( full && payload.isEmpty() ) )
1516 QgsDebugError( u
"Update of authcfg %1 FAILED for auth method %2"_s.arg( authcfg, authMethodKey ) );
1519 QgsDebugMsgLevel( u
"Load %1 config SUCCESS for authcfg: %2"_s.arg( full ?
"full" :
"base", authcfg ), 2 );
1524 if ( storages.empty() )
1547 QMutexLocker locker( mMutex.get() );
1551 if ( authcfg.isEmpty() )
1577 if ( storages.empty() )
1599 if ( filename.isEmpty() )
1602 QDomDocument document( u
"qgis_authentication"_s );
1603 QDomElement root = document.createElement( u
"qgis_authentication"_s );
1604 document.appendChild( root );
1607 if ( !password.isEmpty() )
1612 root.setAttribute( u
"salt"_s, salt );
1613 root.setAttribute( u
"hash"_s, hash );
1614 root.setAttribute( u
"civ"_s, civ );
1617 QDomElement configurations = document.createElement( u
"configurations"_s );
1618 for (
const QString &authcfg : authcfgs )
1625 authMethodConfig.
writeXml( configurations, document );
1628 if ( !password.isEmpty() )
1630 QString configurationsString;
1631 QTextStream ts( &configurationsString );
1632 configurations.save( ts, 2 );
1633 root.appendChild( document.createTextNode(
QgsAuthCrypto::encrypt( password, civ, configurationsString ) ) );
1637 root.appendChild( configurations );
1640 QFile file( filename );
1641 if ( !file.open( QFile::WriteOnly | QIODevice::Truncate ) )
1644 QTextStream ts( &file );
1645#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1646 ts.setCodec(
"UTF-8" );
1648 document.save( ts, 2 );
1652 Q_UNUSED( filename )
1653 Q_UNUSED( authcfgs )
1654 Q_UNUSED( password )
1664 QFile file( filename );
1665 if ( !file.open( QFile::ReadOnly ) )
1670 QDomDocument document( u
"qgis_authentication"_s );
1671 if ( !document.setContent( &file ) )
1678 QDomElement root = document.documentElement();
1679 if ( root.tagName() !=
"qgis_authentication"_L1 )
1684 QDomElement configurations;
1685 if ( root.hasAttribute( u
"salt"_s ) )
1687 QString salt = root.attribute( u
"salt"_s );
1688 QString hash = root.attribute( u
"hash"_s );
1689 QString civ = root.attribute( u
"civ"_s );
1694 configurations = document.firstChild().toElement();
1698 configurations = root.firstChildElement( u
"configurations"_s );
1701 QDomElement configuration = configurations.firstChildElement();
1702 while ( !configuration.isNull() )
1705 ( void )authMethodConfig.
readXml( configuration );
1708 configuration = configuration.nextSiblingElement();
1712 Q_UNUSED( filename )
1713 Q_UNUSED( password )
1714 Q_UNUSED( overwrite )
1724 QMutexLocker locker( mMutex.get() );
1730 if ( defaultStorage->clearMethodConfigs() )
1739 QgsDebugMsgLevel( u
"FAILED to remove all configs from the default storage"_s, 2 );
1759 QMutexLocker locker( mMutex.get() );
1763 const char *err = QT_TR_NOOP(
"The authentication storage is not filesystem-based" );
1771 const char *err = QT_TR_NOOP(
"No authentication database file found" );
1781 if ( authConn.isValid() && authConn.isOpen() )
1785 QString datestamp( QDateTime::currentDateTime().toString( u
"yyyy-MM-dd-hhmmss"_s ) );
1787 dbbackup.replace(
".db"_L1, u
"_%1.db"_s.arg( datestamp ) );
1791 const char *err = QT_TR_NOOP(
"Could not back up authentication database" );
1798 *backuppath = dbbackup;
1803 Q_UNUSED( backuppath )
1813 QMutexLocker locker( mMutex.get() );
1824 if ( backuppath && !dbbackup.isEmpty() )
1825 *backuppath = dbbackup;
1829 if ( defaultStorage->erase() )
1831 mMasterPass = QString();
1858 Q_UNUSED( backuppath )
1864 const QString &dataprovider )
1877 QgsDebugError( u
"Network request updating not supported by authcfg: %1"_s.arg( authcfg ) );
1892 Q_UNUSED( dataprovider )
1898 const QString &dataprovider )
1911 QgsDebugMsgLevel( u
"Network reply updating not supported by authcfg: %1"_s.arg( authcfg ), 3 );
1927 Q_UNUSED( dataprovider )
1933 const QString &dataprovider )
1946 QgsDebugError( u
"Data source URI updating not supported by authcfg: %1"_s.arg( authcfg ) );
1960 Q_UNUSED( connectionItems )
1962 Q_UNUSED( dataprovider )
1980 QgsDebugError( u
"Proxy updating not supported by authcfg: %1"_s.arg( authcfg ) );
1989 QgsDebugMsgLevel( u
"Proxy updated successfully from authcfg: %1"_s.arg( authcfg ), 2 );
1997 Q_UNUSED( dataprovider )
2007 QMutexLocker locker( mMutex.get() );
2008 if ( key.isEmpty() )
2011 QString storeval( value.toString() );
2034 if ( !defaultStorage->storeAuthSetting( key, storeval ) )
2059 QMutexLocker locker( mMutex.get() );
2060 if ( key.isEmpty() )
2066 QVariant value = defaultValue;
2074 if ( !storeval.isEmpty() )
2085 if ( storages.empty() )
2093 Q_UNUSED( defaultValue )
2104 QMutexLocker locker( mMutex.get() );
2105 if ( key.isEmpty() )
2119 if ( storages.empty() )
2136 QMutexLocker locker( mMutex.get() );
2137 if ( key.isEmpty() )
2164 if ( storages.empty() )
2184 QMutexLocker locker( mMutex.get() );
2190 mCustomConfigByHostCache.clear();
2191 mHasCheckedIfCustomConfigByHostExists =
false;
2206 QMutexLocker locker( mMutex.get() );
2207 if ( cert.isNull() )
2221 QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
2226 QgsDebugError( u
"Store certificate identity: FAILED to remove pre-existing certificate identity %1"_s.arg(
id ) );
2234 if ( !defaultStorage->storeCertIdentity( cert, keypem ) )
2258 QMutexLocker locker( mMutex.get() );
2260 QSslCertificate cert;
2271 if ( !cert.isNull() )
2277 if ( storages.empty() )
2285 return QSslCertificate();
2293 QMutexLocker locker( mMutex.get() );
2294 QPair<QSslCertificate, QSslKey> bundle;
2309 if ( encryptedBundle.first.isNull() )
2311 QgsDebugError( u
"Certificate identity bundle is null for id: %1"_s.arg(
id ) );
2314 QSslKey key(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), encryptedBundle.second ).toLatin1(),
2315 QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey );
2318 QgsDebugError( u
"Certificate identity bundle: FAILED to create private key"_s );
2321 bundle = qMakePair( encryptedBundle.first, key );
2326 if ( storages.empty() )
2340 QMutexLocker locker( mMutex.get() );
2342 if ( QgsAuthCertUtils::certIsViable( bundle.first ) && !bundle.second.isNull() )
2344 return QStringList() << QString( bundle.first.toPem() ) << QString( bundle.second.toPem() );
2346 return QStringList();
2349 return QStringList();
2358 QMutexLocker locker( mMutex.get() );
2359 QList<QSslCertificate> certs;
2366 const QList<QSslCertificate> storageCerts = storage->
certIdentities();
2368 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
2370 if ( !certs.contains( cert ) )
2372 certs.append( cert );
2381 if ( storages.empty() )
2388 return QList<QSslCertificate>();
2397 QMutexLocker locker( mMutex.get() );
2411 for (
const QString &
id : std::as_const( storageIds ) )
2413 if ( !ids.contains(
id ) )
2426 return QStringList();
2435 QMutexLocker locker( mMutex.get() );
2450 if ( storages.empty() )
2467 QMutexLocker locker( mMutex.get() );
2490 if ( storages.empty() )
2508 QMutexLocker locker( mMutex.get() );
2516 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
2520 QgsDebugError( u
"Store SSL certificate custom config: FAILED to remove pre-existing config %1"_s.arg(
id ) );
2526 if ( !defaultStorage->storeSslCertCustomConfig( config ) )
2539 mCustomConfigByHostCache.clear();
2553 QMutexLocker locker( mMutex.get() );
2556 if (
id.isEmpty() || hostport.isEmpty() )
2558 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2582 if ( storages.empty() )
2591 Q_UNUSED( hostport )
2602 if ( hostport.isEmpty() )
2607 QMutexLocker locker( mMutex.get() );
2609 if ( mCustomConfigByHostCache.contains( hostport ) )
2610 return mCustomConfigByHostCache.value( hostport );
2620 mCustomConfigByHostCache.insert( hostport, config );
2625 if ( storages.empty() )
2632 Q_UNUSED( hostport )
2642 QMutexLocker locker( mMutex.get() );
2643 QList<QgsAuthConfigSslServer> configs;
2654 for (
const auto &config : std::as_const( storageConfigs ) )
2656 const QString id( QgsAuthCertUtils::shaHexForCert( config.sslCertificate() ) );
2657 const QString hostPort = config.sslHostPort();
2658 const QString shaHostPort( u
"%1:%2"_s.arg(
id, hostPort ) );
2659 if ( ! ids.contains( shaHostPort ) )
2661 ids.append( shaHostPort );
2662 configs.append( config );
2671 if ( storages.empty() )
2678 return QList<QgsAuthConfigSslServer>();
2687 QMutexLocker locker( mMutex.get() );
2688 if (
id.isEmpty() || hostPort.isEmpty() )
2690 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2705 if ( storages.empty() )
2713 Q_UNUSED( hostPort )
2723 QMutexLocker locker( mMutex.get() );
2724 if (
id.isEmpty() || hostport.isEmpty() )
2726 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2730 mCustomConfigByHostCache.clear();
2744 const QString shaHostPort( u
"%1:%2"_s.arg(
id, hostport ) );
2745 if ( mIgnoredSslErrorsCache.contains( shaHostPort ) )
2747 mIgnoredSslErrorsCache.remove( shaHostPort );
2753 if ( storages.empty() )
2761 Q_UNUSED( hostport )
2772 QMutexLocker locker( mMutex.get() );
2773 if ( !mIgnoredSslErrorsCache.isEmpty() )
2776 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = mIgnoredSslErrorsCache.constBegin();
2777 while ( i != mIgnoredSslErrorsCache.constEnd() )
2780 for (
auto err : i.value() )
2782 errs << QgsAuthCertUtils::sslErrorEnumString( err );
2800 QMutexLocker locker( mMutex.get() );
2807 QString shahostport( u
"%1:%2"_s
2808 .arg( QgsAuthCertUtils::shaHexForCert( config.
sslCertificate() ).trimmed(),
2810 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2812 mIgnoredSslErrorsCache.remove( shahostport );
2815 if ( !errenums.isEmpty() )
2817 mIgnoredSslErrorsCache.insert( shahostport, QSet<QSslError::SslError>( errenums.begin(), errenums.end() ) );
2818 QgsDebugMsgLevel( u
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1"_s.arg( shahostport ), 2 );
2823 QgsDebugMsgLevel( u
"No ignored SSL errors to cache for sha:host:port = %1"_s.arg( shahostport ), 2 );
2836 QMutexLocker locker( mMutex.get() );
2837 const thread_local QRegularExpression rx( QRegularExpression::anchoredPattern(
"\\S+:\\S+:\\d+" ) );
2838 if ( !rx.match( shahostport ).hasMatch() )
2840 QgsDebugError(
"Passed shahostport does not match \\S+:\\S+:\\d+, "
2841 "e.g. 74a4ef5ea94512a43769b744cda0ca5049a72491:www.example.com:443" );
2845 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2847 mIgnoredSslErrorsCache.remove( shahostport );
2850 if ( errors.isEmpty() )
2856 QSet<QSslError::SslError> errs;
2857 for (
const auto &error : errors )
2859 if ( error.error() == QSslError::NoError )
2862 errs.insert( error.error() );
2865 if ( errs.isEmpty() )
2867 QgsDebugError( u
"Passed errors list does not contain errors"_s );
2871 mIgnoredSslErrorsCache.insert( shahostport, errs );
2873 QgsDebugMsgLevel( u
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1"_s.arg( shahostport ), 2 );
2877 Q_UNUSED( shahostport )
2888 QMutexLocker locker( mMutex.get() );
2889 QHash<QString, QSet<QSslError::SslError> > prevcache( mIgnoredSslErrorsCache );
2890 QHash<QString, QSet<QSslError::SslError> > nextcache;
2900 for (
const auto &config : std::as_const( customConfigs ) )
2902 const QString shaHostPort( u
"%1:%2"_s.arg( QgsAuthCertUtils::shaHexForCert( config.sslCertificate() ), config.sslHostPort() ) );
2903 if ( ! ids.contains( shaHostPort ) )
2905 ids.append( shaHostPort );
2906 if ( !config.sslIgnoredErrorEnums().isEmpty() )
2908 nextcache.insert( shaHostPort, QSet<QSslError::SslError>( config.sslIgnoredErrorEnums().cbegin(), config.sslIgnoredErrorEnums().cend() ) );
2910 if ( prevcache.contains( shaHostPort ) )
2912 prevcache.remove( shaHostPort );
2922 if ( !prevcache.isEmpty() )
2925 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = prevcache.constBegin();
2926 while ( i != prevcache.constEnd() )
2928 nextcache.insert( i.key(), i.value() );
2933 if ( nextcache != mIgnoredSslErrorsCache )
2935 mIgnoredSslErrorsCache.clear();
2936 mIgnoredSslErrorsCache = nextcache;
2942 QgsDebugMsgLevel( u
"Rebuild of ignored SSL errors cache SAME AS BEFORE"_s, 2 );
2955 QMutexLocker locker( mMutex.get() );
2956 if ( certs.isEmpty() )
2962 for (
const auto &cert : certs )
2979 QMutexLocker locker( mMutex.get() );
2982 if ( cert.isNull() )
2990 QgsDebugError( u
"Store certificate authority: FAILED to remove pre-existing certificate authority"_s );
2996 return defaultStorage->storeCertAuthority( cert );
3016 QMutexLocker locker( mMutex.get() );
3017 QSslCertificate emptycert;
3018 QSslCertificate cert;
3028 if ( !cert.isNull() )
3034 if ( storages.empty() )
3043 return QSslCertificate();
3052 QMutexLocker locker( mMutex.get() );
3053 if ( cert.isNull() )
3070 if ( storages.empty() )
3086 QMutexLocker locker( mMutex.get() );
3087 if ( cert.isNull() )
3116 if ( storages.empty() )
3131 return QSslConfiguration::systemCaCertificates();
3133 return QList<QSslCertificate>();
3142 QMutexLocker locker( mMutex.get() );
3143 QList<QSslCertificate> certs;
3144 QList<QSslCertificate> filecerts;
3153 QString cafile( cafileval.toString() );
3154 if ( !cafile.isEmpty() && QFile::exists( cafile ) )
3156 filecerts = QgsAuthCertUtils::certsFromFile( cafile );
3159 for (
const auto &cert : std::as_const( filecerts ) )
3161 if ( !allowinvalid.toBool() && ( cert.isBlacklisted()
3163 || cert.expiryDate() <= QDateTime::currentDateTime()
3164 || cert.effectiveDate() > QDateTime::currentDateTime() ) )
3169 if ( QgsAuthCertUtils::certificateIsAuthorityOrIssuer( cert ) )
3176 return QList<QSslCertificate>();
3185 QMutexLocker locker( mMutex.get() );
3190 QList<QSslCertificate> certs;
3194 const QList<QSslCertificate> storageCerts = storage->
caCerts();
3196 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
3198 if ( !certs.contains( cert ) )
3200 certs.append( cert );
3209 if ( storages.empty() )
3216 return QList<QSslCertificate>();
3224 QMutexLocker locker( mMutex.get() );
3225 return QgsAuthCertUtils::mapDigestToCerts(
databaseCAs() );
3233 QMutexLocker locker( mMutex.get() );
3234 mCaCertsCache.clear();
3240 bool res = !mCaCertsCache.isEmpty();
3254 QMutexLocker locker( mMutex.get() );
3255 if ( cert.isNull() )
3274 return defaultStorage->storeCertTrustPolicy( cert, policy );
3293 QMutexLocker locker( mMutex.get() );
3294 if ( cert.isNull() )
3312 if ( storages.empty() )
3329 QMutexLocker locker( mMutex.get() );
3330 if ( certs.empty() )
3336 for (
const auto &cert : certs )
3353 QMutexLocker locker( mMutex.get() );
3354 if ( cert.isNull() )
3382 if ( storages.empty() )
3399 QMutexLocker locker( mMutex.get() );
3400 if ( cert.isNull() )
3405 QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
3410 if ( trustedids.contains(
id ) )
3414 else if ( untrustedids.contains(
id ) )
3435 return storeAuthSetting( u
"certdefaulttrust"_s,
static_cast< int >( policy ) );
3447 QMutexLocker locker( mMutex.get() );
3448 QVariant policy(
authSetting( u
"certdefaulttrust"_s ) );
3464 QMutexLocker locker( mMutex.get() );
3465 mCertTrustCache.clear();
3476 for (
auto it = trustedCerts.cbegin(); it != trustedCerts.cend(); ++it )
3478 const QString
id { it.key( )};
3479 if ( ! ids.contains(
id ) )
3500 if ( ! storages.empty() )
3520 QMutexLocker locker( mMutex.get() );
3524 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
3526 QList<QSslCertificate> trustedcerts;
3527 for (
int i = 0; i < certpairs.size(); ++i )
3529 QSslCertificate cert( certpairs.at( i ).second );
3530 QString certid( QgsAuthCertUtils::shaHexForCert( cert ) );
3531 if ( trustedids.contains( certid ) )
3534 trustedcerts.append( cert );
3538 if ( !includeinvalid && !QgsAuthCertUtils::certIsViable( cert ) )
3540 trustedcerts.append( cert );
3545 QSslConfiguration sslconfig( QSslConfiguration::defaultConfiguration() );
3546 sslconfig.setCaCertificates( trustedcerts );
3547 QSslConfiguration::setDefaultConfiguration( sslconfig );
3549 return trustedcerts;
3551 Q_UNUSED( includeinvalid )
3552 return QList<QSslCertificate>();
3561 QMutexLocker locker( mMutex.get() );
3562 if ( trustedCAs.isEmpty() )
3564 if ( mTrustedCaCertsCache.isEmpty() )
3571 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
3573 QList<QSslCertificate> untrustedCAs;
3574 for (
int i = 0; i < certpairs.size(); ++i )
3576 QSslCertificate cert( certpairs.at( i ).second );
3577 if ( !trustedCAs.contains( cert ) )
3579 untrustedCAs.append( cert );
3582 return untrustedCAs;
3584 Q_UNUSED( trustedCAs )
3585 return QList<QSslCertificate>();
3594 QMutexLocker locker( mMutex.get() );
3609 QMutexLocker locker( mMutex.get() );
3612 return QByteArray();
3621 QMutexLocker locker( mMutex.get() );
3624 return passwordHelperWrite( mMasterPass );
3638 bool readOk =
false;
3639 const QString currentPass = passwordHelperRead( readOk );
3643 if ( !currentPass.isEmpty() && ( mPasswordHelperErrorCode == QKeychain::NoError ) )
3656#if defined(Q_OS_MAC)
3657 return titleCase ? QObject::tr(
"Keychain" ) : QObject::tr(
"keychain" );
3658#elif defined(Q_OS_WIN)
3659 return titleCase ? QObject::tr(
"Password Manager" ) : QObject::tr(
"password manager" );
3660#elif defined(Q_OS_LINUX)
3662 const QString desktopSession = qgetenv(
"DESKTOP_SESSION" );
3663 const QString currentDesktop = qgetenv(
"XDG_CURRENT_DESKTOP" );
3664 const QString gdmSession = qgetenv(
"GDMSESSION" );
3666 if ( desktopSession.contains(
"kde"_L1, Qt::CaseInsensitive ) || currentDesktop.contains(
"kde"_L1, Qt::CaseInsensitive ) || gdmSession.contains(
"kde"_L1, Qt::CaseInsensitive ) )
3668 return titleCase ? QObject::tr(
"Wallet" ) : QObject::tr(
"wallet" );
3671 return titleCase ? QObject::tr(
"Wallet/Key Ring" ) : QObject::tr(
"wallet/key ring" );
3673 return titleCase ? QObject::tr(
"Password Manager" ) : QObject::tr(
"password manager" );
3676 Q_UNUSED( titleCase )
3695 for (
const auto &authcfg : ids )
3720void QgsAuthManager::writeToConsole(
const QString &message,
3737 msg +=
"WARNING: "_L1;
3740 msg +=
"ERROR: "_L1;
3747 QTextStream out( stdout, QIODevice::WriteOnly );
3748 out << msg << Qt::endl;
3756void QgsAuthManager::tryToStartDbErase()
3761 ++mScheduledDbEraseRequestCount;
3763 int trycutoff = 90 / ( mScheduledDbEraseRequestWait ? mScheduledDbEraseRequestWait : 3 );
3764 if ( mScheduledDbEraseRequestCount >= trycutoff )
3767 QgsDebugMsgLevel( u
"authDatabaseEraseRequest emitting/scheduling canceled"_s, 2 );
3773 .arg( mScheduledDbEraseRequestCount ).arg( trycutoff ), 2 );
3779 mScheduledDbEraseRequestEmitted =
true;
3795 QMutexLocker locker( mMutex.get() );
3797 QMapIterator<QThread *, QMetaObject::Connection> iterator( mConnectedThreads );
3798 while ( iterator.hasNext() )
3801 QThread::disconnect( iterator.value() );
3812 qDeleteAll( mAuthMethods );
3817 if ( authConn.isValid() && authConn.isOpen() )
3821 QSqlDatabase::removeDatabase( u
"authentication.configs"_s );
3827 QMutexLocker locker( mMutex.get() );
3828 if ( ! mAuthConfigurationStorageRegistry )
3830 mAuthConfigurationStorageRegistry = std::make_unique<QgsAuthConfigurationStorageRegistry>();
3832 return mAuthConfigurationStorageRegistry.get();
3836QString QgsAuthManager::passwordHelperName()
const
3839 return tr(
"Password Helper" );
3846void QgsAuthManager::passwordHelperLog(
const QString &msg )
const
3867 QKeychain::DeletePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3870 job.setAutoDelete(
false );
3871 job.setKey( authPasswordHelperKeyName() );
3873 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3878 mPasswordHelperErrorCode = job.error();
3879 mPasswordHelperErrorMessage = tr(
"Delete password failed: %1." ).arg( job.errorString() );
3890 passwordHelperProcessError();
3897QString QgsAuthManager::passwordHelperRead(
bool &ok )
3906 QKeychain::ReadPasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3909 job.setAutoDelete(
false );
3910 job.setKey( authPasswordHelperKeyName() );
3912 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3917 mPasswordHelperErrorCode = job.error();
3918 mPasswordHelperErrorMessage = tr(
"Retrieving password from the %1 failed: %2." ).arg(
passwordHelperDisplayName(), job.errorString() );
3924 password = job.textData();
3926 if ( password.isEmpty() )
3928 mPasswordHelperErrorCode = QKeychain::EntryNotFound;
3940 passwordHelperProcessError();
3948bool QgsAuthManager::passwordHelperWrite(
const QString &password )
3953 Q_ASSERT( !password.isEmpty() );
3956 QKeychain::WritePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3957 QgsSettings settings;
3959 job.setAutoDelete(
false );
3960 job.setKey( authPasswordHelperKeyName() );
3961 job.setTextData( password );
3963 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3968 mPasswordHelperErrorCode = job.error();
3969 mPasswordHelperErrorMessage = tr(
"Storing password in the %1 failed: %2." ).arg(
passwordHelperDisplayName(), job.errorString() );
3976 passwordHelperClearErrors();
3981 passwordHelperProcessError();
3984 Q_UNUSED( password )
4005 emit
messageLog( enabled ? tr(
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
4007 tr(
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
4035void QgsAuthManager::passwordHelperClearErrors()
4038 mPasswordHelperErrorCode = QKeychain::NoError;
4039 mPasswordHelperErrorMessage.clear();
4043void QgsAuthManager::passwordHelperProcessError()
4048 if ( mPasswordHelperErrorCode == QKeychain::AccessDenied ||
4049 mPasswordHelperErrorCode == QKeychain::AccessDeniedByUser ||
4050 mPasswordHelperErrorCode == QKeychain::NoBackendAvailable ||
4051 mPasswordHelperErrorCode == QKeychain::NotImplemented )
4057 mPasswordHelperErrorMessage = tr(
"There was an error and integration with your %1 has been disabled. "
4058 "You can re-enable it at any time through the \"Utilities\" menu "
4059 "in the Authentication pane of the options dialog. %2" )
4062 if ( mPasswordHelperErrorCode != QKeychain::NoError )
4068 passwordHelperClearErrors();
4073bool QgsAuthManager::masterPasswordInput()
4082 bool storedPasswordIsValid =
false;
4088 bool readOk =
false;
4089 pass = passwordHelperRead( readOk );
4090 if ( readOk && ! pass.isEmpty() && ( mPasswordHelperErrorCode == QKeychain::NoError ) )
4096 storedPasswordIsValid =
true;
4111 if ( ok && !pass.isEmpty() && mMasterPass != pass )
4116 if ( !passwordHelperWrite( pass ) )
4129bool QgsAuthManager::masterPasswordRowsInDb(
int &rows )
const
4140 QMutexLocker locker( mMutex.get() );
4145 if ( storages.empty() )
4151 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4159 catch (
const QgsNotSupportedException &e )
4183 if ( !masterPasswordRowsInDb( rows ) )
4185 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
4191 return ( rows == 1 );
4197bool QgsAuthManager::masterPasswordCheckAgainstDb(
const QString &compare )
const
4210 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords( ) };
4211 if ( passwords.size() == 0 )
4216 const QgsAuthConfigurationStorage::MasterPasswordConfig storedPassword { passwords.first() };
4219 catch (
const QgsNotSupportedException &e )
4238bool QgsAuthManager::masterPasswordStoreInDb()
const
4246 QString salt, hash, civ;
4254 return defaultStorage->storeMasterPassword( { salt, civ, hash } );
4256 catch (
const QgsNotSupportedException &e )
4273bool QgsAuthManager::masterPasswordClearDb()
4286 return defaultStorage->clearMasterPasswords();
4288 catch (
const QgsNotSupportedException &e )
4306const QString QgsAuthManager::masterPasswordCiv()
const
4318 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords( ) };
4319 if ( passwords.size() == 0 )
4324 return passwords.first().civ;
4326 catch (
const QgsNotSupportedException &e )
4348 QStringList configKeys = QStringList();
4362 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
4364 if ( !configKeys.contains( it.key() ) )
4366 configKeys.append( it.key() );
4383 return QStringList();
4387bool QgsAuthManager::verifyPasswordCanDecryptConfigs()
const
4400 for (
const QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4411 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
4413 QString configstring(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), it.value().config( u
"encrypted_payload"_s ) ) );
4414 if ( configstring.isEmpty() )
4416 QgsDebugError( u
"Verify password can decrypt configs FAILED, could not decrypt a config (id: %1) from storage %2"_s
4417 .arg( it.key(), storage->
name() ) );
4422 catch (
const QgsNotSupportedException &e )
4431 if ( storages.empty() )
4443bool QgsAuthManager::reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv )
4453 for (
const auto &configid : ids )
4455 res = res && reencryptAuthenticationConfig( configid, prevpass, prevciv );
4459 Q_UNUSED( prevpass )
4465bool QgsAuthManager::reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv )
4478 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4490 const QgsAuthMethodConfig config = storage->
loadMethodConfig( authcfg, payload,
true );
4491 if ( payload.isEmpty() || ! config.
isValid(
true ) )
4493 QgsDebugError( u
"Reencrypt FAILED, could not find config (id: %1)"_s.arg( authcfg ) );
4498 if ( configstring.isEmpty() )
4500 QgsDebugError( u
"Reencrypt FAILED, could not decrypt config (id: %1)"_s.arg( authcfg ) );
4514 catch (
const QgsNotSupportedException &e )
4522 if ( storages.empty() )
4534 Q_UNUSED( prevpass )
4540bool QgsAuthManager::reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv )
4545 Q_UNUSED( prevpass )
4558 QStringList encryptedsettings;
4559 encryptedsettings <<
"";
4561 for (
const auto & sett, std::as_const( encryptedsettings ) )
4568 QSqlQuery query( authDbConnection() );
4570 query.prepare( QStringLiteral(
"SELECT value FROM %1 "
4571 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
4573 query.bindValue(
":setting", sett );
4575 if ( !authDbQuery( &query ) )
4578 if ( !query.isActive() || !query.isSelect() )
4580 QgsDebugError( u
"Reencrypt FAILED, query not active or a select operation for setting: %2"_s.arg( sett ) );
4584 if ( query.first() )
4590 query.prepare( QStringLiteral(
"UPDATE %1 "
4591 "SET value = :value "
4592 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
4594 query.bindValue(
":setting", sett );
4597 if ( !authDbStartTransaction() )
4600 if ( !authDbQuery( &query ) )
4603 if ( !authDbCommit() )
4611 QgsDebugError( u
"Reencrypt FAILED, could not find in db setting: %2"_s.arg( sett ) );
4617 QgsDebugError( u
"Select contains more than one for setting: %1"_s.arg( sett ) );
4628bool QgsAuthManager::reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv )
4638 for (
const auto &identid : ids )
4640 res = res && reencryptAuthenticationIdentity( identid, prevpass, prevciv );
4644 Q_UNUSED( prevpass )
4650bool QgsAuthManager::reencryptAuthenticationIdentity(
4651 const QString &identid,
4652 const QString &prevpass,
4653 const QString &prevciv )
4667 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4682 if ( keystring.isEmpty() )
4684 QgsDebugError( u
"Reencrypt FAILED, could not decrypt identity id: %1"_s.arg( identid ) );
4692 catch (
const QgsNotSupportedException &e )
4700 if ( storages.empty() )
4712 Q_UNUSED( prevpass )
4724 for (
const auto &cert : certs )
4726 mCaCertsCache.insert( QgsAuthCertUtils::shaHexForCert( cert ),
4727 QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>( source, cert ) );
4736QString QgsAuthManager::authPasswordHelperKeyName()
const
4741 QString dbProfilePath;
4747 const QFileInfo info( mAuthDatabaseConnectionUri );
4748 dbProfilePath = info.dir().dirName();
4752 dbProfilePath = QCryptographicHash::hash( ( mAuthDatabaseConnectionUri.toUtf8() ), QCryptographicHash::Md5 ).toHex();
4756 return AUTH_PASSWORD_HELPER_KEY_NAME_BASE + ( dbProfilePath.compare(
"default"_L1, Qt::CaseInsensitive ) == 0 ? QString() : dbProfilePath );
4769 if ( qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
4784 Q_UNUSED( capability )
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.
CertTrustPolicy
Type of certificate trust policy.
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...
void messageLog(const QString &message, const QString &tag=u"Authentication"_s, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Custom logging signal to relay to console output and QgsMessageLog.
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.
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 which offers an interface to manage the authentication configuration database and to utiliz...
bool storeAuthSetting(const QString &key, const QVariant &value, bool encrypt=false)
Stores an authentication setting.
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.
QString sqliteDatabasePath() const
Returns the path to the authentication database file or an empty string if the database is not SQLite...
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)
Returns a previously set authentication setting.
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.
static const QgsSettingsEntryBool * settingsGenerateRandomPasswordForPasswordHelper
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.
bool createAndStoreRandomMasterPasswordInKeyChain()
Creates a new securely seeded random password and stores it in the system keychain as the new master ...
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.
const QString passwordHelperErrorMessage()
Error message getter.
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.
static const QgsSettingsEntryBool * settingsUsingGeneratedRandomPassword
bool resetMasterPassword(const QString &newpass, const QString &oldpass, bool keepbackup, QString *backuppath=nullptr)
Reset the master password to a new one, then re-encrypts all previous configs with the new password.
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,...
static QgsAuthManager * instance()
Enforce singleton pattern.
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.
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.
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME
The display name of the password helper (platform dependent).
bool storeAuthenticationConfig(QgsAuthMethodConfig &mconfig, bool overwrite=false)
Store an authentication config in the database.
bool verifyStoredPasswordHelperPassword()
Verify the password stored in the password helper.
bool removeCertIdentity(const QString &id)
Remove a certificate identity.
static QString passwordHelperDisplayName(bool titleCase=false)
Returns a translated display name of the password helper (platform dependent).
bool resetMasterPasswordUsingStoredPasswordHelper(const QString &newPassword, bool keepBackup, QString *backupPath=nullptr)
Reset the master password to a new one, hen re-encrypts all previous configs with the new password.
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.
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.
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, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
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.
A boolean settings entry.
static QgsSettingsTreeNode * sTreeAuthentication
Stores settings for use within QGIS.
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)