|
|
|
@ -11,7 +11,9 @@ |
|
|
|
|
#include <QtNetwork/QSslCertificate> |
|
|
|
|
#include <QtCore/QDateTime> |
|
|
|
|
|
|
|
|
|
// show certificate information
|
|
|
|
|
void show(const suisseid::Certificate& cert) { |
|
|
|
|
// makes use of qt library's certificate class
|
|
|
|
|
QSslCertificate c(QByteArray(cert.data(), cert.size()), QSsl::Der); |
|
|
|
|
std::cout<<"Certificate info: CN=" |
|
|
|
|
<<QString(c.subjectInfo(QSslCertificate::CommonName) |
|
|
|
@ -22,8 +24,9 @@ void show(const suisseid::Certificate& cert) { |
|
|
|
|
<<std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// call with option -h for help
|
|
|
|
|
int main(int argc, char** argv) try { |
|
|
|
|
std::string lib("libcvP11.so"); |
|
|
|
|
std::string lib("libcvP11.so"); // default pkcs#11/cryptoki library
|
|
|
|
|
mrw::args::parse(argc, argv, |
|
|
|
|
"Sign a text (optionally several times for performance" |
|
|
|
|
" measurements).", |
|
|
|
@ -31,7 +34,9 @@ int main(int argc, char** argv) try { |
|
|
|
|
<<mrw::args::decl("l", "library", "cryptoki lirary to load", |
|
|
|
|
mrw::args::decl::param_list() |
|
|
|
|
<<mrw::args::param(lib, "lib"))); |
|
|
|
|
// now lib contains the dynamic library to load
|
|
|
|
|
|
|
|
|
|
// scan for suisseid cards
|
|
|
|
|
suisseid::Cards cards(suisseid::Scanner(lib).scan()); |
|
|
|
|
for (suisseid::Cards::iterator card(cards.begin()); |
|
|
|
|
card!=cards.end(); ++card) { |
|
|
|
@ -68,10 +73,11 @@ int main(int argc, char** argv) try { |
|
|
|
|
<<" a: show authentication certificate"<<std::endl |
|
|
|
|
<<" d: show digital signature certificate"<<std::endl |
|
|
|
|
<<" q: quit"<<std::endl; |
|
|
|
|
std::cin>>choice; |
|
|
|
|
std::cin>>choice; // small user menu
|
|
|
|
|
try { |
|
|
|
|
if (choice=="n") { // handled above in the while-loop
|
|
|
|
|
} else if (choice=="c") { |
|
|
|
|
// run a check of the card status
|
|
|
|
|
TextualCycle check(*card); |
|
|
|
|
if (check.run()) |
|
|
|
|
std::cout<<"----> SuisseID is fine"<<std::endl; |
|
|
|
@ -80,6 +86,7 @@ int main(int argc, char** argv) try { |
|
|
|
|
} else if (choice=="r") { |
|
|
|
|
std::cout<<"Not yet implemented."<<std::endl; |
|
|
|
|
} else if (choice=="p") { |
|
|
|
|
// change card pins
|
|
|
|
|
std::string oldpin, newpin; |
|
|
|
|
std::cout<<"Enter Old PIN: "; |
|
|
|
|
std::cin>>oldpin; |
|
|
|
@ -88,20 +95,26 @@ int main(int argc, char** argv) try { |
|
|
|
|
if (oldpin.size() && newpin.size()) |
|
|
|
|
(*card)->changePins(newpin, oldpin); |
|
|
|
|
} else if (choice=="i") { |
|
|
|
|
// install new certificates - not fully implemented
|
|
|
|
|
TextualCycle check(*card); |
|
|
|
|
check.installCerts(true); |
|
|
|
|
} else if (choice=="z") { |
|
|
|
|
// show all certificates on the card
|
|
|
|
|
for (suisseid::Certificates::iterator cert(certs.begin()); |
|
|
|
|
cert!=certs.end(); ++cert) { |
|
|
|
|
show(*cert); |
|
|
|
|
} |
|
|
|
|
} else if (choice=="a") { |
|
|
|
|
// show authentication certificate only
|
|
|
|
|
show((*card)->authenticationCertificate()); |
|
|
|
|
} else if (choice=="d") { |
|
|
|
|
// show authentication certificate only
|
|
|
|
|
show((*card)->digitalSignatureCertificate()); |
|
|
|
|
} else if (choice=="q") { |
|
|
|
|
// done, user quits
|
|
|
|
|
return 0; |
|
|
|
|
} else { |
|
|
|
|
// unknown user command
|
|
|
|
|
std::cout<<"I beg your pardon, Sir?"<<std::endl; |
|
|
|
|
} |
|
|
|
|
} catch (const std::exception& x) { |
|
|
|
@ -109,7 +122,7 @@ int main(int argc, char** argv) try { |
|
|
|
|
} |
|
|
|
|
} catch (std::exception& x) { |
|
|
|
|
std::cerr<<"**** ERROR: "<<x.what()<<std::endl; |
|
|
|
|
choice="n"; // proceed
|
|
|
|
|
choice="n"; // proceed to next card
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|