Mercurial > trustbridge
annotate ui/certificate.cpp @ 82:1f27d6db5ee3
Polarssl based certificate handling
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 19 Mar 2014 18:04:14 +0000 |
parents | 112228bd7e4b |
children | ba8a548ff252 |
rev | line source |
---|---|
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #include "certificate.h" |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
2 #include <QDebug> |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 #include <QObject> |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 |
78 | 5 const QString& Certificate::shortDescription() const { |
21
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 return mShortDescription; |
dc1e1e9e62ce
Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 } |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
8 |
81
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
9 Certificate::Certificate(const QByteArray& asn1data) : |
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
10 mValid(false), |
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
11 mShortDescription(QObject::tr("Invalid Certificate")) |
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
12 { |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
13 int ret = -1; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
14 char buf[2000]; |
81
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
15 |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
16 x509_crt_init(&mX509Cert); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
17 ret = x509_crt_parse(&mX509Cert, |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
18 (const unsigned char*) asn1data.constData(), |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
19 asn1data.size()); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
20 if (ret != 0) { |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
21 qDebug() << "Parsing certificate failed with error: " << ret; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
22 return; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
23 } |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
24 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
25 ret = x509_crt_info(buf, 2000, "", &mX509Cert); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
26 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
27 if (ret <= 0) { |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
28 qDebug() << "Getting certificate info failed with error: " << ret; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
29 return; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
30 } |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
31 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
32 /* In case of success the return value is the size of the information |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
33 * written into buf |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
34 * |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
35 * TODO: This is currently not short description but all x509 information |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
36 * */ |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
37 mShortDescription = QString::fromUtf8(buf, ret); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
38 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
39 mValid = true; |
81
112228bd7e4b
Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents:
78
diff
changeset
|
40 } |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
41 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
42 Certificate::~Certificate() |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
43 { |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
44 x509_crt_free(&mX509Cert); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
81
diff
changeset
|
45 } |