Namespaces
Variants
Actions

Showing certificate details in Qt

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia N79, Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 3rd Edition FP2, S60 5th Edition

Article
Keywords: QSslCertificate, Certificate
Created: User:Kbwiki (14 Dec 2009)
Last edited: hamishwillee (11 Oct 2012)

Description

This article provides a way for a Qt application to display certificate information such as issuer info or expiry date.

Solution

The QSslCertificate class can be used to display the information of an X509 certificate. The type can be either DER or PEM. Required headers and module

 //QT += network
#include <QSslCertificate>
#include <QSslKey>

Displaying certificate information

 // Selecting a certificate from the file dialog
QString crtFilename = QFileDialog::getOpenFileName(this,QString()
,tr("Certificate Files (*.der *.pem)"));
QFile crtFile(crtFilename);
if(!crtFile.open(QIODevice::ReadOnly))
{
return ;
}
else
{
if(crtFilename.contains(".der"))
{
// Loading DER certificate
iCrt = new QSslCertificate(&crtFile,QSsl::Der);
}
else
{
// Loading PEM certificate
iCrt = new QSslCertificate(&crtFile,QSsl::Pem);
}
QStringList issuerInfo;
//Fetchin the issuer info
issuerInfo.append(iCrt->issuerInfo(QSslCertificate::Organization));
issuerInfo.append(iCrt->issuerInfo(QSslCertificate::CountryName));
issuerInfo.append(iCrt->issuerInfo(QSslCertificate::LocalityName));
//Fetching effective and expiry dates
QString effDate;
QString xDate;
effDate.append(iCrt->effectiveDate().toString());
xDate.append(iCrt->expiryDate().toString());
//Fetching the serial number
QString serial;
serial.append(iCrt->serialNumber());
//Checking whether the certificate is valid or not
bool isValid = iCrt-> isValid();
//Fetching the public key
QSslKey pubKey;
pubKey = iCrt->publicKey();
QString algo;
//Fetching the algorithm
if(pubKey.algorithm() == QSsl::Rsa)
{
algo.append("RSA");
}
else
{
algo.append("DSA");
}
}

Note

We can get a handle to the certificate using QSslCertificate::handle() to access extended information about the certificate.

This page was last modified on 11 October 2012, at 04:18.
108 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved