diff --git a/doc/examples/suisse-id-demo.cxx b/doc/examples/suisse-id-demo.cxx index ace3514..dfe9d3d 100644 --- a/doc/examples/suisse-id-demo.cxx +++ b/doc/examples/suisse-id-demo.cxx @@ -37,17 +37,14 @@ int main(int argc, char** argv) try { <<" SigG: "<<(*card)->sigGPinRetries()<transportPinRetries()<pukRetries()<slot()); - cryptoki::Session::Info info(session.getsessioninfo()); + cryptoki::Session::Info info((*card)->sessionInfo()); std::cout<<" Session:"<(CKO_CERTIFICATE))); + suisseid::Certificates certs((*card)->certificates()); std::cout<<" Certificates: "<attribute(CKA_VALUE).value); - QByteArray der(QByteArray(data.data(), data.size())); + QByteArray der(QByteArray(cert->data(), cert->size())); QSslCertificate c(der, QSsl::Der); std::cout<<"Certificate info: CN=" < label; FixString<32> manufacturerID; @@ -607,6 +610,7 @@ namespace cryptoki { FixString<16> utcTime; TokenInfo() { + CRYPTOLOG("log"); } //! Convert C-Structure of Token Information Into C++ @@ -629,8 +633,34 @@ namespace cryptoki { hardwareVersion(cInfo.hardwareVersion), firmwareVersion(cInfo.firmwareVersion), utcTime(cInfo.utcTime) { + CRYPTOLOG("log *this={"<C_GetTokenInfo(_slot, &cInfo), CRYPTOKI_FN_LOG("C_GetTokenInfo"))) - return TokenInfo(cInfo); + return TokenInfo(); + return TokenInfo(cInfo); } /*! @bug does not compile: @@ -1266,7 +1298,27 @@ namespace cryptoki { - @c ulDeviceError An error code defined by the cryptographic device. Used for errors not covered by Cryptoki. */ - typedef CK_SESSION_INFO Info; + struct Info: public CK_SESSION_INFO { + Info(const CK_SESSION_INFO& si): CK_SESSION_INFO(si) { + } + bool readonly() { + return !readwrite(); + } + bool readwrite() { + return flags|CKF_RW_SESSION; + } + std::string stateString() { + switch (state) { + case 0: return "CKS_RO_PUBLIC_SESSION"; + case 1: return "CKS_RO_USER_FUNCTIONS"; + case 2: return "CKS_RW_PUBLIC_SESSION "; + case 3: return "CKS_RW_USER_FUNCTIONS"; + case 4: return "CKS_RW_SO_FUNCTIONS"; + default: return ""; + } + } + }; + /** @return session information */ Info getsessioninfo() { @@ -1278,17 +1330,6 @@ namespace cryptoki { return info; } - std::string state(const Info& info) { - switch (info.state) { - case 0: return "CKS_RO_PUBLIC_SESSION"; - case 1: return "CKS_RO_USER_FUNCTIONS"; - case 2: return "CKS_RW_PUBLIC_SESSION "; - case 3: return "CKS_RW_USER_FUNCTIONS"; - case 4: return "CKS_RW_SO_FUNCTIONS"; - default: return ""; - } - } - /*! @todo Not implemented: @code bool initpin() { diff --git a/src/suisseid.hxx b/src/suisseid.hxx index ea2aec0..fb0647a 100644 --- a/src/suisseid.hxx +++ b/src/suisseid.hxx @@ -75,6 +75,9 @@ namespace suisseid { */ + /// List of DER encoded binary certificates + typedef std::vector Certificates; + //! Represents a SuisseID Card /*! This is the parent class for special classes for the respecive SuisseID providers. */ @@ -123,6 +126,26 @@ namespace suisseid { return MISSING; } + cryptoki::Session session() { + return cryptoki::Session(slot()); + } + + cryptoki::Session::Info sessionInfo() { + return session().getsessioninfo(); + } + + /// @returns Certificates in DER format. + Certificates certificates() { + Certificates res; + cryptoki::ObjectList certs + (session().find(cryptoki::Attribute(CKA_CLASS) + .from(CKO_CERTIFICATE))); + for (cryptoki::ObjectList::iterator cert(certs.begin()); + cert!=certs.end(); ++cert) + res.push_back(cert->attribute(CKA_VALUE).value); + return res; + } + protected: cryptoki::Library _cryptoki;