Mercurial > trustbridge
comparison ui/certificate.cpp @ 94:f1ebab8639dc
Do not save the x509 cert as a member variable
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 21 Mar 2014 10:06:50 +0000 |
parents | ba8a548ff252 |
children | 2551ad24d3c2 |
comparison
equal
deleted
inserted
replaced
93:0798b9e35725 | 94:f1ebab8639dc |
---|---|
1 #include "certificate.h" | 1 #include "certificate.h" |
2 #include <QDebug> | 2 #include <QDebug> |
3 #include <QObject> | 3 #include <QObject> |
4 | |
5 #include <polarssl/x509_crt.h> | |
4 | 6 |
5 Certificate::Certificate(const QString& b64Line) : | 7 Certificate::Certificate(const QString& b64Line) : |
6 mValid(false), | 8 mValid(false), |
7 mShortDescription(QObject::tr("Invalid Certificate")) | 9 mShortDescription(QObject::tr("Invalid Certificate")) |
8 { | 10 { |
9 int ret = -1; | 11 int ret = -1; |
10 char buf[2000]; | 12 char buf[2000]; |
13 x509_crt x509cert; | |
11 | 14 |
12 /* Cut of the first two chars (e.g. I: and decode) */ | 15 /* Cut of the first two chars (e.g. I: and decode) */ |
13 QByteArray asn1data = QByteArray::fromBase64( | 16 QByteArray asn1data = QByteArray::fromBase64( |
14 b64Line.right(b64Line.size() - 2).toLatin1()); | 17 b64Line.right(b64Line.size() - 2).toLatin1()); |
15 | 18 |
16 x509_crt_init(&mX509Cert); | 19 x509_crt_init(&x509cert); |
17 ret = x509_crt_parse(&mX509Cert, | 20 ret = x509_crt_parse(&x509cert, |
18 (const unsigned char*) asn1data.constData(), | 21 (const unsigned char*) asn1data.constData(), |
19 asn1data.size()); | 22 asn1data.size()); |
20 if (ret != 0) { | 23 if (ret != 0) { |
21 qDebug() << "Parsing certificate failed with error: " << ret; | 24 qDebug() << "Parsing certificate failed with error: " << ret; |
25 x509_crt_free(&x509cert); | |
22 return; | 26 return; |
23 } | 27 } |
24 | 28 |
25 ret = x509_crt_info(buf, 2000, "", &mX509Cert); | 29 ret = x509_crt_info(buf, 2000, "", &x509cert); |
30 x509_crt_free(&x509cert); | |
26 | 31 |
27 if (ret <= 0) { | 32 if (ret <= 0) { |
28 qDebug() << "Getting certificate info failed with error: " << ret; | 33 qDebug() << "Getting certificate info failed with error: " << ret; |
29 return; | 34 return; |
30 } | 35 } |
39 | 44 |
40 mValid = true; | 45 mValid = true; |
41 | 46 |
42 mBaseLine = b64Line; | 47 mBaseLine = b64Line; |
43 } | 48 } |
44 | |
45 Certificate::~Certificate() | |
46 { | |
47 x509_crt_free(&mX509Cert); | |
48 } |