completely new, megacool build system step 1
This commit is contained in:
		| @@ -660,7 +660,7 @@ WARN_LOGFILE           = doxygen.errors | ||||
| # directories like "/usr/src/myproject". Separate the files or directories  | ||||
| # with spaces. | ||||
|  | ||||
| INPUT                  = @SRCDIR@/../src | ||||
| INPUT                  = @top_srcdir@/src | ||||
|  | ||||
| # This tag can be used to specify the character encoding of the source files  | ||||
| # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is  | ||||
| @@ -723,7 +723,7 @@ EXCLUDE_SYMBOLS        = | ||||
| # directories that contain example code fragments that are included (see  | ||||
| # the \include command). | ||||
|  | ||||
| EXAMPLE_PATH           = examples | ||||
| EXAMPLE_PATH           = @top_srcdir@/examples | ||||
|  | ||||
| # If the value of the EXAMPLE_PATH tag contains directories, you can use the  | ||||
| # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp  | ||||
| @@ -1220,7 +1220,7 @@ SERVER_BASED_SEARCH    = NO | ||||
| # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will  | ||||
| # generate Latex output. | ||||
|  | ||||
| GENERATE_LATEX         = YES | ||||
| GENERATE_LATEX         = NO | ||||
|  | ||||
| # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.  | ||||
| # If a relative path is entered the value of OUTPUT_DIRECTORY will be  | ||||
|   | ||||
| @@ -1,165 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| // #include <pcsc.hxx> | ||||
| // #include <cryptaux.hxx> | ||||
| // #include <openssl.hxx> | ||||
|  | ||||
| #include <string> | ||||
| #include <mrw/checkcxx11.hxx> | ||||
| #include <memory> | ||||
| #include <cctype> | ||||
| #include <stdexcept> | ||||
| #include <sstream> | ||||
| #include <iostream> | ||||
| #include <iomanip> | ||||
|  | ||||
| #define CARDOS_LOG(X) std::cout<<X<<std::endl | ||||
| #include <cardos.hxx> | ||||
|  | ||||
| class Commands: public cardos::Commands { | ||||
|      | ||||
|   public: | ||||
|  | ||||
|     void help() { | ||||
|       std::cout | ||||
|         <<"Commands: "<<std::endl | ||||
|         <<"  COMMAND              DATA  PURPOSE"<<std::endl | ||||
|         <<"  (h)elp                     Show this help"<<std::endl | ||||
|         <<"  (q)quit                    Quit"<<std::endl | ||||
|         <<"  (l)ist                     List all reader"<<std::endl | ||||
|         <<"  (r)eader             <num> Select reader by number"<<std::endl | ||||
|         <<"  (s)erial                   Show token serial number"<<std::endl | ||||
|         <<"  (a)pdu               <hex> Send APDU hex data"<<std::endl | ||||
|         <<"  (m)aster(f)ile             Select master file"<<std::endl | ||||
|         <<"  (p)kcs(15)                 Select PKCS#15 file"<<std::endl | ||||
|         <<"  (s)ig(g)                   Select SigG file"<<std::endl | ||||
|         <<"  (s)elect(f)ile       <hex> Select file below master"<<std::endl | ||||
|         <<"  (s)elect(p)15(f)ile  <hex> Select file below PKCS#15"<<std::endl | ||||
|         <<"  (s)elect(s)igg(f)ile <hex> Select file below SigG"<<std::endl | ||||
|         <<"  (r)ead(b)erfile            Read selected BER file"<<std::endl | ||||
|         <<"  (r)ead(b)in(f)ile          Read selected binary file"<<std::endl | ||||
|         <<"  (r)ead(a)bsolute(r)ecord   Read absolute record"<<std::endl | ||||
|         <<"  (r)ead(f)irst(r)ecord      Read first record"<<std::endl | ||||
|         <<"  (r)ead(n)ext(r)ecord       Read next record"<<std::endl | ||||
|         <<"  (p)in(s)status       <id>  Query status of PIN <id>"<<std::endl | ||||
|         <<"  (l)ogon         <id> <pin> logon to key with PIN"<<std::endl | ||||
|         <<"  (l)ogon(p)15         <pin> logon with user PIN"<<std::endl | ||||
|         <<"  (l)ogonpu(k)         <pin> logon with user PUK"<<std::endl | ||||
|         <<"  (l)ogon(s)igg        <pin> logon with SigG PIN"<<std::endl | ||||
|         <<"  (l)ogon(t)transport  <pin> logon with transport PIN"<<std::endl | ||||
|         <<"  (g)et(p)in(l)engths       get PIN min max lengths"<<std::endl | ||||
|         <<"Note: \"(h)elp\" means: type \"help\" or simply \"h\""<<std::endl; | ||||
|     } | ||||
|  | ||||
|     int run() { | ||||
|       std::string cmd; | ||||
|       while (std::cout<<"cmd> ", std::cin>>cmd) try { | ||||
|           if (cmd=="help"||cmd=="h") help(); | ||||
|           else if (cmd=="quit"||cmd=="q") return 0; | ||||
|           else if (cmd=="list"||cmd=="l") listReader(); | ||||
|           else if (cmd=="reader"||cmd=="r") selectReader(); | ||||
|           else if (cmd=="serial"||cmd=="s") serial(); | ||||
|           else if (cmd=="apdu"||cmd=="a") sendAPDU(apdu()); | ||||
|           else if (cmd=="masterfile"||cmd=="mf") selectMF(); | ||||
|           else if (cmd=="pkcs15"||cmd=="p15") selectPkcs15(); | ||||
|           else if (cmd=="sigg"||cmd=="sg") selectSigG(); | ||||
|           else if (cmd=="selectfile"||cmd=="sf") selectMfFile(apdu()); | ||||
|           else if (cmd=="selectp15file"||cmd=="spf") selectPkcs15File(apdu()); | ||||
|           else if (cmd=="selectsiggfile"||cmd=="ssf") selectSigGFile(apdu()); | ||||
|           else if (cmd=="readberfile"||cmd=="rb") _ber=readBerFile(); | ||||
|           else if (cmd=="readbinfile"||cmd=="rbf") readBinary(); | ||||
|           else if (cmd=="readabsoluterecord"||cmd=="rar") _ber=readRecord(); | ||||
|           else if (cmd=="readfirstrecord"||cmd=="rfr") | ||||
|             _ber=readRecord(0, 0, FIRST_RECORD); | ||||
|           else if (cmd=="readnextrecord"||cmd=="rnr") | ||||
|             _ber=readRecord(0, 0, NEXT_RECORD); | ||||
|           else if (cmd=="pinstatus"||cmd=="ps") pinStatus(id()); | ||||
|           else if (cmd=="logon"||cmd=="l") logon(id(), pin()); | ||||
|           else if (cmd=="logonp15"||cmd=="lp") logonPkcs15(pin()); | ||||
|           else if (cmd=="logonppuk"||cmd=="lk") logonPuk(pin()); | ||||
|           else if (cmd=="logonsigg"||cmd=="ls") logonSigG(pin()); | ||||
|           else if (cmd=="logontransport"||cmd=="lt") logonTransport(pin()); | ||||
|           else if (cmd=="getpinlengths"||cmd=="gpl") getPinLengths(); | ||||
|           else if (cmd=="print"||cmd=="p") std::cout<<_ber.print()<<std::endl; | ||||
|           else help(); | ||||
|         } catch (const std::exception& e) { | ||||
|           std::cout<<"**** Error: "<<e.what()<<std::endl; | ||||
|         } | ||||
|       return 0; | ||||
|     } | ||||
|  | ||||
|     void listReader() { | ||||
|       _readers = pcsc::Connection::scan(); | ||||
|       std::cout<<"Found "<<_readers.size()<<" readers" | ||||
|                <<(_readers.size()?":":".")<<std::endl; | ||||
|       int i(0); | ||||
|       for (pcsc::Connection::Strings::const_iterator it(_readers.begin()); | ||||
|            it!=_readers.end(); ++it, ++i) | ||||
|         std::cout<<"  "<<i<<". "<<*it<<std::endl; | ||||
|     } | ||||
|  | ||||
|     void selectReader() { | ||||
|       listReader(); | ||||
|       pcsc::Connection::Strings::size_type num(0); | ||||
|       if (std::cin>>num && num<_readers.size()) { | ||||
|         _reader = pcsc::Connection::reader(_readers[num]); | ||||
|         std::cout<<"Active Reader: "<<_readers[num]<<std::endl; | ||||
|       } else throw std::runtime_error("no valid reader selected"); | ||||
|     } | ||||
|      | ||||
|     void getPinLengths() { | ||||
|       selectPkcs15File("4408"); | ||||
|       _ber.clear(); | ||||
|       while (true) { | ||||
|         std::string res(send(0x00, 0xB2, 0, NEXT_RECORD)); | ||||
|         if (cardos::Commands::retCode(res)!=0x9000) break; | ||||
|         cardos::BerValues record(cardos::Commands::retData(res).substr(2)); | ||||
|         _ber += record; | ||||
|         std::cout<<record[0][0][0].string() | ||||
|                  <<": len=" | ||||
|                  <<record[0][2][0][2].ulong() | ||||
|                  <<"-"<<record[0][2][0][4].ulong()<<std::endl; | ||||
|       } | ||||
|     } | ||||
|          | ||||
|   private: | ||||
|  | ||||
|     std::string apdu() { | ||||
|       std::string data; | ||||
|       if (!(std::cin>>data)) | ||||
|         throw std::runtime_error("please enter bytes in hex"); | ||||
|       return data; | ||||
|     } | ||||
|  | ||||
|     std::string pin() { | ||||
|       std::string data; | ||||
|       if (!(std::cin>>data)) | ||||
|         throw std::runtime_error("please enter pin"); | ||||
|       return data; | ||||
|     } | ||||
|  | ||||
|     unsigned char id() { | ||||
|       std::string data; | ||||
|       if (!(std::cin>>data) || data.size()!=2 || | ||||
|           data.find_first_not_of("0123456789abcdef")!=std::string::npos) | ||||
|         throw std::runtime_error("please enter one byte in hex"); | ||||
|       return crypto::hexToBin(data)[0]; | ||||
|     } | ||||
|  | ||||
|   private: | ||||
|      | ||||
|     pcsc::Connection::Strings _readers; | ||||
|  | ||||
|     cardos::BerValues _ber; | ||||
|  | ||||
| }; | ||||
|  | ||||
| int main(int, char**) { | ||||
|   std::cout<<"Type \"help\" for help."<<std::endl; | ||||
|   return Commands().run(); | ||||
| } | ||||
| @@ -1,90 +0,0 @@ | ||||
| /*! @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 <mrw/checkcxx11.hxx> | ||||
| #include <memory> | ||||
| #include <cctype> | ||||
| #include <stdexcept> | ||||
| #include <sstream> | ||||
| #include <iostream> | ||||
| #include <iomanip> | ||||
|  | ||||
| void list() { | ||||
|   pcsc::Connection::Strings readers(pcsc::Connection::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 { | ||||
|   unsigned int reader(0); | ||||
|   std::string pin; | ||||
|   std::string path("3f00"); | ||||
|   std::string id("8888"); | ||||
|   std::string data("Hallo Welt"); | ||||
|   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")) | ||||
|                    <<mrw::args::decl("l", "pin", "full path", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(path, "path")) | ||||
|                    <<mrw::args::decl("i", "id", "file id", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(id, "file")) | ||||
|                    <<mrw::args::decl("d", "data", "data", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(data, "text")) | ||||
|                    ); | ||||
|   pcsc::Connection::Strings readers(pcsc::Connection::scan()); | ||||
|   if (readers.size()<reader) { | ||||
|     std::cerr<<"reader not found: "<<reader<<std::endl; | ||||
|     return 1; | ||||
|   } | ||||
|   cardos::Commands cmd(pcsc::Connection::reader(readers[reader])); | ||||
|   cardos::Dir d(cmd, path); | ||||
|   //cardos::BerValues d(cmd.readBerFile(path)); | ||||
|   //cardos::BerValues d(cmd.directory(path)); | ||||
|   std::cout<<"-----------------------------------------------------"<<std::endl | ||||
|            <<d.print()<<std::endl | ||||
|            <<"-----------------------------------------------------"<<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; | ||||
|   // if (!pin.size()) { | ||||
|   //   std::cout<<"PIN: "; | ||||
|   //   std::cin>>pin; | ||||
|   // } | ||||
|   // if (pin.size()) cmd.logonTransport(pin); | ||||
|   // cmd.phaseControl(); | ||||
|   // cmd.createBinary(path, id, data); | ||||
|   // cmd.phaseControl(); | ||||
|   return 0; | ||||
|  } catch (std::exception& x) { | ||||
|   std::cerr<<"ERROR: "<<x.what()<<std::endl; | ||||
|   return 2; | ||||
|  } | ||||
| @@ -1,95 +0,0 @@ | ||||
| // g++ -I ../../src -I /usr/include/opencryptoki cryptoki-demo.cpp ../../src/cryptoki.cxx -ldl -ggdb3 | ||||
| #include <cryptoki.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| template <typename Array> void print(const std::vector<Array>& v) { | ||||
|   for (typename std::vector<Array>::const_iterator it(v.begin()); | ||||
|        it!=v.end(); ++it) | ||||
|     std::cout<<"Item: "<<*it<<std::endl; | ||||
| } | ||||
|  | ||||
| int main(int argc, char const*const*const argv) try { | ||||
|   std::cout<<"Example for buffer to vector conversion:"<<std::endl; | ||||
|   int buff[] = {1, 2, 3, 4}; | ||||
|   std::vector<int> vec(cryptoki::toVector(buff)); | ||||
|   print(vec); | ||||
|   std::cout<<std::endl; | ||||
|   cryptoki::Library cryptoki(argc==2?argv[1]:"onepin-opensc-pkcs11.so"); | ||||
|   cryptoki::Info inf(cryptoki.info()); | ||||
|   std::cout<<"Library-Version: "<<pcsc::version()<<std::endl; | ||||
|   std::cout<<"##################### INFO #####################"<<std::endl | ||||
|            <<"cryptokiVersion: \""<<(int)inf.cryptokiVersion.major | ||||
|            <<'.'<<(int)inf.cryptokiVersion.minor<<'"'<<std::endl | ||||
|            <<"manufacturerID: \""<<inf.manufacturerID<<'"'<<std::endl | ||||
|            <<"flags: \""<<inf.flags<<'"'<<std::endl | ||||
|            <<"libraryDescription: \""<<inf.libraryDescription<<'"'<<std::endl | ||||
|            <<"libraryVersion: \""<<(int)inf.libraryVersion.major | ||||
|            <<'.'<<(int)inf.libraryVersion.minor<<'"'<<std::endl; | ||||
|   cryptoki::SlotList slots(cryptoki.slotList()); | ||||
|   for (cryptoki::SlotList::iterator it(slots.begin()); it!=slots.end(); ++it) | ||||
|     try { | ||||
|       cryptoki::SlotInfo slotInfo(it->slotinfo()); | ||||
|       std::cout<<"##################### S-CARD #####################"<<std::endl | ||||
|                <<"slotDescription: \""<<slotInfo.slotDescription<<'"'<<std::endl | ||||
|                <<"manufacturerID: \""<<slotInfo.manufacturerID<<'"'<<std::endl | ||||
|                <<"flags: \""<<slotInfo.flags<<'"'<<std::endl | ||||
|                <<"hardwareVersion: \""<<(int)slotInfo.hardwareVersion.major | ||||
|                <<'.'<<(int)slotInfo.hardwareVersion.minor<<'"'<<std::endl | ||||
|                <<"firmwareVersion: \""<<(int)slotInfo.firmwareVersion.major | ||||
|                <<'.'<<(int)slotInfo.firmwareVersion.minor<<'"'<<std::endl; | ||||
|       cryptoki::TokenInfo info(it->tokeninfo()); | ||||
|       std::cout<<"--------------------- Token ----------------------"<<std::endl | ||||
|                <<"label: \""<<info.label<<'"'<<std::endl | ||||
|                <<"manufacturerID: \""<<info.manufacturerID<<'"'<<std::endl | ||||
|                <<"model: \""<<info.model<<'"'<<std::endl | ||||
|                <<"serialNumber: \""<<crypto::readable(info.serialNumber) | ||||
|                <<'"'<<std::endl | ||||
|                <<"flags: \""<<info.flags<<'"'<<std::endl | ||||
|                <<"maxSessionCount: \""<<info.maxSessionCount<<'"'<<std::endl | ||||
|                <<"sessionCount: \""<<info.sessionCount<<'"'<<std::endl | ||||
|                <<"maxRwSessionCount: \""<<info.maxRwSessionCount<<'"'<<std::endl | ||||
|                <<"rwSessionCount: \""<<info.rwSessionCount<<'"'<<std::endl | ||||
|                <<"maxPinLen: \""<<info.maxPinLen<<'"'<<std::endl | ||||
|                <<"minPinLen: \""<<info.minPinLen<<'"'<<std::endl | ||||
|                <<"totalPublicMemory: \""<<info.totalPublicMemory<<'"'<<std::endl | ||||
|                <<"freePublicMemory: \""<<info.freePublicMemory<<'"'<<std::endl | ||||
|                <<"totalPrivateMemory: \""<<info.totalPrivateMemory<<'"' | ||||
|                <<std::endl | ||||
|                <<"freePrivateMemory: \""<<info.freePrivateMemory<<'"'<<std::endl | ||||
|                <<"hardwareVersion: \""<<(int)info.hardwareVersion.major | ||||
|                <<'.'<<(int)info.hardwareVersion.minor<<'"'<<std::endl | ||||
|                <<"firmwareVersion: \""<<(int)info.firmwareVersion.major | ||||
|                <<'.'<<(int)info.firmwareVersion.minor<<'"'<<std::endl | ||||
|                <<"utcTime: \""<<crypto::readable(info.utcTime) | ||||
|                <<'"'<<std::endl; | ||||
|       cryptoki::MechanismList mechs(it->mechanismlist()); | ||||
|       for (cryptoki::MechanismList::iterator mechinfo(mechs.begin()); | ||||
|            mechinfo!=mechs.end(); ++mechinfo) { | ||||
|         std::cout<<"-------------------- Mechanism -----------------"<<std::endl | ||||
|                  <<"id: \""<<mechinfo->id<<'"'<<std::endl | ||||
|                  <<"name: \""<<mechinfo->name<<'"'<<std::endl | ||||
|                  <<"minKeySize: \""<<mechinfo->minKeySize<<'"'<<std::endl | ||||
|                  <<"maxKeySize: \""<<mechinfo->maxKeySize<<'"'<<std::endl | ||||
|                  <<"flags: \""<<mechinfo->flags<<'"'<<std::endl; | ||||
|       } | ||||
|       cryptoki::Session session(*it); | ||||
|       cryptoki::ObjectList objs(session.find()); | ||||
|       std::cout<<"Objects Found: "<<objs.size()<<std::endl; | ||||
|       for (cryptoki::ObjectList::iterator it2(objs.begin()); | ||||
|            it2!=objs.end(); ++it2) { | ||||
|         std::cout<<"-------------------- Object -----------------"<<std::endl; | ||||
|         cryptoki::AttributeMap attrs(it2->attributes()); | ||||
|         for (cryptoki::AttributeMap::iterator it3(attrs.begin()); | ||||
|              it3!=attrs.end(); ++it3) { | ||||
|           std::cout<<" - attribute: "<<it3->second.name()<<" = "<<std::endl | ||||
|                    <<crypto::readable(it3->second.value, 15, 5)<<std::endl; | ||||
|         } | ||||
|       } | ||||
|       std::cout<<"**** Success"<<std::endl; | ||||
|     } catch (std::exception& x) { | ||||
|       std::cerr<<"**** FEHLER in "<<*argv<<": "<<x.what()<<std::endl; | ||||
|     } | ||||
|   return 0; | ||||
|  } catch (std::exception& x) { | ||||
|   std::cerr<<"**** FEHLER in "<<*argv<<": "<<x.what()<<std::endl; | ||||
|  } | ||||
| @@ -1,122 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #include <mrw/args.hxx> | ||||
| #include <mrw/vector.hxx> | ||||
| #include <cryptoki.hxx> | ||||
|  | ||||
| #include <string> | ||||
| #include <map> | ||||
| #include <iostream> | ||||
| #include <iomanip> | ||||
| #include <algorithm> | ||||
| #include <sstream> | ||||
| #include <fstream> | ||||
| #include <streambuf> | ||||
| #ifndef MRW__OLD_PRE11_COMPILER | ||||
| #include <chrono> | ||||
| #endif | ||||
|  | ||||
|  | ||||
| int main(int argc, char** argv) try { | ||||
|  | ||||
|   // options | ||||
|   unsigned long r(1); | ||||
|   std::string txt("This is an example."); | ||||
|   std::string lib("libcvP11.so"); | ||||
|   std::string slot; | ||||
|   std::string cert; | ||||
|  | ||||
|   mrw::args::parse(argc, argv, | ||||
|                    "Sign a text (optionally several times for performance" | ||||
|                    " measurements).", | ||||
|                    mrw::args::list() | ||||
|                    <<mrw::args::decl("h", "help", "show help", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::help() | ||||
|                                      <<mrw::args::exit()) | ||||
|                    <<mrw::args::decl("r", "repeat", "number of repetitions", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(r, "number")) | ||||
|                    <<mrw::args::decl("t", "text", "text to sign", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(txt, "text")) | ||||
|                    <<mrw::args::decl("l", "library", "cryptoki lirary to load", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(lib, "lib")) | ||||
|                    <<mrw::args::decl("s", "slot", "name of slot", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(slot, "name")) | ||||
|                    <<mrw::args::decl("c","cert", "name of certificate", | ||||
|                                      mrw::args::decl::param_list() | ||||
|                                      <<mrw::args::param(cert, "name"))); | ||||
|    | ||||
|   std::cout<<"Sign text "<<r<<" times:"<<std::endl | ||||
|            <<"-----------------------------------------------------"<<std::endl | ||||
|            <<txt<<std::endl | ||||
|            <<"-----------------------------------------------------"<<std::endl; | ||||
|   cryptoki::Library c(lib); | ||||
|   cryptoki::SlotList sl(c.slotList()); | ||||
|   for (cryptoki::SlotList::iterator s(sl.begin()); s!=sl.end(); ++s) { | ||||
|     cryptoki::SlotInfo si(s->slotinfo()); | ||||
|     if (slot.size()&&slot!=si.slotDescription) continue; | ||||
|     std::cout<<"Found Slot: "<<si.slotDescription<<std::endl; | ||||
|     cryptoki::TokenInfo ti(s->tokeninfo()); | ||||
|     std::cout<<"Found token: "<<ti.label<<std::endl; | ||||
|     cryptoki::Session session(*s); | ||||
|     cryptoki::ObjectList certs | ||||
|       (session.find(cryptoki::Attribute(CKA_CLASS) | ||||
|                     .from<CK_OBJECT_CLASS>(CKO_CERTIFICATE))); | ||||
|     for (cryptoki::ObjectList::iterator it(certs.begin()); | ||||
|          it!=certs.end(); ++it) { | ||||
|       std::string label(it->attribute(CKA_LABEL).value); | ||||
|       if (cert.size()&&cert!=label) continue; | ||||
|       cryptoki::Attribute id(it->attribute(CKA_ID)); | ||||
|       cryptoki::ObjectList keys | ||||
|         (session.find(cryptoki::Attribute(CKA_CLASS) | ||||
|                       .from<CK_OBJECT_CLASS>(CKO_PUBLIC_KEY), | ||||
|                       id)); | ||||
|       if (!keys.size()) continue; | ||||
|       std::cout<<"Found Certificate: " | ||||
|                    <<it->attribute(CKA_LABEL).value<<std::endl; | ||||
|       if (!cert.size()) continue; | ||||
|       std::cout<<"Pin: "; | ||||
|       std::string pin; | ||||
|       std::cin>>pin; | ||||
|       session.login(pin); | ||||
|       keys = session.find(cryptoki::Attribute(CKA_CLASS) | ||||
|                           .from<CK_OBJECT_CLASS>(CKO_PRIVATE_KEY), | ||||
|                           id); | ||||
|       if (keys.size()!=1) { | ||||
|         std::cerr<<"**** ERROR: No private key: "<<keys.size()<<std::endl; | ||||
|         return 1; | ||||
|       } | ||||
|       std::cout<<"Signing ..."<<std::endl; | ||||
| #ifndef MRW__OLD_PRE11_COMPILER | ||||
|       auto start = std::chrono::system_clock::now(); | ||||
| #endif | ||||
|       for (unsigned int i(0); i<r; ++i) | ||||
|         std::cout<<"Text:"<<std::endl | ||||
|                  <<crypto::readable(txt)<<std::endl | ||||
|                  <<"Signature:"<<std::endl | ||||
|                  <<crypto::readable(keys[0].sign(txt, CKM_RSA_PKCS)) | ||||
|                  <<std::endl; | ||||
| #ifndef MRW__OLD_PRE11_COMPILER | ||||
|       auto end = std::chrono::system_clock::now(); | ||||
|       auto elapsed(std::chrono::duration_cast<std::chrono::milliseconds> | ||||
|                    (end-start)); | ||||
|       std::cout<<"Done in "<<elapsed.count()<<"ms"<<std::endl; | ||||
| #else | ||||
|       std::cout<<"Done."<<std::endl; | ||||
| #endif | ||||
|     } | ||||
|   } | ||||
|   return 0; | ||||
|  } catch (std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|   return 1; | ||||
|  } | ||||
| @@ -1,52 +0,0 @@ | ||||
| ## @id $Id$ | ||||
|  | ||||
| ##       1         2         3         4         5         6         7         8 | ||||
| ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| noinst_PROGRAMS = pcsc-demo cryptoki-sign-demo cryptoki-demo		\ | ||||
|                   openssl-tcp-demo openssl-ssl-demo			\ | ||||
|                   openssl-engine-demo cardos-demo        \ | ||||
|                   create-files-demo | ||||
|  | ||||
| AM_CPPFLAGS += -I${top_srcdir}/src | ||||
| AM_LDFLAGS = -L${top_builddir}/src -lpcscxx | ||||
| if MINGW32 | ||||
| AM_LDFLAGS += -lwinscard -lws2_32 -lgdi32 | ||||
| endif | ||||
|  | ||||
| if MAC | ||||
| AM_CPPFLAGS+=-I/Library/OpenSC/include | ||||
| AM_LDFLAGS += -F/System/Library/Frameworks/PCSC.framework -framework PCSC -L/opt/local/lib -lcrypto | ||||
| endif | ||||
| if !MINGW32 | ||||
| if !MAC | ||||
| AM_LDFLAGS += -lpcsclite | ||||
| endif | ||||
| endif | ||||
| if !MINGW32 | ||||
| AM_LDFLAGS += -ldl -lpthread -lssl -lcrypto | ||||
| endif | ||||
|  | ||||
| pcsc_demo_SOURCES = pcsc-demo.cxx | ||||
| cryptoki_demo_SOURCES = cryptoki-demo.cxx | ||||
| cryptoki_sign_demo_SOURCES = cryptoki-sign-demo.cxx | ||||
| openssl_tcp_demo_SOURCES = openssl-tcp-demo.cxx | ||||
| openssl_ssl_demo_SOURCES = openssl-ssl-demo.cxx | ||||
| openssl_engine_demo_SOURCES = openssl-engine-demo.cxx | ||||
| cardos_demo_SOURCES = cardos-demo.cxx | ||||
| create_files_demo_SOURCES = create-files-demo.cxx | ||||
|  | ||||
| if HAVE_QTNETWORK | ||||
| noinst_PROGRAMS += suisse-id-demo | ||||
| noinst_HEADERS = suisse-id-demo.hxx | ||||
| suisse_id_demo_SOURCES = suisse-id-demo.cxx | ||||
| endif | ||||
|  | ||||
| %_ui.hxx: %.ui | ||||
| 	@UIC@ -o $@ $< | ||||
|  | ||||
| moc_%.cxx: %.hxx | ||||
| 	@MOC@ -o $@ $< | ||||
|  | ||||
| CLEANFILES = ${BUILT_SOURCES} | ||||
| MAINTAINERCLEANFILES = makefile.in | ||||
| @@ -1,88 +0,0 @@ | ||||
| /**************************************************************************** | ||||
| ** Meta object code from reading C++ file 'cardgui-model.hxx' | ||||
| ** | ||||
| ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.0.2) | ||||
| ** | ||||
| ** WARNING! All changes made in this file will be lost! | ||||
| *****************************************************************************/ | ||||
|  | ||||
| #include "cardgui-model.hxx" | ||||
| #include <QtCore/qbytearray.h> | ||||
| #include <QtCore/qmetatype.h> | ||||
| #if !defined(Q_MOC_OUTPUT_REVISION) | ||||
| #error "The header file 'cardgui-model.hxx' doesn't include <QObject>." | ||||
| #elif Q_MOC_OUTPUT_REVISION != 67 | ||||
| #error "This file was generated using the moc from 5.0.2. It" | ||||
| #error "cannot be used with the include files from this version of Qt." | ||||
| #error "(The moc has changed too much.)" | ||||
| #endif | ||||
|  | ||||
| QT_BEGIN_MOC_NAMESPACE | ||||
| struct qt_meta_stringdata_CardGuiModel_t { | ||||
|     QByteArrayData data[1]; | ||||
|     char stringdata[14]; | ||||
| }; | ||||
| #define QT_MOC_LITERAL(idx, ofs, len) \ | ||||
|     Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ | ||||
|     offsetof(qt_meta_stringdata_CardGuiModel_t, stringdata) + ofs \ | ||||
|         - idx * sizeof(QByteArrayData) \ | ||||
|     ) | ||||
| static const qt_meta_stringdata_CardGuiModel_t qt_meta_stringdata_CardGuiModel = { | ||||
|     { | ||||
| QT_MOC_LITERAL(0, 0, 12) | ||||
|     }, | ||||
|     "CardGuiModel\0" | ||||
| }; | ||||
| #undef QT_MOC_LITERAL | ||||
|  | ||||
| static const uint qt_meta_data_CardGuiModel[] = { | ||||
|  | ||||
|  // content: | ||||
|        7,       // revision | ||||
|        0,       // classname | ||||
|        0,    0, // classinfo | ||||
|        0,    0, // methods | ||||
|        0,    0, // properties | ||||
|        0,    0, // enums/sets | ||||
|        0,    0, // constructors | ||||
|        0,       // flags | ||||
|        0,       // signalCount | ||||
|  | ||||
|        0        // eod | ||||
| }; | ||||
|  | ||||
| void CardGuiModel::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) | ||||
| { | ||||
|     Q_UNUSED(_o); | ||||
|     Q_UNUSED(_id); | ||||
|     Q_UNUSED(_c); | ||||
|     Q_UNUSED(_a); | ||||
| } | ||||
|  | ||||
| const QMetaObject CardGuiModel::staticMetaObject = { | ||||
|     { &QAbstractItemModel::staticMetaObject, qt_meta_stringdata_CardGuiModel.data, | ||||
|       qt_meta_data_CardGuiModel,  qt_static_metacall, 0, 0} | ||||
| }; | ||||
|  | ||||
|  | ||||
| const QMetaObject *CardGuiModel::metaObject() const | ||||
| { | ||||
|     return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; | ||||
| } | ||||
|  | ||||
| void *CardGuiModel::qt_metacast(const char *_clname) | ||||
| { | ||||
|     if (!_clname) return 0; | ||||
|     if (!strcmp(_clname, qt_meta_stringdata_CardGuiModel.stringdata)) | ||||
|         return static_cast<void*>(const_cast< CardGuiModel*>(this)); | ||||
|     return QAbstractItemModel::qt_metacast(_clname); | ||||
| } | ||||
|  | ||||
| int CardGuiModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | ||||
| { | ||||
|     _id = QAbstractItemModel::qt_metacall(_c, _id, _a); | ||||
|     if (_id < 0) | ||||
|         return _id; | ||||
|     return _id; | ||||
| } | ||||
| QT_END_MOC_NAMESPACE | ||||
| @@ -1,37 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #include <openssl-engine.hxx> | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| class TestEngine: virtual public openssl::Engine { | ||||
|        | ||||
|   public: | ||||
|  | ||||
|     virtual const char* id() { | ||||
|       CRYPTOLOG("log"); | ||||
|       return "TestEngine_ID"; | ||||
|     } | ||||
|     virtual const char* name() { | ||||
|       CRYPTOLOG("log"); | ||||
|       return "TestEngine_NAME"; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| int main(int, char**) { | ||||
|   { | ||||
|     openssl::RegisterEngine<> testEngine(new TestEngine); | ||||
|      | ||||
|     for (ENGINE* e(ENGINE_get_first()); e; e = ENGINE_get_next(e)) { | ||||
|       std::cout<<"Found Engine: "<<ENGINE_get_id(e)<<std::endl; | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   ENGINE_cleanup(); | ||||
|   return 0; | ||||
| } | ||||
| @@ -1,29 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #define OPENSSL_LOG(X) | ||||
| #include <openssl.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| int main(int argc, char** argv) try { | ||||
|   openssl::Init init; | ||||
|   std::string host(argc>1?argv[1]:"dev.swisssign.com"); | ||||
|   std::string port(argc>2?argv[2]:"443"); | ||||
|   std::string path(argc>3?argv[3]:"/"); | ||||
|   std::cout<<"Library-Version: "<<pcsc::version()<<std::endl; | ||||
|   std::cout<<"Connect to: "<<host<<':'<<port<<std::endl; | ||||
|   openssl::SSL ssl | ||||
|     (openssl::TrustStore("/usr/lib/ssl/certs/SwissSign_Gold_CA_-_G2.pem")); | ||||
|   ssl.connect(host+':'+port)<<"GET "<<path<<" HTTP/1.1\n" | ||||
|                             <<"Host: "<<host<<"\n" | ||||
|                             <<"Connection: Close\n\n"; | ||||
|   while (ssl) std::cout<<ssl; | ||||
|   return 0; | ||||
|  } catch (const std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|   return 1; | ||||
|  } | ||||
| @@ -1,26 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| //#define OPENSSL_LOG(X) | ||||
| #include <openssl.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| int main(int argc, char** argv) try { | ||||
|   openssl::Init init; | ||||
|   std::string host(argc>1?argv[1]:"swisssign.com"); | ||||
|   std::string port(argc>2?argv[2]:"80"); | ||||
|   std::cout<<"Library-Version: "<<pcsc::version()<<std::endl; | ||||
|   std::cout<<"Connect to: "<<host<<':'<<port<<std::endl; | ||||
|   openssl::TCP ssl(host+':'+port); | ||||
|   ssl<<"GET / HTTP/1.1\x0D\x0AHost: "<<host | ||||
|      <<"\x0D\x0A\x43onnection: Close\x0D\x0A\x0D\x0A"; | ||||
|   while (ssl) std::cout<<ssl; | ||||
|   return 0; | ||||
|  } catch (const std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|   return 1; | ||||
|  } | ||||
| @@ -1,20 +0,0 @@ | ||||
| //g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3 | ||||
| #include <pcsc.hxx> | ||||
| #include <iostream> | ||||
|  | ||||
| int main(int, char const*const*const argv) try { | ||||
|   pcsc::Connection::Strings reader(pcsc::Connection::scan()); | ||||
|   std::cout<<"Library-Version: "<<pcsc::version()<<std::endl; | ||||
|   std::cout<<"Suche PCSC-Reader ..."<<std::endl; | ||||
|   if (!reader.size()) std::cout<<"Keine gefunden."<<std::endl; | ||||
|   for (pcsc::Connection::Strings::const_iterator it(reader.begin()); | ||||
|        it!=reader.end(); ++it) { | ||||
|     std::cout<<"Reader: "<<*it<<std::endl; | ||||
|     pcsc::Connection::Reader::Status s(pcsc::Connection::reader(*it)->status()); | ||||
|     std::cout<<"Status = "<<s.state<<std::endl; | ||||
|     std::cout<<"ATR = "<<crypto::hex(s.atr)<<std::endl; | ||||
|   } | ||||
|   return 0; | ||||
|  } catch (std::exception& x) { | ||||
|   std::cerr<<"**** FEHLER in "<<*argv<<": "<<x.what()<<std::endl; | ||||
|  } | ||||
| @@ -1,139 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #include <suisse-id-demo.hxx> | ||||
| #include <mrw/args.hxx> | ||||
|  | ||||
| #include <QtNetwork/QSslCertificate> | ||||
| #include <QtCore/QDateTime> | ||||
| #include <QtCore/QStringList> | ||||
|  | ||||
| void show(const QString& s, const std::string& p="item: ") { | ||||
|   std::cout<<p<<QString(s.toUtf8()).toStdString()<<std::endl; | ||||
| } | ||||
|  | ||||
| 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; | ||||
| } | ||||
|  | ||||
| // 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:"; | ||||
|   show(c.subjectInfo(QSslCertificate::CommonName), "  CN="); | ||||
|   std::cout<<"  Valid until: " | ||||
|            <<QString(c.expiryDate().toString().toUtf8()).toStdString() | ||||
|            <<std::endl; | ||||
| } | ||||
|  | ||||
| // call with option -h for help | ||||
| int main(int argc, char** argv) try { | ||||
|   std::string lib("libcvP11.so"); // default pkcs#11/cryptoki library | ||||
|   mrw::args::parse(argc, argv, | ||||
|                    "Sign a text (optionally several times for performance" | ||||
|                    " measurements).", | ||||
|                    mrw::args::defaults() | ||||
|                    <<mrw::args::decl("l", "library", "cryptoki library 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) { | ||||
|     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::Info info((*card)->sessionInfo()); | ||||
|       std::cout<<"  Session:"<<std::endl | ||||
|                <<"    Slot:        "<<info.slotID<<std::endl | ||||
|                <<"    State:       "<<info.stateString()<<std::endl | ||||
|                <<"    Flags:       "<<(info.readwrite() | ||||
|                                        ?"read/write":"read only")<<std::endl | ||||
|                <<"    Device Error: "<<info.ulDeviceError<<std::endl; | ||||
|       suisseid::Certificates certs((*card)->certificates()); | ||||
|       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 | ||||
|                <<"  z: show certificates"<<std::endl | ||||
|                <<"  a: show authentication certificate"<<std::endl | ||||
|                <<"  d: show digital signature certificate"<<std::endl | ||||
|                <<"  q: quit"<<std::endl; | ||||
|       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; | ||||
|           else | ||||
|             std::cout<<"****> SuisseID is bad"<<std::endl; | ||||
|         } 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; | ||||
|           std::cout<<"Enter New PIN: "; | ||||
|           std::cin>>newpin; | ||||
|           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) { | ||||
|         std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|       } | ||||
|     } catch (std::exception& x) { | ||||
|       std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|       choice="n"; // proceed to next card | ||||
|     } | ||||
|   } | ||||
|   return 0; | ||||
|  } catch (std::exception& x) { | ||||
|   std::cerr<<"**** ERROR: "<<x.what()<<std::endl; | ||||
|  } | ||||
| @@ -1,110 +0,0 @@ | ||||
| /*! @file | ||||
|  | ||||
|     @id $Id$ | ||||
| */ | ||||
| //       1         2         3         4         5         6         7         8 | ||||
| // 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| #ifndef SUISSE_ID_DEMO_HXX | ||||
| #define SUISSE_ID_DEMO_HXX | ||||
|  | ||||
| #include <suisseid.hxx> | ||||
| #include <iostream> | ||||
| #include <cassert> | ||||
|  | ||||
| // implements a status cycle for text user interface | ||||
| class TextualCycle: public suisseid::StatusCycle { | ||||
|  | ||||
|   public: | ||||
|  | ||||
|     // just pass the card to parent | ||||
|     TextualCycle(std::shared_ptr<suisseid::Card> card): | ||||
|         StatusCycle(card) { | ||||
|     } | ||||
|  | ||||
|   protected: | ||||
|  | ||||
|     // callback: ask user for transport pin  | ||||
|     virtual PinPukChange pinChangeTransportPin() { | ||||
|       PinPukChange pinpuk; | ||||
|       std::cout<<"Enter Transport PIN: "; | ||||
|       std::cin>>pinpuk.oldpin; | ||||
|       std::cout<<"Enter New PIN: "; | ||||
|       std::cin>>pinpuk.newpin; | ||||
|       return pinpuk; | ||||
|     } | ||||
|  | ||||
|     // callback: ask user for puk | ||||
|     virtual PinPukChange pinChangePuk() { | ||||
|       PinPukChange pinpuk; | ||||
|       std::cout<<"Enter PUK to unlock PKCS#15 PIN: "; | ||||
|       std::cin>>pinpuk.oldpin; | ||||
|       std::cout<<"Enter New PKCS#15 PIN: "; | ||||
|       std::cin>>pinpuk.newpin; | ||||
|       return pinpuk; | ||||
|     } | ||||
|      | ||||
|     // callback: tell user that transport pin is locked | ||||
|     virtual void transportPinLocked() { | ||||
|       std::cout<<"Transport PIN is Locked!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that pkcs15 pin is locked | ||||
|     virtual void pkcs15PinLocked() { | ||||
|       std::cout<<"PKCS#15 PIN is Locked!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that digital signature pin is locked | ||||
|     virtual void sigGPinLocked() { | ||||
|       std::cout<<"SigG PIN is Locked!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that puk is locked | ||||
|     virtual void pukLocked() { | ||||
|       std::cout<<"PUK is Locked!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that certificates will expire soon | ||||
|     virtual void certsExpireSoon() { | ||||
|       std::cout<<"Certificates Expire Soon!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that certificates have expired | ||||
|     virtual void certsExpired() { | ||||
|       std::cout<<"Certificates Expired!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|     // callback: tell user that certificates have been revoked | ||||
|     virtual void certsRevoked() { | ||||
|       std::cout<<"Certificates Revoked!"<<std::endl; | ||||
|     } | ||||
|  | ||||
|   public: | ||||
|  | ||||
|     // install certificates on the card | ||||
|     virtual bool installCerts(bool force = true) { | ||||
|       std::cout<<"Installing Certificates ..."<<std::endl; | ||||
|       std::string pin; | ||||
|       std::cout<<"Enter PIN (x to abort): "; | ||||
|       std::cin>>pin; | ||||
|       if (pin=="x") { | ||||
|         std::cout<<std::endl<<"User aborted"<<std::endl; | ||||
|         return false; // user aborts | ||||
|       } | ||||
|       cryptoki::Session session(card()->slot()); | ||||
|       try { | ||||
|         // log into the card using the user's pin | ||||
|         session.login(pin); | ||||
|       } catch (const cryptoki::wrong_pin& x) { | ||||
|         std::cout<<"**** Wrong PIN!"<<std::endl; | ||||
|         std::cout<<x.what()<<std::endl; | ||||
|         return false; | ||||
|       } | ||||
|       // now store certificates on the card | ||||
|       std::cout<<"**** Not implemented"<<std::endl; | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| }; | ||||
|  | ||||
| #endif | ||||
| @@ -1,48 +1,9 @@ | ||||
| ## @file | ||||
| ## | ||||
| ## $Id$ | ||||
| ## | ||||
| ## @id $Id$ | ||||
| # | ||||
| # This file has been added by bootstrap.sh on Wed, 11 Mar 2015 16:57:43 +0100 | ||||
| # Feel free to change it or even remove and rebuild it, up to your needs | ||||
| # | ||||
| ##       1         2         3         4         5         6         7         8 | ||||
| ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 | ||||
|  | ||||
| SUBDIRS = examples | ||||
| ALL_SRC = ${top_srcdir}/src/*.[ch]xx ${top_srcdir}/src/*.doc | ||||
| # ${top_srcdir}/src/*.doc | ||||
|  | ||||
| DIRS = html | ||||
| #latex | ||||
|  | ||||
| all: ${DIRS} | ||||
|  | ||||
| .PHONY: doc clean-local distclean-local dist-hool install-data-hook \ | ||||
|         uninstall-hook | ||||
|  | ||||
| deps = ${top_srcdir}/COPYING ${top_srcdir}/README		 \ | ||||
|        ${top_srcdir}/INSTALL ${top_srcdir}/NEWS ${top_srcdir}/ChangeLog | ||||
|  | ||||
| html: ${ALL_SRC} doxyfile ${deps} | ||||
| 	doxygen doxyfile | ||||
| if PEDANTIC | ||||
| 	test \! -s doxygen.errors | ||||
| endif | ||||
| #	cd latex && make | ||||
| #	mv latex/refman.pdf @PACKAGE_NAME@-@PACKAGE_VERSION@.pdf | ||||
|  | ||||
| CLEANFILES = doxygen.errors @PACKAGE_NAME@-@PACKAGE_VERSION@.pdf | ||||
| DISTCLEANFILES = @PACKAGE_NAME@.doxytag | ||||
| MAINTAINERCLEANFILES = makefile.in | ||||
|  | ||||
| distclean-local: | ||||
| 	- rm -r html latex | ||||
|  | ||||
| dist-hook: html | ||||
| #	cp -r html latex ${distdir}/ | ||||
|  | ||||
| install-data-hook: | ||||
| 	test -d $(DESTDIR)${docdir} || mkdir -p $(DESTDIR)${docdir} | ||||
| 	chmod -R u+w $(DESTDIR)${docdir} | ||||
| 	cp -r html $(DESTDIR)${docdir}/ | ||||
|  | ||||
| uninstall-hook: | ||||
| 	-chmod -R u+w $(DESTDIR)${docdir} | ||||
| 	-rm -rf $(DESTDIR)${docdir}/* | ||||
|   | ||||
		Reference in New Issue
	
	Block a user