QGIS API Documentation  2.12.0-Lyon
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  QgsAuthMethodConfig( const QgsAuthMethodConfig& methodconfig );
49 
51  bool operator==( const QgsAuthMethodConfig& other ) const;
52 
54  bool operator!=( const QgsAuthMethodConfig& other ) const;
55 
57 
62  const QString id() const { return mId; }
64  void setId( const QString& id ) { mId = id; }
65 
67  const QString name() const { return mName; }
69  void setName( const QString& name ) { mName = name; }
70 
72  const QString uri() const { return mUri; }
73  void setUri( const QString& uri ) { mUri = uri; }
74 
76  QString method() const { return mMethod; }
77  void setMethod( const QString& method ) { mMethod = method; }
78 
80  int version() const { return mVersion; }
82  void setVersion( int version ) { mVersion = version; }
83 
88  bool isValid( bool validateid = false ) const;
89 
94  const QString configString() const;
99  void loadConfigString( const QString& configstr );
100 
102  QgsStringMap configMap() const { return mConfigMap; }
107  void setConfigMap( const QgsStringMap& map ) { mConfigMap = map; }
108 
115  void setConfig( const QString &key, const QString &value );
122  void setConfigList( const QString &key, const QStringList &value );
123 
129  int removeConfig( const QString &key );
130 
136  QString config( const QString &key, const QString& defaultvalue = QString() ) const;
137 
142  QStringList configList( const QString &key ) const;
143 
148  bool hasConfig( const QString &key ) const;
149 
151  void clearConfigMap() { mConfigMap.clear(); }
152 
161  static bool uriToResource( const QString &accessurl, QString *resource, bool withpath = false );
162 
163  private:
164  QString mId;
165  QString mName;
166  QString mUri;
167  QString mMethod;
168  int mVersion;
169 
170  QgsStringMap mConfigMap;
171 
172  static const QString mConfigSep;
173  static const QString mConfigKeySep;
174  static const QString mConfigListSep;
175 
176  static const int mConfigVersion;
177 };
178 
180 
181 
182 #ifndef QT_NO_OPENSSL
183 
188 class CORE_EXPORT QgsPkiBundle
189 {
190  public:
197  QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(),
198  const QSslKey &clientKey = QSslKey(),
199  const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
200  ~QgsPkiBundle();
201 
209  static const QgsPkiBundle fromPemPaths( const QString &certPath,
210  const QString &keyPath,
211  const QString &keyPass = QString::null,
212  const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
213 
219  static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath,
220  const QString &bundlepass = QString::null );
221 
223  bool isNull() const;
224 
226  bool isValid() const;
227 
229  const QString certId() const;
230 
232  const QSslCertificate clientCert() const { return mCert; }
234  void setClientCert( const QSslCertificate &cert );
235 
237  const QSslKey clientKey() const { return mCertKey; }
239  void setClientKey( const QSslKey &certkey );
240 
242  const QList<QSslCertificate> caChain() const { return mCaChain; }
244  void setCaChain( const QList<QSslCertificate> &cachain ) { mCaChain = cachain; }
245 
246  private:
247  QSslCertificate mCert;
248  QSslKey mCertKey;
249  QList<QSslCertificate> mCaChain;
250 };
251 
252 
256 class CORE_EXPORT QgsPkiConfigBundle
257 {
258  public:
266  const QSslCertificate& cert,
267  const QSslKey& certkey );
269 
271  bool isValid();
272 
274  const QgsAuthMethodConfig config() const { return mConfig; }
276  void setConfig( const QgsAuthMethodConfig& config ) { mConfig = config; }
277 
279  const QSslCertificate clientCert() const { return mCert; }
281  void setClientCert( const QSslCertificate& cert ) { mCert = cert; }
282 
284  const QSslKey clientCertKey() const { return mCertKey; }
286  void setClientCertKey( const QSslKey& certkey ) { mCertKey = certkey; }
287 
288  private:
289  QgsAuthMethodConfig mConfig;
290  QSslCertificate mCert;
291  QSslKey mCertKey;
292 };
293 
294 
298 class CORE_EXPORT QgsAuthConfigSslServer
299 {
300  public:
303 
305 
307  const QSslCertificate sslCertificate() const { return mSslCert; }
309  void setSslCertificate( const QSslCertificate& cert ) { mSslCert = cert; }
310 
312  const QString sslHostPort() const { return mSslHostPort; }
314  void setSslHostPort( const QString& hostport ) { mSslHostPort = hostport; }
315 
317  QSsl::SslProtocol sslProtocol() const { return mSslProtocol; }
319  void setSslProtocol( QSsl::SslProtocol protocol ) { mSslProtocol = protocol; }
320 
322  const QList<QSslError> sslIgnoredErrors() const;
324  const QList<QSslError::SslError> sslIgnoredErrorEnums() const { return mSslIgnoredErrors; }
326  void setSslIgnoredErrorEnums( const QList<QSslError::SslError>& errors ) { mSslIgnoredErrors = errors; }
327 
329  QSslSocket::PeerVerifyMode sslPeerVerifyMode() const { return mSslPeerVerifyMode; }
331  void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode ) { mSslPeerVerifyMode = mode; }
332 
336  int sslPeerVerifyDepth() const { return mSslPeerVerifyDepth; }
340  void setSslPeerVerifyDepth( int depth ) { mSslPeerVerifyDepth = depth; }
341 
343  int version() const { return mVersion; }
345  void setVersion( int version ) { mVersion = version; }
346 
348  int qtVersion() const { return mQtVersion; }
350  void setQtVersion( int version ) { mQtVersion = version; }
351 
353  const QString configString() const;
355  void loadConfigString( const QString& config = QString() );
356 
358  bool isNull() const;
359 
360  private:
361 
362  QString mSslHostPort;
363  QSslCertificate mSslCert;
364 
365  QSsl::SslProtocol mSslProtocol;
366  int mQtVersion;
367  QList<QSslError::SslError> mSslIgnoredErrors;
368  QSslSocket::PeerVerifyMode mSslPeerVerifyMode;
369  int mSslPeerVerifyDepth;
370  int mVersion;
371 
372  static const QString mConfSep;
373 };
374 #endif
375 
376 #endif // QGSAUTHCONFIG_H
const QSslCertificate clientCert() const
Client certificate object.
void setUri(const QString &uri)
Definition: qgsauthconfig.h:73
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:64
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's peer verify mode to use in connections.
const QString name() const
Get name of configuration.
Definition: qgsauthconfig.h:67
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:72
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.
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const
SSL client's peer verify mode to use in connections.
void setMethod(const QString &method)
Definition: qgsauthconfig.h:77
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 'authcfg' 7-character alphanumeric ID of the config.
Definition: qgsauthconfig.h:62
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'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:82
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'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:80
void setName(const QString &name)
Set name of configuration.
Definition: qgsauthconfig.h:69
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:76
bool isNull(const QVariant &v)
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.