aheinecke@21: #include "certificate.h" aheinecke@82: #include aheinecke@21: #include aheinecke@21: aheinecke@78: const QString& Certificate::shortDescription() const { aheinecke@21: return mShortDescription; aheinecke@21: } aheinecke@82: aheinecke@81: Certificate::Certificate(const QByteArray& asn1data) : aheinecke@81: mValid(false), aheinecke@81: mShortDescription(QObject::tr("Invalid Certificate")) aheinecke@81: { aheinecke@82: int ret = -1; aheinecke@82: char buf[2000]; aheinecke@81: aheinecke@82: x509_crt_init(&mX509Cert); aheinecke@82: ret = x509_crt_parse(&mX509Cert, aheinecke@82: (const unsigned char*) asn1data.constData(), aheinecke@82: asn1data.size()); aheinecke@82: if (ret != 0) { aheinecke@82: qDebug() << "Parsing certificate failed with error: " << ret; aheinecke@82: return; aheinecke@82: } aheinecke@82: aheinecke@82: ret = x509_crt_info(buf, 2000, "", &mX509Cert); aheinecke@82: aheinecke@82: if (ret <= 0) { aheinecke@82: qDebug() << "Getting certificate info failed with error: " << ret; aheinecke@82: return; aheinecke@82: } aheinecke@82: aheinecke@82: /* In case of success the return value is the size of the information aheinecke@82: * written into buf aheinecke@82: * aheinecke@82: * TODO: This is currently not short description but all x509 information aheinecke@82: * */ aheinecke@82: mShortDescription = QString::fromUtf8(buf, ret); aheinecke@82: aheinecke@82: mValid = true; aheinecke@81: } aheinecke@82: aheinecke@82: Certificate::~Certificate() aheinecke@82: { aheinecke@82: x509_crt_free(&mX509Cert); aheinecke@82: }