/*! @file @id $Id$ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 // #include // #include // #include #include #include #include #include #include #include #include #include #define CARDOS_LOG(X) std::cout< class Commands: public cardos::Commands { public: void help() { std::cout <<"Commands: "< Select reader by number"< Send APDU hex data"< Select file below master"< Select file below PKCS#15"< Select file below SigG"< Query status of PIN "< logon to key with PIN"< logon with user PIN"< logon with user PUK"< logon with SigG PIN"< logon with transport PIN"< ", 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()<>num && num<_readers.size()) { _reader = pcsc::Connection::reader(_readers[num]); std::cout<<"Active Reader: "<<_readers[num]<>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."<