QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
qgsauthconfig.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsauthconfig.h
3  ---------------------
4  begin : October 5, 2014
5  copyright : (C) 2014 by Boundless Spatial, Inc. USA
6  author : Larry Shaffer
7  email : lshaffer at boundlessgeo dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSAUTHCONFIG_H
18 #define QGSAUTHCONFIG_H
19 
20 #include <QHash>
21 #include <QString>
22 
23 #ifndef QT_NO_OPENSSL
24 #include <QSslCertificate>
25 #include <QSslKey>
26 #include <QSslError>
27 #include <QSslSocket>
28 #endif
29 
30 #include "qgis.h"
31 
32 
36 class CORE_EXPORT QgsAuthMethodConfig
37 {
38  public:
39 
45  QgsAuthMethodConfig( const QString& method = QString(), int version = 0 );
46 
48  bool operator==( const QgsAuthMethodConfig& other ) const;
49 
51  bool operator!=( const QgsAuthMethodConfig& other ) const;
52 
57  const QString id() const { return mId; }
59  void setId( const QString& id ) { mId = id; }
60 
62  const QString name() const { return mName; }
64  void setName( const QString& name ) { mName = name; }
65 
67  const QString uri() const { return mUri; }
68  void setUri( const QString& uri ) { mUri = uri; }
69 
71  QString method() const { return mMethod; }
72  void setMethod( const QString& method ) { mMethod = method; }
73 
75  int version() const { return mVersion; }
77  void setVersion( int version ) { mVersion = version; }
78 
83  bool isValid( bool validateid = false ) const;
84 
89  const QString configString() const;
94  void loadConfigString( const QString& configstr );
95 
97  QgsStringMap configMap() const { return mConfigMap; }
102  void setConfigMap( const QgsStringMap& map ) { mConfigMap = map; }
103 
110  void setConfig( const QString &key, const QString &value );
117  void setConfigList( const QString &key, const QStringList &value );
118 
124  int removeConfig( const QString &key );
125 
131  QString config( const QString &key, const QString& defaultvalue = QString() ) const;
132 
137  QStringList configList( const QString &key ) const;
138 
143  bool hasConfig( const QString &key ) const;
144 
146  void clearConfigMap() { mConfigMap.clear(); }
147 
156  static bool uriToResource( const QString &accessurl, QString *resource, bool withpath = false );
157 
158  private:
159  QString mId;
160  QString mName;
161  QString mUri;
162  QString mMethod;
163  int mVersion;
164 
165  QgsStringMap mConfigMap;
166 
167  static const QString mConfigSep;
168  static const QString mConfigKeySep;
169  static const QString mConfigListSep;
170 
171  static const int mConfigVersion;
172 };
173 
175 
176 
177 #ifndef QT_NO_OPENSSL
178 
183 class CORE_EXPORT QgsPkiBundle
184 {
185  public:
192  QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(),
193  const QSslKey &clientKey = QSslKey(),
194  const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
195 
203  static const QgsPkiBundle fromPemPaths( const QString &certPath,
204  const QString &keyPath,
205  const QString &keyPass = QString::null,
206  const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
207 
213  static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath,
214  const QString &bundlepass = QString::null );
215 
217  bool isNull() const;
218 
220  bool isValid() const;
221 
223  const QString certId() const;
224 
226  const QSslCertificate clientCert() const { return mCert; }
228  void setClientCert( const QSslCertificate &cert );
229 
231  const QSslKey clientKey() const { return mCertKey; }
233  void setClientKey( const QSslKey &certkey );
234 
236  const QList<QSslCertificate> caChain() const { return mCaChain; }
238  void setCaChain( const QList<QSslCertificate> &cachain ) { mCaChain = cachain; }
239 
240  private:
241  QSslCertificate mCert;
242  QSslKey mCertKey;
243  QList<QSslCertificate> mCaChain;
244 };
245 
246 
250 class CORE_EXPORT QgsPkiConfigBundle
251 {
252  public:
260  const QSslCertificate& cert,
261  const QSslKey& certkey );
262 
264  bool isValid();
265 
267  const QgsAuthMethodConfig config() const { return mConfig; }
269  void setConfig( const QgsAuthMethodConfig& config ) { mConfig = config; }
270 
272  const QSslCertificate clientCert() const { return mCert; }
274  void setClientCert( const QSslCertificate& cert ) { mCert = cert; }
275 
277  const QSslKey clientCertKey() const { return mCertKey; }
279  void setClientCertKey( const QSslKey& certkey ) { mCertKey = certkey; }
280 
281  private:
282  QgsAuthMethodConfig mConfig;
283  QSslCertificate mCert;
284  QSslKey mCertKey;
285 };
286 
287 
291 class CORE_EXPORT QgsAuthConfigSslServer
292 {
293  public:
296 
298 
300  const QSslCertificate sslCertificate() const { return mSslCert; }
302  void setSslCertificate( const QSslCertificate& cert ) { mSslCert = cert; }
303 
305  const QString sslHostPort() const { return mSslHostPort; }
307  void setSslHostPort( const QString& hostport ) { mSslHostPort = hostport; }
308 
310  QSsl::SslProtocol sslProtocol() const { return mSslProtocol; }
312  void setSslProtocol( QSsl::SslProtocol protocol ) { mSslProtocol = protocol; }
313 
315  const QList<QSslError> sslIgnoredErrors() const;
317  const QList<QSslError::SslError> sslIgnoredErrorEnums() const { return mSslIgnoredErrors; }
319  void setSslIgnoredErrorEnums( const QList<QSslError::SslError>& errors ) { mSslIgnoredErrors = errors; }
320 
322  QSslSocket::PeerVerifyMode sslPeerVerifyMode() const { return mSslPeerVerifyMode; }
324  void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode ) { mSslPeerVerifyMode = mode; }
325 
329  int sslPeerVerifyDepth() const { return mSslPeerVerifyDepth; }
333  void setSslPeerVerifyDepth( int depth ) { mSslPeerVerifyDepth = depth; }
334 
336  int version() const { return mVersion; }
338  void setVersion( int version ) { mVersion = version; }
339 
341  int qtVersion() const { return mQtVersion; }
343  void setQtVersion( int version ) { mQtVersion = version; }
344 
346  const QString configString() const;
348  void loadConfigString( const QString& config = QString() );
349 
351  bool isNull() const;
352 
353  private:
354 
355  QString mSslHostPort;
356  QSslCertificate mSslCert;
357 
358  QSsl::SslProtocol mSslProtocol;
359  int mQtVersion;
360  QList<QSslError::SslError> mSslIgnoredErrors;
361  QSslSocket::PeerVerifyMode mSslPeerVerifyMode;
362  int mSslPeerVerifyDepth;
363  int mVersion;
364 
365  static const QString mConfSep;
366 };
367 #endif
368 
369 #endif // QGSAUTHCONFIG_H
const QSslCertificate clientCert() const
Client certificate object.
void setUri(const QString &uri)
Definition: qgsauthconfig.h:68
Storage set for constructed SSL certificate, key, associated with an authentication config...
const QSslKey clientCertKey() const
Private key object.
void setId(const QString &id)
Set auth config ID.
Definition: qgsauthconfig.h:59
const QgsAuthMethodConfig config() const
Authentication method configuration.
void setCaChain(const QList< QSslCertificate > &cachain)
Set chain of Certificate Authorities for client certificate.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
int qtVersion() const
Qt version when the configuration was made (SSL protocols may differ)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Configuration container for SSL server connection exceptions or overrides.
void setClientCert(const QSslCertificate &cert)
Set client certificate object.
void setSslPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
Set SSL client&#39;s peer verify mode to use in connections.
const QString name() const
Get name of configuration.
Definition: qgsauthconfig.h:62
Storage set for PKI bundle: SSL certificate, key, optional CA cert chain.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
Definition: qgsauthconfig.h:67
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
void setVersion(int version)
Set version of the configuration (used for future upgrading)
QgsStringMap configMap() const
Get extended configuration, mapped to key/value pairs of QStrings.
Definition: qgsauthconfig.h:97
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const
SSL client&#39;s peer verify mode to use in connections.
void setMethod(const QString &method)
Definition: qgsauthconfig.h:72
QSsl::SslProtocol sslProtocol() const
SSL server protocol to use in connections.
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:36
const QString id() const
Get &#39;authcfg&#39; 7-character alphanumeric ID of the config.
Definition: qgsauthconfig.h:57
const QSslCertificate sslCertificate() const
Server certificate object.
void setClientCertKey(const QSslKey &certkey)
Set private key object.
void setConfig(const QgsAuthMethodConfig &config)
Set authentication method configuration.
void setSslHostPort(const QString &hostport)
Set server host:port string.
int version() const
Version of the configuration (used for future upgrading)
void setSslProtocol(QSsl::SslProtocol protocol)
Set SSL server protocol to use in connections.
const QList< QSslCertificate > caChain() const
Chain of Certificate Authorities for client certificate.
int sslPeerVerifyDepth() const
Number or SSL client&#39;s peer to verify in connections.
void setSslIgnoredErrorEnums(const QList< QSslError::SslError > &errors)
Set SSL server errors (as enum list) to ignore in connections.
const QSslKey clientKey() const
Private key object.
void setVersion(int version)
Set version of the configuration.
Definition: qgsauthconfig.h:77
void setQtVersion(int version)
Set Qt version when the configuration was made (SSL protocols may differ)
void setSslPeerVerifyDepth(int depth)
Set number or SSL client&#39;s peer to verify in connections.
void clearConfigMap()
Clear all configs.
const QString sslHostPort() const
Server host:port string.
int version() const
Get version of the configuration.
Definition: qgsauthconfig.h:75
void setName(const QString &name)
Set name of configuration.
Definition: qgsauthconfig.h:64
void setSslCertificate(const QSslCertificate &cert)
Set server certificate object.
void setConfigMap(const QgsStringMap &map)
Set extended configuration map.
const QSslCertificate clientCert() const
Client certificate object.
QString method() const
Textual key of the associated authentication method.
Definition: qgsauthconfig.h:71
bool isNull(const QVariant &v)
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.