2013-10-11 13:51:04 +00:00
|
|
|
/*! @file
|
|
|
|
|
|
|
|
@id $Id$
|
|
|
|
*/
|
|
|
|
// 1 2 3 4 5 6 7 8
|
|
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
|
2013-11-06 12:24:52 +00:00
|
|
|
#include <suisse-id-demo.hxx>
|
2013-10-21 07:10:46 +00:00
|
|
|
#include <mrw/args.hxx>
|
2013-10-11 13:51:04 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) try {
|
|
|
|
std::string lib("libcvP11.so");
|
|
|
|
mrw::args::parse(argc, argv,
|
|
|
|
"Sign a text (optionally several times for performance"
|
|
|
|
" measurements).",
|
2013-10-21 12:13:55 +00:00
|
|
|
mrw::args::defaults()
|
2013-10-11 13:51:04 +00:00
|
|
|
<<mrw::args::decl("l", "library", "cryptoki lirary to load",
|
|
|
|
mrw::args::decl::param_list()
|
|
|
|
<<mrw::args::param(lib, "lib")));
|
|
|
|
|
2013-10-21 07:10:46 +00:00
|
|
|
suisseid::Cards cards(suisseid::Scanner(lib).scan());
|
2013-11-06 12:24:52 +00:00
|
|
|
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;
|
|
|
|
cryptoki::Session session((*card)->slot());
|
|
|
|
cryptoki::Session::Info info(session.getsessioninfo());
|
|
|
|
std::cout<<" Session:"<<std::endl
|
|
|
|
<<" Slot: "<<info.slotID<<std::endl
|
|
|
|
<<" State: "<<session.state(info)<<std::endl
|
|
|
|
<<" Flags: "<<((info.flags|CKF_RW_SESSION)
|
|
|
|
?"read/write":"read only")<<std::endl
|
|
|
|
<<" Device Error: "<<info.ulDeviceError<<std::endl;
|
|
|
|
cryptoki::ObjectList certs
|
|
|
|
(session.find(cryptoki::Attribute(CKA_CLASS)
|
|
|
|
.from<CK_OBJECT_CLASS>(CKO_CERTIFICATE)));
|
|
|
|
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
|
|
|
|
<<" q: quit"<<std::endl;
|
|
|
|
std::cin>>choice;
|
|
|
|
try {
|
|
|
|
if (choice=="n") { // handled above in the while-loop
|
|
|
|
} else if (choice=="c") {
|
|
|
|
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") {
|
|
|
|
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") {
|
|
|
|
TextualCycle check(*card);
|
|
|
|
check.installCerts(true);
|
|
|
|
} else if (choice=="q") {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
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;
|
|
|
|
choice="n"; // proceed
|
|
|
|
}
|
|
|
|
}
|
2013-10-11 13:51:04 +00:00
|
|
|
return 0;
|
|
|
|
} catch (std::exception& x) {
|
2013-11-06 12:24:52 +00:00
|
|
|
std::cerr<<"**** ERROR: "<<x.what()<<std::endl;
|
2013-10-11 13:51:04 +00:00
|
|
|
}
|