|
|
@ -13,6 +13,7 @@ |
|
|
|
#include <pcsc.hxx> |
|
|
|
#include <pcsc.hxx> |
|
|
|
#include <mrw/vector.hxx> |
|
|
|
#include <mrw/vector.hxx> |
|
|
|
#include <mrw/checkcxx11.hxx> |
|
|
|
#include <mrw/checkcxx11.hxx> |
|
|
|
|
|
|
|
#include <mrw/regexp.hxx> |
|
|
|
#include <memory> |
|
|
|
#include <memory> |
|
|
|
|
|
|
|
|
|
|
|
/*! @defgroup gsuisseid C++ library to access SuisseID smart cards
|
|
|
|
/*! @defgroup gsuisseid C++ library to access SuisseID smart cards
|
|
|
@ -149,19 +150,31 @@ namespace suisseid { |
|
|
|
public: |
|
|
|
public: |
|
|
|
Certificate(const std::string& v, |
|
|
|
Certificate(const std::string& v, |
|
|
|
const std::string& l, |
|
|
|
const std::string& l, |
|
|
|
|
|
|
|
const std::string& s, |
|
|
|
|
|
|
|
const std::string& si, |
|
|
|
const cryptoki::Attribute& i): |
|
|
|
const cryptoki::Attribute& i): |
|
|
|
std::string(v), |
|
|
|
std::string(v), |
|
|
|
_label(l), |
|
|
|
_label(l), |
|
|
|
|
|
|
|
_subject(s), |
|
|
|
|
|
|
|
_si(si), |
|
|
|
_id(i) { |
|
|
|
_id(i) { |
|
|
|
} |
|
|
|
} |
|
|
|
const std::string& label() { |
|
|
|
const std::string& label() { |
|
|
|
return _label; |
|
|
|
return _label; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const std::string& subject() { |
|
|
|
|
|
|
|
return _label; |
|
|
|
|
|
|
|
} |
|
|
|
const cryptoki::Attribute& id() { |
|
|
|
const cryptoki::Attribute& id() { |
|
|
|
return _id; |
|
|
|
return _id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const std::string& subjectInfo() { |
|
|
|
|
|
|
|
return _si; |
|
|
|
|
|
|
|
} |
|
|
|
private: |
|
|
|
private: |
|
|
|
std::string _label; |
|
|
|
std::string _label; |
|
|
|
|
|
|
|
std::string _subject; |
|
|
|
|
|
|
|
std::string _si; |
|
|
|
cryptoki::Attribute _id; |
|
|
|
cryptoki::Attribute _id; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -269,6 +282,8 @@ namespace suisseid { |
|
|
|
cert!=certs.end(); ++cert) |
|
|
|
cert!=certs.end(); ++cert) |
|
|
|
res.push_back(Certificate(cert->attribute(CKA_VALUE).value, |
|
|
|
res.push_back(Certificate(cert->attribute(CKA_VALUE).value, |
|
|
|
cert->attribute(CKA_LABEL).value, |
|
|
|
cert->attribute(CKA_LABEL).value, |
|
|
|
|
|
|
|
cert->attribute(CKA_SUBJECT).value, |
|
|
|
|
|
|
|
cert->attribute(CKA_SUBJECT_INFO).value, |
|
|
|
cert->attribute(CKA_ID))); |
|
|
|
cert->attribute(CKA_ID))); |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
@ -308,6 +323,7 @@ namespace suisseid { |
|
|
|
for (cryptoki::ObjectList::iterator cert(certs.begin()); |
|
|
|
for (cryptoki::ObjectList::iterator cert(certs.begin()); |
|
|
|
cert!=certs.end(); ++cert) // return first matching cert
|
|
|
|
cert!=certs.end(); ++cert) // return first matching cert
|
|
|
|
return Certificate(cert->attribute(CKA_VALUE).value, |
|
|
|
return Certificate(cert->attribute(CKA_VALUE).value, |
|
|
|
|
|
|
|
cert->attribute(CKA_SUBJECT).value, |
|
|
|
cert->attribute(CKA_LABEL).value, |
|
|
|
cert->attribute(CKA_LABEL).value, |
|
|
|
id); |
|
|
|
id); |
|
|
|
# ifdef __APPLE__ |
|
|
|
# ifdef __APPLE__ |
|
|
@ -355,10 +371,16 @@ namespace suisseid { |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum CardType { |
|
|
|
|
|
|
|
SUISSE_ID, |
|
|
|
|
|
|
|
UNKNOWN |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/// @copydoc Card::Card
|
|
|
|
/// @copydoc Card::Card
|
|
|
|
Post(std::shared_ptr<pcsc::Connection::Reader> reader, |
|
|
|
Post(std::shared_ptr<pcsc::Connection::Reader> reader, |
|
|
|
const cryptoki::Library& cryptoki): |
|
|
|
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() { |
|
|
|
virtual unsigned int minimalPinLength() { |
|
|
@ -379,7 +401,12 @@ namespace suisseid { |
|
|
|
virtual CertStatus certStatus() { |
|
|
|
virtual CertStatus certStatus() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Certificate auth(authenticationCertificate()); |
|
|
|
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; |
|
|
|
return VALID; |
|
|
|
} catch (const no_auth& x) { |
|
|
|
} catch (const no_auth& x) { |
|
|
|
return MISSING; |
|
|
|
return MISSING; |
|
|
@ -430,6 +457,7 @@ namespace suisseid { |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CardType _type; |
|
|
|
std::string _version; // version is cached
|
|
|
|
std::string _version; // version is cached
|
|
|
|
unsigned int _minPinLen; // minimal PIN length is cached
|
|
|
|
unsigned int _minPinLen; // minimal PIN length is cached
|
|
|
|
unsigned int _maxPinLen; // maximal PIN length is cached
|
|
|
|
unsigned int _maxPinLen; // maximal PIN length is cached
|
|
|
|