annotate ui/certificate.cpp @ 91:80ab2168760f

Also add output size handling to str_append_str
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 21 Mar 2014 09:47:05 +0000
parents ba8a548ff252
children f1ebab8639dc
rev   line source
21
dc1e1e9e62ce Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 #include "certificate.h"
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
2 #include <QDebug>
21
dc1e1e9e62ce Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 #include <QObject>
dc1e1e9e62ce Add certificate class and use it
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
5 Certificate::Certificate(const QString& b64Line) :
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
6 mValid(false),
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
7 mShortDescription(QObject::tr("Invalid Certificate"))
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
8 {
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
9 int ret = -1;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
10 char buf[2000];
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
11
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
12 /* Cut of the first two chars (e.g. I: and decode) */
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
13 QByteArray asn1data = QByteArray::fromBase64(
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
14 b64Line.right(b64Line.size() - 2).toLatin1());
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
15
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
16 x509_crt_init(&mX509Cert);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
17 ret = x509_crt_parse(&mX509Cert,
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
18 (const unsigned char*) asn1data.constData(),
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
19 asn1data.size());
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
20 if (ret != 0) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
21 qDebug() << "Parsing certificate failed with error: " << ret;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
22 return;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
23 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
24
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
25 ret = x509_crt_info(buf, 2000, "", &mX509Cert);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
26
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
27 if (ret <= 0) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
28 qDebug() << "Getting certificate info failed with error: " << ret;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
29 return;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
30 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
31
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
32 /* In case of success the return value is the size of the information
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
33 * written into buf
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
34 * */
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
35
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
36 mDetails = QString::fromUtf8(buf, ret);
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
37
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
38 mShortDescription = mDetails; /* TODO */
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
39
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
40 mValid = true;
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
41
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
42 mBaseLine = b64Line;
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
43 }
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
44
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
45 Certificate::~Certificate()
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
46 {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
47 x509_crt_free(&mX509Cert);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
48 }

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