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.
 
 
 
 

72 lines
2.3 KiB

/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
// #include <pcsc.hxx>
// #include <cryptaux.hxx>
// #include <openssl.hxx>
#include <cardos.hxx>
#include <mrw/vector.hxx>
#include <mrw/args.hxx>
#include <string>
#include <memory>
#include <cctype>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
pcsc::Connection c;
pcsc::Connection::Strings readers;
void list() {
pcsc::Connection c;
pcsc::Connection::Strings readers(c.scan());
std::cout<<"Found "<<readers.size()<<" readers"
<<(readers.size()?":":".")<<std::endl;
int i(0);
for (pcsc::Connection::Strings::iterator r(readers.begin());
r!=readers.end(); ++r, ++i)
std::cout<<i<<": "<<*r<<std::endl;
}
int main(int argc, char** argv) try {
int reader(0);
std::string path("3f005015");
mrw::args::parse(argc, argv, "Write data to card.",
mrw::args::defaults()
<<mrw::args::decl("l", "list", "list readers",
mrw::args::decl::param_list()
<<mrw::args::func(list)
<<mrw::args::exit())
<<mrw::args::decl("r", "reader", "select reader",
mrw::args::decl::param_list()
<<mrw::args::param(reader, "num"))
<<mrw::args::decl("p", "path", "full path",
mrw::args::decl::param_list()
<<mrw::args::param(path, "path"))
);
pcsc::Connection c;
pcsc::Connection::Strings readers(c.scan());
if (reader<0 || readers.size()<reader) {
std::cerr<<"reader not found: "<<reader<<std::endl;
return 1;
}
cardos::Commands cmd(c.reader(readers[reader]));
//cardos::BerValues d(cmd.directory(path));
//cardos::BerValues d(cmd.readBerFile(path));
//std::cout<<d.print()<<std::endl;
std::string res(cmd.readBinary(path));
std::cout<<"HEX:"<<std::endl<<crypto::readable(res)<<std::endl;
std::cout<<"BER:"<<std::endl<<cardos::BerValues(res).print()<<std::endl;
return 0;
} catch (std::exception& x) {
std::cerr<<"ERROR: "<<x.what()<<std::endl;
return 2;
}