This library provides a simple and nice C++ wrapper around these libraries, so that programmers can concentrate on functionality. It offers general support for PCSC-lite, OpenSSL, PKCS#11, plus specific functionality for the SuisseID.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
5.7 KiB
140 lines
5.7 KiB
11 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
11 years ago
|
#include <suisse-id-demo.hxx>
|
||
11 years ago
|
#include <mrw/args.hxx>
|
||
11 years ago
|
|
||
11 years ago
|
#include <QtNetwork/QSslCertificate>
|
||
|
#include <QtCore/QDateTime>
|
||
11 years ago
|
#include <QtCore/QStringList>
|
||
|
|
||
|
void show(const QString& s, const std::string& p="item: ") {
|
||
|
std::cout<<p<<QString(s.toUtf8()).toStdString()<<std::endl;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
void show(const QStringList& sl, const std::string& p="item: ") {
|
||
|
for (QStringList::const_iterator s(sl.begin()); s!=sl.end(); ++s)
|
||
|
std::cout<<p<<QString(s->toUtf8()).toStdString()<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// show certificate information
|
||
11 years ago
|
void show(const suisseid::Certificate& cert) {
|
||
11 years ago
|
// makes use of qt library's certificate class
|
||
11 years ago
|
QSslCertificate c(QByteArray(cert.data(), cert.size()), QSsl::Der);
|
||
11 years ago
|
std::cout<<"Certificate info:";
|
||
|
show(c.subjectInfo(QSslCertificate::CommonName), " CN=");
|
||
|
std::cout<<" Valid until: "
|
||
11 years ago
|
<<QString(c.expiryDate().toString().toUtf8()).toStdString()
|
||
|
<<std::endl;
|
||
|
}
|
||
|
|
||
11 years ago
|
// call with option -h for help
|
||
11 years ago
|
int main(int argc, char** argv) try {
|
||
11 years ago
|
std::string lib("libcvP11.so"); // default pkcs#11/cryptoki library
|
||
11 years ago
|
mrw::args::parse(argc, argv,
|
||
|
"Sign a text (optionally several times for performance"
|
||
|
" measurements).",
|
||
11 years ago
|
mrw::args::defaults()
|
||
11 years ago
|
<<mrw::args::decl("l", "library", "cryptoki library to load",
|
||
11 years ago
|
mrw::args::decl::param_list()
|
||
|
<<mrw::args::param(lib, "lib")));
|
||
11 years ago
|
// now lib contains the dynamic library to load
|
||
11 years ago
|
|
||
11 years ago
|
// scan for suisseid cards
|
||
11 years ago
|
suisseid::Cards cards(suisseid::Scanner(lib).scan());
|
||
11 years ago
|
for (suisseid::Cards::iterator card(cards.begin());
|
||
|
card!=cards.end(); ++card) {
|
||
|
std::string choice;
|
||
|
while (choice!="n") try {
|
||
|
std::cout<<"=================================================="<<std::endl
|
||
|
<<"Found SuisseID:"<<std::endl
|
||
|
<<" Reader Name: "<<(*card)->name()<<std::endl
|
||
|
<<" Version: "<<(*card)->version()<<std::endl
|
||
|
<<" PIN-Length: "<<(*card)->minimalPinLength()
|
||
|
<<" - "<<(*card)->maximalPinLength()<<std::endl
|
||
|
<<" PIN retries:"<<std::endl
|
||
|
<<" PKCS#15: "<<(*card)->pkcs15PinRetries()<<std::endl
|
||
|
<<" SigG: "<<(*card)->sigGPinRetries()<<std::endl
|
||
|
<<" Transport: "<<(*card)->transportPinRetries()<<std::endl
|
||
|
<<" PUK: "<<(*card)->pukRetries()<<std::endl;
|
||
11 years ago
|
cryptoki::Session::Info info((*card)->sessionInfo());
|
||
11 years ago
|
std::cout<<" Session:"<<std::endl
|
||
|
<<" Slot: "<<info.slotID<<std::endl
|
||
11 years ago
|
<<" State: "<<info.stateString()<<std::endl
|
||
|
<<" Flags: "<<(info.readwrite()
|
||
11 years ago
|
?"read/write":"read only")<<std::endl
|
||
|
<<" Device Error: "<<info.ulDeviceError<<std::endl;
|
||
11 years ago
|
suisseid::Certificates certs((*card)->certificates());
|
||
11 years ago
|
std::cout<<" Certificates: "<<certs.size()<<std::endl;
|
||
|
std::cout<<"--------------------------------------------------"<<std::endl
|
||
|
<<"Your Order Sir:"<<std::endl
|
||
|
<<" n: proceed to next card"<<std::endl
|
||
|
<<" c: check this card"<<std::endl
|
||
|
<<" r: remove all certificates"<<std::endl
|
||
|
<<" p: PIN change"<<std::endl
|
||
|
<<" i: (re-) import certificates"<<std::endl
|
||
11 years ago
|
<<" z: show certificates"<<std::endl
|
||
11 years ago
|
<<" a: show authentication certificate"<<std::endl
|
||
|
<<" d: show digital signature certificate"<<std::endl
|
||
11 years ago
|
<<" q: quit"<<std::endl;
|
||
11 years ago
|
std::cin>>choice; // small user menu
|
||
11 years ago
|
try {
|
||
|
if (choice=="n") { // handled above in the while-loop
|
||
|
} else if (choice=="c") {
|
||
11 years ago
|
// run a check of the card status
|
||
11 years ago
|
TextualCycle check(*card);
|
||
|
if (check.run())
|
||
|
std::cout<<"----> SuisseID is fine"<<std::endl;
|
||
|
else
|
||
|
std::cout<<"****> SuisseID is bad"<<std::endl;
|
||
|
} else if (choice=="r") {
|
||
|
std::cout<<"Not yet implemented."<<std::endl;
|
||
|
} else if (choice=="p") {
|
||
11 years ago
|
// change card pins
|
||
11 years ago
|
std::string oldpin, newpin;
|
||
|
std::cout<<"Enter Old PIN: ";
|
||
|
std::cin>>oldpin;
|
||
|
std::cout<<"Enter New PIN: ";
|
||
|
std::cin>>newpin;
|
||
|
if (oldpin.size() && newpin.size())
|
||
|
(*card)->changePins(newpin, oldpin);
|
||
|
} else if (choice=="i") {
|
||
11 years ago
|
// install new certificates - not fully implemented
|
||
11 years ago
|
TextualCycle check(*card);
|
||
|
check.installCerts(true);
|
||
11 years ago
|
} else if (choice=="z") {
|
||
11 years ago
|
// show all certificates on the card
|
||
11 years ago
|
for (suisseid::Certificates::iterator cert(certs.begin());
|
||
11 years ago
|
cert!=certs.end(); ++cert) {
|
||
11 years ago
|
show(*cert);
|
||
11 years ago
|
}
|
||
11 years ago
|
} else if (choice=="a") {
|
||
11 years ago
|
// show authentication certificate only
|
||
11 years ago
|
show((*card)->authenticationCertificate());
|
||
|
} else if (choice=="d") {
|
||
11 years ago
|
// show authentication certificate only
|
||
11 years ago
|
show((*card)->digitalSignatureCertificate());
|
||
11 years ago
|
} else if (choice=="q") {
|
||
11 years ago
|
// done, user quits
|
||
11 years ago
|
return 0;
|
||
|
} else {
|
||
11 years ago
|
// unknown user command
|
||
11 years ago
|
std::cout<<"I beg your pardon, Sir?"<<std::endl;
|
||
|
}
|
||
|
} catch (const std::exception& x) {
|
||
|
std::cerr<<"**** ERROR: "<<x.what()<<std::endl;
|
||
|
}
|
||
|
} catch (std::exception& x) {
|
||
|
std::cerr<<"**** ERROR: "<<x.what()<<std::endl;
|
||
11 years ago
|
choice="n"; // proceed to next card
|
||
11 years ago
|
}
|
||
|
}
|
||
11 years ago
|
return 0;
|
||
|
} catch (std::exception& x) {
|
||
11 years ago
|
std::cerr<<"**** ERROR: "<<x.what()<<std::endl;
|
||
11 years ago
|
}
|