2004-12-30 09:32:01 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Justin Karneges
|
2005-04-25 11:57:45 +00:00
|
|
|
Copyright (C) 2005 Brad Hards <bradh@frogmouth.net>
|
2004-12-30 09:32:01 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2003-09-17 00:53:41 +00:00
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
#include <QtCrypto>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
static void dumpCertificateInfo( QCA::CertificateInfo subject)
|
|
|
|
{
|
|
|
|
std::cout << " Common Name: " << std::endl;
|
|
|
|
QList<QString> commonNameList = subject.values(QCA::CommonName);
|
|
|
|
QString commonName;
|
|
|
|
foreach( commonName, commonNameList ) {
|
|
|
|
std::cout << " " << qPrintable(commonName) << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << " Organization: " << std::endl;
|
|
|
|
QList<QString> orgInfo = subject.values(QCA::Organization);
|
|
|
|
QString organization;
|
|
|
|
foreach( organization, orgInfo ) {
|
|
|
|
std::cout << " " << qPrintable(organization) << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << " Country: " << std::endl;
|
|
|
|
QList<QString> countryList = subject.values(QCA::Country);
|
|
|
|
QString country;
|
|
|
|
foreach( country, countryList ) {
|
|
|
|
std::cout << " " << qPrintable(country) << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpSubjectInfo( QCA::CertificateInfo subject)
|
2003-09-17 00:53:41 +00:00
|
|
|
{
|
2005-04-25 11:57:45 +00:00
|
|
|
std::cout << "Subject: " << std::endl;
|
|
|
|
|
|
|
|
dumpCertificateInfo( subject );
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
static void dumpIssuerInfo( QCA::CertificateInfo subject)
|
2003-09-17 00:53:41 +00:00
|
|
|
{
|
2005-04-25 11:57:45 +00:00
|
|
|
std::cout << "Issuer: " << std::endl;
|
|
|
|
|
|
|
|
dumpCertificateInfo( subject );
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
2003-09-17 00:53:41 +00:00
|
|
|
{
|
2005-04-25 11:57:45 +00:00
|
|
|
// the Initializer object sets things up, and
|
|
|
|
// also does cleanup when it goes out of scope
|
|
|
|
QCA::Initializer init;
|
2003-09-17 00:53:41 +00:00
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
// get all the available providers loaded.
|
|
|
|
QCA::scanForPlugins();
|
|
|
|
|
|
|
|
if ( !QCA::isSupported( "cert" ) ) {
|
|
|
|
std::cout << "Sorry, no PKI certificate support" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QCA::Certificate> certlist;
|
|
|
|
|
|
|
|
if (argc >= 2) {
|
|
|
|
std::cout << "Reading certificates from : " << argv[1] << std::endl;
|
|
|
|
QCA::CertificateCollection filecerts;
|
|
|
|
QCA::ConvertResult importResult;
|
|
|
|
filecerts = QCA::CertificateCollection::fromPKCS7File( argv[1], &importResult );
|
|
|
|
if ( QCA::ConvertGood == importResult) {
|
|
|
|
std::cout << "Import succeeded" << std::endl;
|
|
|
|
certlist == filecerts.certificates();
|
|
|
|
} else {
|
|
|
|
std::cout << "Import failed" << std::endl;
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
2005-04-25 11:57:45 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if ( !QCA::haveSystemStore() ) {
|
|
|
|
std::cout << "System certificates not available" << std::endl;
|
|
|
|
return 2;
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
2005-04-25 11:57:45 +00:00
|
|
|
|
|
|
|
QCA::CertificateCollection systemcerts = QCA::systemStore();
|
|
|
|
|
|
|
|
certlist = systemcerts.certificates();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::Certificate cert;
|
|
|
|
foreach (cert, certlist) {
|
|
|
|
std::cout << "Serial Number:";
|
|
|
|
std::cout << qPrintable(cert.serialNumber().toString()) << std::endl;
|
|
|
|
|
|
|
|
dumpSubjectInfo( cert.subjectInfo() );
|
|
|
|
|
|
|
|
dumpIssuerInfo( cert.issuerInfo() );
|
|
|
|
|
|
|
|
if ( cert.isCA() ) {
|
|
|
|
std::cout << "Is certificate authority" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << "Is not a certificate authority" << std::endl;
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
if (cert.isSelfSigned() ) {
|
|
|
|
std::cout << "Self signed" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << "Is not self-signed!!!" << std::endl;
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
|
|
|
|
2005-04-25 11:57:45 +00:00
|
|
|
std::cout << "Valid from " << qPrintable(cert.notValidBefore().toString());
|
|
|
|
std::cout << ", until " << qPrintable(cert.notValidAfter().toString());
|
|
|
|
//std::cout << std::endl;
|
|
|
|
//std::cout << "PEM:" << std::endl;
|
|
|
|
//std::cout << qPrintable(cert.toPEM());
|
|
|
|
std::cout << std::endl << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2003-09-17 00:53:41 +00:00
|
|
|
}
|
|
|
|
|