added draft lib for suisseid - by now: detect Post SuisseID; refs #28
This commit is contained in:
@@ -12,8 +12,8 @@ int main(int argc, char const*const*const argv) try {
|
||||
// //std::vector<int> v(toVector<4>((int[]){1,2,3,4}));
|
||||
// std::vector<int> v(VECTOR(((int[]){1,2,3,4})));
|
||||
// print(v);
|
||||
cryptoki::Init init(argc==2?argv[1]:"onepin-opensc-pkcs11.so");
|
||||
cryptoki::Info inf(init.info());
|
||||
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
|
||||
@@ -23,7 +23,7 @@ int main(int argc, char const*const*const argv) try {
|
||||
<<"libraryDescription: \""<<inf.libraryDescription<<'"'<<std::endl
|
||||
<<"libraryVersion: \""<<(int)inf.libraryVersion.major
|
||||
<<'.'<<(int)inf.libraryVersion.minor<<'"'<<std::endl;
|
||||
cryptoki::SlotList slots(init.slotList());
|
||||
cryptoki::SlotList slots(cryptoki.slotList());
|
||||
for (cryptoki::SlotList::iterator it(slots.begin()); it!=slots.end(); ++it)
|
||||
try {
|
||||
cryptoki::SlotInfo slotInfo(it->slotinfo());
|
||||
|
@@ -58,7 +58,7 @@ int main(int argc, char** argv) try {
|
||||
<<"-----------------------------------------------------"<<std::endl
|
||||
<<txt<<std::endl
|
||||
<<"-----------------------------------------------------"<<std::endl;
|
||||
cryptoki::Init c(lib);
|
||||
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());
|
||||
|
@@ -11,7 +11,7 @@ int main(int, char const*const*const argv) try {
|
||||
for (pcsc::Connection::Strings::const_iterator it(reader.begin());
|
||||
it!=reader.end(); ++it) {
|
||||
std::cout<<"Reader: "<<*it<<std::endl;
|
||||
pcsc::Connection::Reader::Status s(c.reader(*it).status());
|
||||
pcsc::Connection::Reader::Status s(c.reader(*it)->status());
|
||||
std::cout<<"Status = "<<s.state<<std::endl;
|
||||
std::cout<<"ATR = "<<crypto::hex(s.atr)<<std::endl;
|
||||
}
|
||||
|
@@ -9,10 +9,87 @@
|
||||
#include <pcsc.hxx>
|
||||
#include <mrw/args.hxx>
|
||||
#include <mrw/vector.hxx>
|
||||
#include <mrw/shared.hxx>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
namespace suisseid {
|
||||
|
||||
class Card {
|
||||
public:
|
||||
Card(mrw::Shared<pcsc::Connection::Reader> reader,
|
||||
mrw::Shared<cryptoki::Slot> slot):
|
||||
_reader(reader),
|
||||
_slot(slot) {
|
||||
}
|
||||
virtual ~Card() {}
|
||||
const std::string& name() {
|
||||
return _reader->name;
|
||||
}
|
||||
private:
|
||||
mrw::Shared<pcsc::Connection::Reader> _reader;
|
||||
mrw::Shared<cryptoki::Slot> _slot;
|
||||
};
|
||||
|
||||
class PostSuisseID: public Card {
|
||||
public:
|
||||
PostSuisseID(mrw::Shared<pcsc::Connection::Reader> reader,
|
||||
mrw::Shared<cryptoki::Slot> slot):
|
||||
Card(reader, slot) {
|
||||
}
|
||||
};
|
||||
|
||||
class Manager {
|
||||
|
||||
public:
|
||||
|
||||
Manager(const std::string& lib="libcvP11.so"):
|
||||
_cryptoki(lib) {
|
||||
}
|
||||
|
||||
Manager(const pcsc::Connection& pcsc,
|
||||
const std::string& lib="libcvP11.so"):
|
||||
_pcsc(pcsc),
|
||||
_cryptoki(lib) {
|
||||
}
|
||||
|
||||
Manager(const cryptoki::Library& cryptoki):
|
||||
_cryptoki(cryptoki) {
|
||||
}
|
||||
|
||||
Manager(const pcsc::Connection& pcsc,
|
||||
const cryptoki::Library& cryptoki):
|
||||
_pcsc(pcsc),
|
||||
_cryptoki(cryptoki) {
|
||||
}
|
||||
|
||||
typedef std::vector<mrw::Shared<Card> > Cards;
|
||||
|
||||
Cards scan() {
|
||||
Cards res;
|
||||
// By now, scan only for PostSuisseID; in future use factory pattern
|
||||
pcsc::Connection::Strings readers
|
||||
(_pcsc.getReadersWithAtr("4b53776973735369676e"));
|
||||
for (pcsc::Connection::Strings::iterator reader(readers.begin());
|
||||
reader!=readers.end(); ++reader) {
|
||||
cryptoki::SlotList slots(_cryptoki.slotList(true, *reader));
|
||||
if (slots.size()==1)
|
||||
res.push_back(dynamic_cast<Card*>
|
||||
(new PostSuisseID(_pcsc.reader(*reader), slots[0])));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
pcsc::Connection _pcsc;
|
||||
cryptoki::Library _cryptoki;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
|
||||
std::string lib("libcvP11.so");
|
||||
@@ -28,20 +105,11 @@ int main(int argc, char** argv) try {
|
||||
mrw::args::decl::param_list()
|
||||
<<mrw::args::param(lib, "lib")));
|
||||
|
||||
pcsc::Connection pcsc;
|
||||
cryptoki::Init cryptoki(lib);
|
||||
|
||||
// Scan for a Post SuisseID
|
||||
pcsc::Connection::Strings readers
|
||||
(pcsc.getReadersWithAtr("4b53776973735369676e"));
|
||||
std::cout<<"found "<<readers.size()<<" readers"<<std::endl;
|
||||
for (pcsc::Connection::Strings::iterator reader(readers.begin());
|
||||
reader!=readers.end(); ++reader) {
|
||||
std::cout<<"Found SuisseID in reader: "<<*reader<<std::endl;
|
||||
// Each PCSC reader has exactly one corresponding Cryptoki slot; find it
|
||||
cryptoki::SlotList slots(cryptoki.slotList(true, *reader));
|
||||
if (slots.size()!=1) throw std::runtime_error("error scanning cryptoki");
|
||||
}
|
||||
suisseid::Manager suisseid;
|
||||
suisseid::Manager::Cards cards(suisseid.scan());
|
||||
for (suisseid::Manager::Cards::iterator card(cards.begin());
|
||||
card!=cards.end(); ++card)
|
||||
std::cout<<"Found SuisseID: "<<(*card)->name()<<std::endl;
|
||||
return 0;
|
||||
} catch (std::exception& x) {
|
||||
std::cerr<<"**** ERROR in "<<*argv<<": "<<x.what()<<std::endl;
|
||||
|
Reference in New Issue
Block a user