2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* \brief Configuration storage class for authentication method configurations
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
class QgsAuthMethodConfig
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsauthconfig.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Construct a configuration for an authentication method
|
|
|
|
* @param method Textual key of the authentication method
|
|
|
|
* @param version Version of the configuration (for updating previously saved configs later on)
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
QgsAuthMethodConfig( const QString& method = QString(), int version = 0 );
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Operator used to compare configs' equality */
|
2015-09-24 05:34:25 -06:00
|
|
|
bool operator==( const QgsAuthMethodConfig& other ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Operator used to compare configs' inequality */
|
2015-09-24 05:34:25 -06:00
|
|
|
bool operator!=( const QgsAuthMethodConfig& other ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Get 'authcfg' 7-character alphanumeric ID of the config
|
|
|
|
* @note This is set by QgsAuthManager when the config is initially stored
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString id() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set auth config ID */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setId( const QString& id );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Get name of configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString name() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set name of configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setName( const QString& name );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** A URI to auto-select a config when connecting to a resource */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString uri() const;
|
|
|
|
void setUri( const QString& uri );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Textual key of the associated authentication method */
|
2015-09-21 06:17:48 -06:00
|
|
|
QString method() const;
|
2015-10-07 11:55:34 +11:00
|
|
|
void setMethod( const QString& method );
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Get version of the configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
int version() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set version of the configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setVersion( int version );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Whether the configuration is valid
|
|
|
|
* @param validateid Additionally verify the auth config ID is not empty
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
bool isValid( bool validateid = false ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* The extended configuration, as stored and retrieved from the authentication database
|
|
|
|
* @note This is an internal construct used by QgsAuthManager that should generally not be set by client code
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString configString() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Load existing extended configuration
|
|
|
|
* @param configstr Configuration string to load
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
void loadConfigString( const QString& configstr );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Get extended configuration, mapped to key/value pairs of QStrings */
|
2015-09-21 06:17:48 -06:00
|
|
|
QgsStringMap configMap() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set extended configuration map
|
|
|
|
* @param map Map to set
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
void setConfigMap( const QgsStringMap& map );
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set a single config value per key in the map
|
|
|
|
* @note if key exists, it is replaced
|
|
|
|
* @param key Config key
|
|
|
|
* @param value Config value
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
void setConfig( const QString &key, const QString &value );
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Set a multiple config values per key in the map
|
|
|
|
* @note if key exists, it is replaced
|
|
|
|
* @param key Config key
|
|
|
|
* @param value Config value
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
void setConfigList( const QString &key, const QStringList &value );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Remove a config from map
|
|
|
|
* @param key Config to remove
|
|
|
|
* @return Number of keys removed (should always be 1 or 0)
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
int removeConfig( const QString &key );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Return a config's value
|
|
|
|
* @param key Config key
|
|
|
|
* @param defaultvalue Default value, if key not found
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
QString config( const QString &key, const QString& defaultvalue = QString() ) const;
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Return a config's list of values
|
|
|
|
* @param key
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
QStringList configList( const QString &key ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Whether a config key exists in config map
|
|
|
|
* @param key
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
bool hasConfig( const QString &key ) const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Clear all configs */
|
2015-09-21 06:17:48 -06:00
|
|
|
void clearConfigMap();
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* A utility function for generating a resource from a URL to be compared
|
|
|
|
* against the config's uri() for auto-selecting authentication configs to use
|
|
|
|
* @note Essentially strips the URL query variables, and by default, strips the path as well
|
|
|
|
* @param accessurl A URL to process
|
|
|
|
* @param resource Ouput variable for result
|
|
|
|
* @param withpath Whether to include the URI's path in output
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
static bool uriToResource( const QString &accessurl, QString *resource, bool withpath = false );
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QHash<QString, QgsAuthMethodConfig> QgsAuthMethodConfigsMap;
|
|
|
|
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* \brief Storage set for PKI bundle: SSL certificate, key, optional CA cert chain
|
|
|
|
* \note Useful for caching the bundle during application run sessions
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
class QgsPkiBundle
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsauthconfig.h>
|
|
|
|
%End
|
|
|
|
public:
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Construct a bundle from existing PKI components
|
|
|
|
* @param clientCert Certificate to store in bundle
|
|
|
|
* @param clientKey Private key to store in bundle
|
|
|
|
* @param caChain Chain of Certificate Authorities for client certificate
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(),
|
|
|
|
const QSslKey &clientKey = QSslKey(),
|
|
|
|
const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Construct a bundle of PKI components from PEM-formatted file paths
|
|
|
|
* @param certPath Certificate file path
|
|
|
|
* @param keyPath Private key path
|
|
|
|
* @param keyPass Private key passphrase
|
|
|
|
* @param caChain Chain of Certificate Authorities for client certificate
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
static const QgsPkiBundle fromPemPaths( const QString &certPath,
|
|
|
|
const QString &keyPath,
|
|
|
|
const QString &keyPass = QString::null,
|
|
|
|
const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Construct a bundle of PKI components from a PKCS#12 file path
|
|
|
|
* @param bundlepath Bundle file path
|
|
|
|
* @param bundlepass Optional bundle passphrase
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath,
|
2016-02-14 03:50:23 +01:00
|
|
|
const QString &bundlepass = QString::null );
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Whether the bundle, either its certificate or private key, is null */
|
2015-09-21 06:17:48 -06:00
|
|
|
bool isNull() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/** Whether the bundle is valid */
|
2015-09-21 06:17:48 -06:00
|
|
|
bool isValid() const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** The sha hash of the client certificate */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString certId() const;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Client certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QSslCertificate clientCert() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set client certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setClientCert( const QSslCertificate &cert );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Private key object */
|
2015-09-24 06:44:05 -06:00
|
|
|
const QSslKey clientKey() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set private key object */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setClientKey( const QSslKey &certkey );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Chain of Certificate Authorities for client certificate */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QList<QSslCertificate> caChain() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set chain of Certificate Authorities for client certificate */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setCaChain( const QList<QSslCertificate> &cachain );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* \brief Storage set for constructed SSL certificate, key, associated with an authentication config
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
class QgsPkiConfigBundle
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsauthconfig.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Construct a bundle from existing PKI components and authentication method configuration
|
|
|
|
* @param config Authentication method configuration
|
|
|
|
* @param cert Certificate to store in bundle
|
|
|
|
* @param certkey Private key to store in bundle
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
QgsPkiConfigBundle( const QgsAuthMethodConfig& config,
|
2016-02-14 03:50:23 +01:00
|
|
|
const QSslCertificate& cert,
|
|
|
|
const QSslKey& certkey );
|
2015-09-21 06:17:48 -06:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Whether the bundle is valid */
|
2015-09-21 06:17:48 -06:00
|
|
|
bool isValid();
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Authentication method configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QgsAuthMethodConfig config() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set authentication method configuration */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setConfig( const QgsAuthMethodConfig& config );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Client certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QSslCertificate clientCert() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set client certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setClientCert( const QSslCertificate& cert );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Private key object */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QSslKey clientCertKey() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set private key object */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setClientCertKey( const QSslKey& certkey );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
%MappedType QList<QSslError::SslError>
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <QList>
|
|
|
|
%End
|
|
|
|
|
|
|
|
%ConvertFromTypeCode
|
|
|
|
// Create the list.
|
|
|
|
PyObject *l;
|
|
|
|
|
|
|
|
if ((l = PyList_New(sipCpp->size())) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Set the list elements.
|
|
|
|
QList<QSslError::SslError>::iterator it = sipCpp->begin();
|
|
|
|
for (int i = 0; it != sipCpp->end(); ++it, ++i)
|
|
|
|
{
|
|
|
|
PyObject *tobj;
|
|
|
|
|
|
|
|
if ((tobj = sipConvertFromEnum(*it, sipType_QSslError_SslError)) == NULL)
|
|
|
|
{
|
|
|
|
Py_DECREF(l);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
PyList_SET_ITEM(l, i, tobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return l;
|
|
|
|
%End
|
|
|
|
|
|
|
|
%ConvertToTypeCode
|
|
|
|
// Check the type if that is all that is required.
|
|
|
|
if (sipIsErr == NULL)
|
|
|
|
return PyList_Check(sipPy);
|
|
|
|
|
|
|
|
QList<QSslError::SslError> *qlist = new QList<QSslError::SslError>;
|
|
|
|
|
|
|
|
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
|
|
|
|
{
|
|
|
|
*qlist << (QSslError::SslError)SIPLong_AsLong(PyList_GET_ITEM(sipPy, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
*sipCppPtr = qlist;
|
|
|
|
return sipGetState(sipTransferObj);
|
|
|
|
%End
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* \brief Configuration container for SSL server connection exceptions or overrides
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
class QgsAuthConfigSslServer
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsauthconfig.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
QgsAuthConfigSslServer();
|
|
|
|
|
|
|
|
~QgsAuthConfigSslServer();
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Server certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QSslCertificate sslCertificate() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set server certificate object */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslCertificate( const QSslCertificate& cert );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Server host:port string */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString sslHostPort() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set server host:port string */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslHostPort( const QString& hostport );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** SSL server protocol to use in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
QSsl::SslProtocol sslProtocol() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set SSL server protocol to use in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslProtocol( QSsl::SslProtocol protocol );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** SSL server errors to ignore in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QList<QSslError> sslIgnoredErrors() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** SSL server errors (as enum list) to ignore in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QList<QSslError::SslError> sslIgnoredErrorEnums() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set SSL server errors (as enum list) to ignore in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslIgnoredErrorEnums( const QList<QSslError::SslError>& errors );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** SSL client's peer verify mode to use in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set SSL client's peer verify mode to use in connections */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Number or SSL client's peer to verify in connections
|
|
|
|
* @note When set to 0 = unlimited depth
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
int sslPeerVerifyDepth() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set number or SSL client's peer to verify in connections
|
|
|
|
* @note When set to 0 = unlimited depth
|
|
|
|
*/
|
2015-09-21 06:17:48 -06:00
|
|
|
void setSslPeerVerifyDepth( int depth );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Version of the configuration (used for future upgrading) */
|
2015-09-21 06:17:48 -06:00
|
|
|
int version() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set version of the configuration (used for future upgrading) */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setVersion( int version );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Qt version when the configuration was made (SSL protocols may differ) */
|
2015-09-21 06:17:48 -06:00
|
|
|
int qtVersion() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Set Qt version when the configuration was made (SSL protocols may differ) */
|
2015-09-21 06:17:48 -06:00
|
|
|
void setQtVersion( int version );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Configuration as a concatenated string */
|
2015-09-21 06:17:48 -06:00
|
|
|
const QString configString() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Load concatenated string into configuration, e.g. from auth database */
|
2015-09-21 06:17:48 -06:00
|
|
|
void loadConfigString( const QString& config = QString() );
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Whether configuration is null (missing components) */
|
2015-09-21 06:17:48 -06:00
|
|
|
bool isNull() const;
|
|
|
|
};
|
|
|
|
|