17 #ifndef QGSAUTHMANAGER_H
18 #define QGSAUTHMANAGER_H
20 #include "qgis_core.h"
24 #include <QNetworkReply>
25 #include <QNetworkRequest>
26 #include <QSqlDatabase>
29 #include <QStringList>
32 #include <QSslCertificate>
52 class QgsAuthProvider;
77 Q_ENUM( MessageLevel )
87 bool init(
const QString &pluginPath = QString(),
const QString &authDatabasePath = QString() );
92 QSqlDatabase authDatabaseConnection()
const;
102 bool isDisabled()
const;
105 const QString disabledMessage()
const;
118 bool setMasterPassword(
bool verify =
false );
126 bool setMasterPassword(
const QString &pass,
bool verify =
false );
133 bool verifyMasterPassword(
const QString &compare = QString() );
136 bool masterPasswordIsSet()
const;
139 bool masterPasswordHashInDatabase()
const;
151 bool masterPasswordSame(
const QString &pass )
const;
161 bool resetMasterPassword(
const QString &newpass,
const QString &oldpass,
bool keepbackup, QString *backuppath
SIP_INOUT =
nullptr );
181 void setScheduledAuthDatabaseErase(
bool scheduleErase )
SIP_SKIP;
197 bool registerCoreAuthMethods();
203 void updateConfigAuthMethods();
215 QString configAuthMethodKey(
const QString &authcfg )
const;
220 QStringList authMethodsKeys(
const QString &dataprovider = QString() );
240 QWidget *authMethodEditWidget( const QString &authMethodKey, QWidget *parent );
246 QgsAuthMethod::Expansions supportedAuthMethodExpansions( const QString &authcfg );
249 const QString uniqueConfigId() const;
255 bool configIdUnique( const QString &
id ) const;
261 bool hasConfigId( const QString &txt ) const;
264 QString configIdRegex()
const {
return AUTH_CFG_REGEX;}
267 QStringList configIds()
const;
297 bool removeAuthenticationConfig(
const QString &authcfg );
303 bool removeAllAuthenticationConfigs();
309 bool backupAuthenticationDatabase( QString *backuppath
SIP_INOUT =
nullptr );
317 bool eraseAuthenticationDatabase(
bool backup, QString *backuppath
SIP_INOUT =
nullptr );
329 bool updateNetworkRequest( QNetworkRequest &request
SIP_INOUT,
const QString &authcfg,
330 const QString &dataprovider = QString() );
339 bool updateNetworkReply( QNetworkReply *reply,
const QString &authcfg,
340 const QString &dataprovider = QString() );
349 bool updateDataSourceUriItems( QStringList &connectionItems
SIP_INOUT,
const QString &authcfg,
350 const QString &dataprovider = QString() );
359 bool updateNetworkProxy( QNetworkProxy &proxy
SIP_INOUT,
const QString &authcfg,
360 const QString &dataprovider = QString() );
365 bool storeAuthSetting(
const QString &key,
const QVariant &value,
bool encrypt =
false );
375 QVariant authSetting(
const QString &key,
const QVariant &defaultValue = QVariant(),
bool decrypt =
false );
378 bool existsAuthSetting(
const QString &key );
381 bool removeAuthSetting(
const QString &key );
387 bool initSslCaches();
390 bool storeCertIdentity(
const QSslCertificate &cert,
const QSslKey &key );
398 const QSslCertificate certIdentity(
const QString &
id );
407 const QPair<QSslCertificate, QSslKey> certIdentityBundle(
const QString &
id )
SIP_SKIP;
415 const QStringList certIdentityBundleToPem(
const QString &
id );
422 const QList<QSslCertificate> certIdentities();
431 QStringList certIdentityIds()
const;
434 bool existsCertIdentity(
const QString &
id );
437 bool removeCertIdentity(
const QString &
id );
465 const QList<QgsAuthConfigSslServer> sslCertCustomConfigs();
468 bool existsSslCertCustomConfig(
const QString &
id,
const QString &hostport );
471 bool removeSslCertCustomConfig(
const QString &
id,
const QString &hostport );
482 void dumpIgnoredSslErrorsCache_();
488 bool updateIgnoredSslErrorsCache(
const QString &shahostport,
const QList<QSslError> &errors );
491 bool rebuildIgnoredSslErrorCache();
495 bool storeCertAuthorities(
const QList<QSslCertificate> &certs );
498 bool storeCertAuthority(
const QSslCertificate &cert );
508 const QSslCertificate certAuthority(
const QString &
id );
511 bool existsCertAuthority(
const QSslCertificate &cert );
514 bool removeCertAuthority(
const QSslCertificate &cert );
521 const QList<QSslCertificate> systemRootCAs();
528 const QList<QSslCertificate> extraFileCAs();
535 const QList<QSslCertificate> databaseCAs();
542 const QMap<QString, QSslCertificate> mappedDatabaseCAs();
552 return mCaCertsCache;
556 bool rebuildCaCertsCache();
570 bool removeCertTrustPolicies(
const QList<QSslCertificate> &certs );
573 bool removeCertTrustPolicy(
const QSslCertificate &cert );
594 const QMap<QgsAuthCertUtils::CertTrustPolicy, QStringList >
certTrustCache() {
return mCertTrustCache; }
597 bool rebuildCertTrustCache();
605 const QList<QSslCertificate> trustedCaCerts(
bool includeinvalid =
false );
612 const QList<QSslCertificate> untrustedCaCerts( QList<QSslCertificate> trustedCAs = QList<QSslCertificate>() );
615 bool rebuildTrustedCaCertsCache();
629 const QByteArray trustedCaCertsPemText();
643 bool passwordHelperDelete()
SIP_SKIP;
649 bool passwordHelperEnabled() const;
655 void setPasswordHelperEnabled(
bool enabled );
661 bool passwordHelperLoggingEnabled() const
SIP_SKIP;
667 void setPasswordHelperLoggingEnabled(
bool enabled )
SIP_SKIP;
673 bool passwordHelperSync();
676 static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME;
679 static const QString AUTH_MAN_TAG;
687 void passwordHelperFailure();
693 void passwordHelperSuccess();
718 void masterPasswordVerified(
bool verified );
721 void authDatabaseEraseRequested();
724 void authDatabaseChanged();
728 void clearAllCachedConfigs();
731 void clearCachedConfig( const QString &authcfg );
745 void tryToStartDbErase();
769 QString passwordHelperName()
const;
772 void passwordHelperLog(
const QString &msg )
const;
775 QString passwordHelperRead();
778 bool passwordHelperWrite(
const QString &password );
781 void passwordHelperSetErrorMessage(
const QString &errorMessage ) { mPasswordHelperErrorMessage = errorMessage; }
784 void passwordHelperClearErrors();
790 void passwordHelperProcessError();
792 bool createConfigTables();
794 bool createCertTables();
796 bool masterPasswordInput();
798 bool masterPasswordRowsInDb(
int *rows )
const;
800 bool masterPasswordCheckAgainstDb(
const QString &compare = QString() )
const;
802 bool masterPasswordStoreInDb()
const;
804 bool masterPasswordClearDb();
806 const QString masterPasswordCiv()
const;
808 bool verifyPasswordCanDecryptConfigs()
const;
810 bool reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv );
812 bool reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv );
814 bool reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv );
816 bool reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv );
818 bool reencryptAuthenticationIdentity(
const QString &identid,
const QString &prevpass,
const QString &prevciv );
820 bool authDbOpen()
const;
822 bool authDbQuery( QSqlQuery *query )
const;
824 bool authDbStartTransaction()
const;
826 bool authDbCommit()
const;
828 bool authDbTransactionQuery( QSqlQuery *query )
const;
834 const QString authDbPassTable()
const {
return AUTH_PASS_TABLE; }
836 const QString authDbSettingsTable()
const {
return AUTH_SETTINGS_TABLE; }
838 const QString authDbIdentitiesTable()
const {
return AUTH_IDENTITIES_TABLE; }
840 const QString authDbAuthoritiesTable()
const {
return AUTH_AUTHORITIES_TABLE; }
842 const QString authDbTrustTable()
const {
return AUTH_TRUST_TABLE; }
845 static const QString AUTH_CONFIG_TABLE;
846 static const QString AUTH_PASS_TABLE;
847 static const QString AUTH_SETTINGS_TABLE;
848 static const QString AUTH_IDENTITIES_TABLE;
849 static const QString AUTH_SERVERS_TABLE;
850 static const QString AUTH_AUTHORITIES_TABLE;
851 static const QString AUTH_TRUST_TABLE;
852 static const QString AUTH_CFG_REGEX;
854 bool mAuthInit =
false;
857 std::unique_ptr<QCA::Initializer> mQcaInitializer;
859 QHash<QString, QString> mConfigAuthMethods;
860 QHash<QString, QgsAuthMethod *> mAuthMethods;
864 bool mAuthDisabled =
false;
865 QString mAuthDisabledMessage;
866 QTimer *mScheduledDbEraseTimer =
nullptr;
867 bool mScheduledDbErase =
false;
868 int mScheduledDbEraseRequestWait = 3 ;
869 bool mScheduledDbEraseRequestEmitted =
false;
870 int mScheduledDbEraseRequestCount = 0;
872 std::unique_ptr<QMutex> mMutex;
873 std::unique_ptr<QMutex> mMasterPasswordMutex;
878 QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > mCaCertsCache;
880 QMap<QgsAuthCertUtils::CertTrustPolicy, QStringList > mCertTrustCache;
882 QList<QSslCertificate> mTrustedCaCertsCache;
884 QHash<QString, QSet<QSslError::SslError> > mIgnoredSslErrorsCache;
886 bool mHasCustomConfigByHost =
false;
887 bool mHasCheckedIfCustomConfigByHostExists =
false;
888 QMap< QString, QgsAuthConfigSslServer > mCustomConfigByHostCache;
895 bool mPasswordHelperVerificationError =
false;
898 QString mPasswordHelperErrorMessage;
901 QKeychain::Error mPasswordHelperErrorCode = QKeychain::NoError;
904 bool mPasswordHelperLoggingEnabled =
false;
907 bool mPasswordHelperFailedInit =
false;
910 static const QLatin1String AUTH_PASSWORD_HELPER_KEY_NAME;
913 static const QLatin1String AUTH_PASSWORD_HELPER_FOLDER_NAME;
915 mutable QMap<QThread *, QMetaObject::Connection> mConnectedThreads;
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
CertTrustPolicy
Type of certificate trust policy.
CaCertSource
Type of CA certificate source.
Configuration container for SSL server connection exceptions or overrides.
Singleton offering an interface to manage the authentication configuration database and to utilize co...
const QString authDatabaseServersTable() const
Name of the authentication database table that stores server exceptions/configs.
const QMap< QgsAuthCertUtils::CertTrustPolicy, QStringList > certTrustCache()
certTrustCache get cache of certificate sha1s, per trust policy
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
bool scheduledAuthDatabaseErase()
Whether there is a scheduled opitonal erase of authentication database.
QHash< QString, QSet< QSslError::SslError > > ignoredSslErrorCache()
ignoredSslErrorCache Get ignored SSL error cache, keyed with cert/connection's sha:host:port.
const QString authenticationDatabasePath() const
The standard authentication database file in ~/.qgis3/ or defined location.
QString authManTag() const
Simple text tag describing authentication system for message logs.
void setScheduledAuthDatabaseEraseRequestEmitted(bool emitted)
Re-emit a signal to schedule an optional erase of authentication database.
void clearMasterPassword()
Clear supplied master password.
const QString passwordHelperErrorMessage()
Error message getter.
const QString authDatabaseConfigTable() const
Name of the authentication database table that stores configs.
const QMap< QString, QPair< QgsAuthCertUtils::CaCertSource, QSslCertificate > > caCertsCache()
caCertsCache get all CA certs mapped to their sha1 from cache.
const QList< QSslCertificate > trustedCaCertsCache()
trustedCaCertsCache cache of trusted certificate authorities, ready for network connections
Configuration storage class for authentication method configurations.
Abstract base class for the edit widget of authentication method plugins.
Abstract base class for authentication method plugins.
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
QHash< QString, QgsAuthMethod * > QgsAuthMethodsMap