QGIS API Documentation  2.12.0-Lyon
qgsauthcertutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsauthcertutils.h
3  ---------------------
4  begin : May 1, 2015
5  copyright : (C) 2015 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 
18 #ifndef QGSAUTHCERTUTILS_H
19 #define QGSAUTHCERTUTILS_H
20 
21 #include <QtCrypto>
22 #include <QSslCertificate>
23 #include <QSslError>
24 
25 #include "qgsauthconfig.h"
26 
27 #if QT_VERSION >= 0x050000
28 #define SSL_ISSUER_INFO( var, prop ) var.issuerInfo( prop ).first()
29 #else
30 #define SSL_ISSUER_INFO( var, prop ) var.issuerInfo( prop )
31 #endif
32 
33 #if QT_VERSION >= 0x050000
34 #define SSL_SUBJECT_INFO( var, prop ) var.subjectInfo( prop ).first()
35 #else
36 #define SSL_SUBJECT_INFO( var, prop ) var.subjectInfo( prop )
37 #endif
38 
42 class CORE_EXPORT QgsAuthCertUtils
43 {
44  public:
47  {
48  SystemRoot = 0,
49  FromFile = 1,
50  InDatabase = 2,
51  Connection = 3
52  };
53 
56  {
57  DefaultTrust = 0,
58  Trusted = 1,
59  Untrusted = 2,
60  NoPolicy = 3
61  };
62 
65  {
66  UndeterminedUsage = 0,
76  CRLSigningUsage
77  };
78 
81  {
82  KeyUsage = 0,
83  ExtendedKeyUsage = 1
84  };
85 
86 
88  static QString getSslProtocolName( QSsl::SslProtocol protocol );
89 
91  static QMap<QString, QSslCertificate> mapDigestToCerts( const QList<QSslCertificate>& certs );
92 
94  static QMap< QString, QList<QSslCertificate> > certsGroupedByOrg( const QList<QSslCertificate>& certs );
95 
97  static QMap<QString, QgsAuthConfigSslServer> mapDigestToSslConfigs( const QList<QgsAuthConfigSslServer>& configs );
98 
100  static QMap< QString, QList<QgsAuthConfigSslServer> > sslConfigsGroupedByOrg( const QList<QgsAuthConfigSslServer>& configs );
101 
103  static QList<QSslCertificate> certsFromFile( const QString &certspath );
104 
106  static QSslCertificate certFromFile( const QString &certpath );
107 
113  static QSslKey keyFromFile( const QString &keypath,
114  const QString &keypass = QString(),
115  QString *algtype = 0 );
116 
118  static QList<QSslCertificate> certsFromString( const QString &pemtext );
119 
127  static QStringList certKeyBundleToPem( const QString &certpath,
128  const QString &keypath,
129  const QString &keypass = QString(),
130  bool reencrypt = true );
131 
138  static QStringList pkcs12BundleToPem( const QString &bundlepath,
139  const QString &bundlepass = QString(),
140  bool reencrypt = true );
141 
146  static QString getCaSourceName( QgsAuthCertUtils::CaCertSource source , bool single = false );
147 
149  static QString resolvedCertName( const QSslCertificate& cert, bool issuer = false );
150 
156  static QString getCertDistinguishedName( const QSslCertificate& qcert,
157  const QCA::Certificate& acert = QCA::Certificate(),
158  bool issuer = false );
159 
161  static QString getCertTrustName( QgsAuthCertUtils::CertTrustPolicy trust );
162 
164  static QString getColonDelimited( const QString& txt );
165 
170  static QString shaHexForCert( const QSslCertificate &cert , bool formatted = false );
171 
173  static QCA::Certificate qtCertToQcaCert( const QSslCertificate& cert );
174 
176  static QCA::CertificateCollection qtCertsToQcaCollection( const QList<QSslCertificate>& certs );
177 
179  static QCA::KeyBundle qcaKeyBundle( const QString &path, const QString &pass );
180 
182  static QString qcaValidityMessage( QCA::Validity validity );
183 
185  static QString qcaSignatureAlgorithm( QCA::SignatureAlgorithm algorithm );
186 
188  static QString qcaKnownConstraint( QCA::ConstraintTypeKnown constraint );
189 
191  static QString certificateUsageTypeString( QgsAuthCertUtils::CertUsageType usagetype );
192 
194  static QList<QgsAuthCertUtils::CertUsageType> certificateUsageTypes( const QSslCertificate& cert );
195 
197  static bool certificateIsAuthority( const QSslCertificate& cert );
198 
200  static bool certificateIsIssuer( const QSslCertificate& cert );
201 
203  static bool certificateIsAuthorityOrIssuer( const QSslCertificate& cert );
204 
206  static bool certificateIsSslServer( const QSslCertificate& cert );
207 
209  static bool certificateIsSslClient( const QSslCertificate& cert );
210 
212  static QString sslErrorEnumString( QSslError::SslError errenum );
213 
215  static QList<QPair<QSslError::SslError, QString> > sslErrorEnumStrings();
216 
217  private:
218  static void appendDirSegment_( QStringList &dirname, const QString &segment, QString value );
219 };
220 
221 #endif // QGSAUTHCERTUTILS_H
CertTrustPolicy
Type of certificate trust policy.
Utilities for working with certificates and keys.
CertUsageType
Type of certificate usage.
CaCertSource
Type of CA certificate source.
ConstraintGroup
Type of certificate key group.