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