LeechCraft  0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
sslerror2treeitem.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "sslerror2treeitem.h"
31 #include <QStringList>
32 #include <QDateTime>
33 #include <QTreeWidgetItem>
34 #include <QSslError>
35 
36 namespace LeechCraft
37 {
38 namespace Util
39 {
40  QTreeWidgetItem* SslError2TreeItem (const QSslError& error)
41  {
42  const auto item = new QTreeWidgetItem { { "Error:", error.errorString () } };
43 
44  const auto& cer = error.certificate ();
45  if (cer.isNull ())
46  {
47  new QTreeWidgetItem
48  {
49  item,
50  { QObject::tr ("Certificate"), QObject::tr ("(No certificate available for this error)") }
51  };
52  return item;
53  }
54 
55  new QTreeWidgetItem
56  {
57  item,
58  {
59  QObject::tr ("Valid:"),
60  !cer.isBlacklisted () ? QObject::tr ("yes") : QObject::tr ("no")
61  }
62  };
63  new QTreeWidgetItem { item, { QObject::tr ("Effective date:"), cer.effectiveDate ().toString () } };
64  new QTreeWidgetItem { item, { QObject::tr ("Expiry date:"), cer.expiryDate ().toString () } };
65  new QTreeWidgetItem { item, { QObject::tr ("Version:"), cer.version () } };
66  new QTreeWidgetItem { item, { QObject::tr ("Serial number:"), cer.serialNumber () } };
67  new QTreeWidgetItem { item, { QObject::tr ("MD5 digest:"), cer.digest ().toHex () } };
68  new QTreeWidgetItem { item, { QObject::tr ("SHA1 digest:"), cer.digest (QCryptographicHash::Sha1).toHex () } };
69 
70  QString tmpString;
71  auto cvt = [] (const QStringList& list) { return list.join ("; "); };
72 
73  const auto issuer = new QTreeWidgetItem { item, { QObject::tr ("Issuer info") } };
74  auto mkIssuerItem = [&cvt, &cer, issuer] (const QString& name,
75  QSslCertificate::SubjectInfo field)
76  {
77  const auto& value = cvt (cer.issuerInfo (field));
78  if (!value.isEmpty ())
79  new QTreeWidgetItem { issuer, { name, value } };
80  };
81 
82  mkIssuerItem (QObject::tr ("Organization:"), QSslCertificate::Organization);
83  mkIssuerItem (QObject::tr ("Common name:"), QSslCertificate::CommonName);
84  mkIssuerItem (QObject::tr ("Locality:"), QSslCertificate::LocalityName);
85  mkIssuerItem (QObject::tr ("Organizational unit name:"), QSslCertificate::OrganizationalUnitName);
86  mkIssuerItem (QObject::tr ("Country name:"), QSslCertificate::CountryName);
87  mkIssuerItem (QObject::tr ("State or province name:"), QSslCertificate::StateOrProvinceName);
88 
89  const auto subject = new QTreeWidgetItem { item, { QObject::tr ("Subject info") } };
90  auto mkSubjectItem = [&cvt, &cer, subject] (const QString& name,
91  QSslCertificate::SubjectInfo field)
92  {
93  const auto& value = cvt (cer.subjectInfo (field));
94  if (!value.isEmpty ())
95  new QTreeWidgetItem { subject, { name, value } };
96  };
97 
98  mkSubjectItem (QObject::tr ("Organization:"), QSslCertificate::Organization);
99  mkSubjectItem (QObject::tr ("Common name:"), QSslCertificate::CommonName);
100  mkSubjectItem (QObject::tr ("Locality:"), QSslCertificate::LocalityName);
101  mkSubjectItem (QObject::tr ("Organizational unit name:"), QSslCertificate::OrganizationalUnitName);
102  mkSubjectItem (QObject::tr ("Country name:"), QSslCertificate::CountryName);
103  mkSubjectItem (QObject::tr ("State or province name:"), QSslCertificate::StateOrProvinceName);
104 
105  return item;
106  }
107 }
108 }
QTreeWidgetItem * SslError2TreeItem(const QSslError &error)
Builds a tree widget representation of the given SSL error.