annotate ui/certificate.cpp @ 152:dbbd761959ae

Include line endings in check
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 17:45:59 +0000
parents f1ebab8639dc
children 2551ad24d3c2
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
94
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
5 #include <polarssl/x509_crt.h>
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
6
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
7 Certificate::Certificate(const QString& b64Line) :
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
8 mValid(false),
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
9 mShortDescription(QObject::tr("Invalid Certificate"))
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
10 {
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
11 int ret = -1;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
12 char buf[2000];
94
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
13 x509_crt x509cert;
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
14
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
15 /* 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
16 QByteArray asn1data = QByteArray::fromBase64(
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
17 b64Line.right(b64Line.size() - 2).toLatin1());
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
18
94
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
19 x509_crt_init(&x509cert);
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
20 ret = x509_crt_parse(&x509cert,
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
21 (const unsigned char*) asn1data.constData(),
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
22 asn1data.size());
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
23 if (ret != 0) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
24 qDebug() << "Parsing certificate failed with error: " << ret;
94
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
25 x509_crt_free(&x509cert);
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
26 return;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
27 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
28
94
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
29 ret = x509_crt_info(buf, 2000, "", &x509cert);
f1ebab8639dc Do not save the x509 cert as a member variable
Andre Heinecke <aheinecke@intevation.de>
parents: 83
diff changeset
30 x509_crt_free(&x509cert);
82
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 if (ret <= 0) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
33 qDebug() << "Getting certificate info failed with error: " << ret;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
34 return;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
35 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
36
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
37 /* 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
38 * written into buf
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 81
diff changeset
39 * */
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
40
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
41 mDetails = QString::fromUtf8(buf, ret);
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
42
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
43 mShortDescription = mDetails; /* TODO */
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 mValid = true;
83
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
46
ba8a548ff252 Expand certificate class to make raw data accessible
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
47 mBaseLine = b64Line;
81
112228bd7e4b Remove platform specific certificate immplementations.
Andre Heinecke <aheinecke@intevation.de>
parents: 78
diff changeset
48 }

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