view ui/certificate.cpp @ 115:5ed770c41a73

Change garbage input to invalid input. Fix InvalidInstructions test. InvalidInstructions test now fails as instruction validation is not yet implemented
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 21 Mar 2014 16:33:18 +0000
parents f1ebab8639dc
children 2551ad24d3c2
line wrap: on
line source
#include "certificate.h"
#include <QDebug>
#include <QObject>

#include <polarssl/x509_crt.h>

Certificate::Certificate(const QString& b64Line) :
    mValid(false),
    mShortDescription(QObject::tr("Invalid Certificate"))
{
    int ret = -1;
    char buf[2000];
    x509_crt x509cert;

    /* Cut of the first two chars (e.g. I: and decode) */
    QByteArray asn1data = QByteArray::fromBase64(
            b64Line.right(b64Line.size() - 2).toLatin1());

    x509_crt_init(&x509cert);
    ret = x509_crt_parse(&x509cert,
                         (const unsigned char*) asn1data.constData(),
                         asn1data.size());
    if (ret != 0) {
        qDebug() << "Parsing certificate failed with error: " << ret;
        x509_crt_free(&x509cert);
        return;
    }

    ret = x509_crt_info(buf, 2000, "", &x509cert);
    x509_crt_free(&x509cert);

    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
     * */

    mDetails = QString::fromUtf8(buf, ret);

    mShortDescription = mDetails; /* TODO */

    mValid = true;

    mBaseLine = b64Line;
}

http://wald.intevation.org/projects/trustbridge/