forked from open-eid/qt-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSslCertificate.h
140 lines (123 loc) · 3.67 KB
/
SslCertificate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* QEstEidCommon
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#pragma once
#include <QtNetwork/QSslCertificate>
#include <QtCore/QCoreApplication>
template<class Key,class T> class QHash;
class SslCertificate: public QSslCertificate
{
Q_DECLARE_TR_FUNCTIONS( SslCertificate )
public:
enum EnhancedKeyUsage
{
EnhancedKeyUsageNone = -1,
All = 0,
ClientAuth,
ServerAuth,
EmailProtect,
OCSPSign,
TimeStamping
};
enum KeyUsage
{
KeyUsageNone = -1,
DigitalSignature = 0,
NonRepudiation,
KeyEncipherment,
DataEncipherment,
KeyAgreement,
KeyCertificateSign,
CRLSign,
EncipherOnly,
DecipherOnly
};
enum CertType
{
UnknownType = 0,
DigiIDType = 1,
EstEidType = 2,
MobileIDType = 4,
OCSPType = 8,
TempelType = 16,
TestType = 32,
DigiIDTestType = DigiIDType|TestType,
EstEidTestType = EstEidType|TestType,
MobileIDTestType = MobileIDType|TestType,
OCSPTestType = OCSPType|TestType,
TempelTestType = TempelType|TestType
};
SslCertificate();
SslCertificate( const QByteArray &data, QSsl::EncodingFormat format );
SslCertificate( const QSslCertificate &cert );
#if QT_VERSION >= 0x050000
QString issuerInfo( const QByteArray &tag ) const;
QString issuerInfo( QSslCertificate::SubjectInfo subject ) const;
QString subjectInfo( const QByteArray &tag ) const;
QString subjectInfo( QSslCertificate::SubjectInfo subject ) const;
#endif
QByteArray authorityKeyIdentifier() const;
bool canUpdate() const;
QHash<EnhancedKeyUsage,QString> enhancedKeyUsage() const;
QString friendlyName() const;
bool isCA() const;
QString keyName() const;
QHash<KeyUsage,QString> keyUsage() const;
QStringList policies() const;
QString policyInfo( const QString &oid ) const;
QString publicKeyHex() const;
bool showCN() const;
QByteArray serialNumber( bool hex = false ) const;
QString signatureAlgorithm() const;
QByteArray subjectKeyIdentifier() const;
static QByteArray toHex( const QByteArray &in, QChar separator = ' ' );
QString toString( const QString &format ) const;
CertType type() const;
static QString formatName( const QString &name );
static QSslCertificate fromX509( Qt::HANDLE x509 );
static QSslKey keyFromEVP( Qt::HANDLE evp );
private:
Qt::HANDLE extension( int nid ) const;
};
uint qHash( const SslCertificate &cert );
class PKCS12CertificatePrivate;
class PKCS12Certificate
{
public:
enum ErrorType
{
NullError = 0,
InvalidPasswordError = 1,
FileNotExist = 2,
FailedToRead = 3,
UnknownError = -1
};
PKCS12Certificate( QIODevice *device, const QString &pin );
PKCS12Certificate( const QByteArray &data, const QString &pin );
PKCS12Certificate( const PKCS12Certificate &other );
~PKCS12Certificate();
QList<QSslCertificate> caCertificates() const;
QSslCertificate certificate() const;
ErrorType error() const;
QString errorString() const;
bool isNull() const;
QSslKey key() const;
static PKCS12Certificate fromPath( const QString &path, const QString &pin );
private:
QSharedDataPointer<PKCS12CertificatePrivate> d;
};