2009-08-27 14:46:29 +00:00
|
|
|
// g++ -I ../../src -I /usr/include/opencryptoki cryptoki-demo.cpp ../../src/cryptoki.cxx -ldl -ggdb3
|
|
|
|
#include <cryptoki.hxx>
|
|
|
|
#include <iostream>
|
|
|
|
|
2009-08-31 11:28:33 +00:00
|
|
|
template <typename Array> void print(const std::vector<Array>& v) {
|
2009-08-31 13:59:23 +00:00
|
|
|
for (typename std::vector<Array>::const_iterator it(v.begin());
|
|
|
|
it!=v.end(); ++it)
|
2009-08-31 11:28:33 +00:00
|
|
|
std::cout<<"Item: "<<*it<<std::endl;
|
|
|
|
}
|
|
|
|
|
2009-08-27 14:46:29 +00:00
|
|
|
int main(int argc, char const*const*const argv) try {
|
2014-02-27 12:57:44 +00:00
|
|
|
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;
|
2013-10-15 11:57:29 +00:00
|
|
|
cryptoki::Library cryptoki(argc==2?argv[1]:"onepin-opensc-pkcs11.so");
|
|
|
|
cryptoki::Info inf(cryptoki.info());
|
2010-08-03 13:48:47 +00:00
|
|
|
std::cout<<"Library-Version: "<<pcsc::version()<<std::endl;
|
2009-08-27 14:46:29 +00:00
|
|
|
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;
|
2013-10-15 11:57:29 +00:00
|
|
|
cryptoki::SlotList slots(cryptoki.slotList());
|
2009-08-27 14:46:29 +00:00
|
|
|
for (cryptoki::SlotList::iterator it(slots.begin()); it!=slots.end(); ++it)
|
|
|
|
try {
|
2009-08-28 14:57:40 +00:00
|
|
|
cryptoki::SlotInfo slotInfo(it->slotinfo());
|
2009-08-27 14:46:29 +00:00
|
|
|
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;
|
2009-08-28 14:57:40 +00:00
|
|
|
cryptoki::TokenInfo info(it->tokeninfo());
|
|
|
|
std::cout<<"--------------------- Token ----------------------"<<std::endl
|
2009-08-27 14:46:29 +00:00
|
|
|
<<"label: \""<<info.label<<'"'<<std::endl
|
|
|
|
<<"manufacturerID: \""<<info.manufacturerID<<'"'<<std::endl
|
|
|
|
<<"model: \""<<info.model<<'"'<<std::endl
|
2009-09-21 07:43:32 +00:00
|
|
|
<<"serialNumber: \""<<crypto::readable(info.serialNumber)
|
2009-09-02 13:57:56 +00:00
|
|
|
<<'"'<<std::endl
|
2009-08-27 14:46:29 +00:00
|
|
|
<<"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
|
2009-09-21 07:43:32 +00:00
|
|
|
<<"utcTime: \""<<crypto::readable(info.utcTime)
|
2009-09-02 13:57:56 +00:00
|
|
|
<<'"'<<std::endl;
|
2009-08-28 14:57:40 +00:00
|
|
|
cryptoki::MechanismList mechs(it->mechanismlist());
|
2014-02-27 12:57:44 +00:00
|
|
|
for (cryptoki::MechanismList::iterator mechinfo(mechs.begin());
|
|
|
|
mechinfo!=mechs.end(); ++mechinfo) {
|
2009-08-28 14:57:40 +00:00
|
|
|
std::cout<<"-------------------- Mechanism -----------------"<<std::endl
|
2014-02-27 12:57:44 +00:00
|
|
|
<<"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;
|
2009-08-28 14:57:40 +00:00
|
|
|
}
|
2009-09-01 16:15:36 +00:00
|
|
|
cryptoki::Session session(*it);
|
|
|
|
cryptoki::ObjectList objs(session.find());
|
|
|
|
std::cout<<"Objects Found: "<<objs.size()<<std::endl;
|
2014-04-01 13:10:51 +00:00
|
|
|
for (cryptoki::ObjectList::iterator it2(objs.begin());
|
|
|
|
it2!=objs.end(); ++it2) {
|
2009-09-02 13:57:56 +00:00
|
|
|
std::cout<<"-------------------- Object -----------------"<<std::endl;
|
2014-04-01 13:10:51 +00:00
|
|
|
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;
|
2009-09-02 08:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-02 13:57:56 +00:00
|
|
|
std::cout<<"**** Success"<<std::endl;
|
2009-08-27 14:46:29 +00:00
|
|
|
} 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;
|
|
|
|
}
|