• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE Support
  • Sitemap
  • Contact Us
 

qca

certviewdlg.cpp

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2007 Justin Karneges <justin@affinix.com>
00003 
00004  Permission is hereby granted, free of charge, to any person obtaining a copy
00005  of this software and associated documentation files (the "Software"), to deal
00006  in the Software without restriction, including without limitation the rights
00007  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  copies of the Software, and to permit persons to whom the Software is
00009  furnished to do so, subject to the following conditions:
00010 
00011  The above copyright notice and this permission notice shall be included in
00012  all copies or substantial portions of the Software.
00013 
00014  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00017  AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00018  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00019  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020 */
00021 
00022 #include "certviewdlg.h"
00023 
00024 #include <QtCore>
00025 #include <QtGui>
00026 #include <QtCrypto>
00027 #include "ui_certview.h"
00028 
00029 // from qcatool
00030 class InfoType
00031 {
00032 public:
00033     QCA::CertificateInfoType type;
00034     QString varname;
00035     QString shortname;
00036     QString name;
00037     QString desc;
00038 
00039     InfoType()
00040     {
00041     }
00042 
00043     InfoType(QCA::CertificateInfoType _type, const QString &_varname, const QString &_shortname, const QString &_name, const QString &_desc) :
00044         type(_type),
00045         varname(_varname),
00046         shortname(_shortname),
00047         name(_name),
00048         desc(_desc)
00049     {
00050     }
00051 };
00052 
00053 static QList<InfoType> makeInfoTypeList(bool legacyEmail = false)
00054 {
00055     QList<InfoType> out;
00056     out += InfoType(QCA::CommonName,             "CommonName",             "CN",  CertViewDlg::tr("Common Name (CN)"),          "Full name, domain, anything");
00057     out += InfoType(QCA::Email,                  "Email",                  "",    CertViewDlg::tr("Email Address"),             "");
00058     if(legacyEmail)
00059         out += InfoType(QCA::EmailLegacy,            "EmailLegacy",       "",    CertViewDlg::tr("PKCS#9 Email Address"),      "");
00060     out += InfoType(QCA::Organization,           "Organization",           "O",   CertViewDlg::tr("Organization (O)"),          "Company, group, etc");
00061     out += InfoType(QCA::OrganizationalUnit,     "OrganizationalUnit",     "OU",  CertViewDlg::tr("Organizational Unit (OU)"),  "Division/branch of organization");
00062     out += InfoType(QCA::Locality,               "Locality",               "",    CertViewDlg::tr("Locality (L)"),              "City, shire, part of a state");
00063     out += InfoType(QCA::State,                  "State",                  "",    CertViewDlg::tr("State (ST)"),                "State within the country");
00064     out += InfoType(QCA::Country,                "Country",                "C",   CertViewDlg::tr("Country Code (C)"),          "2-letter code");
00065     out += InfoType(QCA::IncorporationLocality,  "IncorporationLocality",  "",    CertViewDlg::tr("Incorporation Locality"),    "For EV certificates");
00066     out += InfoType(QCA::IncorporationState,     "IncorporationState",     "",    CertViewDlg::tr("Incorporation State"),       "For EV certificates");
00067     out += InfoType(QCA::IncorporationCountry,   "IncorporationCountry",   "",    CertViewDlg::tr("Incorporation Country"),     "For EV certificates");
00068     out += InfoType(QCA::URI,                    "URI",                    "",    CertViewDlg::tr("URI"),                       "");
00069     out += InfoType(QCA::DNS,                    "DNS",                    "",    CertViewDlg::tr("Domain Name"),               "Domain (dnsName)");
00070     out += InfoType(QCA::IPAddress,              "IPAddress",              "",    CertViewDlg::tr("IP Adddress"),               "");
00071     out += InfoType(QCA::XMPP,                   "XMPP",                   "",    CertViewDlg::tr("XMPP Address (JID)"),        "From RFC 3920 (id-on-xmppAddr)");
00072     return out;
00073 }
00074 
00075 static QString try_print_info(const QString &name, const QStringList &values)
00076 {
00077     QString out;
00078     if(!values.isEmpty())
00079     {
00080         QString value = values.join(", ");
00081         out = QString("   ") + CertViewDlg::tr("%1: %2").arg(name, value) + '\n';
00082     }
00083     return out;
00084 }
00085 
00086 static QString print_info(const QString &title, const QCA::CertificateInfo &info)
00087 {
00088     QString out;
00089     QList<InfoType> list = makeInfoTypeList();
00090     out += title + '\n';
00091     foreach(const InfoType &t, list)
00092         out += try_print_info(t.name, info.values(t.type));
00093     return out;
00094 }
00095 
00096 static QString cert_info_string(const QCA::Certificate &cert)
00097 {
00098     QString out;
00099     out += CertViewDlg::tr("Serial Number: %1").arg(cert.serialNumber().toString()) + '\n';
00100     out += print_info(CertViewDlg::tr("Subject"), cert.subjectInfo());
00101     out += print_info(CertViewDlg::tr("Issuer"), cert.issuerInfo());
00102     out += CertViewDlg::tr("Validity") + '\n';
00103     out += QString("   ") + CertViewDlg::tr("Not before: %1").arg(cert.notValidBefore().toString()) + '\n';
00104     out += QString("   ") + CertViewDlg::tr("Not after:  %1").arg(cert.notValidAfter().toString()) + '\n';
00105     return out;
00106 }
00107 
00108 class CertViewDlg::Private : public QObject
00109 {
00110     Q_OBJECT
00111 public:
00112     CertViewDlg *q;
00113     Ui_CertView ui;
00114     QCA::CertificateChain chain;
00115 
00116     Private(CertViewDlg *_q) :
00117         QObject(_q),
00118         q(_q)
00119     {
00120         ui.setupUi(q);
00121         connect(ui.cb_chain, SIGNAL(activated(int)), SLOT(cb_activated(int)));
00122         ui.lb_info->setTextInteractionFlags(Qt::TextSelectableByMouse);
00123     }
00124 
00125     void update()
00126     {
00127         QStringList names = QCA::makeFriendlyNames(chain);
00128         ui.cb_chain->clear();
00129         foreach(const QString &s, names)
00130             ui.cb_chain->insertItem(ui.cb_chain->count(), s);
00131         updateInfo();
00132     }
00133 
00134     void updateInfo()
00135     {
00136         int x = ui.cb_chain->currentIndex();
00137         if(x == -1)
00138         {
00139             ui.lb_info->setText("");
00140             return;
00141         }
00142 
00143         ui.lb_info->setText(cert_info_string(chain[x]));
00144     }
00145 
00146 private slots:
00147     void cb_activated(int)
00148     {
00149         updateInfo();
00150     }
00151 };
00152 
00153 CertViewDlg::CertViewDlg(const QCA::CertificateChain &chain, QWidget *parent) :
00154     QDialog(parent)
00155 {
00156     d = new Private(this);
00157     d->chain = chain;
00158     d->update();
00159 }
00160 
00161 CertViewDlg::~CertViewDlg()
00162 {
00163     delete d;
00164 }
00165 
00166 #include "certviewdlg.moc"

qca

Skip menu "qca"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE Support

Skip menu "KDE Support"
  • akonadi
  • Decibel
  • grantlee
  • kdewin
  • phonon
  •     Backend
  • polkit-qt
  • qca
  • qimageblitz
  • soprano
  • strigi
  •     searchclient
  •     streamanalyzer
  •     streams
Generated for KDE Support by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal