17 #ifndef QGSAUTHMANAGER_H
18 #define QGSAUTHMANAGER_H
20 #include "qgis_core.h"
23 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
26 #include <QRecursiveMutex>
28 #include <QNetworkReply>
29 #include <QNetworkRequest>
30 #include <QSqlDatabase>
33 #include <QStringList>
36 #include <QSslCertificate>
56 class QgsAuthProvider;
81 Q_ENUM( MessageLevel )
91 bool init(
const QString &pluginPath = QString(),
const QString &authDatabasePath = QString() );
96 QSqlDatabase authDatabaseConnection()
const;
106 bool isDisabled()
const;
109 const QString disabledMessage()
const;
122 bool setMasterPassword(
bool verify =
false );
130 bool setMasterPassword(
const QString &pass,
bool verify =
false );
137 bool verifyMasterPassword(
const QString &compare = QString() );
140 bool masterPasswordIsSet()
const;
143 bool masterPasswordHashInDatabase()
const;
155 bool masterPasswordSame(
const QString &pass )
const;
165 bool resetMasterPassword(
const QString &newpass,
const QString &oldpass,
bool keepbackup, QString *backuppath
SIP_INOUT =
nullptr );
185 void setScheduledAuthDatabaseErase(
bool scheduleErase )
SIP_SKIP;
201 bool registerCoreAuthMethods();
207 void updateConfigAuthMethods();
219 QString configAuthMethodKey(
const QString &authcfg )
const;
224 QStringList authMethodsKeys(
const QString &dataprovider = QString() );
244 QWidget *authMethodEditWidget( const QString &authMethodKey, QWidget *parent );
250 QgsAuthMethod::Expansions supportedAuthMethodExpansions( const QString &authcfg );
253 const QString uniqueConfigId() const;
259 bool configIdUnique( const QString &
id ) const;
265 bool hasConfigId( const QString &txt ) const;
268 QString configIdRegex()
const {
return AUTH_CFG_REGEX;}
271 QStringList configIds()
const;
302 bool removeAuthenticationConfig(
const QString &authcfg );
311 bool exportAuthenticationConfigsToXml(
const QString &filename,
const QStringList &authcfgs,
const QString &password = QString() );
320 bool importAuthenticationConfigsFromXml(
const QString &filename,
const QString &password = QString(),
bool overwrite =
false );
326 bool removeAllAuthenticationConfigs();
332 bool backupAuthenticationDatabase( QString *backuppath
SIP_INOUT =
nullptr );
340 bool eraseAuthenticationDatabase(
bool backup, QString *backuppath
SIP_INOUT =
nullptr );
352 bool updateNetworkRequest( QNetworkRequest &request
SIP_INOUT,
const QString &authcfg,
353 const QString &dataprovider = QString() );
362 bool updateNetworkReply( QNetworkReply *reply,
const QString &authcfg,
363 const QString &dataprovider = QString() );
372 bool updateDataSourceUriItems( QStringList &connectionItems
SIP_INOUT,
const QString &authcfg,
373 const QString &dataprovider = QString() );
382 bool updateNetworkProxy( QNetworkProxy &proxy
SIP_INOUT,
const QString &authcfg,
383 const QString &dataprovider = QString() );
388 bool storeAuthSetting(
const QString &key,
const QVariant &value,
bool encrypt =
false );
398 QVariant authSetting(
const QString &key,
const QVariant &defaultValue = QVariant(),
bool decrypt =
false );
401 bool existsAuthSetting(
const QString &key );
404 bool removeAuthSetting(
const QString &key );
410 bool initSslCaches();
413 bool storeCertIdentity(
const QSslCertificate &cert,
const QSslKey &key );
421 const QSslCertificate certIdentity(
const QString &
id );
430 const QPair<QSslCertificate, QSslKey> certIdentityBundle(
const QString &
id )
SIP_SKIP;
438 const QStringList certIdentityBundleToPem(
const QString &
id );
445 const QList<QSslCertificate> certIdentities();
454 QStringList certIdentityIds()
const;
457 bool existsCertIdentity(
const QString &
id );
460 bool removeCertIdentity(
const QString &
id );
488 const QList<QgsAuthConfigSslServer> sslCertCustomConfigs();
491 bool existsSslCertCustomConfig(
const QString &
id,
const QString &hostport );
494 bool removeSslCertCustomConfig(
const QString &
id,
const QString &hostport );
505 void dumpIgnoredSslErrorsCache_();
511 bool updateIgnoredSslErrorsCache(
const QString &shahostport,
const QList<QSslError> &errors );
514 bool rebuildIgnoredSslErrorCache();
518 bool storeCertAuthorities(
const QList<QSslCertificate> &certs );
521 bool storeCertAuthority(
const QSslCertificate &cert );
531 const QSslCertificate certAuthority(
const QString &
id );
534 bool existsCertAuthority(
const QSslCertificate &cert );
537 bool removeCertAuthority(
const QSslCertificate &cert );
544 const QList<QSslCertificate> systemRootCAs();
551 const QList<QSslCertificate> extraFileCAs();
558 const QList<QSslCertificate> databaseCAs();
565 const QMap<QString, QSslCertificate> mappedDatabaseCAs();
575 return mCaCertsCache;
579 bool rebuildCaCertsCache();
593 bool removeCertTrustPolicies(
const QList<QSslCertificate> &certs );
596 bool removeCertTrustPolicy(
const QSslCertificate &cert );
617 const QMap<QgsAuthCertUtils::CertTrustPolicy, QStringList >
certTrustCache() {
return mCertTrustCache; }
620 bool rebuildCertTrustCache();
628 const QList<QSslCertificate> trustedCaCerts(
bool includeinvalid =
false );
635 const QList<QSslCertificate> untrustedCaCerts( QList<QSslCertificate> trustedCAs = QList<QSslCertificate>() );
638 bool rebuildTrustedCaCertsCache();
652 const QByteArray trustedCaCertsPemText();
666 bool passwordHelperDelete()
SIP_SKIP;
672 bool passwordHelperEnabled() const;
678 void setPasswordHelperEnabled(
bool enabled );
684 bool passwordHelperLoggingEnabled() const
SIP_SKIP;
690 void setPasswordHelperLoggingEnabled(
bool enabled )
SIP_SKIP;
696 bool passwordHelperSync();
699 static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME;
702 static const QString AUTH_MAN_TAG;
710 void passwordHelperFailure();
716 void passwordHelperSuccess();
741 void masterPasswordVerified(
bool verified );
744 void authDatabaseEraseRequested();
747 void authDatabaseChanged();
751 void clearAllCachedConfigs();
754 void clearCachedConfig( const QString &authcfg );
768 void tryToStartDbErase();
793 QString passwordHelperName()
const;
796 void passwordHelperLog(
const QString &msg )
const;
799 QString passwordHelperRead();
802 bool passwordHelperWrite(
const QString &password );
805 void passwordHelperSetErrorMessage(
const QString &errorMessage ) { mPasswordHelperErrorMessage = errorMessage; }
808 void passwordHelperClearErrors();
814 void passwordHelperProcessError();
816 bool createConfigTables();
818 bool createCertTables();
820 bool masterPasswordInput();
822 bool masterPasswordRowsInDb(
int *rows )
const;
824 bool masterPasswordCheckAgainstDb(
const QString &compare = QString() )
const;
826 bool masterPasswordStoreInDb()
const;
828 bool masterPasswordClearDb();
830 const QString masterPasswordCiv()
const;
832 bool verifyPasswordCanDecryptConfigs()
const;
834 bool reencryptAllAuthenticationConfigs(
const QString &prevpass,
const QString &prevciv );
836 bool reencryptAuthenticationConfig(
const QString &authcfg,
const QString &prevpass,
const QString &prevciv );
838 bool reencryptAllAuthenticationSettings(
const QString &prevpass,
const QString &prevciv );
840 bool reencryptAllAuthenticationIdentities(
const QString &prevpass,
const QString &prevciv );
842 bool reencryptAuthenticationIdentity(
const QString &identid,
const QString &prevpass,
const QString &prevciv );
844 bool authDbOpen()
const;
846 bool authDbQuery( QSqlQuery *query )
const;
848 bool authDbStartTransaction()
const;
850 bool authDbCommit()
const;
852 bool authDbTransactionQuery( QSqlQuery *query )
const;
858 const QString authDbPassTable()
const {
return AUTH_PASS_TABLE; }
860 const QString authDbSettingsTable()
const {
return AUTH_SETTINGS_TABLE; }
862 const QString authDbIdentitiesTable()
const {
return AUTH_IDENTITIES_TABLE; }
864 const QString authDbAuthoritiesTable()
const {
return AUTH_AUTHORITIES_TABLE; }
866 const QString authDbTrustTable()
const {
return AUTH_TRUST_TABLE; }
869 static const QString AUTH_CONFIG_TABLE;
870 static const QString AUTH_PASS_TABLE;
871 static const QString AUTH_SETTINGS_TABLE;
872 static const QString AUTH_IDENTITIES_TABLE;
873 static const QString AUTH_SERVERS_TABLE;
874 static const QString AUTH_AUTHORITIES_TABLE;
875 static const QString AUTH_TRUST_TABLE;
876 static const QString AUTH_CFG_REGEX;
878 bool mAuthInit =
false;
881 std::unique_ptr<QCA::Initializer> mQcaInitializer;
883 QHash<QString, QString> mConfigAuthMethods;
884 QHash<QString, QgsAuthMethod *> mAuthMethods;
888 bool mAuthDisabled =
false;
889 QString mAuthDisabledMessage;
890 QTimer *mScheduledDbEraseTimer =
nullptr;
891 bool mScheduledDbErase =
false;
892 int mScheduledDbEraseRequestWait = 3 ;
893 bool mScheduledDbEraseRequestEmitted =
false;
894 int mScheduledDbEraseRequestCount = 0;
896 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
897 std::unique_ptr<QMutex> mMutex;
898 std::unique_ptr<QMutex> mMasterPasswordMutex;
900 std::unique_ptr<QRecursiveMutex> mMutex;
901 std::unique_ptr<QRecursiveMutex> mMasterPasswordMutex;
906 QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > mCaCertsCache;
908 QMap<QgsAuthCertUtils::CertTrustPolicy, QStringList > mCertTrustCache;
910 QList<QSslCertificate> mTrustedCaCertsCache;
912 QHash<QString, QSet<QSslError::SslError> > mIgnoredSslErrorsCache;
914 bool mHasCustomConfigByHost =
false;
915 bool mHasCheckedIfCustomConfigByHostExists =
false;
916 QMap< QString, QgsAuthConfigSslServer > mCustomConfigByHostCache;
923 bool mPasswordHelperVerificationError =
false;
926 QString mPasswordHelperErrorMessage;
929 QKeychain::Error mPasswordHelperErrorCode = QKeychain::NoError;
932 bool mPasswordHelperLoggingEnabled =
false;
935 bool mPasswordHelperFailedInit =
false;
938 static const QLatin1String AUTH_PASSWORD_HELPER_KEY_NAME;
941 static const QLatin1String AUTH_PASSWORD_HELPER_FOLDER_NAME;
943 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