Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
81:112228bd7e4b | 82:1f27d6db5ee3 |
---|---|
1 #include "certificate.h" | 1 #include "certificate.h" |
2 #include <QDebug> | |
2 #include <QObject> | 3 #include <QObject> |
3 | 4 |
4 const QString& Certificate::shortDescription() const { | 5 const QString& Certificate::shortDescription() const { |
5 return mShortDescription; | 6 return mShortDescription; |
6 } | 7 } |
8 | |
7 Certificate::Certificate(const QByteArray& asn1data) : | 9 Certificate::Certificate(const QByteArray& asn1data) : |
8 mValid(false), | 10 mValid(false), |
9 mShortDescription(QObject::tr("Invalid Certificate")) | 11 mShortDescription(QObject::tr("Invalid Certificate")) |
10 { | 12 { |
13 int ret = -1; | |
14 char buf[2000]; | |
11 | 15 |
16 x509_crt_init(&mX509Cert); | |
17 ret = x509_crt_parse(&mX509Cert, | |
18 (const unsigned char*) asn1data.constData(), | |
19 asn1data.size()); | |
20 if (ret != 0) { | |
21 qDebug() << "Parsing certificate failed with error: " << ret; | |
22 return; | |
23 } | |
24 | |
25 ret = x509_crt_info(buf, 2000, "", &mX509Cert); | |
26 | |
27 if (ret <= 0) { | |
28 qDebug() << "Getting certificate info failed with error: " << ret; | |
29 return; | |
30 } | |
31 | |
32 /* In case of success the return value is the size of the information | |
33 * written into buf | |
34 * | |
35 * TODO: This is currently not short description but all x509 information | |
36 * */ | |
37 mShortDescription = QString::fromUtf8(buf, ret); | |
38 | |
39 mValid = true; | |
12 } | 40 } |
41 | |
42 Certificate::~Certificate() | |
43 { | |
44 x509_crt_free(&mX509Cert); | |
45 } |