17#include <QCoreApplication>
19#include <QDomDocument>
24#include <QMutexLocker>
26#include <QRandomGenerator>
27#include <QRegularExpression>
29#include <QSqlDatabase>
39using namespace Qt::StringLiterals;
46#include <QSslConfiguration>
61#include "moc_qgsauthmanager.cpp"
72const QString QgsAuthManager::AUTH_CONFIG_TABLE = u
"auth_configs"_s;
73const QString QgsAuthManager::AUTH_SERVERS_TABLE = u
"auth_servers"_s;
75const QString QgsAuthManager::AUTH_CFG_REGEX = u
"authcfg=([a-z]|[A-Z]|[0-9]){7}"_s;
78const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_KEY_NAME_BASE(
"QGIS-Master-Password" );
79const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_FOLDER_NAME(
"QGIS" );
93#if defined( Q_OS_MAC )
95#elif defined( Q_OS_WIN )
97#elif defined( Q_OS_LINUX )
107 static QMutex sMutex;
108 QMutexLocker locker( &sMutex );
123 mMutex = std::make_unique<QRecursiveMutex>();
124 mMasterPasswordMutex = std::make_unique<QRecursiveMutex>();
141 QMutexLocker locker( mMutex.get() );
146 return storage->authDatabaseConnection();
151 return QSqlDatabase();
164 const QList<QgsAuthConfigurationStorage *> storages { storageRegistry->
readyStorages() };
167 if (
auto dbStorage = qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
171 return dbStorage->quotedQualifiedIdentifier( dbStorage->methodConfigTableName() );
188 const auto drivers { QSqlDatabase::drivers() };
189 for (
const QString &driver : std::as_const( drivers ) )
191 if ( driver != ( u
"QSQLITE"_s ) && driver != ( u
"QSPATIALITE"_s ) && uri.startsWith( driver ) )
206 return mAuthDatabaseConnectionUri;
215 QRegularExpression re( u
"password=(.*)"_s );
216 QString uri = mAuthDatabaseConnectionUri;
217 return uri.replace( re, u
"password=*****"_s );
227 mAuthDatabaseConnectionUri = authDatabasePath.startsWith(
"QSQLITE://"_L1 ) ? authDatabasePath : u
"QSQLITE://"_s + authDatabasePath;
228 return initPrivate( pluginPath );
230 Q_UNUSED( pluginPath )
231 Q_UNUSED( authDatabasePath )
239 static QRecursiveMutex sInitializationMutex;
240 static bool sInitialized =
false;
242 sInitializationMutex.lock();
245 sInitializationMutex.unlock();
246 return mLazyInitResult;
249 mLazyInitResult =
const_cast< QgsAuthManager *
>( this )->initPrivate( mPluginPath );
251 sInitializationMutex.unlock();
253 return mLazyInitResult;
260static char *sPassFileEnv =
nullptr;
263bool QgsAuthManager::initPrivate(
const QString &pluginPath )
273 mQcaInitializer = std::make_unique<QCA::Initializer>( QCA::Practical, 256 );
276 QCA::scanForPlugins();
278 QgsDebugMsgLevel( u
"QCA Plugin Diagnostics Context: %1"_s.arg( QCA::pluginDiagnosticText() ), 2 );
279 QStringList capabilities;
281 capabilities = QCA::supportedFeatures();
282 QgsDebugMsgLevel( u
"QCA supports: %1"_s.arg( capabilities.join(
"," ) ), 2 );
285 if ( !QCA::isSupported(
"cert", u
"qca-ossl"_s ) )
287 mAuthDisabled =
true;
288 mAuthDisabledMessage = tr(
"QCA's OpenSSL plugin (qca-ossl) is missing" );
292 QgsDebugMsgLevel( u
"Prioritizing qca-ossl over all other QCA providers..."_s, 2 );
293 const QCA::ProviderList provds = QCA::providers();
295 for ( QCA::Provider *p : provds )
297 QString pn = p->name();
299 if ( pn !=
"qca-ossl"_L1 )
301 pr = QCA::providerPriority( pn ) + 1;
303 QCA::setProviderPriority( pn, pr );
304 prlist << u
"%1:%2"_s.arg( pn ).arg( QCA::providerPriority( pn ) );
306 QgsDebugMsgLevel( u
"QCA provider priorities: %1"_s.arg( prlist.join(
", " ) ), 2 );
313 QgsDebugMsgLevel( u
"Authentication methods found: %1"_s.arg( methods.join(
", " ) ), 2 );
315 if ( methods.isEmpty() )
317 mAuthDisabled =
true;
318 mAuthDisabledMessage = tr(
"No authentication method plugins found" );
324 mAuthDisabled =
true;
325 mAuthDisabledMessage = tr(
"No authentication method plugins could be loaded" );
329 QgsDebugMsgLevel( u
"Auth database URI: %1"_s.arg( mAuthDatabaseConnectionUri ), 2 );
333 if ( !sqliteDbPath.isEmpty() )
337 else if ( !mAuthDatabaseConnectionUri.isEmpty() )
341 QgsAuthConfigurationStorageDb *storage =
new QgsAuthConfigurationStorageDb( mAuthDatabaseConnectionUri );
351 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
360 const QString err = tr(
"Failed to initialize storage %1: %2" ).arg( storage->
name(), storage->
lastError() );
380 QString passpath( sPassFileEnv );
381 free( sPassFileEnv );
382 sPassFileEnv =
nullptr;
385 QFile passfile( passpath );
386 if ( passfile.exists() && passfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
388 QTextStream passin( &passfile );
389 while ( !passin.atEnd() )
391 masterpass = passin.readLine();
396 if ( !masterpass.isEmpty() )
400 QgsDebugMsgLevel( u
"Authentication master password set from QGIS_AUTH_PASSWORD_FILE"_s, 2 );
404 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to set password using: " + passpath );
410 QgsDebugError(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to read password from: " + passpath );
421 Q_UNUSED( pluginPath )
429 mPluginPath = pluginPath;
430 mAuthDatabaseConnectionUri = authDatabasePath;
432 const char *p = getenv(
"QGIS_AUTH_PASSWORD_FILE" );
435 sPassFileEnv = qstrdup( p );
440 putenv(
"QGIS_AUTH_PASSWORD_FILE" );
442 unsetenv(
"QGIS_AUTH_PASSWORD_FILE" );
446 Q_UNUSED( pluginPath )
447 Q_UNUSED( authDatabasePath )
451QString QgsAuthManager::generatePassword()
454 QRandomGenerator generator = QRandomGenerator::securelySeeded();
457 static const QString sPwChars = u
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-{}[]"_s;
458 for (
int i = 0; i < pw.size(); ++i )
460 pw[i] = sPwChars.at( generator.bounded( 0, sPwChars.length() ) );
475 QgsDebugError( u
"Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing"_s );
477 return mAuthDisabled;
488 return tr(
"Authentication system is DISABLED:\n%1" ).arg( mAuthDisabledMessage );
497 QMutexLocker locker( mMasterPasswordMutex.get() );
501 if ( mScheduledDbErase )
507 if ( !mMasterPass.isEmpty() )
513 const QString newPassword = generatePassword();
514 if ( passwordHelperWrite( newPassword ) )
516 mMasterPass = newPassword;
548 QString path = mAuthDatabaseConnectionUri;
549 if ( path.startsWith( u
"QSQLITE://"_s, Qt::CaseSensitivity::CaseInsensitive ) )
551 path = path.mid( 10 );
553 else if ( path.startsWith( u
"QSPATIALITE://"_s, Qt::CaseSensitivity::CaseInsensitive ) )
555 path = path.mid( 14 );
558 return QDir::cleanPath( path );
578 QMutexLocker locker( mMasterPasswordMutex.get() );
582 if ( mScheduledDbErase )
585 if ( mMasterPass.isEmpty() )
588 if ( !masterPasswordInput() )
617 QMutexLocker locker( mMutex.get() );
621 if ( mScheduledDbErase )
625 QString prevpass = QString( mMasterPass );
629 mMasterPass = prevpass;
630 const char *err = QT_TR_NOOP(
"Master password set: FAILED to verify, reset to previous" );
636 QgsDebugMsgLevel( u
"Master password set: SUCCESS%1"_s.arg( verify ?
" and verified" :
"" ), 2 );
654 if ( !masterPasswordRowsInDb( rows ) )
656 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
664 QgsDebugMsgLevel( u
"Master password: %1 rows in database"_s.arg( rows ), 2 );
668 const char *err = QT_TR_NOOP(
"Master password: FAILED to find just one master password record in database" );
675 else if ( rows == 1 )
677 if ( !masterPasswordCheckAgainstDb( compare ) )
679 if ( compare.isNull() )
681 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
690 if ( mPassTries >= 5 )
692 mAuthDisabled =
true;
693 const char *err = QT_TR_NOOP(
"Master password: failed 5 times authentication system DISABLED" );
701 QgsDebugMsgLevel( u
"Master password: verified against hash in database"_s, 2 );
702 if ( compare.isNull() )
706 else if ( compare.isNull() )
708 if ( !masterPasswordStoreInDb() )
710 const char *err = QT_TR_NOOP(
"Master password: hash FAILED to be stored in database" );
722 if ( !masterPasswordCheckAgainstDb() )
724 const char *err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
734 QgsDebugMsgLevel( u
"Master password: verified against hash in database"_s, 2 );
751 return !mMasterPass.isEmpty();
762 return mMasterPass == pass;
786 QgsDebugMsgLevel( u
"Master password reset: backed up current database"_s, 2 );
789 QString prevpass = QString( mMasterPass );
790 QString prevciv = QString( masterPasswordCiv() );
796 if ( ok && !masterPasswordClearDb() )
799 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not clear current password from database" );
805 QgsDebugMsgLevel( u
"Master password reset: cleared current password from database"_s, 2 );
812 if ( ok && !masterPasswordStoreInDb() )
815 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not store new password in database" );
821 QgsDebugMsgLevel( u
"Master password reset: stored new password in database"_s, 2 );
828 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify new password in database" );
834 if ( ok && !reencryptAllAuthenticationConfigs( prevpass, prevciv ) )
837 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt configs in database" );
843 QgsDebugMsgLevel( u
"Master password reset: re-encrypted configs in database"_s, 2 );
847 if ( ok && !verifyPasswordCanDecryptConfigs() )
850 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not verify password can decrypt re-encrypted configs" );
855 if ( ok && !reencryptAllAuthenticationSettings( prevpass, prevciv ) )
858 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt settings in database" );
863 if ( ok && !reencryptAllAuthenticationIdentities( prevpass, prevciv ) )
866 const char *err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt identities in database" );
874 const QString err = tr(
"Master password reset FAILED: could not sync password helper: %1" ).arg(
passwordHelperErrorMessage() );
883 QString errdbbackup( dbbackup );
884 errdbbackup.replace(
".db"_L1,
"_ERROR.db"_L1 );
886 QgsDebugError( u
"Master password reset FAILED: backed up failed db at %1"_s.arg( errdbbackup ) );
889 mMasterPass = prevpass;
890 QgsDebugError( u
"Master password reset FAILED: reinstated previous password and database"_s );
894 *backuppath = errdbbackup;
899 if ( !keepbackup && !QFile::remove( dbbackup ) )
901 const char *err = QT_TR_NOOP(
"Master password reset: could not remove old database backup" );
909 QgsDebugMsgLevel( u
"Master password reset: backed up previous db at %1"_s.arg( dbbackup ), 2 );
911 *backuppath = dbbackup;
922 Q_UNUSED( keepbackup )
923 Q_UNUSED( backuppath )
938 const QString existingPassword = passwordHelperRead( readOk );
947 Q_UNUSED( newPassword )
948 Q_UNUSED( keepBackup )
949 Q_UNUSED( backupPath )
959 mScheduledDbErase = scheduleErase;
961 mScheduledDbEraseRequestEmitted =
false;
962 mScheduledDbEraseRequestCount = 0;
966 if ( !mScheduledDbEraseTimer )
968 mScheduledDbEraseTimer = std::make_unique<QTimer>(
this );
969 connect( mScheduledDbEraseTimer.get(), &QTimer::timeout,
this, &QgsAuthManager::tryToStartDbErase );
970 mScheduledDbEraseTimer->start( mScheduledDbEraseRequestWait * 1000 );
972 else if ( !mScheduledDbEraseTimer->isActive() )
974 mScheduledDbEraseTimer->start();
979 if ( mScheduledDbEraseTimer && mScheduledDbEraseTimer->isActive() )
980 mScheduledDbEraseTimer->stop();
983 Q_UNUSED( scheduleErase )
993 qDeleteAll( mAuthMethods );
994 mAuthMethods.clear();
996 for (
const auto &authMethodKey : methods )
1001 return !mAuthMethods.isEmpty();
1017#ifndef __clang_analyzer__
1020 QTimer::singleShot( 3, &loop, &QEventLoop::quit );
1027 for (
int i = 0; i < len; i++ )
1029 switch ( QRandomGenerator::system()->generate() % 2 )
1032 id +=
static_cast<char>(
'0' + QRandomGenerator::system()->generate() % 10 );
1035 id +=
static_cast<char>(
'a' + QRandomGenerator::system()->generate() % 26 );
1039 if ( !configids.contains(
id ) )
1061 const char *err = QT_TR_NOOP(
"Config ID is empty" );
1067 return !configids.contains(
id );
1077 const thread_local QRegularExpression authCfgRegExp( AUTH_CFG_REGEX );
1078 return txt.indexOf( authCfgRegExp ) != -1;
1090 QMutexLocker locker( mMutex.get() );
1091 QStringList providerAuthMethodsKeys;
1092 if ( !dataprovider.isEmpty() )
1109 if ( providerAuthMethodsKeys.isEmpty() || providerAuthMethodsKeys.contains( config.method() ) )
1112 if ( baseConfigs.contains( config.id() ) )
1119 baseConfigs.insert( config.id(), config );
1125 if ( storages.empty() )
1134 Q_UNUSED( dataprovider )
1152 if ( !
configIds.contains( config.id() ) )
1154 mConfigAuthMethods.insert( config.id(), config.method() );
1155 QgsDebugMsgLevel( u
"Stored auth config/methods:\n%1 %2"_s.arg( config.id(), config.method() ), 2 );
1161 QgsDebugMsgLevel( u
"A config with same id %1 was already added, skipping from %2"_s.arg( config.id(), storage->
name() ), 2 );
1176 if ( !mConfigAuthMethods.contains( authcfg ) )
1178 QgsDebugError( u
"No config auth method found in database for authcfg: %1"_s.arg( authcfg ) );
1182 QString authMethodKey = mConfigAuthMethods.value( authcfg );
1199 return mConfigAuthMethods.value( authcfg, QString() );
1214 Q_UNUSED( dataprovider )
1215 return QStringList();
1224 if ( !mAuthMethods.contains( authMethodKey ) )
1226 QgsDebugError( u
"No auth method registered for auth method key: %1"_s.arg( authMethodKey ) );
1230 return mAuthMethods.value( authMethodKey );
1232 Q_UNUSED( authMethodKey )
1242 if ( !mAuthMethods.contains( authMethodKey ) )
1244 QgsDebugError( u
"No auth method registered for auth method key: %1"_s.arg( authMethodKey ) );
1250 Q_UNUSED( authMethodKey )
1261 if ( dataprovider.isEmpty() )
1263 return mAuthMethods;
1267 QgsAuthMethodsMap::const_iterator i = mAuthMethods.constBegin();
1268 while ( i != mAuthMethods.constEnd() )
1270 if ( i.value() && ( i.value()->supportedDataProviders().contains( u
"all"_s ) || i.value()->supportedDataProviders().contains( dataprovider ) ) )
1272 filteredmap.insert( i.key(), i.value() );
1278 Q_UNUSED( dataprovider )
1284QWidget *QgsAuthManager::authMethodEditWidget(
const QString &authMethodKey, QWidget *parent )
1290 return method->editWidget( parent );
1322 QMutexLocker locker( mMutex.get() );
1329 const char *err = QT_TR_NOOP(
"Store config: FAILED because config is invalid" );
1335 QString uid = config.
id();
1336 bool passedinID = !uid.isEmpty();
1337 if ( uid.isEmpty() )
1345 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 is not unique" );
1353 const char *err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID %1 could not be removed" );
1362 if ( configstring.isEmpty() )
1364 const char *err = QT_TR_NOOP(
"Store config: FAILED because config string is empty" );
1372 if ( defaultStorage->isEncrypted() )
1379 configCopy.
setId( uid );
1380 if ( !defaultStorage->storeMethodConfig( configCopy, configstring ) )
1394 config.
setId( uid );
1398 QgsDebugMsgLevel( u
"Store config SUCCESS for authcfg: %1"_s.arg( uid ), 2 );
1402 Q_UNUSED( overwrite )
1412 QMutexLocker locker( mMutex.get() );
1417 if ( !config.
isValid(
true ) )
1419 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is invalid" );
1426 if ( configstring.isEmpty() )
1428 const char *err = QT_TR_NOOP(
"Update config: FAILED because config is empty" );
1459 if ( storages.empty() )
1470 QgsDebugMsgLevel( u
"Update config SUCCESS for authcfg: %1"_s.arg( config.
id() ), 2 );
1490 QMutexLocker locker( mMutex.get() );
1502 if ( !config.
isValid(
true ) || ( full && payload.isEmpty() ) )
1525 QgsDebugError( u
"Update of authcfg %1 FAILED for auth method %2"_s.arg( authcfg, authMethodKey ) );
1528 QgsDebugMsgLevel( u
"Load %1 config SUCCESS for authcfg: %2"_s.arg( full ?
"full" :
"base", authcfg ), 2 );
1533 if ( storages.empty() )
1556 QMutexLocker locker( mMutex.get() );
1560 if ( authcfg.isEmpty() )
1586 if ( storages.empty() )
1608 if ( filename.isEmpty() )
1611 QDomDocument document( u
"qgis_authentication"_s );
1612 QDomElement root = document.createElement( u
"qgis_authentication"_s );
1613 document.appendChild( root );
1616 if ( !password.isEmpty() )
1621 root.setAttribute( u
"salt"_s, salt );
1622 root.setAttribute( u
"hash"_s, hash );
1623 root.setAttribute( u
"civ"_s, civ );
1626 QDomElement configurations = document.createElement( u
"configurations"_s );
1627 for (
const QString &authcfg : authcfgs )
1634 authMethodConfig.
writeXml( configurations, document );
1637 if ( !password.isEmpty() )
1639 QString configurationsString;
1640 QTextStream ts( &configurationsString );
1641 configurations.save( ts, 2 );
1642 root.appendChild( document.createTextNode(
QgsAuthCrypto::encrypt( password, civ, configurationsString ) ) );
1646 root.appendChild( configurations );
1649 QFile file( filename );
1650 if ( !file.open( QFile::WriteOnly | QIODevice::Truncate ) )
1653 QTextStream ts( &file );
1654 document.save( ts, 2 );
1658 Q_UNUSED( filename )
1659 Q_UNUSED( authcfgs )
1660 Q_UNUSED( password )
1670 QFile file( filename );
1671 if ( !file.open( QFile::ReadOnly ) )
1676 QDomDocument document( u
"qgis_authentication"_s );
1677 if ( !document.setContent( &file ) )
1684 QDomElement root = document.documentElement();
1685 if ( root.tagName() !=
"qgis_authentication"_L1 )
1690 QDomElement configurations;
1691 if ( root.hasAttribute( u
"salt"_s ) )
1693 QString salt = root.attribute( u
"salt"_s );
1694 QString hash = root.attribute( u
"hash"_s );
1695 QString civ = root.attribute( u
"civ"_s );
1700 configurations = document.firstChild().toElement();
1704 configurations = root.firstChildElement( u
"configurations"_s );
1707 QDomElement configuration = configurations.firstChildElement();
1708 while ( !configuration.isNull() )
1711 ( void ) authMethodConfig.
readXml( configuration );
1714 configuration = configuration.nextSiblingElement();
1718 Q_UNUSED( filename )
1719 Q_UNUSED( password )
1720 Q_UNUSED( overwrite )
1730 QMutexLocker locker( mMutex.get() );
1736 if ( defaultStorage->clearMethodConfigs() )
1745 QgsDebugMsgLevel( u
"FAILED to remove all configs from the default storage"_s, 2 );
1765 QMutexLocker locker( mMutex.get() );
1769 const char *err = QT_TR_NOOP(
"The authentication storage is not filesystem-based" );
1777 const char *err = QT_TR_NOOP(
"No authentication database file found" );
1787 if ( authConn.isValid() && authConn.isOpen() )
1791 QString datestamp( QDateTime::currentDateTime().toString( u
"yyyy-MM-dd-hhmmss"_s ) );
1793 dbbackup.replace(
".db"_L1, u
"_%1.db"_s.arg( datestamp ) );
1797 const char *err = QT_TR_NOOP(
"Could not back up authentication database" );
1804 *backuppath = dbbackup;
1809 Q_UNUSED( backuppath )
1819 QMutexLocker locker( mMutex.get() );
1830 if ( backuppath && !dbbackup.isEmpty() )
1831 *backuppath = dbbackup;
1835 if ( defaultStorage->erase() )
1837 mMasterPass = QString();
1864 Q_UNUSED( backuppath )
1882 QgsDebugError( u
"Network request updating not supported by authcfg: %1"_s.arg( authcfg ) );
1897 Q_UNUSED( dataprovider )
1915 QgsDebugMsgLevel( u
"Network reply updating not supported by authcfg: %1"_s.arg( authcfg ), 3 );
1931 Q_UNUSED( dataprovider )
1949 QgsDebugError( u
"Data source URI updating not supported by authcfg: %1"_s.arg( authcfg ) );
1963 Q_UNUSED( connectionItems )
1965 Q_UNUSED( dataprovider )
1983 QgsDebugError( u
"Proxy updating not supported by authcfg: %1"_s.arg( authcfg ) );
1992 QgsDebugMsgLevel( u
"Proxy updated successfully from authcfg: %1"_s.arg( authcfg ), 2 );
2000 Q_UNUSED( dataprovider )
2010 QMutexLocker locker( mMutex.get() );
2011 if ( key.isEmpty() )
2014 QString storeval( value.toString() );
2037 if ( !defaultStorage->storeAuthSetting( key, storeval ) )
2062 QMutexLocker locker( mMutex.get() );
2063 if ( key.isEmpty() )
2069 QVariant value = defaultValue;
2077 if ( !storeval.isEmpty() )
2088 if ( storages.empty() )
2096 Q_UNUSED( defaultValue )
2107 QMutexLocker locker( mMutex.get() );
2108 if ( key.isEmpty() )
2122 if ( storages.empty() )
2139 QMutexLocker locker( mMutex.get() );
2140 if ( key.isEmpty() )
2167 if ( storages.empty() )
2187 QMutexLocker locker( mMutex.get() );
2193 mCustomConfigByHostCache.clear();
2194 mHasCheckedIfCustomConfigByHostExists =
false;
2209 QMutexLocker locker( mMutex.get() );
2210 if ( cert.isNull() )
2224 QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
2229 QgsDebugError( u
"Store certificate identity: FAILED to remove pre-existing certificate identity %1"_s.arg(
id ) );
2237 if ( !defaultStorage->storeCertIdentity( cert, keypem ) )
2261 QMutexLocker locker( mMutex.get() );
2263 QSslCertificate cert;
2274 if ( !cert.isNull() )
2280 if ( storages.empty() )
2288 return QSslCertificate();
2296 QMutexLocker locker( mMutex.get() );
2297 QPair<QSslCertificate, QSslKey> bundle;
2312 if ( encryptedBundle.first.isNull() )
2314 QgsDebugError( u
"Certificate identity bundle is null for id: %1"_s.arg(
id ) );
2317 QSslKey key(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), encryptedBundle.second ).toLatin1(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey );
2320 QgsDebugError( u
"Certificate identity bundle: FAILED to create private key"_s );
2323 bundle = qMakePair( encryptedBundle.first, key );
2328 if ( storages.empty() )
2342 QMutexLocker locker( mMutex.get() );
2344 if ( QgsAuthCertUtils::certIsViable( bundle.first ) && !bundle.second.isNull() )
2346 return QStringList() << QString( bundle.first.toPem() ) << QString( bundle.second.toPem() );
2348 return QStringList();
2351 return QStringList();
2360 QMutexLocker locker( mMutex.get() );
2361 QList<QSslCertificate> certs;
2368 const QList<QSslCertificate> storageCerts = storage->
certIdentities();
2370 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
2372 if ( !certs.contains( cert ) )
2374 certs.append( cert );
2383 if ( storages.empty() )
2390 return QList<QSslCertificate>();
2399 QMutexLocker locker( mMutex.get() );
2413 for (
const QString &
id : std::as_const( storageIds ) )
2415 if ( !ids.contains(
id ) )
2428 return QStringList();
2437 QMutexLocker locker( mMutex.get() );
2452 if ( storages.empty() )
2469 QMutexLocker locker( mMutex.get() );
2492 if ( storages.empty() )
2510 QMutexLocker locker( mMutex.get() );
2518 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
2522 QgsDebugError( u
"Store SSL certificate custom config: FAILED to remove pre-existing config %1"_s.arg(
id ) );
2528 if ( !defaultStorage->storeSslCertCustomConfig( config ) )
2541 mCustomConfigByHostCache.clear();
2555 QMutexLocker locker( mMutex.get() );
2558 if (
id.isEmpty() || hostport.isEmpty() )
2560 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2584 if ( storages.empty() )
2593 Q_UNUSED( hostport )
2604 if ( hostport.isEmpty() )
2609 QMutexLocker locker( mMutex.get() );
2611 if ( mCustomConfigByHostCache.contains( hostport ) )
2612 return mCustomConfigByHostCache.value( hostport );
2622 mCustomConfigByHostCache.insert( hostport, config );
2626 if ( storages.empty() )
2633 Q_UNUSED( hostport )
2643 QMutexLocker locker( mMutex.get() );
2644 QList<QgsAuthConfigSslServer> configs;
2655 for (
const auto &config : std::as_const( storageConfigs ) )
2657 const QString id( QgsAuthCertUtils::shaHexForCert( config.sslCertificate() ) );
2658 const QString hostPort = config.sslHostPort();
2659 const QString shaHostPort( u
"%1:%2"_s.arg(
id, hostPort ) );
2660 if ( !ids.contains( shaHostPort ) )
2662 ids.append( shaHostPort );
2663 configs.append( config );
2672 if ( storages.empty() )
2679 return QList<QgsAuthConfigSslServer>();
2688 QMutexLocker locker( mMutex.get() );
2689 if (
id.isEmpty() || hostPort.isEmpty() )
2691 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2706 if ( storages.empty() )
2714 Q_UNUSED( hostPort )
2724 QMutexLocker locker( mMutex.get() );
2725 if (
id.isEmpty() || hostport.isEmpty() )
2727 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
2731 mCustomConfigByHostCache.clear();
2745 const QString shaHostPort( u
"%1:%2"_s.arg(
id, hostport ) );
2746 if ( mIgnoredSslErrorsCache.contains( shaHostPort ) )
2748 mIgnoredSslErrorsCache.remove( shaHostPort );
2754 if ( storages.empty() )
2762 Q_UNUSED( hostport )
2773 QMutexLocker locker( mMutex.get() );
2774 if ( !mIgnoredSslErrorsCache.isEmpty() )
2777 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = mIgnoredSslErrorsCache.constBegin();
2778 while ( i != mIgnoredSslErrorsCache.constEnd() )
2781 for (
auto err : i.value() )
2783 errs << QgsAuthCertUtils::sslErrorEnumString( err );
2801 QMutexLocker locker( mMutex.get() );
2808 QString shahostport( u
"%1:%2"_s.arg( QgsAuthCertUtils::shaHexForCert( config.
sslCertificate() ).trimmed(), config.
sslHostPort().trimmed() ) );
2809 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2811 mIgnoredSslErrorsCache.remove( shahostport );
2814 if ( !errenums.isEmpty() )
2816 mIgnoredSslErrorsCache.insert( shahostport, QSet<QSslError::SslError>( errenums.begin(), errenums.end() ) );
2817 QgsDebugMsgLevel( u
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1"_s.arg( shahostport ), 2 );
2822 QgsDebugMsgLevel( u
"No ignored SSL errors to cache for sha:host:port = %1"_s.arg( shahostport ), 2 );
2835 QMutexLocker locker( mMutex.get() );
2836 const thread_local QRegularExpression rx( QRegularExpression::anchoredPattern(
"\\S+:\\S+:\\d+" ) );
2837 if ( !rx.match( shahostport ).hasMatch() )
2840 "Passed shahostport does not match \\S+:\\S+:\\d+, "
2841 "e.g. 74a4ef5ea94512a43769b744cda0ca5049a72491:www.example.com:443"
2846 if ( mIgnoredSslErrorsCache.contains( shahostport ) )
2848 mIgnoredSslErrorsCache.remove( shahostport );
2851 if ( errors.isEmpty() )
2857 QSet<QSslError::SslError> errs;
2858 for (
const auto &error : errors )
2860 if ( error.error() == QSslError::NoError )
2863 errs.insert( error.error() );
2866 if ( errs.isEmpty() )
2868 QgsDebugError( u
"Passed errors list does not contain errors"_s );
2872 mIgnoredSslErrorsCache.insert( shahostport, errs );
2874 QgsDebugMsgLevel( u
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1"_s.arg( shahostport ), 2 );
2878 Q_UNUSED( shahostport )
2889 QMutexLocker locker( mMutex.get() );
2890 QHash<QString, QSet<QSslError::SslError> > prevcache( mIgnoredSslErrorsCache );
2891 QHash<QString, QSet<QSslError::SslError> > nextcache;
2901 for (
const auto &config : std::as_const( customConfigs ) )
2903 const QString shaHostPort( u
"%1:%2"_s.arg( QgsAuthCertUtils::shaHexForCert( config.sslCertificate() ), config.sslHostPort() ) );
2904 if ( !ids.contains( shaHostPort ) )
2906 ids.append( shaHostPort );
2907 if ( !config.sslIgnoredErrorEnums().isEmpty() )
2909 nextcache.insert( shaHostPort, QSet<QSslError::SslError>( config.sslIgnoredErrorEnums().cbegin(), config.sslIgnoredErrorEnums().cend() ) );
2911 if ( prevcache.contains( shaHostPort ) )
2913 prevcache.remove( shaHostPort );
2923 if ( !prevcache.isEmpty() )
2926 QHash<QString, QSet<QSslError::SslError> >::const_iterator i = prevcache.constBegin();
2927 while ( i != prevcache.constEnd() )
2929 nextcache.insert( i.key(), i.value() );
2934 if ( nextcache != mIgnoredSslErrorsCache )
2936 mIgnoredSslErrorsCache.clear();
2937 mIgnoredSslErrorsCache = nextcache;
2943 QgsDebugMsgLevel( u
"Rebuild of ignored SSL errors cache SAME AS BEFORE"_s, 2 );
2956 QMutexLocker locker( mMutex.get() );
2957 if ( certs.isEmpty() )
2963 for (
const auto &cert : certs )
2980 QMutexLocker locker( mMutex.get() );
2983 if ( cert.isNull() )
2991 QgsDebugError( u
"Store certificate authority: FAILED to remove pre-existing certificate authority"_s );
2997 return defaultStorage->storeCertAuthority( cert );
3017 QMutexLocker locker( mMutex.get() );
3018 QSslCertificate emptycert;
3019 QSslCertificate cert;
3029 if ( !cert.isNull() )
3035 if ( storages.empty() )
3044 return QSslCertificate();
3053 QMutexLocker locker( mMutex.get() );
3054 if ( cert.isNull() )
3071 if ( storages.empty() )
3087 QMutexLocker locker( mMutex.get() );
3088 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() || cert.isNull() || cert.expiryDate() <= QDateTime::currentDateTime() || cert.effectiveDate() > QDateTime::currentDateTime() ) )
3166 if ( QgsAuthCertUtils::certificateIsAuthorityOrIssuer( cert ) )
3173 return QList<QSslCertificate>();
3182 QMutexLocker locker( mMutex.get() );
3187 QList<QSslCertificate> certs;
3191 const QList<QSslCertificate> storageCerts = storage->
caCerts();
3193 for (
const QSslCertificate &cert : std::as_const( storageCerts ) )
3195 if ( !certs.contains( cert ) )
3197 certs.append( cert );
3206 if ( storages.empty() )
3213 return QList<QSslCertificate>();
3221 QMutexLocker locker( mMutex.get() );
3222 return QgsAuthCertUtils::mapDigestToCerts(
databaseCAs() );
3230 QMutexLocker locker( mMutex.get() );
3231 mCaCertsCache.clear();
3237 bool res = !mCaCertsCache.isEmpty();
3251 QMutexLocker locker( mMutex.get() );
3252 if ( cert.isNull() )
3271 return defaultStorage->storeCertTrustPolicy( cert, policy );
3290 QMutexLocker locker( mMutex.get() );
3291 if ( cert.isNull() )
3309 if ( storages.empty() )
3326 QMutexLocker locker( mMutex.get() );
3327 if ( certs.empty() )
3333 for (
const auto &cert : certs )
3350 QMutexLocker locker( mMutex.get() );
3351 if ( cert.isNull() )
3379 if ( storages.empty() )
3396 QMutexLocker locker( mMutex.get() );
3397 if ( cert.isNull() )
3402 QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
3407 if ( trustedids.contains(
id ) )
3411 else if ( untrustedids.contains(
id ) )
3432 return storeAuthSetting( u
"certdefaulttrust"_s,
static_cast< int >( policy ) );
3444 QMutexLocker locker( mMutex.get() );
3445 QVariant policy(
authSetting( u
"certdefaulttrust"_s ) );
3461 QMutexLocker locker( mMutex.get() );
3462 mCertTrustCache.clear();
3472 for (
auto it = trustedCerts.cbegin(); it != trustedCerts.cend(); ++it )
3474 const QString
id { it.key() };
3475 if ( !ids.contains(
id ) )
3496 if ( !storages.empty() )
3516 QMutexLocker locker( mMutex.get() );
3520 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
3522 QList<QSslCertificate> trustedcerts;
3523 for (
int i = 0; i < certpairs.size(); ++i )
3525 QSslCertificate cert( certpairs.at( i ).second );
3526 QString certid( QgsAuthCertUtils::shaHexForCert( cert ) );
3527 if ( trustedids.contains( certid ) )
3530 trustedcerts.append( cert );
3534 if ( !includeinvalid && !QgsAuthCertUtils::certIsViable( cert ) )
3536 trustedcerts.append( cert );
3541 QSslConfiguration sslconfig( QSslConfiguration::defaultConfiguration() );
3542 sslconfig.setCaCertificates( trustedcerts );
3543 QSslConfiguration::setDefaultConfiguration( sslconfig );
3545 return trustedcerts;
3547 Q_UNUSED( includeinvalid )
3548 return QList<QSslCertificate>();
3557 QMutexLocker locker( mMutex.get() );
3558 if ( trustedCAs.isEmpty() )
3560 if ( mTrustedCaCertsCache.isEmpty() )
3567 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
3569 QList<QSslCertificate> untrustedCAs;
3570 for (
int i = 0; i < certpairs.size(); ++i )
3572 QSslCertificate cert( certpairs.at( i ).second );
3573 if ( !trustedCAs.contains( cert ) )
3575 untrustedCAs.append( cert );
3578 return untrustedCAs;
3580 Q_UNUSED( trustedCAs )
3581 return QList<QSslCertificate>();
3590 QMutexLocker locker( mMutex.get() );
3605 QMutexLocker locker( mMutex.get() );
3608 return QByteArray();
3617 QMutexLocker locker( mMutex.get() );
3620 return passwordHelperWrite( mMasterPass );
3634 bool readOk =
false;
3635 const QString currentPass = passwordHelperRead( readOk );
3639 if ( !currentPass.isEmpty() && ( mPasswordHelperErrorCode == QKeychain::NoError ) )
3652#if defined( Q_OS_MAC )
3653 return titleCase ? QObject::tr(
"Keychain" ) : QObject::tr(
"keychain" );
3654#elif defined( Q_OS_WIN )
3655 return titleCase ? QObject::tr(
"Password Manager" ) : QObject::tr(
"password manager" );
3656#elif defined( Q_OS_LINUX )
3658 const QString desktopSession = qgetenv(
"DESKTOP_SESSION" );
3659 const QString currentDesktop = qgetenv(
"XDG_CURRENT_DESKTOP" );
3660 const QString gdmSession = qgetenv(
"GDMSESSION" );
3662 if ( desktopSession.contains(
"kde"_L1, Qt::CaseInsensitive ) || currentDesktop.contains(
"kde"_L1, Qt::CaseInsensitive ) || gdmSession.contains(
"kde"_L1, Qt::CaseInsensitive ) )
3664 return titleCase ? QObject::tr(
"Wallet" ) : QObject::tr(
"wallet" );
3667 return titleCase ? QObject::tr(
"Wallet/Key Ring" ) : QObject::tr(
"wallet/key ring" );
3669 return titleCase ? QObject::tr(
"Password Manager" ) : QObject::tr(
"password manager" );
3672 Q_UNUSED( titleCase )
3691 for (
const auto &authcfg : ids )
3716void QgsAuthManager::writeToConsole(
const QString &message,
const QString &tag,
Qgis::MessageLevel level )
3731 msg +=
"WARNING: "_L1;
3734 msg +=
"ERROR: "_L1;
3741 QTextStream out( stdout, QIODevice::WriteOnly );
3742 out << msg << Qt::endl;
3750void QgsAuthManager::tryToStartDbErase()
3755 ++mScheduledDbEraseRequestCount;
3757 int trycutoff = 90 / ( mScheduledDbEraseRequestWait ? mScheduledDbEraseRequestWait : 3 );
3758 if ( mScheduledDbEraseRequestCount >= trycutoff )
3761 QgsDebugMsgLevel( u
"authDatabaseEraseRequest emitting/scheduling canceled"_s, 2 );
3766 QgsDebugMsgLevel( u
"authDatabaseEraseRequest attempt (%1 of %2)"_s.arg( mScheduledDbEraseRequestCount ).arg( trycutoff ), 2 );
3772 mScheduledDbEraseRequestEmitted =
true;
3788 QMutexLocker locker( mMutex.get() );
3790 QMapIterator<QThread *, QMetaObject::Connection> iterator( mConnectedThreads );
3791 while ( iterator.hasNext() )
3794 QThread::disconnect( iterator.value() );
3805 qDeleteAll( mAuthMethods );
3810 if ( authConn.isValid() && authConn.isOpen() )
3814 QSqlDatabase::removeDatabase( u
"authentication.configs"_s );
3820 QMutexLocker locker( mMutex.get() );
3821 if ( !mAuthConfigurationStorageRegistry )
3823 mAuthConfigurationStorageRegistry = std::make_unique<QgsAuthConfigurationStorageRegistry>();
3825 return mAuthConfigurationStorageRegistry.get();
3829QString QgsAuthManager::passwordHelperName()
const
3832 return tr(
"Password Helper" );
3839void QgsAuthManager::passwordHelperLog(
const QString &msg )
const
3860 QKeychain::DeletePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3862 job.setAutoDelete(
false );
3863 job.setKey( authPasswordHelperKeyName() );
3865 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3870 mPasswordHelperErrorCode = job.error();
3871 mPasswordHelperErrorMessage = tr(
"Delete password failed: %1." ).arg( job.errorString() );
3882 passwordHelperProcessError();
3889QString QgsAuthManager::passwordHelperRead(
bool &ok )
3898 QKeychain::ReadPasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3900 job.setAutoDelete(
false );
3901 job.setKey( authPasswordHelperKeyName() );
3903 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3908 mPasswordHelperErrorCode = job.error();
3909 mPasswordHelperErrorMessage = tr(
"Retrieving password from the %1 failed: %2." ).arg(
passwordHelperDisplayName(), job.errorString() );
3915 password = job.textData();
3917 if ( password.isEmpty() )
3919 mPasswordHelperErrorCode = QKeychain::EntryNotFound;
3931 passwordHelperProcessError();
3939bool QgsAuthManager::passwordHelperWrite(
const QString &password )
3944 Q_ASSERT( !password.isEmpty() );
3947 QKeychain::WritePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
3949 job.setAutoDelete(
false );
3950 job.setKey( authPasswordHelperKeyName() );
3951 job.setTextData( password );
3953 connect( &job, &QKeychain::Job::finished, &loop, &QEventLoop::quit );
3958 mPasswordHelperErrorCode = job.error();
3959 mPasswordHelperErrorMessage = tr(
"Storing password in the %1 failed: %2." ).arg(
passwordHelperDisplayName(), job.errorString() );
3966 passwordHelperClearErrors();
3971 passwordHelperProcessError();
3974 Q_UNUSED( password )
3994 enabled ? tr(
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." ).arg(
passwordHelperDisplayName() )
3995 : tr(
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." ).arg(
passwordHelperDisplayName() )
4021void QgsAuthManager::passwordHelperClearErrors()
4024 mPasswordHelperErrorCode = QKeychain::NoError;
4025 mPasswordHelperErrorMessage.clear();
4029void QgsAuthManager::passwordHelperProcessError()
4034 if ( mPasswordHelperErrorCode == QKeychain::AccessDenied
4035 || mPasswordHelperErrorCode == QKeychain::AccessDeniedByUser
4036 || mPasswordHelperErrorCode == QKeychain::NoBackendAvailable
4037 || mPasswordHelperErrorCode == QKeychain::NotImplemented )
4043 mPasswordHelperErrorMessage = tr(
4044 "There was an error and integration with your %1 has been disabled. "
4045 "You can re-enable it at any time through the \"Utilities\" menu "
4046 "in the Authentication pane of the options dialog. %2"
4050 if ( mPasswordHelperErrorCode != QKeychain::NoError )
4056 passwordHelperClearErrors();
4061bool QgsAuthManager::masterPasswordInput()
4070 bool storedPasswordIsValid =
false;
4076 bool readOk =
false;
4077 pass = passwordHelperRead( readOk );
4078 if ( readOk && !pass.isEmpty() && ( mPasswordHelperErrorCode == QKeychain::NoError ) )
4084 storedPasswordIsValid =
true;
4099 if ( ok && !pass.isEmpty() && mMasterPass != pass )
4104 if ( !passwordHelperWrite( pass ) )
4117bool QgsAuthManager::masterPasswordRowsInDb(
int &rows )
const
4128 QMutexLocker locker( mMutex.get() );
4133 if ( storages.empty() )
4139 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4147 catch (
const QgsNotSupportedException &e )
4171 if ( !masterPasswordRowsInDb( rows ) )
4173 const char *err = QT_TR_NOOP(
"Master password: FAILED to access database" );
4179 return ( rows == 1 );
4185bool QgsAuthManager::masterPasswordCheckAgainstDb(
const QString &compare )
const
4198 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords() };
4199 if ( passwords.size() == 0 )
4204 const QgsAuthConfigurationStorage::MasterPasswordConfig storedPassword { passwords.first() };
4207 catch (
const QgsNotSupportedException &e )
4225bool QgsAuthManager::masterPasswordStoreInDb()
const
4233 QString salt, hash, civ;
4241 return defaultStorage->storeMasterPassword( { salt, civ, hash } );
4243 catch (
const QgsNotSupportedException &e )
4260bool QgsAuthManager::masterPasswordClearDb()
4272 return defaultStorage->clearMasterPasswords();
4274 catch (
const QgsNotSupportedException &e )
4291const QString QgsAuthManager::masterPasswordCiv()
const
4303 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords { defaultStorage->masterPasswords() };
4304 if ( passwords.size() == 0 )
4309 return passwords.first().civ;
4311 catch (
const QgsNotSupportedException &e )
4333 QStringList configKeys = QStringList();
4347 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
4349 if ( !configKeys.contains( it.key() ) )
4351 configKeys.append( it.key() );
4368 return QStringList();
4372bool QgsAuthManager::verifyPasswordCanDecryptConfigs()
const
4385 for (
const QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4395 for (
auto it = configs.cbegin(); it != configs.cend(); ++it )
4397 QString configstring(
QgsAuthCrypto::decrypt( mMasterPass, masterPasswordCiv(), it.value().config( u
"encrypted_payload"_s ) ) );
4398 if ( configstring.isEmpty() )
4400 QgsDebugError( u
"Verify password can decrypt configs FAILED, could not decrypt a config (id: %1) from storage %2"_s.arg( it.key(), storage->
name() ) );
4405 catch (
const QgsNotSupportedException &e )
4413 if ( storages.empty() )
4425bool QgsAuthManager::reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv )
4435 for (
const auto &configid : ids )
4437 res = res && reencryptAuthenticationConfig( configid, prevpass, prevciv );
4441 Q_UNUSED( prevpass )
4447bool QgsAuthManager::reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv )
4460 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4472 const QgsAuthMethodConfig config = storage->
loadMethodConfig( authcfg, payload,
true );
4473 if ( payload.isEmpty() || !config.
isValid(
true ) )
4475 QgsDebugError( u
"Reencrypt FAILED, could not find config (id: %1)"_s.arg( authcfg ) );
4480 if ( configstring.isEmpty() )
4482 QgsDebugError( u
"Reencrypt FAILED, could not decrypt config (id: %1)"_s.arg( authcfg ) );
4496 catch (
const QgsNotSupportedException &e )
4504 if ( storages.empty() )
4516 Q_UNUSED( prevpass )
4522bool QgsAuthManager::reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv )
4527 Q_UNUSED( prevpass )
4540 QStringList encryptedsettings;
4541 encryptedsettings <<
"";
4543 for (
const auto & sett, std::as_const( encryptedsettings ) )
4550 QSqlQuery query( authDbConnection() );
4552 query.prepare( QStringLiteral(
"SELECT value FROM %1 "
4553 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
4555 query.bindValue(
":setting", sett );
4557 if ( !authDbQuery( &query ) )
4560 if ( !query.isActive() || !query.isSelect() )
4562 QgsDebugError( u
"Reencrypt FAILED, query not active or a select operation for setting: %2"_s.arg( sett ) );
4566 if ( query.first() )
4572 query.prepare( QStringLiteral(
"UPDATE %1 "
4573 "SET value = :value "
4574 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
4576 query.bindValue(
":setting", sett );
4579 if ( !authDbStartTransaction() )
4582 if ( !authDbQuery( &query ) )
4585 if ( !authDbCommit() )
4593 QgsDebugError( u
"Reencrypt FAILED, could not find in db setting: %2"_s.arg( sett ) );
4599 QgsDebugError( u
"Select contains more than one for setting: %1"_s.arg( sett ) );
4610bool QgsAuthManager::reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv )
4620 for (
const auto &identid : ids )
4622 res = res && reencryptAuthenticationIdentity( identid, prevpass, prevciv );
4626 Q_UNUSED( prevpass )
4632bool QgsAuthManager::reencryptAuthenticationIdentity(
const QString &identid,
const QString &prevpass,
const QString &prevciv )
4646 for ( QgsAuthConfigurationStorage *storage : std::as_const( storages ) )
4659 if ( keystring.isEmpty() )
4661 QgsDebugError( u
"Reencrypt FAILED, could not decrypt identity id: %1"_s.arg( identid ) );
4669 catch (
const QgsNotSupportedException &e )
4677 if ( storages.empty() )
4689 Q_UNUSED( prevpass )
4701 for (
const auto &cert : certs )
4703 mCaCertsCache.insert( QgsAuthCertUtils::shaHexForCert( cert ), QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>( source, cert ) );
4712QString QgsAuthManager::authPasswordHelperKeyName()
const
4717 QString dbProfilePath;
4723 const QFileInfo info( mAuthDatabaseConnectionUri );
4724 dbProfilePath = info.dir().dirName();
4728 dbProfilePath = QCryptographicHash::hash( ( mAuthDatabaseConnectionUri.toUtf8() ), QCryptographicHash::Md5 ).toHex();
4732 return AUTH_PASSWORD_HELPER_KEY_NAME_BASE + ( dbProfilePath.compare(
"default"_L1, Qt::CaseInsensitive ) == 0 ? QString() : dbProfilePath );
4745 if ( qobject_cast<QgsAuthConfigurationStorageDb *>( storage ) )
4760 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.
static const QgsSettingsEntryBool * settingsPasswordHelperInsecureFallback
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.
static const QgsSettingsEntryBool * settingsPasswordHelperLogging
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.
static const QgsSettingsEntryBool * settingsUsePasswordHelper
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
A boolean settings entry.
static QgsSettingsTreeNode * sTreeAuthentication
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)