diff --git a/src/qbrowserlib/certs.hxx b/src/qbrowserlib/certs.hxx new file mode 100644 index 0000000..f0f7ae2 --- /dev/null +++ b/src/qbrowserlib/certs.hxx @@ -0,0 +1,77 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#ifndef __QBROWSERLIB_CERTS_HXX__ +#define __QBROWSERLIB_CERTS_HXX__ + +#include +#include +#include + +namespace qbrowserlib { + +#if defined(Q_OS_LINUX) + QString LIBNAME("libcvP11.so"); +#elif defined(Q_OS_MAC) + QString LIBNAME("libcvP11.dylib"); +#elif defined(Q_OS_WIN) + QString LIBNAME("cvP11.dll"); +#else + QString LIBNAME; +#endif + + + //! Access certificate information from cryptoki library. + /*! Advice: Keep one instance per executable, because library is + loaded, instanciated and unloaded on each object creation or + deletion. */ + class Certs { + + public: + + //! Initialize cryptoki library. + /*! Advice: Keep one instance per executable, because library is + loaded, instanciated and unloaded on each object creation or + deletion. + + @throws throws std::exception in case of error */ + Certs(const QString& lib = LIBNAME): _cryptoki(lib.toStdString()) {} + + //! Get a list of authentification certificates. + /*! @throws throws std::exception in case of error */ + QList auth() { + QList authCerts; + cryptoki::SlotList slotlist(_cryptoki.slotList()); + for (cryptoki::SlotList::iterator slot(slotlist.begin()); + slot!=slotlist.end(); ++slot) { + cryptoki::Session session(*slot); + cryptoki::ObjectList certs(session.find + (cryptoki::Attribute(CKA_CLASS) + .from(CKO_CERTIFICATE))); + for (cryptoki::ObjectList::iterator cert(certs.begin()); + cert!=certs.end(); ++cert) { + cryptoki::Attribute label(cert->attribute(CKA_LABEL)); + if (label.value.find("auth")==0 || + label.value.find("Authentication")!=std::string::npos) { + std::string data(cert->attribute(CKA_VALUE).value); + authCerts.push_back(QSslCertificate(QByteArray(data.data(), + data.size()), + QSsl::Der)); + } + } + } + return authCerts; + } + + private: + + cryptoki::Init _cryptoki; + + }; + +} +#endif diff --git a/src/qbrowserlib/qmake.pro.in b/src/qbrowserlib/qmake.pro.in index c87b3a6..569cb1a 100644 --- a/src/qbrowserlib/qmake.pro.in +++ b/src/qbrowserlib/qmake.pro.in @@ -39,7 +39,7 @@ SOURCES = HEADERS = @srcdir@/swisswebview.hxx @srcdir@/swisswebpage.hxx \ @srcdir@/pluginfactory.hxx @srcdir@/saveorrun.hxx \ @srcdir@/buttonlineedit.hxx \ - @srcdir@/filestorage.hxx + @srcdir@/filestorage.hxx @srcdir@/certs.hxx FORMS = @srcdir@/saveorrun.ui