23 #include <QMutexLocker> 26 #include <QSqlDatabase> 29 #include <QTextStream> 37 #include <QSslConfiguration> 51 const QString QgsAuthManager::smAuthConfigTable =
"auth_configs";
52 const QString QgsAuthManager::smAuthPassTable =
"auth_pass";
53 const QString QgsAuthManager::smAuthSettingsTable =
"auth_settings";
54 const QString QgsAuthManager::smAuthIdentitiesTable =
"auth_identities";
55 const QString QgsAuthManager::smAuthServersTable =
"auth_servers";
56 const QString QgsAuthManager::smAuthAuthoritiesTable =
"auth_authorities";
57 const QString QgsAuthManager::smAuthTrustTable =
"auth_trust";
59 const QString QgsAuthManager::smAuthCfgRegex =
"authcfg=([a-z]|[A-Z]|[0-9]){7}";
77 QString connectionname =
"authentication.configs";
91 const char* err = QT_TR_NOOP(
"Opening of authentication db FAILED" );
107 mQcaInitializer =
new QCA::Initializer( QCA::Practical, 256 );
110 QCA::scanForPlugins();
112 QgsDebugMsg(
QString(
"QCA Plugin Diagnostics Context: %1" ).arg( QCA::pluginDiagnosticText() ) );
115 capabilities = QCA::supportedFeatures();
119 if ( !QCA::isSupported(
"cert",
"qca-ossl" ) )
121 mAuthDisabled =
true;
122 mAuthDisabledMessage =
tr(
"QCA's OpenSSL plugin (qca-ossl) is missing" );
126 QgsDebugMsg(
"Prioritizing qca-ossl over all other QCA providers..." );
127 QCA::ProviderList provds = QCA::providers();
129 Q_FOREACH ( QCA::Provider* p, provds )
135 pr = QCA::providerPriority( pn ) + 1;
137 QCA::setProviderPriority( pn, pr );
138 prlist <<
QString(
"%1:%2" ).
arg( pn ).
arg( QCA::providerPriority( pn ) );
151 mAuthDisabled =
true;
152 mAuthDisabledMessage =
tr(
"No authentication method plugins found" );
158 mAuthDisabled =
true;
159 mAuthDisabledMessage =
tr(
"No authentication method plugins could be loaded" );
170 if ( !dbdirinfo.exists() )
172 QgsDebugMsg(
QString(
"Auth db directory path does not exist, making path: %1" ).arg( dbdirinfo.filePath() ) );
173 if ( !
QDir().mkpath( dbdirinfo.filePath() ) )
175 const char* err = QT_TR_NOOP(
"Auth db directory path could not be created" );
184 if ( !dbinfo.
permission( QFile::ReadOwner | QFile::WriteOwner ) )
186 const char* err = QT_TR_NOOP(
"Auth db is not readable or writable by user" );
191 if ( dbinfo.
size() > 0 )
195 if ( !createCertTables() )
200 #ifndef QT_NO_OPENSSL 205 const char* passenv =
"QGIS_AUTH_PASSWORD_FILE";
208 QString passpath( getenv( passenv ) );
217 QFile passfile( passpath );
218 if ( passfile.
exists() && passfile.
open( QIODevice::ReadOnly | QIODevice::Text ) )
221 while ( !passin.
atEnd() )
232 QgsDebugMsg(
"Authentication master password set from QGIS_AUTH_PASSWORD_FILE" );
236 QgsDebugMsg(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to set password using: " + passpath );
242 QgsDebugMsg(
"QGIS_AUTH_PASSWORD_FILE set, but FAILED to read password from: " + passpath );
252 QgsDebugMsg(
"Auth db does not exist: creating through QSqlDatabase initial connection" );
254 if ( !createConfigTables() )
257 if ( !createCertTables() )
261 #ifndef QT_NO_OPENSSL 268 bool QgsAuthManager::createConfigTables()
273 const char* err = QT_TR_NOOP(
"Auth db could not be created and opened" );
284 qstr =
QString(
"CREATE TABLE %1 (\n" 285 " 'salt' TEXT NOT NULL,\n" 286 " 'civ' TEXT NOT NULL\n" 287 ", 'hash' TEXT NOT NULL);" ).
arg( authDbPassTable() );
289 if ( !authDbQuery( &query ) )
293 qstr =
QString(
"CREATE TABLE %1 (\n" 294 " 'id' TEXT NOT NULL,\n" 295 " 'name' TEXT NOT NULL,\n" 297 " 'type' TEXT NOT NULL,\n" 298 " 'version' INTEGER NOT NULL\n" 301 if ( !authDbQuery( &query ) )
307 if ( !authDbQuery( &query ) )
313 if ( !authDbQuery( &query ) )
320 bool QgsAuthManager::createCertTables()
331 qstr =
QString(
"CREATE TABLE IF NOT EXISTS %1 (\n" 332 " 'setting' TEXT NOT NULL\n" 333 ", 'value' TEXT);" ).
arg( authDbSettingsTable() );
335 if ( !authDbQuery( &query ) )
340 qstr =
QString(
"CREATE TABLE IF NOT EXISTS %1 (\n" 341 " 'id' TEXT NOT NULL,\n" 342 " 'key' TEXT NOT NULL\n" 343 ", 'cert' TEXT NOT NULL);" ).
arg( authDbIdentitiesTable() );
345 if ( !authDbQuery( &query ) )
349 qstr =
QString(
"CREATE UNIQUE INDEX IF NOT EXISTS 'id_index' on %1 (id ASC);" ).
arg( authDbIdentitiesTable() );
351 if ( !authDbQuery( &query ) )
356 qstr =
QString(
"CREATE TABLE IF NOT EXISTS %1 (\n" 357 " 'id' TEXT NOT NULL,\n" 358 " 'host' TEXT NOT NULL,\n" 362 if ( !authDbQuery( &query ) )
368 if ( !authDbQuery( &query ) )
373 qstr =
QString(
"CREATE TABLE IF NOT EXISTS %1 (\n" 374 " 'id' TEXT NOT NULL\n" 375 ", 'cert' TEXT NOT NULL);" ).
arg( authDbAuthoritiesTable() );
377 if ( !authDbQuery( &query ) )
381 qstr =
QString(
"CREATE UNIQUE INDEX IF NOT EXISTS 'id_index' on %1 (id ASC);" ).
arg( authDbAuthoritiesTable() );
383 if ( !authDbQuery( &query ) )
387 qstr =
QString(
"CREATE TABLE IF NOT EXISTS %1 (\n" 388 " 'id' TEXT NOT NULL\n" 389 ", 'policy' TEXT NOT NULL);" ).
arg( authDbTrustTable() );
391 if ( !authDbQuery( &query ) )
395 qstr =
QString(
"CREATE UNIQUE INDEX IF NOT EXISTS 'id_index' on %1 (id ASC);" ).
arg( authDbTrustTable() );
397 if ( !authDbQuery( &query ) )
408 QgsDebugMsg(
"Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing" );
410 return mAuthDisabled;
415 return tr(
"Authentication system is DISABLED:\n%1" ).
arg( mAuthDisabledMessage );
424 if ( mScheduledDbErase )
429 QgsDebugMsg(
"Master password is not yet set by user" );
430 if ( !masterPasswordInput() )
432 QgsDebugMsg(
"Master password input canceled by user" );
446 QgsDebugMsg(
"Master password is set and verified" );
456 if ( mScheduledDbErase )
464 mMasterPass = prevpass;
465 const char* err = QT_TR_NOOP(
"Master password set: FAILED to verify, reset to previous" );
471 QgsDebugMsg(
QString(
"Master password set: SUCCESS%1" ).arg( verify ?
" and verified" :
"" ) );
481 if ( !masterPasswordRowsInDb( &rows ) )
483 const char* err = QT_TR_NOOP(
"Master password: FAILED to access database" );
495 const char* err = QT_TR_NOOP(
"Master password: FAILED to find just one master password record in database" );
502 else if ( rows == 1 )
504 if ( !masterPasswordCheckAgainstDb( compare ) )
508 const char* err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
517 if ( mPassTries >= 5 )
519 mAuthDisabled =
true;
520 const char* err = QT_TR_NOOP(
"Master password: failed 5 times authentication system DISABLED" );
528 QgsDebugMsg(
"Master password: verified against hash in database" );
533 else if ( compare.
isNull() )
535 if ( !masterPasswordStoreInDb() )
537 const char* err = QT_TR_NOOP(
"Master password: hash FAILED to be stored in database" );
546 QgsDebugMsg(
"Master password: hash stored in database" );
549 if ( !masterPasswordCheckAgainstDb() )
551 const char* err = QT_TR_NOOP(
"Master password: FAILED to verify against hash in database" );
561 QgsDebugMsg(
"Master password: verified against hash in database" );
576 return mMasterPass == pass;
580 bool keepbackup,
QString *backuppath )
594 QgsDebugMsg(
"Master password reset: backed up current database" );
607 if ( ok && !masterPasswordClearDb() )
610 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not clear current password from database" );
616 QgsDebugMsg(
"Master password reset: cleared current password from database" );
623 if ( ok && !masterPasswordStoreInDb() )
626 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not store new password in database" );
632 QgsDebugMsg(
"Master password reset: stored new password in database" );
639 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not verify new password in database" );
645 if ( ok && !reencryptAllAuthenticationConfigs( prevpass, prevciv ) )
648 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt configs in database" );
654 QgsDebugMsg(
"Master password reset: re-encrypted configs in database" );
658 if ( ok && !verifyPasswordCanDecryptConfigs() )
661 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not verify password can decrypt re-encrypted configs" );
666 if ( ok && !reencryptAllAuthenticationSettings( prevpass, prevciv ) )
669 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt settings in database" );
674 if ( ok && !reencryptAllAuthenticationIdentities( prevpass, prevciv ) )
677 const char* err = QT_TR_NOOP(
"Master password reset FAILED: could not re-encrypt identities in database" );
687 QString errdbbackup( dbbackup );
690 QgsDebugMsg(
QString(
"Master password reset FAILED: backed up failed db at %1" ).arg( errdbbackup ) );
694 mMasterPass = prevpass;
696 QgsDebugMsg(
"Master password reset FAILED: reinstated previous password and database" );
700 *backuppath = errdbbackup;
708 const char* err = QT_TR_NOOP(
"Master password reset: could not remove old database backup" );
716 QgsDebugMsg(
QString(
"Master password reset: backed up previous db at %1" ).arg( dbbackup ) );
718 *backuppath = dbbackup;
728 mScheduledDbErase = scheduleErase;
730 mScheduledDbEraseRequestEmitted =
false;
731 mScheduledDbEraseRequestCount = 0;
735 if ( !mScheduledDbEraseTimer )
737 mScheduledDbEraseTimer =
new QTimer(
this );
738 connect( mScheduledDbEraseTimer, SIGNAL( timeout() ),
this, SLOT( tryToStartDbErase() ) );
739 mScheduledDbEraseTimer->
start( mScheduledDbEraseRequestWait * 1000 );
741 else if ( !mScheduledDbEraseTimer->
isActive() )
743 mScheduledDbEraseTimer->
start();
748 if ( mScheduledDbEraseTimer && mScheduledDbEraseTimer->
isActive() )
749 mScheduledDbEraseTimer->
stop();
758 qDeleteAll( mAuthMethods );
759 mAuthMethods.
clear();
765 return !mAuthMethods.
isEmpty();
784 for (
int i = 0; i < len; i++ )
786 switch ( qrand() % 2 )
789 id += (
'0' + qrand() % 10 );
792 id += (
'a' + qrand() % 26 );
812 const char* err = QT_TR_NOOP(
"Config ID is empty" );
824 return rx.
indexIn( txt ) != -1;
844 if ( !authDbQuery( &query ) )
851 while ( query.
next() )
855 config.
setId( authcfg );
866 baseConfigs.insert( authcfg, config );
881 if ( !authDbQuery( &query ) )
888 QgsDebugMsg(
"Synching existing auth config and their auth methods" );
889 mConfigAuthMethods.
clear();
891 while ( query.
next() )
906 if ( !mConfigAuthMethods.
contains( authcfg ) )
908 QgsDebugMsg(
QString(
"No config auth method found in database for authcfg: %1" ).arg( authcfg ) );
912 QString authMethodKey = mConfigAuthMethods.
value( authcfg );
933 if ( !mAuthMethods.
contains( authMethodKey ) )
935 QgsDebugMsg(
QString(
"No auth method registered for auth method key: %1" ).arg( authMethodKey ) );
939 return mAuthMethods.
value( authMethodKey );
951 while ( i != mAuthMethods.
constEnd() )
954 && ( i.
value()->supportedDataProviders().contains(
"all" )
955 || i.
value()->supportedDataProviders().contains( dataprovider ) ) )
972 return QgsAuthMethod::Expansions(
nullptr );
979 return QgsAuthMethod::Expansions(
nullptr );
991 const char* err = QT_TR_NOOP(
"Store config: FAILED because config is invalid" );
998 bool passedinID = !uid.
isEmpty();
1005 const char* err = QT_TR_NOOP(
"Store config: FAILED because pre-defined config ID is not unique" );
1014 const char* err = QT_TR_NOOP(
"Store config: FAILED because config string is empty" );
1029 query.
prepare(
QString(
"INSERT INTO %1 (id, name, uri, type, version, config) " 1030 "VALUES (:id, :name, :uri, :type, :version, :config)" ).arg(
authDbConfigTable() ) );
1039 if ( !authDbStartTransaction() )
1042 if ( !authDbQuery( &query ) )
1045 if ( !authDbCommit() )
1050 mconfig.
setId( uid );
1066 if ( !config.
isValid(
true ) )
1068 const char* err = QT_TR_NOOP(
"Update config: FAILED because config is invalid" );
1077 const char* err = QT_TR_NOOP(
"Update config: FAILED because config is empty" );
1095 "SET name = :name, uri = :uri, type = :type, version = :version, config = :config " 1098 const char* err = QT_TR_NOOP(
"Update config: FAILED to prepare query" );
1111 if ( !authDbStartTransaction() )
1114 if ( !authDbQuery( &query ) )
1117 if ( !authDbCommit() )
1142 query.
prepare(
QString(
"SELECT id, name, uri, type, version, config FROM %1 " 1147 query.
prepare(
QString(
"SELECT id, name, uri, type, version FROM %1 " 1153 if ( !authDbQuery( &query ) )
1160 if ( query.
first() )
1181 QgsDebugMsg(
QString(
"Update of authcfg %1 FAILED for auth method %2" ).arg( authcfg, authMethodKey ) );
1184 QgsDebugMsg(
QString(
"Load %1 config SUCCESS for authcfg: %2" ).arg( full ?
"full" :
"base", authcfg ) );
1189 QgsDebugMsg(
QString(
"Select contains more than one for authcfg: %1" ).arg( authcfg ) );
1212 if ( !authDbStartTransaction() )
1215 if ( !authDbQuery( &query ) )
1218 if ( !authDbCommit() )
1238 bool res = authDbTransactionQuery( &query );
1246 QgsDebugMsg(
QString(
"Remove configs from database: %1" ).arg( res ?
"SUCCEEDED" :
"FAILED" ) );
1256 const char* err = QT_TR_NOOP(
"No authentication database found" );
1274 const char* err = QT_TR_NOOP(
"Could not back up authentication database" );
1281 *backuppath = dbbackup;
1299 if ( backuppath && !dbbackup.
isEmpty() )
1300 *backuppath = dbbackup;
1305 if ( !dbinfo.
permission( QFile::ReadOwner | QFile::WriteOwner ) )
1307 const char* err = QT_TR_NOOP(
"Auth db is not readable or writable by user" );
1315 const char* err = QT_TR_NOOP(
"No authentication database found" );
1323 const char* err = QT_TR_NOOP(
"Authentication database could not be deleted" );
1331 QgsDebugMsg(
"Creating Auth db through QSqlDatabase initial connection" );
1336 const char* err = QT_TR_NOOP(
"Authentication database could not be initialized" );
1342 if ( !createConfigTables() )
1344 const char* err = QT_TR_NOOP(
"FAILED to create auth database config tables" );
1350 if ( !createCertTables() )
1352 const char* err = QT_TR_NOOP(
"FAILED to create auth database cert tables" );
1378 QgsDebugMsg(
QString(
"Network request updating not supported by authcfg: %1" ).arg( authcfg ) );
1404 QgsDebugMsg(
QString(
"Network reply updating not supported by authcfg: %1" ).arg( authcfg ) );
1430 QgsDebugMsg(
QString(
"Data source URI updating not supported by authcfg: %1" ).arg( authcfg ) );
1467 "VALUES (:setting, :value)" ).arg( authDbSettingsTable() ) );
1472 if ( !authDbStartTransaction() )
1475 if ( !authDbQuery( &query ) )
1478 if ( !authDbCommit() )
1497 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
1501 if ( !authDbQuery( &query ) )
1506 if ( query.
first() )
1514 value = query.
value( 0 );
1520 QgsDebugMsg(
QString(
"Select contains more than one for setting key: %1" ).arg( key ) );
1536 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
1540 if ( !authDbQuery( &query ) )
1546 if ( query.
first() )
1553 QgsDebugMsg(
QString(
"Select contains more than one for setting key: %1" ).arg( key ) );
1569 query.
prepare(
QString(
"DELETE FROM %1 WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
1573 if ( !authDbStartTransaction() )
1576 if ( !authDbQuery( &query ) )
1579 if ( !authDbCommit() )
1588 #ifndef QT_NO_OPENSSL 1601 QgsDebugMsg(
QString(
"Init of SSL caches %1" ).arg( res ?
"SUCCEEDED" :
"FAILED" ) );
1630 "VALUES (:id, :key, :cert)" ).arg( authDbIdentitiesTable() ) );
1636 if ( !authDbStartTransaction() )
1639 if ( !authDbQuery( &query ) )
1642 if ( !authDbCommit() )
1659 "WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
1663 if ( !authDbQuery( &query ) )
1668 if ( query.
first() )
1675 QgsDebugMsg(
QString(
"Select contains more than one certificate identity for id: %1" ).arg(
id ) );
1695 "WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
1699 if ( !authDbQuery( &query ) )
1706 if ( query.
first() )
1709 QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey );
1712 const char* err = QT_TR_NOOP(
"Retrieve certificate identity bundle: FAILED to create private key" );
1720 const char* err = QT_TR_NOOP(
"Retrieve certificate identity bundle: FAILED to create certificate" );
1725 QgsDebugMsg(
QString(
"Certificate identity bundle retrieved for id: %1" ).arg(
id ) );
1729 QgsDebugMsg(
QString(
"Select contains more than one certificate identity for id: %1" ).arg(
id ) );
1733 bundle = qMakePair( cert, key );
1742 if ( bundle.first.isValid() && !bundle.second.isNull() )
1755 query.
prepare(
QString(
"SELECT id, cert FROM %1" ).arg( authDbIdentitiesTable() ) );
1757 if ( !authDbQuery( &query ) )
1762 while ( query.
next() )
1780 query.
prepare(
QString(
"SELECT id FROM %1" ).arg( authDbIdentitiesTable() ) );
1782 if ( !authDbQuery( &query ) )
1789 while ( query.
next() )
1805 "WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
1809 if ( !authDbQuery( &query ) )
1815 if ( query.
first() )
1822 QgsDebugMsg(
QString(
"Select contains more than one certificate bundle for id: %1" ).arg(
id ) );
1841 query.
prepare(
QString(
"DELETE FROM %1 WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
1845 if ( !authDbStartTransaction() )
1848 if ( !authDbQuery( &query ) )
1851 if ( !authDbCommit() )
1872 QString certpem( cert.toPem() );
1875 query.prepare(
QString(
"INSERT INTO %1 (id, host, cert, config) " 1878 query.bindValue(
":id",
id );
1880 query.bindValue(
":cert", certpem );
1883 if ( !authDbStartTransaction() )
1886 if ( !authDbQuery( &query ) )
1889 if ( !authDbCommit() )
1892 QgsDebugMsg(
QString(
"Store SSL cert custom config SUCCESS for host:port, id: %1, %2" )
1905 if (
id.isEmpty() || hostport.
isEmpty() )
1907 QgsDebugMsg(
"Passed config ID or host:port is empty" );
1918 if ( !authDbQuery( &query ) )
1923 if ( query.
first() )
1928 QgsDebugMsg(
QString(
"SSL cert custom config retrieved for host:port, id: %1, %2" ).arg( hostport,
id ) );
1932 QgsDebugMsg(
QString(
"Select contains more than one SSL cert custom config for host:port, id: %1, %2" ).arg( hostport,
id ) );
1933 emit
messageOut(
tr(
"Authentication database contains duplicate SSL cert custom configs for host:port, id: %1, %2" )
1959 if ( !authDbQuery( &query ) )
1964 if ( query.
first() )
1969 QgsDebugMsg(
QString(
"SSL cert custom config retrieved for host:port: %1" ).arg( hostport ) );
1973 QgsDebugMsg(
QString(
"Select contains more than one SSL cert custom config for host:port: %1" ).arg( hostport ) );
1974 emit
messageOut(
tr(
"Authentication database contains duplicate SSL cert custom configs for host:port: %1" )
1991 if ( !authDbQuery( &query ) )
1996 while ( query.
next() )
2003 configs.
append( config );
2013 if (
id.isEmpty() || hostport.
isEmpty() )
2015 QgsDebugMsg(
"Passed config ID or host:port is empty" );
2026 if ( !authDbQuery( &query ) )
2032 if ( query.
first() )
2034 QgsDebugMsg(
QString(
"SSL cert custom config exists for host:port, id: %1, %2" ).arg( hostport,
id ) );
2039 QgsDebugMsg(
QString(
"Select contains more than one SSL cert custom config for host:port, id: %1, %2" ).arg( hostport,
id ) );
2040 emit
messageOut(
tr(
"Authentication database contains duplicate SSL cert custom configs for host:port, id: %1, %2" )
2051 if (
id.isEmpty() || hostport.
isEmpty() )
2053 QgsDebugMsg(
"Passed config ID or host:port is empty" );
2064 if ( !authDbStartTransaction() )
2067 if ( !authDbQuery( &query ) )
2070 if ( !authDbCommit() )
2074 if ( mIgnoredSslErrorsCache.
contains( shahostport ) )
2076 mIgnoredSslErrorsCache.
remove( shahostport );
2079 QgsDebugMsg(
QString(
"REMOVED SSL cert custom config for host:port, id: %1, %2" ).arg( hostport,
id ) );
2087 if ( !mIgnoredSslErrorsCache.
isEmpty() )
2091 while ( i != mIgnoredSslErrorsCache.
constEnd() )
2094 Q_FOREACH ( QSslError::SslError err, i.
value() )
2120 if ( mIgnoredSslErrorsCache.
contains( shahostport ) )
2122 mIgnoredSslErrorsCache.
remove( shahostport );
2125 if ( !errenums.isEmpty() )
2128 QgsDebugMsg(
QString(
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1" ).arg( shahostport ) );
2133 QgsDebugMsg(
QString(
"No ignored SSL errors to cache for sha:host:port = %1" ).arg( shahostport ) );
2140 QRegExp rx(
"\\S+:\\S+:\\d+" );
2143 QgsDebugMsg(
"Passed shahostport does not match \\S+:\\S+:\\d+, " 2144 "e.g. 74a4ef5ea94512a43769b744cda0ca5049a72491:www.example.com:443" );
2148 if ( mIgnoredSslErrorsCache.
contains( shahostport ) )
2150 mIgnoredSslErrorsCache.
remove( shahostport );
2160 Q_FOREACH (
const QSslError &error, errors )
2162 if ( error.
error() == QSslError::NoError )
2170 QgsDebugMsg(
"Passed errors list does not contain errors" );
2174 mIgnoredSslErrorsCache.
insert( shahostport, errs );
2176 QgsDebugMsg(
QString(
"Update of ignored SSL errors cache SUCCEEDED for sha:host:port = %1" ).arg( shahostport ) );
2190 if ( !authDbQuery( &query ) )
2192 QgsDebugMsg(
"Rebuild of ignored SSL errors cache FAILED" );
2198 while ( query.
next() )
2206 if ( !errenums.isEmpty() )
2210 if ( prevcache.
contains( shahostport ) )
2212 prevcache.
remove( shahostport );
2221 while ( i != prevcache.
constEnd() )
2228 if ( nextcache != mIgnoredSslErrorsCache )
2230 mIgnoredSslErrorsCache.
clear();
2231 mIgnoredSslErrorsCache = nextcache;
2232 QgsDebugMsg(
"Rebuild of ignored SSL errors cache SUCCEEDED" );
2237 QgsDebugMsg(
"Rebuild of ignored SSL errors cache SAME AS BEFORE" );
2246 if ( certs.
size() < 1 )
2248 QgsDebugMsg(
"Passed certificate list has no certs" );
2277 query.prepare(
QString(
"INSERT INTO %1 (id, cert) " 2278 "VALUES (:id, :cert)" ).arg( authDbAuthoritiesTable() ) );
2280 query.bindValue(
":id",
id );
2281 query.bindValue(
":cert", pem );
2283 if ( !authDbStartTransaction() )
2286 if ( !authDbQuery( &query ) )
2289 if ( !authDbCommit() )
2292 QgsDebugMsg(
QString(
"Store certificate authority SUCCESS for id: %1" ).arg(
id ) );
2306 "WHERE id = :id" ).arg( authDbAuthoritiesTable() ) );
2310 if ( !authDbQuery( &query ) )
2315 if ( query.
first() )
2322 QgsDebugMsg(
QString(
"Select contains more than one certificate authority for id: %1" ).arg(
id ) );
2343 "WHERE id = :id" ).arg( authDbAuthoritiesTable() ) );
2347 if ( !authDbQuery( &query ) )
2353 if ( query.
first() )
2360 QgsDebugMsg(
QString(
"Select contains more than one certificate authority for id: %1" ).arg(
id ) );
2381 query.
prepare(
QString(
"DELETE FROM %1 WHERE id = :id" ).arg( authDbAuthoritiesTable() ) );
2385 if ( !authDbStartTransaction() )
2388 if ( !authDbQuery( &query ) )
2391 if ( !authDbCommit() )
2414 if ( cafileval.
isNull() )
2418 if ( allowinvalid.
isNull() )
2448 query.
prepare(
QString(
"SELECT id, cert FROM %1" ).arg( authDbAuthoritiesTable() ) );
2450 if ( !authDbQuery( &query ) )
2455 while ( query.
next() )
2473 mCaCertsCache.
clear();
2479 bool res = !mCaCertsCache.
isEmpty();
2480 QgsDebugMsg(
QString(
"Rebuild of CA certs cache %1" ).arg( res ?
"SUCCEEDED" :
"FAILED" ) );
2499 QgsDebugMsg(
QString(
"Passed policy was default, all cert records in database were removed for id: %1" ).arg(
id ) );
2505 "VALUES (:id, :policy)" ).arg( authDbTrustTable() ) );
2508 query.
bindValue(
":policy", static_cast< int >( policy ) );
2510 if ( !authDbStartTransaction() )
2513 if ( !authDbQuery( &query ) )
2516 if ( !authDbCommit() )
2519 QgsDebugMsg(
QString(
"Store certificate trust policy SUCCESS for id: %1" ).arg(
id ) );
2536 "WHERE id = :id" ).arg( authDbTrustTable() ) );
2540 if ( !authDbQuery( &query ) )
2546 if ( query.
first() )
2549 QgsDebugMsg(
QString(
"Authentication cert trust policy retrieved for id: %1" ).arg(
id ) );
2553 QgsDebugMsg(
QString(
"Select contains more than one cert trust policy for id: %1" ).arg(
id ) );
2564 if ( certs.
size() < 1 )
2566 QgsDebugMsg(
"Passed certificate list has no certs" );
2591 query.
prepare(
QString(
"DELETE FROM %1 WHERE id = :id" ).arg( authDbTrustTable() ) );
2595 if ( !authDbStartTransaction() )
2598 if ( !authDbQuery( &query ) )
2601 if ( !authDbCommit() )
2626 else if ( untrustedids.
contains(
id ) )
2640 return storeAuthSetting(
"certdefaulttrust", static_cast< int >( policy ) );
2657 mCertTrustCache.
clear();
2660 query.
prepare(
QString(
"SELECT id, policy FROM %1" ).arg( authDbTrustTable() ) );
2662 if ( !authDbQuery( &query ) )
2664 QgsDebugMsg(
"Rebuild of cert trust policy cache FAILED" );
2670 while ( query.
next() )
2676 if ( mCertTrustCache.
contains( policy ) )
2678 ids = mCertTrustCache.
value( policy );
2680 mCertTrustCache.
insert( policy, ids <<
id );
2684 QgsDebugMsg(
"Rebuild of cert trust policy cache SUCCEEDED" );
2697 for (
int i = 0; i < certpairs.size(); ++i )
2701 if ( trustedids.
contains( certid ) )
2704 trustedcerts.
append( cert );
2708 if ( !includeinvalid && !cert.isValid() )
2710 trustedcerts.
append( cert );
2719 return trustedcerts;
2727 if ( mTrustedCaCertsCache.
isEmpty() )
2737 for (
int i = 0; i < certpairs.size(); ++i )
2740 if ( !trustedCAs.
contains( cert ) )
2742 untrustedCAs.
append( cert );
2745 return untrustedCAs;
2752 QgsDebugMsg(
"Rebuilt trusted cert authorities cache" );
2767 certslist << cert.
toPem();
2802 void QgsAuthManager::writeToConsole(
const QString &message,
2830 void QgsAuthManager::tryToStartDbErase()
2832 ++mScheduledDbEraseRequestCount;
2834 int trycutoff = 90 / ( mScheduledDbEraseRequestWait ? mScheduledDbEraseRequestWait : 3 );
2835 if ( mScheduledDbEraseRequestCount >= trycutoff )
2838 QgsDebugMsg(
"authDatabaseEraseRequest emitting/scheduling cancelled" );
2844 .arg( mScheduledDbEraseRequestCount ).arg( trycutoff ) );
2850 mScheduledDbEraseRequestEmitted =
true;
2855 QgsDebugMsg(
"authDatabaseEraseRequest emitted" );
2858 QgsDebugMsg(
"authDatabaseEraseRequest emit skipped" );
2863 , mAuthInit( false )
2865 , mQcaInitializer( nullptr )
2868 , mAuthDisabled( false )
2869 , mScheduledDbEraseTimer( nullptr )
2870 , mScheduledDbErase( false )
2871 , mScheduledDbEraseRequestWait( 3 )
2872 , mScheduledDbEraseRequestEmitted( false )
2873 , mScheduledDbEraseRequestCount( 0 )
2877 mMutex =
new QMutex( QMutex::Recursive );
2887 qDeleteAll( mAuthMethods );
2895 delete mScheduledDbEraseTimer;
2896 mScheduledDbEraseTimer =
nullptr;
2897 delete mQcaInitializer;
2898 mQcaInitializer =
nullptr;
2902 bool QgsAuthManager::masterPasswordInput()
2921 bool QgsAuthManager::masterPasswordRowsInDb(
int *rows )
const 2927 query.
prepare(
QString(
"SELECT Count(*) FROM %1" ).arg( authDbPassTable() ) );
2929 bool ok = authDbQuery( &query );
2930 if ( query.
first() )
2944 if ( !masterPasswordRowsInDb( &rows ) )
2946 const char* err = QT_TR_NOOP(
"Master password: FAILED to access database" );
2952 return ( rows == 1 );
2955 bool QgsAuthManager::masterPasswordCheckAgainstDb(
const QString &compare )
const 2963 query.
prepare(
QString(
"SELECT salt, hash FROM %1" ).arg( authDbPassTable() ) );
2964 if ( !authDbQuery( &query ) )
2967 if ( !query.
first() )
2976 bool QgsAuthManager::masterPasswordStoreInDb()
const 2985 query.
prepare(
QString(
"INSERT INTO %1 (salt, hash, civ) VALUES (:salt, :hash, :civ)" ).arg( authDbPassTable() ) );
2991 if ( !authDbStartTransaction() )
2994 if ( !authDbQuery( &query ) )
2997 if ( !authDbCommit() )
3003 bool QgsAuthManager::masterPasswordClearDb()
3009 query.
prepare(
QString(
"DELETE FROM %1" ).arg( authDbPassTable() ) );
3010 bool res = authDbTransactionQuery( &query );
3016 const QString QgsAuthManager::masterPasswordCiv()
const 3022 query.
prepare(
QString(
"SELECT civ FROM %1" ).arg( authDbPassTable() ) );
3023 if ( !authDbQuery( &query ) )
3026 if ( !query.
first() )
3042 if ( !authDbQuery( &query ) )
3049 while ( query.
next() )
3057 bool QgsAuthManager::verifyPasswordCanDecryptConfigs()
const 3068 if ( !authDbQuery( &query ) )
3073 QgsDebugMsg(
QString(
"Verify password can decrypt configs FAILED, query not active or a select operation" ) );
3078 while ( query.
next() )
3084 QgsDebugMsg(
QString(
"Verify password can decrypt configs FAILED, could not decrypt a config (id: %1)" )
3090 QgsDebugMsg(
QString(
"Verify password can decrypt configs SUCCESS (checked %1 configs)" ).arg( checked ) );
3094 bool QgsAuthManager::reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv )
3102 res = res && reencryptAuthenticationConfig( configid, prevpass, prevciv );
3107 bool QgsAuthManager::reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv )
3121 if ( !authDbQuery( &query ) )
3126 QgsDebugMsg(
QString(
"Reencrypt FAILED, query not active or a select operation for authcfg: %2" ).arg( authcfg ) );
3130 if ( query.
first() )
3136 QgsDebugMsg(
QString(
"Select contains more than one for authcfg: %1" ).arg( authcfg ) );
3144 "SET config = :config " 3150 if ( !authDbStartTransaction() )
3153 if ( !authDbQuery( &query ) )
3156 if ( !authDbCommit() )
3164 QgsDebugMsg(
QString(
"Reencrypt FAILED, could not find in db authcfg: %2" ).arg( authcfg ) );
3169 bool QgsAuthManager::reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv )
3172 Q_UNUSED( prevpass );
3173 Q_UNUSED( prevciv );
3186 encryptedsettings <<
"";
3188 Q_FOREACH (
const QString &sett, encryptedsettings )
3198 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
3202 if ( !authDbQuery( &query ) )
3207 QgsDebugMsg(
QString(
"Reencrypt FAILED, query not active or a select operation for setting: %2" ).arg( sett ) );
3211 if ( query.
first() )
3218 "SET value = :value " 3219 "WHERE setting = :setting" ).arg( authDbSettingsTable() ) );
3224 if ( !authDbStartTransaction() )
3227 if ( !authDbQuery( &query ) )
3230 if ( !authDbCommit() )
3238 QgsDebugMsg(
QString(
"Reencrypt FAILED, could not find in db setting: %2" ).arg( sett ) );
3244 QgsDebugMsg(
QString(
"Select contains more than one for setting: %1" ).arg( sett ) );
3255 bool QgsAuthManager::reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv )
3263 res = res && reencryptAuthenticationIdentity( identid, prevpass, prevciv );
3268 bool QgsAuthManager::reencryptAuthenticationIdentity(
3281 "WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
3285 if ( !authDbQuery( &query ) )
3290 QgsDebugMsg(
QString(
"Reencrypt FAILED, query not active or a select operation for identity id: %2" ).arg( identid ) );
3294 if ( query.
first() )
3300 QgsDebugMsg(
QString(
"Select contains more than one for identity id: %1" ).arg( identid ) );
3309 "WHERE id = :id" ).arg( authDbIdentitiesTable() ) );
3314 if ( !authDbStartTransaction() )
3317 if ( !authDbQuery( &query ) )
3320 if ( !authDbCommit() )
3328 QgsDebugMsg(
QString(
"Reencrypt FAILED, could not find in db identity id: %2" ).arg( identid ) );
3333 bool QgsAuthManager::authDbOpen()
const 3341 if ( !authdb.
open() )
3343 QgsDebugMsg(
QString(
"Unable to establish database connection\nDatabase: %1\nDriver error: %2\nDatabase error: %3" )
3354 bool QgsAuthManager::authDbQuery(
QSqlQuery *query )
const 3360 if ( !query->
exec() )
3362 const char* err = QT_TR_NOOP(
"Auth db query exec() FAILED" );
3380 bool QgsAuthManager::authDbStartTransaction()
const 3387 const char* err = QT_TR_NOOP(
"Auth db FAILED to start transaction" );
3396 bool QgsAuthManager::authDbCommit()
const 3403 const char* err = QT_TR_NOOP(
"Auth db FAILED to rollback changes" );
3413 bool QgsAuthManager::authDbTransactionQuery(
QSqlQuery *query )
const 3420 const char* err = QT_TR_NOOP(
"Auth db FAILED to start transaction" );
3426 bool ok = authDbQuery( query );
3430 const char* err = QT_TR_NOOP(
"Auth db FAILED to rollback changes" );
Singleton offering an interface to manage the authentication configuration database and to utilize co...
bool rebuildTrustedCaCertsCache()
Rebuild trusted certificate authorities cache.
bool getMasterPassword(QString &password, bool stored=false)
bool isNull() const
Whether configuration is null (missing components)
void setUri(const QString &uri)
void messageOut(const QString &message, const QString &tag=smAuthManTag, QgsAuthManager::MessageLevel level=INFO) const
Custom logging signal to relay to console output and QgsMessageLog.
QByteArray toByteArray() const
const QList< QSslCertificate > getExtraFileCAs()
Get extra file-based certificate authorities.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
QSqlError lastError() const
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.
iterator insert(const Key &key, const T &value)
QString databaseText() const
void setId(const QString &id)
Set auth config ID.
bool contains(const Key &key) const
const QPair< QSslCertificate, QSslKey > getCertIdentityBundle(const QString &id)
Get a certificate identity bundle by id (sha hash).
const Key key(const T &value) const
static QgsAuthManager * instance()
Enforce singleton pattern.
QgsAuthMethod::Expansions supportedAuthMethodExpansions(const QString &authcfg)
Get supported authentication method expansion(s), e.g.
Interface for requesting credentials in QGIS in GUI independent way.
bool storeSslCertCustomConfig(const QgsAuthConfigSslServer &config)
Store an SSL certificate custom config.
QList< T > values() const
QString readLine(qint64 maxlen)
QgsAuthCertUtils::CertTrustPolicy getCertificateTrustPolicy(const QSslCertificate &cert)
Get trust policy for a particular certificate.
bool existsAuthSetting(const QString &key)
Check if an authentication setting exists.
bool scheduledAuthDbErase()
Whether there is a scheduled opitonal erase of authentication database.
static QString qgisAuthDbFilePath()
Returns the path to the user authentication database file: qgis-auth.db.
QStringList authMethodList() const
Return list of available auth methods by their keys.
bool storeAuthSetting(const QString &key, const QVariant &value, bool encrypt=false)
Store an authentication setting (stored as string via QVariant( value ).toString() ) ...
bool removeCertAuthority(const QSslCertificate &cert)
Remove a certificate authority.
QSslConfiguration sslConfiguration() const
bool masterPasswordSame(const QString &pass) const
Check whether supplied password is the same as the one already set.
const QList< QSslCertificate > getUntrustedCaCerts(QList< QSslCertificate > trustedCAs=QList< QSslCertificate >())
Get list of all untrusted CA certificates.
bool exec(const QString &query)
static QString sslErrorEnumString(QSslError::SslError errenum)
Get short strings describing an SSL error.
bool rename(const QString &newName)
bool initSslCaches()
Initialize various SSL authentication caches.
QSqlDatabase database(const QString &connectionName, bool open)
static QList< QSslCertificate > certsFromFile(const QString &certspath)
Return list of concatenated certs from a PEM or DER formatted file.
const QString authDbConfigTable() const
Name of the authentication database table that stores configs.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static QMap< QString, QSslCertificate > mapDigestToCerts(const QList< QSslCertificate > &certs)
Map certificate sha1 to certificate as simple cache.
Configuration container for SSL server connection exceptions or overrides.
virtual bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Update data source connection items with authentication components.
bool permission(QFlags< QFile::Permission > permissions) const
QSqlDatabase addDatabase(const QString &type, const QString &connectionName)
static QgsCredentials * instance()
retrieves instance
static bool certificateIsAuthorityOrIssuer(const QSslCertificate &cert)
Get whether a certificate is an Authority or can at least sign other certificates.
const QString disabledMessage() const
Standard message for when QCA's qca-ossl plugin is missing and system is disabled.
bool removeCertTrustPolicy(const QSslCertificate &cert)
Remove a certificate authority.
QString join(const QString &separator) const
const QMap< QString, QSslCertificate > getMappedDatabaseCAs()
Get sha1-mapped database-stored certificate authorities.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Get keys of supported authentication methods.
const_iterator insert(const T &value)
QgsAuthMethod * authMethod(const QString &authMethodKey)
Get authentication method from the config/provider cache via its key.
bool storeCertAuthority(const QSslCertificate &cert)
Store a certificate authority.
QString tr(const char *sourceText, const char *disambiguation, int n)
static void passwordKeyHash(const QString &pass, QString *salt, QString *hash, QString *cipheriv=nullptr)
Generate SHA256 hash for master password, with iterations and salt.
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
bool rebuildCaCertsCache()
Rebuild certificate authority cache.
A registry / canonical manager of authentication methods.
bool copy(const QString &newName)
const QString uniqueConfigId() const
Get a unique generated 7-character string to assign to as config id.
bool updateAuthenticationConfig(const QgsAuthMethodConfig &config)
Update an authentication config in the database.
void lock()
Lock the instance against access from multiple threads.
bool eraseAuthenticationDatabase(bool backup, QString *backuppath=nullptr)
Erase all rows from all tables in authentication database.
const QByteArray getTrustedCaCertsPemText()
Get concatenated string of all trusted CA certificates.
virtual bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Update a network request with authentication components.
void clearCachedConfig(const QString &authcfg)
Clear an authentication config from its associated authentication method cache.
QVariant getAuthSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
Get an authentication setting (retrieved as string and returned as QVariant( QString )) ...
const QgsAuthConfigSslServer getSslCertCustomConfig(const QString &id, const QString &hostport)
Get an SSL certificate custom config by id (sha hash) and host:port.
bool contains(const QString &connectionName)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
bool setDefaultCertTrustPolicy(QgsAuthCertUtils::CertTrustPolicy policy)
Set the default certificate trust policy perferred by user.
bool prepare(const QString &query)
const QList< QSslCertificate > getCertIdentities()
Get certificate identities.
QSqlDatabase authDbConnection() const
Set up the application instance of the authentication database connection.
bool removeAllAuthenticationConfigs()
Clear all authentication configs from table in database and from provider caches. ...
bool hasConfigId(const QString &txt) const
Return whether a string includes an authcfg ID token.
void setCaCertificates(const QList< QSslCertificate > &certificates)
void append(const T &value)
void removeDatabase(const QString &connectionName)
QWidget * editWidget(const QString &authMethodKey, QWidget *parent=nullptr)
Return the auth method capabilities.
const_iterator constEnd() const
int toInt(bool *ok) const
QgsAuthMethodConfigsMap availableAuthMethodConfigs(const QString &dataprovider=QString())
Get mapping of authentication config ids and their base configs (not decrypted data) ...
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
QString authManTag() const
Simple text tag describing authentication system for message logs.
void masterPasswordVerified(bool verified) const
Emitted when a password has been verify (or not)
QVariant value(int index) const
bool init(const QString &pluginPath=QString::null)
Initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database...
void setMethod(const QString &method)
void authDatabaseEraseRequested() const
Emitted when a user has indicated they may want to erase the authentication db.
void bindValue(const QString &placeholder, const QVariant &val, QFlags< QSql::ParamTypeFlag > paramType)
Configuration storage class for authentication method configurations.
const QString configString() const
Configuration as a concatenated string.
void seed(uint32_t value)
const QList< QSslCertificate > getTrustedCaCertsCache()
Get cache of trusted certificate authorities, ready for network connections.
bool storeCertIdentity(const QSslCertificate &cert, const QSslKey &key)
Store a certificate identity.
bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QgsDataSourceURI with an authentication config.
bool removeCertTrustPolicies(const QList< QSslCertificate > &certs)
Remove a group certificate authorities.
bool removeSslCertCustomConfig(const QString &id, const QString &hostport)
Remove an SSL certificate custom config.
void loadConfigString(const QString &configstr)
Load existing extended configuration.
QString executedQuery() const
QStringList getCertIdentityIds() const
Get list of certificate identity ids from database.
const QList< QSslCertificate > getDatabaseCAs()
Get database-stored certificate authorities.
const QString name() const
Get name of configuration.
const QString authenticationDbPath() const
The standard authentication database file in ~/.qgis2/ or defined location.
const QString sslHostPort() const
Server host:port string.
int remove(const Key &key)
QStringList configIds() const
Get list of authentication ids from database.
QWidget * authMethodEditWidget(const QString &authMethodKey, QWidget *parent)
Get authentication method edit widget via its key.
void setForwardOnly(bool forward)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
const QString authDbServersTable() const
Name of the authentication database table that stores server exceptions/configs.
QString driverText() const
const QList< QSslCertificate > getTrustedCaCerts(bool includeinvalid=false)
Get list of all trusted CA certificates.
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.
void setSslHostPort(const QString &hostport)
Set server host:port string.
const T value(const Key &key) const
void updateConfigAuthMethods()
Sync the confg/authentication method cache with what is in database.
bool storeCertTrustPolicy(const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy)
Store user trust value for a certificate.
int version() const
Get version of the configuration.
virtual void clearCachedConfig(const QString &authcfg)=0
Clear any cached configuration.
bool contains(const T &value) const
bool storeCertAuthorities(const QList< QSslCertificate > &certs)
Store multiple certificate authorities.
bool existsCertAuthority(const QSslCertificate &cert)
Check if a certificate authority exists.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Get the sha1 hash for certificate.
QString & replace(int position, int n, QChar after)
const QSslCertificate getCertAuthority(const QString &id)
Get a certificate authority by id (sha hash)
QString configAuthMethodKey(const QString &authcfg) const
Get key of authentication method associated with config ID.
QSslConfiguration defaultConfiguration()
QString cleanPath(const QString &path)
const_iterator constBegin() const
const QSslCertificate getCertIdentity(const QString &id)
Get a certificate identity by id (sha hash)
void setDefaultConfiguration(const QSslConfiguration &configuration)
bool updateIgnoredSslErrorsCacheFromConfig(const QgsAuthConfigSslServer &config)
Update ignored SSL error cache with possible ignored SSL errors, using server config.
const QStringList getCertIdentityBundleToPem(const QString &id)
Get a certificate identity bundle by id (sha hash) returned as PEM text.
QDateTime currentDateTime()
QgsAuthMethod * configAuthMethod(const QString &authcfg)
Get authentication method from the config/provider cache.
const QSslCertificate sslCertificate() const
Server certificate object.
Abstract base class for authentication method plugins.
static const QString encrypt(const QString &pass, const QString &cipheriv, const QString &text)
Encrypt data using master password.
CaCertSource
Type of CA certificate source.
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
bool removeCertIdentity(const QString &id)
Remove a certificate identity.
void clearMasterPassword()
Clear supplied master password.
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 setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
bool resetMasterPassword(const QString &newpass, const QString &oldpass, bool keepbackup, QString *backuppath=nullptr)
Reset the master password to a new one, then re-encrypt all previous configs in a new database file...
void setScheduledAuthDbErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
const QList< QSslCertificate > getSystemRootCAs()
Get root system certificate authorities.
bool storeAuthenticationConfig(QgsAuthMethodConfig &mconfig)
Store an authentication config in the database.
bool verifyMasterPassword(const QString &compare=QString::null)
Verify the supplied master password against any existing hash in authentication database.
void setVersion(int version)
Set version of the configuration.
bool loadAuthenticationConfig(const QString &authcfg, QgsAuthMethodConfig &mconfig, bool full=false)
Load an authentication config from the database into subclass.
bool existsSslCertCustomConfig(const QString &id, const QString &hostport)
Check if SSL certificate custom config exists.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
static const QString decrypt(const QString &pass, const QString &cipheriv, const QString &text)
Decrypt data using master password.
QList< QSslCertificate > systemCaCertificates()
virtual bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Update a network reply with authentication components.
bool configIdUnique(const QString &id) const
Verify if provided authentication id is unique.
const QgsAuthConfigSslServer getSslCertCustomConfigByHost(const QString &hostport)
Get an SSL certificate custom config by host:port.
QString method() const
Textual key of the associated authentication method.
QSqlError lastError() const
void loadConfigString(const QString &config=QString())
Load concatenated string into configuration, e.g.
bool masterPasswordHashInDb() const
Verify a password hash existing in authentication database.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
QByteArray toPem(const QByteArray &passPhrase) const
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
QgsAuthCertUtils::CertTrustPolicy getCertTrustPolicy(const QSslCertificate &cert)
Get a whether certificate is trusted by user.
bool existsCertIdentity(const QString &id)
Check if a certificate identity exists.
bool masterPasswordIsSet() const
Whether master password has be input and verified, i.e.
CertTrustPolicy
Type of certificate trust policy.
void setDatabaseName(const QString &name)
QgsAuthMethodsMap authMethodsMap(const QString &dataprovider=QString())
Get available authentication methods mapped to their key.
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...
void unlock()
Unlock the instance after being locked.
bool removeAuthenticationConfig(const QString &authcfg)
Remove an authentication config in the database.
QList< QSslCertificate > caCertificates() const
void dumpIgnoredSslErrorsCache_()
Utility function to dump the cache for debug purposes.
QgsAuthCertUtils::CertTrustPolicy defaultCertTrustPolicy()
Get the default certificate trust policy perferred by user.
QgsAuthMethod::Expansions supportedExpansions() const
Flags that represent the update points (where authentication configurations are expanded) supported b...
bool removeAuthSetting(const QString &key)
Remove an authentication setting.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void authDatabaseChanged() const
Emitted when the authentication db is significantly changed, e.g.
static QgsAuthMethodRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
void setName(const QString &name)
Set name of configuration.
const QString configString() const
The extended configuration, as stored and retrieved from the authentication database.
bool rebuildIgnoredSslErrorCache()
Rebuild ignoredSSL error cache.
void setSslCertificate(const QSslCertificate &cert)
Set server certificate object.
bool backupAuthenticationDatabase(QString *backuppath=nullptr)
Close connection to current authentication database and back it up.
bool exactMatch(const QString &str) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const QList< QgsAuthConfigSslServer > getSslCertCustomConfigs()
Get SSL certificate custom configs.
virtual void updateMethodConfig(QgsAuthMethodConfig &mconfig)=0
Update an authentication configuration in place.
bool registerCoreAuthMethods()
Instantiate and register existing C++ core authentication methods from plugins.
QByteArray toAscii() const
const QString id() const
Get 'authcfg' 7-character alphanumeric ID of the config.
void clearAllCachedConfigs()
Clear all authentication configs from authentication method caches.
const T value(const Key &key) const
bool rebuildCertTrustCache()
Rebuild certificate authority cache.