Mercurial > trustbridge
diff 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 |
line wrap: on
line diff
--- a/ui/certificate.cpp Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/certificate.cpp Wed Mar 19 18:04:14 2014 +0000 @@ -1,12 +1,45 @@ #include "certificate.h" +#include <QDebug> #include <QObject> const QString& Certificate::shortDescription() const { return mShortDescription; } + Certificate::Certificate(const QByteArray& asn1data) : mValid(false), mShortDescription(QObject::tr("Invalid Certificate")) { + int ret = -1; + char buf[2000]; + x509_crt_init(&mX509Cert); + ret = x509_crt_parse(&mX509Cert, + (const unsigned char*) asn1data.constData(), + asn1data.size()); + if (ret != 0) { + qDebug() << "Parsing certificate failed with error: " << ret; + return; + } + + ret = x509_crt_info(buf, 2000, "", &mX509Cert); + + if (ret <= 0) { + qDebug() << "Getting certificate info failed with error: " << ret; + return; + } + + /* In case of success the return value is the size of the information + * written into buf + * + * TODO: This is currently not short description but all x509 information + * */ + mShortDescription = QString::fromUtf8(buf, ret); + + mValid = true; } + +Certificate::~Certificate() +{ + x509_crt_free(&mX509Cert); +}