From 070ce378ff96f8d0b8c93a7daac795a185456c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Thu, 6 Apr 2017 12:44:21 +0000 Subject: [PATCH] improved build scripts --- configure.ac | 10 ++++++++-- src/suisseid.hxx | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 2ccbed3..1c5e9dc 100644 --- a/configure.ac +++ b/configure.ac @@ -23,11 +23,17 @@ AC_ARG_ENABLE(pkcs11-download, [download pkcs11 header])], [have_pedantic="$enableval" if test "$enableval" = "yes"; then - mkdir -p usr/include + test -d usr/include || mkdir -p usr/include cd usr/include - for f in $(wget -q -O- ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/ 2>&1 | html2 | sed -n 's,.*/a/@href=\(.*\.h\)$,\1,gp'); do + for f in $(wget -qO- ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/ 2>&1 | html2 | sed -n 's,.*/a/@href=\(.*\.h\)$,\1,gp'); do wget --unlink $f + if ! test -f "${f##*/}"; then + AC_MSG_ERROR([download failed of PKCS#11 header file: ${f##*/}]) + fi done + if ! test -f cryptoki.h; then + AC_MSG_ERROR([download failed of PKCS#11 - have you installed xml2?]) + fi AM_CPPFLAGS+=" -I$(pwd)" cd - fi diff --git a/src/suisseid.hxx b/src/suisseid.hxx index 620bb4c..6fdc721 100644 --- a/src/suisseid.hxx +++ b/src/suisseid.hxx @@ -13,6 +13,7 @@ #include #include #include +#include #include /*! @defgroup gsuisseid C++ library to access SuisseID smart cards @@ -149,19 +150,31 @@ namespace suisseid { public: Certificate(const std::string& v, const std::string& l, + const std::string& s, + const std::string& si, const cryptoki::Attribute& i): std::string(v), _label(l), + _subject(s), + _si(si), _id(i) { } const std::string& label() { return _label; } + const std::string& subject() { + return _label; + } const cryptoki::Attribute& id() { return _id; } + const std::string& subjectInfo() { + return _si; + } private: std::string _label; + std::string _subject; + std::string _si; cryptoki::Attribute _id; }; @@ -269,6 +282,8 @@ namespace suisseid { cert!=certs.end(); ++cert) res.push_back(Certificate(cert->attribute(CKA_VALUE).value, cert->attribute(CKA_LABEL).value, + cert->attribute(CKA_SUBJECT).value, + cert->attribute(CKA_SUBJECT_INFO).value, cert->attribute(CKA_ID))); return res; } @@ -308,6 +323,7 @@ namespace suisseid { for (cryptoki::ObjectList::iterator cert(certs.begin()); cert!=certs.end(); ++cert) // return first matching cert return Certificate(cert->attribute(CKA_VALUE).value, + cert->attribute(CKA_SUBJECT).value, cert->attribute(CKA_LABEL).value, id); # ifdef __APPLE__ @@ -355,10 +371,16 @@ namespace suisseid { public: + enum CardType { + SUISSE_ID, + UNKNOWN + }; + /// @copydoc Card::Card Post(std::shared_ptr reader, const cryptoki::Library& cryptoki): - Card(reader, cryptoki), _minPinLen(0), _maxPinLen((unsigned int)-1) { + Card(reader, cryptoki), + _type(UNKNOWN), _minPinLen(0), _maxPinLen((unsigned int)-1) { } virtual unsigned int minimalPinLength() { @@ -379,7 +401,12 @@ namespace suisseid { virtual CertStatus certStatus() { try { Certificate auth(authenticationCertificate()); - Certificate sig(digitalSignatureCertificate()); + //auth.subjectInfo(serialNumber); + // if (mrw::RegExp("^$[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}") + // (auth.subjectInfo(serialNumber))) { + // _type = SUISSE_ID; + Certificate sig(digitalSignatureCertificate()); + // } return VALID; } catch (const no_auth& x) { return MISSING; @@ -430,6 +457,7 @@ namespace suisseid { private: + CardType _type; std::string _version; // version is cached unsigned int _minPinLen; // minimal PIN length is cached unsigned int _maxPinLen; // maximal PIN length is cached