diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDoc.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDoc.h index 7bad17c7..d64c6368 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDoc.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDoc.h @@ -21,20 +21,29 @@ #include "Exports.h" +#include #include -#include - -#ifndef LIBCDOC_TESTING -// Remove this in production code -#define LIBCDOC_TESTING 1 -#endif namespace libcdoc { /** * @brief A typedef that indicates that integer value may contain libcdoc result code */ -typedef int64_t result_t; +using result_t = int64_t; + +/** + * @brief The public key type + */ +enum class PKType : uint8_t { + /** + * Elliptic curve + */ + ECC, + /** + * RSA + */ + RSA +}; enum { /** @@ -130,10 +139,83 @@ enum { UNSPECIFIED_ERROR = -199, }; +/** + * @brief Get the standard text description of error code + * + * @param code the error code + * @return the text description + */ CDOC_EXPORT std::string getErrorStr(int64_t code); +/** + * @brief Get the library version + * + * @return The version string + */ CDOC_EXPORT std::string getVersion(); +// Logging interface + +/** + * @brief Log-level enumeration to indicate severity of the log message. + */ +enum LogLevel : uint8_t +{ + /** + * @brief Most critical level. Application is about to abort. + */ + LEVEL_FATAL, + + /** + * @brief Errors where functionality has failed or an exception have been caught. + */ + LEVEL_ERROR, + + /** + * @brief Warnings about validation issues or temporary failures that can be recovered. + */ + LEVEL_WARNING, + + /** + * @brief Information that highlights progress or application lifetime events. + */ + LEVEL_INFO, + + /** + * @brief Debugging the application behavior from internal events of interest. + */ + LEVEL_DEBUG, + + /** + * @brief The most verbose level. Present only in development builds, ignored in production code. + */ + LEVEL_TRACE +}; + +class Logger; + +/** + * @brief Set the Logger object for library + * + * @param logger the Logger implementation + */ +CDOC_EXPORT void setLogger(Logger *logger); +/** + * @brief Set logging level + * + * @param level the requested logging level + */ +CDOC_EXPORT void setLogLevel(LogLevel level); +/** + * @brief Log a message to the library logging system + * + * @param level logging level + * @param file the source file name + * @param line the line in source file + * @param msg the message + */ +CDOC_EXPORT void log(LogLevel level, std::string_view file, int line, std::string_view msg); + /** * @brief A simple container of file name and size * @@ -144,6 +226,38 @@ struct FileInfo { int64_t size; }; +namespace CDoc2 { +namespace Label { + /** + * @brief Recipient types for machine-readable labels + * + */ + static constexpr std::string_view TYPE_PASSWORD = "pw"; + static constexpr std::string_view TYPE_SYMMETRIC = "secret"; + static constexpr std::string_view TYPE_PUBLIC_KEY = "pub_key"; + static constexpr std::string_view TYPE_CERTIFICATE = "cert"; + static constexpr std::string_view TYPE_UNKNOWN = "Unknown"; + static constexpr std::string_view TYPE_ID_CARD = "ID-card"; + static constexpr std::string_view TYPE_DIGI_ID = "Digi-ID"; + static constexpr std::string_view TYPE_DIGI_ID_E_RESIDENT = "Digi-ID E-RESIDENT"; + + /** + * @brief Recipient data for machine-readable labels + * + */ + static constexpr std::string_view VERSION = "v"; + static constexpr std::string_view TYPE = "type"; + static constexpr std::string_view FILE = "file"; + static constexpr std::string_view LABEL = "label"; + static constexpr std::string_view CN = "cn"; + static constexpr std::string_view SERIAL_NUMBER = "serial_number"; + static constexpr std::string_view LAST_NAME = "last_name"; + static constexpr std::string_view FIRST_NAME = "first_name"; + static constexpr std::string_view CERT_SHA1 = "cert_sha1"; + static constexpr const char* EXPIRY = "server_exp"; +} +} + }; // namespace libcdoc #endif // CDOC_H diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocReader.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocReader.h index 5c033aa1..1aa578a2 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocReader.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocReader.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { @@ -39,7 +39,7 @@ struct NetworkBackend; */ class CDOC_EXPORT CDocReader { public: - virtual ~CDocReader() = default; + virtual ~CDocReader() noexcept = default; /** * @brief The container version (1 or 2) @@ -200,10 +200,6 @@ class CDOC_EXPORT CDocReader { */ static CDocReader *createReader(std::istream& ifs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network); -#if LIBCDOC_TESTING - virtual int64_t testConfig(std::vector& dst); - virtual int64_t testNetwork(std::vector>& dst); -#endif protected: explicit CDocReader(int _version) : version(_version) {}; @@ -214,6 +210,9 @@ class CDOC_EXPORT CDocReader { Configuration *conf = nullptr; CryptoBackend *crypto = nullptr; NetworkBackend *network = nullptr; + +private: + CDOC_DISABLE_MOVE_COPY(CDocReader); }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocWriter.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocWriter.h index a2595484..2622b537 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocWriter.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CDocWriter.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { struct Configuration; @@ -38,7 +38,7 @@ namespace libcdoc { */ class CDOC_EXPORT CDocWriter { public: - virtual ~CDocWriter(); + virtual ~CDocWriter() noexcept; /** * @brief The container version (1 or 2) @@ -154,6 +154,7 @@ class CDOC_EXPORT CDocWriter { static CDocWriter *createWriter(int version, const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network); protected: explicit CDocWriter(int _version, DataConsumer *dst, bool take_ownership); + CDOC_DISABLE_MOVE_COPY(CDocWriter); void setLastError(const std::string& message) { last_error = message; } diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Configuration.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Configuration.h index 309c2e31..4ca72e60 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Configuration.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Configuration.h @@ -42,6 +42,7 @@ struct CDOC_EXPORT Configuration { * @brief Fetch URL of keyserver (Domain is server id) */ static constexpr char const *KEYSERVER_FETCH_URL = "KEYSERVER_FETCH_URL"; +#ifdef HAS_KEYSHARES /** * @brief JSON array of share server base urls (Domain is server id) */ @@ -74,6 +75,7 @@ struct CDOC_EXPORT Configuration { * @brief Mobile ID phone number (domain is MOBILE_ID) */ static constexpr char const *PHONE_NUMBER = "PHONE_NUMBER"; +#endif Configuration() = default; virtual ~Configuration() noexcept = default; @@ -92,36 +94,32 @@ struct CDOC_EXPORT Configuration { virtual std::string getValue(std::string_view domain, std::string_view param) const {return {};} /** - * @brief get a value of configuration parameter from default domain + * @brief get a value of configuration parameter from the default domain * @param param the parameter name. * @return a string value or empty string if parameter is not defined. */ std::string getValue(std::string_view param) const {return getValue({}, param);} /** - * @brief get boolean value of configuration parameter from default domain + * @brief get boolean value of configuration parameter from the default domain * @param param the parameter name * @param def_val the default value to return if parameter is not set * @return the parameter value */ bool getBoolean(std::string_view param, bool def_val = false) const; /** - * @brief get integer value of configuration parameter from default domain + * @brief get integer value of configuration parameter from the default domain * @param param the parameter name * @param def_val the default value to return if parameter is not set * @return the key value */ int getInt(std::string_view param, int def_val = 0) const; - -#if LIBCDOC_TESTING - virtual int64_t test(std::vector& dst) { return OK; } -#endif }; /** * @brief A Configuration object implementation that reads values from JSON file * * The file should represent a single object with key/value pairs - * Domain should contain sub-objects with corresponding key/value pairs + * Domains are sub-objects with corresponding key/value pairs * Strings are returned unquoted, everything else is returned as JSON * */ diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ConsoleLogger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ConsoleLogger.h deleted file mode 100644 index 06061d7f..00000000 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ConsoleLogger.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * libcdoc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#pragma once - -#include "ILogger.h" - -#include - -namespace libcdoc -{ - -/** - * @brief Console logger - * - * An ILogger subclass that logs text to console. - * - * Info messages are logged to cout, all others to cerr. - */ -class ConsoleLogger : public ILogger -{ -public: - virtual void LogMessage(LogLevel level, std::string_view file, int line, std::string_view message) override - { - // We ignore by default the file name and line number, and call LogMessage with the level and message. - if (level <= minLogLevel) - { - std::ostream& ofs = (level == LEVEL_INFO) ? std::cout : std::cerr; - ofs << message << '\n'; - } - } -}; - - -} diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CryptoBackend.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CryptoBackend.h index 56e64475..bf63d5b4 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CryptoBackend.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/CryptoBackend.h @@ -21,7 +21,7 @@ #include -#include +#include namespace libcdoc { diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ILogger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ILogger.h deleted file mode 100644 index 3bf1c72c..00000000 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/ILogger.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * libcdoc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __ILOGGER_H__INCLUDED__ -#define __ILOGGER_H__INCLUDED__ - -#include - -#include - -#ifdef __cpp_lib_format -#include -namespace fmt = std; -#else -#define FMT_HEADER_ONLY -#include "fmt/format.h" -#endif - -#define FORMAT fmt::format - -namespace libcdoc -{ - -/** - * @brief Generic interface to implement a logger. - */ -class CDOC_EXPORT ILogger -{ -public: - /** - * @brief Log-level enumeration to indicate severity of the log message. - */ - enum LogLevel - { - /** - * @brief Most critical level. Application is about to abort. - */ - LEVEL_FATAL, - - /** - * @brief Errors where functionality has failed or an exception have been caught. - */ - LEVEL_ERROR, - - /** - * @brief Warnings about validation issues or temporary failures that can be recovered. - */ - LEVEL_WARNING, - - /** - * @brief Information that highlights progress or application lifetime events. - */ - LEVEL_INFO, - - /** - * @brief Debugging the application behavior from internal events of interest. - */ - LEVEL_DEBUG, - - /** - * @brief Most verbose level. Used for development, NOP in production code. - */ - LEVEL_TRACE - }; - - ILogger() : minLogLevel(LEVEL_WARNING) {} - virtual ~ILogger() {} - - /** - * @brief Logs given message with given severity, file name and line number. - * @param level Severity of the log message. - * @param file File name where the log message was recorded. - * @param line Line number in the file where the log message was recorded. - * @param message The log message. - * - * Every class implementing the ILogger interface must implement the member function. - * Default implementation does nothing. - */ - virtual void LogMessage(LogLevel level, std::string_view file, int line, std::string_view message) {} - - /** - * @brief Returns current minimum log level of the logger. - * @return Minimum log level. - */ - LogLevel GetMinLogLevel() const noexcept { return minLogLevel; } - - /** - * @brief Sets minimum log level for the logger. - * @param level minimum level to log. - * - * Sets minimum level of log messages to log. For example, if the minimum log level is set - * to LogLevelInfo (default), then LogLevelFatal, LogLevelError, LogLevelWarning and LogLevelInfo - * messages are logged, but not LogLevelDebug or LogLevelTrace messages. - */ - void SetMinLogLevel(LogLevel level) noexcept { minLogLevel = level; } - - /** - * @brief Adds ILogger implementation to logging queue. - * - * This function does not take ownership of the logger's instance. - * It is up to the caller to free the resources of the logger's instance and - * keep it alive until removed from the queue. - * - * @param logger Logger's instance to be added. - * @return Unique cookie identifying the logger's instance in the logging queue. - */ - static int addLogger(ILogger* logger); - - /** - * @brief Removes logger's instance from the logging queue. - * @param cookie Unique cookie returned by the add_logger function when the logger was added. - * @return Pointer to ILogger object that is removed. It's up to user to free the resources. - */ - static ILogger* removeLogger(int cookie); - - /** - * @brief Returns global logger's instance. - * @return Global logger's instance. - */ - static ILogger* getLogger(); - - static void setLogger(ILogger *logger); - -protected: - /** - * @brief Minimum level of log messages to log. - */ - LogLevel minLogLevel; -}; - -#ifndef SWIG -template -static inline void LogFormat(ILogger::LogLevel level, std::string_view file, int line, fmt::format_string fmt, Args&&... args) -{ - auto msg = fmt::format(fmt, std::forward(args)...); - ILogger::getLogger()->LogMessage(level, file, line, msg); -} - -static inline void LogFormat(ILogger::LogLevel level, std::string_view file, int line, std::string_view msg) -{ - ILogger::getLogger()->LogMessage(level, file, line, msg); -} -#endif - -#define LOG(l,...) LogFormat((l), __FILE__, __LINE__, __VA_ARGS__) -#define LOG_ERROR(...) LogFormat(libcdoc::ILogger::LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_WARN(...) LogFormat(libcdoc::ILogger::LEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_INFO(...) LogFormat(libcdoc::ILogger::LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_DBG(...) LogFormat(libcdoc::ILogger::LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__) - -#ifdef NDEBUG -#define LOG_TRACE(...) -#define LOG_TRACE_KEY(MSG, KEY) -#else -#define LOG_TRACE(...) LogFormat(libcdoc::ILogger::LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_TRACE_KEY(MSG, KEY) LogFormat(libcdoc::ILogger::LEVEL_TRACE, __FILE__, __LINE__, MSG, toHex(KEY)) -#endif - -} - -#endif diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Io.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Io.h index dfc04199..5bc5eecf 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Io.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Io.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace libcdoc { @@ -209,45 +210,6 @@ struct CDOC_EXPORT MultiDataSource : public DataSource { result_t next(FileInfo& info) { return next(info.name, info.size); } }; -struct CDOC_EXPORT ChainedConsumer : public DataConsumer { - ChainedConsumer(DataConsumer *dst, bool take_ownership) : _dst(dst), _owned(take_ownership) {} - ~ChainedConsumer() { - if (_owned) delete _dst; - } - result_t write(const uint8_t *src, size_t size) noexcept override { - return _dst->write(src, size); - } - result_t close() noexcept override { - if (_owned) return _dst->close(); - return OK; - } - bool isError() noexcept override { - return _dst->isError(); - } -protected: - DataConsumer *_dst; - bool _owned; -}; - -struct CDOC_EXPORT ChainedSource : public DataSource { - ChainedSource(DataSource *src, bool take_ownership) : _src(src), _owned(take_ownership) {} - ~ChainedSource() { - if (_owned) delete _src; - } - result_t read(uint8_t *dst, size_t size) noexcept override { - return _src->read(dst, size); - } - bool isError() noexcept override { - return _src->isError(); - } - bool isEof() noexcept override { - return _src->isEof(); - } -protected: - DataSource *_src; - bool _owned; -}; - struct CDOC_EXPORT IStreamSource : public DataSource { IStreamSource(std::istream *ifs, bool take_ownership = false) : _ifs(ifs), _owned(take_ownership) {} IStreamSource(const std::string& path); @@ -259,7 +221,7 @@ struct CDOC_EXPORT IStreamSource : public DataSource { if(_ifs->bad()) return INPUT_STREAM_ERROR; _ifs->clear(); _ifs->seekg(pos); - return bool(_ifs->bad()) ? INPUT_STREAM_ERROR : OK; + return _ifs->bad() ? INPUT_STREAM_ERROR : OK; } result_t read(uint8_t *dst, size_t size) noexcept override try { @@ -302,7 +264,7 @@ struct CDOC_EXPORT OStreamConsumer : public DataConsumer { }; struct CDOC_EXPORT VectorSource : public DataSource { - VectorSource(const std::vector& data) : _data(data), _ptr(0) {} + VectorSource(const std::vector& data) : _data(data) {} result_t seek(size_t pos) override { if (pos > _data.size()) return INPUT_STREAM_ERROR; @@ -321,7 +283,7 @@ struct CDOC_EXPORT VectorSource : public DataSource { bool isEof() noexcept override { return _ptr >= _data.size(); } protected: const std::vector& _data; - size_t _ptr; + size_t _ptr{0}; }; struct CDOC_EXPORT VectorConsumer : public DataConsumer { @@ -333,7 +295,7 @@ struct CDOC_EXPORT VectorConsumer : public DataConsumer { return OUTPUT_STREAM_ERROR; } result_t close() noexcept final { return OK; } - virtual bool isError() noexcept final { return false; } + bool isError() noexcept final { return false; } protected: std::vector& _data; }; @@ -355,25 +317,7 @@ struct CDOC_EXPORT FileListConsumer : public MultiDataConsumer { bool isError() noexcept final { return ofs.bad(); } - result_t open(const std::string& name, int64_t size) override final { - std::string fileName; - if (ofs.is_open()) { - ofs.close(); - } - size_t lastSlashPos = name.find_last_of("\\/"); - if (lastSlashPos != std::string::npos) - { - fileName = name.substr(lastSlashPos + 1); - } - else - { - fileName = name; - } - std::filesystem::path path(base); - path /= fileName; - ofs.open(path.string(), std::ios_base::binary); - return ofs.bad() ? OUTPUT_STREAM_ERROR : OK; - } + result_t open(const std::string &name, int64_t size) final; protected: std::filesystem::path base; @@ -390,7 +334,7 @@ struct CDOC_EXPORT FileListSource : public MultiDataSource { protected: std::filesystem::path _base; const std::vector& _files; - int64_t _current; + int64_t _current = -1; std::ifstream _ifs; }; diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Lock.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Lock.h index 3011f871..c46cea21 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Lock.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Lock.h @@ -19,7 +19,7 @@ #ifndef __LOCK_H__ #define __LOCK_H__ -#include +#include "CDoc.h" #include #include @@ -42,7 +42,7 @@ struct CDOC_EXPORT Lock /** * @brief The lock type */ - enum Type : unsigned char { + enum Type : unsigned char { /** * @brief Valid capsule but not supported by this library version * @@ -51,7 +51,7 @@ struct CDOC_EXPORT Lock /** * @brief Symmetric AES key */ - SYMMETRIC_KEY, + SYMMETRIC_KEY, /** * @brief PBKDF key (derived from password) */ @@ -68,30 +68,18 @@ struct CDOC_EXPORT Lock * @brief Public key stored on keyserver */ SERVER, +#ifdef HAS_KEYSHARES /** * @brief Symmetric key distributed on several servers */ SHARE_SERVER - }; - - /** - * @brief The public key type - */ - enum PKType : unsigned char { - /** - * Elliptic curve - */ - ECC, - /** - * RSA - */ - RSA - }; +#endif + }; /** * @brief Extra parameters depending on key type */ - enum Params : unsigned int { + enum Params : unsigned int { /** * @brief HKDF salt (SYMMETRIC_KEY, PASSWORD and SHARE_SERVER) */ @@ -128,10 +116,12 @@ struct CDOC_EXPORT Lock * @brief Keyshare recipient ID */ RECIPIENT_ID, +#ifdef HAS_KEYSHARES /** * @brief Keyshare server urls (separated by ';') */ SHARE_URLS, +#endif /** * @brief CDoc1 specific */ @@ -152,7 +142,7 @@ struct CDOC_EXPORT Lock * @brief CDoc1 specific */ PARTY_VINFO - }; + }; /** * @brief get lock parameter value @@ -176,20 +166,20 @@ struct CDOC_EXPORT Lock /** * @brief The lock type */ - Type type = Type::UNKNOWN; + Type type = Type::UNKNOWN; /** * @brief algorithm type for public key based locks */ - PKType pk_type = PKType::ECC; + PKType pk_type = PKType::ECC; /** * @brief the lock label */ - std::string label; + std::string label; /** * @brief encrypted FMK (File Master Key) */ - std::vector encrypted_fmk; + std::vector encrypted_fmk; /** * @brief check whether lock is valid @@ -206,11 +196,6 @@ struct CDOC_EXPORT Lock * @return true if type is CDOC1, PUBLIC_KEY or SERVER */ constexpr bool isPKI() const noexcept { return (type == Type::CDOC1) || (type == Type::PUBLIC_KEY) || (type == Type::SERVER); } - /** - * @brief check whether lock is based on certificate - * @return true if type is CDOC1 - */ - constexpr bool isCertificate() const noexcept { return (type == Type::CDOC1); } /** * @brief check whether lock is CDoc1 version * @return true if type is CDOC1 @@ -222,40 +207,21 @@ struct CDOC_EXPORT Lock */ constexpr bool isRSA() const noexcept { return pk_type == PKType::RSA; } - /** - * @brief check whether two locks have the same public key - * - * This convenience method checks whether both locks are public key based, and if they are, - * whether the RCPT_KEY parameters are identical (i.e. both can be decrypted by the same private key) - * @param other the other lock - * @return true if both have the same public key - */ - bool hasTheSameKey(const Lock &other) const; - /** - * @brief check whether lock has the given public key - * - * This convenience method checks whether lock is public key based, and if it is, - * whether the RCPT_KEY parameters is identical to ptovided key(i.e. it can be decrypted by the corresponding private key) - * @param public_key the public key (short format) - * @return true if lock has the same public key - */ - bool hasTheSameKey(const std::vector& public_key) const; - - Lock() noexcept = default; - Lock(Type _type) noexcept : type(_type) {}; + Lock() noexcept = default; + Lock(Type _type) noexcept : type(_type) {}; /** * @brief Set lock parameter value * @param param a parameter type * @param val the value */ - void setBytes(Params param, const std::vector& val) { params[param] = val; } + void setBytes(Params param, std::vector val) { params[param] = std::move(val); } /** * @brief Set lock parameter value from string * @param param a parameter type * @param val the value */ - void setString(Params param, const std::string& val) { params[param] = std::vector(val.cbegin(), val.cend()); } + void setString(Params param, const std::string& val) { setBytes(param, {val.cbegin(), val.cend()}); } /** * @brief Set lock parameter value from integer * @param param a parameter type @@ -264,15 +230,16 @@ struct CDOC_EXPORT Lock void setInt(Params param, int32_t val); /** - * @brief A convenience method to initialize CERTIFICATE, RCPT_KEY and PK_TYPE values from given certificate - * @param cert the certificate (der-encoded) + * @brief parse machine-readable CDoc2 label + * @param label the label + * @return a map of key-value pairs */ - void setCertificate(const std::vector& cert); + static std::map parseLabel(const std::string& label); - bool operator== (const Lock& other) const = default; + bool operator== (const Lock& other) const noexcept = default; private: - std::map> params; + std::map> params; }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Logger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Logger.h new file mode 100644 index 00000000..a3d27234 --- /dev/null +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Logger.h @@ -0,0 +1,79 @@ +/* + * libcdoc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +#include + +namespace libcdoc +{ + +/** + * @brief Generic interface to implement a logger. + */ +class CDOC_EXPORT Logger +{ +public: + virtual ~Logger() noexcept = default; + + /** + * @brief Logs given message with given severity, file name and line number. + * + * It tests the log level and if <= min_level invokes logMessage + * + * @param level Severity of the log message. + * @param file File name where the log message was recorded. + * @param line Line number in the file where the log message was recorded. + * @param msg The log message. + */ + void log(LogLevel level, std::string_view file, int line, std::string_view msg) { + if (level <= min_level) logMessage(level, file, line, msg); + } + + /** + * @brief Sets minimum log level for the logger. + * @param level minimum level to log. + * + * Sets minimum level of log messages to log. For example, if the minimum log level is set + * to LEVEL_INFO (default), then LEVEL_FATAL, LEVEL_ERROR, LEVEL_WARNING and LEVEL_INFO + * messages are logged, but not LEVEL_DEBUG or LEVEL_TRACE messages. + */ + constexpr void setMinLogLevel(LogLevel level) noexcept { min_level = level; } + +protected: + /** + * @brief Logs given message with given severity, file name and line number. + * + * Every class implementing the ILogger interface must implement this member function. + * The efault implementation does nothing. + * The level should be checked by caller, thus the implementation should expect that level <= min_level + * + * @param level Severity of the log message. + * @param file File name where the log message was recorded. + * @param line Line number in the file where the log message was recorded. + * @param msg The log message. + */ + virtual void logMessage(LogLevel level, std::string_view file, int line, std::string_view msg) {} + + /** + * @brief Minimum level of log messages to log. + */ + LogLevel min_level = LEVEL_WARNING; +}; + +} diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/NetworkBackend.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/NetworkBackend.h index 6c082240..4d1dc3d9 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/NetworkBackend.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/NetworkBackend.h @@ -29,6 +29,7 @@ struct CDOC_EXPORT NetworkBackend { * */ static constexpr int NETWORK_ERROR = -300; +#ifdef HAS_KEYSHARES // MID/SID error codes // User refused the session static constexpr int MIDSID_USER_REFUSED = -350; @@ -62,9 +63,10 @@ struct CDOC_EXPORT NetworkBackend { static constexpr int MIDSID_DELIVERY_ERROR = -364; // Invalid response from card static constexpr int MIDSID_SIM_ERROR = -365; +#endif /** - * @brief Share information returned by server + * @brief Capsule information returned by capsule server * */ struct CapsuleInfo { @@ -79,8 +81,9 @@ struct CDOC_EXPORT NetworkBackend { */ uint64_t expiry_time; }; +#ifdef HAS_KEYSHARES /** - * @brief Share information returned by server + * @brief Share information returned by share server * */ struct ShareInfo { @@ -95,6 +98,7 @@ struct CDOC_EXPORT NetworkBackend { */ std::string recipient; }; +#endif /** * @brief Proxy credentials used for network access @@ -146,6 +150,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t sendKey (CapsuleInfo& dst, const std::string& url, const std::vector& rcpt_key, const std::vector &key_material, const std::string& type, uint64_t expiry_ts); +#ifdef HAS_KEYSHARES /** * @brief send key share to server * @@ -157,6 +162,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t sendShare(std::vector& dst, const std::string& url, const std::string& recipient, const std::vector& share); +#endif /** * @brief fetch key material from keyserver * @@ -167,6 +173,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t fetchKey (std::vector& dst, const std::string& url, const std::string& transaction_id); +#ifdef HAS_KEYSHARES /** * @brief fetch authentication nonce from share server * @param dst a destination container for nonce @@ -185,7 +192,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t fetchShare(ShareInfo& share, const std::string& url, const std::string& share_id, const std::string& ticket, const std::vector& cert); - +#endif /** * @brief get client TLS certificate in der format @@ -234,6 +241,7 @@ struct CDOC_EXPORT NetworkBackend { return NOT_IMPLEMENTED; } +#ifdef HAS_KEYSHARES /** * @brief show MID/SID verification code * @@ -277,9 +285,6 @@ struct CDOC_EXPORT NetworkBackend { result_t signMID(std::vector& dst, std::vector& cert, const std::string& url, const std::string& rp_uuid, const std::string& rp_name, const std::string& phone, const std::string& rcpt_id, const std::vector& digest, CryptoBackend::HashAlgorithm algo); - -#if LIBCDOC_TESTING - virtual int64_t test(std::vector> &dst); #endif }; diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Recipient.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Recipient.h index 0b04755b..8374bc4b 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Recipient.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Headers/Recipient.h @@ -19,15 +19,17 @@ #ifndef __RECIPIENT_H__ #define __RECIPIENT_H__ -#include +#include "CDoc.h" -#include #include #include +#include #include namespace libcdoc { +struct Lock; + /** * @brief A descriptor of encryption method and key to be used in container * @@ -50,24 +52,12 @@ struct CDOC_EXPORT Recipient { * @brief Public key */ PUBLIC_KEY, +#ifdef HAS_KEYSHARES /** * @brief n of n shared symmetric key */ KEYSHARE - }; - - /** - * @brief The public key type - */ - enum PKType : uint8_t { - /** - * Elliptic curve - */ - ECC, - /** - * RSA - */ - RSA +#endif }; Recipient() = default; @@ -96,10 +86,12 @@ struct CDOC_EXPORT Recipient { * @brief The recipient's certificate (if present) */ std::vector cert; +#ifdef HAS_KEYSHARES /** * @brief The recipient id for share server (PNOEE-XXXXXXXXXXX) */ std::string id; +#endif /** * @brief The keyserver or share server list id (if present) */ @@ -109,16 +101,6 @@ struct CDOC_EXPORT Recipient { * */ uint64_t expiry_ts = 0; - /** - * @brief key/certificate filename for machine-readable label - * - */ - std::string file_name; - /** - * @brief public key/password name for machine-readable label - * - */ - std::string key_name; /** * @brief test whether the Recipient structure is initialized @@ -145,11 +127,13 @@ struct CDOC_EXPORT Recipient { * @return true if type is SERVER */ bool isKeyServer() const { return (type == Type::PUBLIC_KEY) && !server_id.empty(); } +#ifdef HAS_KEYSHARES /** * @brief check whether Recipient is keyshare * @return true if type is KEYSHARE */ bool isKeyShare() const { return type == Type::KEYSHARE; } +#endif /** * @brief Clear all values and set type to NONE @@ -184,6 +168,12 @@ struct CDOC_EXPORT Recipient { * @return a new Recipient structure */ static Recipient makePublicKey(std::string label, std::vector public_key, PKType pk_type); + /** + * @brief Create a new public key based Recipient + * @param lock Lock to derive parameters from + * @return a new Recipient structure + */ + static Recipient makePublicKey(const Lock &lock); /** * @brief Create a new certificate based Recipient * @param label the label text @@ -215,6 +205,16 @@ struct CDOC_EXPORT Recipient { */ static Recipient makeServer(std::string label, std::vector cert, std::string server_id); + /** + * @brief Create a new capsule server based Recipient + * + * @param lock Lock to derive parameters from + * @param server_id the keyserver id + * @return a new Recipient structure + */ + static Recipient makeServer(const Lock &lock, std::string server_id); + +#ifdef HAS_KEYSHARES /** * @brief Create new keyshare recipient * @@ -224,6 +224,7 @@ struct CDOC_EXPORT Recipient { * @return Recipient a new Recipient structure */ static Recipient makeShare(std::string label, std::string server_id, std::string recipient_id); +#endif /** * @brief Get the label for this recipient @@ -233,18 +234,30 @@ struct CDOC_EXPORT Recipient { * @param extra additional parameter values to use * @return a label value */ - std::string getLabel(const std::vector> &extra) const; + std::string getLabel(std::map extra) const; + + /** + * @brief Set a property for automatic label generation + * + * @param key the property name + * @param value the property value + */ + void setLabelValue(std::string_view key, std::string_view value) { + lbl_parts[std::string(key)] = value; + } /** - * @brief parse machine-readable CDoc2 label - * @param label the label - * @return a map of key-value pairs + * @brief Validate recipient record + * + * @return true if Recipient is valid */ - static std::map parseLabel(const std::string& label); + bool validate() const; bool operator== (const Recipient& other) const = default; protected: Recipient(Type _type) : type(_type) {}; +private: + std::map lbl_parts; }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Info.plist b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Info.plist index f1db506c..3f02ba10 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Info.plist +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Info.plist @@ -12,17 +12,19 @@ ee.ria.cdoc CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.8 + 0.5.0 CFBundleSignature ???? CFBundleVersion - 0 + 32 CSResourcesFileMapped MinimumOSVersion - 15.0 + 16.3 diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Modules/module.modulemap b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Modules/module.modulemap index db570a56..68872550 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Modules/module.modulemap +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/Modules/module.modulemap @@ -10,8 +10,7 @@ framework module cdoc { header "CryptoBackend.h" header "NetworkBackend.h" header "PKCS11Backend.h" - header "ILogger.h" - header "ConsoleLogger.h" + header "Logger.h" export * requires cplusplus } \ No newline at end of file diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/cdoc b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/cdoc index 3a4b0989..cd5a62fd 100755 Binary files a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/cdoc and b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64/cdoc.framework/cdoc differ diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDoc.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDoc.h index 7bad17c7..d64c6368 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDoc.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDoc.h @@ -21,20 +21,29 @@ #include "Exports.h" +#include #include -#include - -#ifndef LIBCDOC_TESTING -// Remove this in production code -#define LIBCDOC_TESTING 1 -#endif namespace libcdoc { /** * @brief A typedef that indicates that integer value may contain libcdoc result code */ -typedef int64_t result_t; +using result_t = int64_t; + +/** + * @brief The public key type + */ +enum class PKType : uint8_t { + /** + * Elliptic curve + */ + ECC, + /** + * RSA + */ + RSA +}; enum { /** @@ -130,10 +139,83 @@ enum { UNSPECIFIED_ERROR = -199, }; +/** + * @brief Get the standard text description of error code + * + * @param code the error code + * @return the text description + */ CDOC_EXPORT std::string getErrorStr(int64_t code); +/** + * @brief Get the library version + * + * @return The version string + */ CDOC_EXPORT std::string getVersion(); +// Logging interface + +/** + * @brief Log-level enumeration to indicate severity of the log message. + */ +enum LogLevel : uint8_t +{ + /** + * @brief Most critical level. Application is about to abort. + */ + LEVEL_FATAL, + + /** + * @brief Errors where functionality has failed or an exception have been caught. + */ + LEVEL_ERROR, + + /** + * @brief Warnings about validation issues or temporary failures that can be recovered. + */ + LEVEL_WARNING, + + /** + * @brief Information that highlights progress or application lifetime events. + */ + LEVEL_INFO, + + /** + * @brief Debugging the application behavior from internal events of interest. + */ + LEVEL_DEBUG, + + /** + * @brief The most verbose level. Present only in development builds, ignored in production code. + */ + LEVEL_TRACE +}; + +class Logger; + +/** + * @brief Set the Logger object for library + * + * @param logger the Logger implementation + */ +CDOC_EXPORT void setLogger(Logger *logger); +/** + * @brief Set logging level + * + * @param level the requested logging level + */ +CDOC_EXPORT void setLogLevel(LogLevel level); +/** + * @brief Log a message to the library logging system + * + * @param level logging level + * @param file the source file name + * @param line the line in source file + * @param msg the message + */ +CDOC_EXPORT void log(LogLevel level, std::string_view file, int line, std::string_view msg); + /** * @brief A simple container of file name and size * @@ -144,6 +226,38 @@ struct FileInfo { int64_t size; }; +namespace CDoc2 { +namespace Label { + /** + * @brief Recipient types for machine-readable labels + * + */ + static constexpr std::string_view TYPE_PASSWORD = "pw"; + static constexpr std::string_view TYPE_SYMMETRIC = "secret"; + static constexpr std::string_view TYPE_PUBLIC_KEY = "pub_key"; + static constexpr std::string_view TYPE_CERTIFICATE = "cert"; + static constexpr std::string_view TYPE_UNKNOWN = "Unknown"; + static constexpr std::string_view TYPE_ID_CARD = "ID-card"; + static constexpr std::string_view TYPE_DIGI_ID = "Digi-ID"; + static constexpr std::string_view TYPE_DIGI_ID_E_RESIDENT = "Digi-ID E-RESIDENT"; + + /** + * @brief Recipient data for machine-readable labels + * + */ + static constexpr std::string_view VERSION = "v"; + static constexpr std::string_view TYPE = "type"; + static constexpr std::string_view FILE = "file"; + static constexpr std::string_view LABEL = "label"; + static constexpr std::string_view CN = "cn"; + static constexpr std::string_view SERIAL_NUMBER = "serial_number"; + static constexpr std::string_view LAST_NAME = "last_name"; + static constexpr std::string_view FIRST_NAME = "first_name"; + static constexpr std::string_view CERT_SHA1 = "cert_sha1"; + static constexpr const char* EXPIRY = "server_exp"; +} +} + }; // namespace libcdoc #endif // CDOC_H diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocReader.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocReader.h index 5c033aa1..1aa578a2 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocReader.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocReader.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { @@ -39,7 +39,7 @@ struct NetworkBackend; */ class CDOC_EXPORT CDocReader { public: - virtual ~CDocReader() = default; + virtual ~CDocReader() noexcept = default; /** * @brief The container version (1 or 2) @@ -200,10 +200,6 @@ class CDOC_EXPORT CDocReader { */ static CDocReader *createReader(std::istream& ifs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network); -#if LIBCDOC_TESTING - virtual int64_t testConfig(std::vector& dst); - virtual int64_t testNetwork(std::vector>& dst); -#endif protected: explicit CDocReader(int _version) : version(_version) {}; @@ -214,6 +210,9 @@ class CDOC_EXPORT CDocReader { Configuration *conf = nullptr; CryptoBackend *crypto = nullptr; NetworkBackend *network = nullptr; + +private: + CDOC_DISABLE_MOVE_COPY(CDocReader); }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocWriter.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocWriter.h index a2595484..2622b537 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocWriter.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CDocWriter.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { struct Configuration; @@ -38,7 +38,7 @@ namespace libcdoc { */ class CDOC_EXPORT CDocWriter { public: - virtual ~CDocWriter(); + virtual ~CDocWriter() noexcept; /** * @brief The container version (1 or 2) @@ -154,6 +154,7 @@ class CDOC_EXPORT CDocWriter { static CDocWriter *createWriter(int version, const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network); protected: explicit CDocWriter(int _version, DataConsumer *dst, bool take_ownership); + CDOC_DISABLE_MOVE_COPY(CDocWriter); void setLastError(const std::string& message) { last_error = message; } diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Configuration.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Configuration.h index 309c2e31..4ca72e60 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Configuration.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Configuration.h @@ -42,6 +42,7 @@ struct CDOC_EXPORT Configuration { * @brief Fetch URL of keyserver (Domain is server id) */ static constexpr char const *KEYSERVER_FETCH_URL = "KEYSERVER_FETCH_URL"; +#ifdef HAS_KEYSHARES /** * @brief JSON array of share server base urls (Domain is server id) */ @@ -74,6 +75,7 @@ struct CDOC_EXPORT Configuration { * @brief Mobile ID phone number (domain is MOBILE_ID) */ static constexpr char const *PHONE_NUMBER = "PHONE_NUMBER"; +#endif Configuration() = default; virtual ~Configuration() noexcept = default; @@ -92,36 +94,32 @@ struct CDOC_EXPORT Configuration { virtual std::string getValue(std::string_view domain, std::string_view param) const {return {};} /** - * @brief get a value of configuration parameter from default domain + * @brief get a value of configuration parameter from the default domain * @param param the parameter name. * @return a string value or empty string if parameter is not defined. */ std::string getValue(std::string_view param) const {return getValue({}, param);} /** - * @brief get boolean value of configuration parameter from default domain + * @brief get boolean value of configuration parameter from the default domain * @param param the parameter name * @param def_val the default value to return if parameter is not set * @return the parameter value */ bool getBoolean(std::string_view param, bool def_val = false) const; /** - * @brief get integer value of configuration parameter from default domain + * @brief get integer value of configuration parameter from the default domain * @param param the parameter name * @param def_val the default value to return if parameter is not set * @return the key value */ int getInt(std::string_view param, int def_val = 0) const; - -#if LIBCDOC_TESTING - virtual int64_t test(std::vector& dst) { return OK; } -#endif }; /** * @brief A Configuration object implementation that reads values from JSON file * * The file should represent a single object with key/value pairs - * Domain should contain sub-objects with corresponding key/value pairs + * Domains are sub-objects with corresponding key/value pairs * Strings are returned unquoted, everything else is returned as JSON * */ diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ConsoleLogger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ConsoleLogger.h deleted file mode 100644 index 06061d7f..00000000 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ConsoleLogger.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * libcdoc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#pragma once - -#include "ILogger.h" - -#include - -namespace libcdoc -{ - -/** - * @brief Console logger - * - * An ILogger subclass that logs text to console. - * - * Info messages are logged to cout, all others to cerr. - */ -class ConsoleLogger : public ILogger -{ -public: - virtual void LogMessage(LogLevel level, std::string_view file, int line, std::string_view message) override - { - // We ignore by default the file name and line number, and call LogMessage with the level and message. - if (level <= minLogLevel) - { - std::ostream& ofs = (level == LEVEL_INFO) ? std::cout : std::cerr; - ofs << message << '\n'; - } - } -}; - - -} diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CryptoBackend.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CryptoBackend.h index 56e64475..bf63d5b4 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CryptoBackend.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/CryptoBackend.h @@ -21,7 +21,7 @@ #include -#include +#include namespace libcdoc { diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ILogger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ILogger.h deleted file mode 100644 index 3bf1c72c..00000000 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/ILogger.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * libcdoc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __ILOGGER_H__INCLUDED__ -#define __ILOGGER_H__INCLUDED__ - -#include - -#include - -#ifdef __cpp_lib_format -#include -namespace fmt = std; -#else -#define FMT_HEADER_ONLY -#include "fmt/format.h" -#endif - -#define FORMAT fmt::format - -namespace libcdoc -{ - -/** - * @brief Generic interface to implement a logger. - */ -class CDOC_EXPORT ILogger -{ -public: - /** - * @brief Log-level enumeration to indicate severity of the log message. - */ - enum LogLevel - { - /** - * @brief Most critical level. Application is about to abort. - */ - LEVEL_FATAL, - - /** - * @brief Errors where functionality has failed or an exception have been caught. - */ - LEVEL_ERROR, - - /** - * @brief Warnings about validation issues or temporary failures that can be recovered. - */ - LEVEL_WARNING, - - /** - * @brief Information that highlights progress or application lifetime events. - */ - LEVEL_INFO, - - /** - * @brief Debugging the application behavior from internal events of interest. - */ - LEVEL_DEBUG, - - /** - * @brief Most verbose level. Used for development, NOP in production code. - */ - LEVEL_TRACE - }; - - ILogger() : minLogLevel(LEVEL_WARNING) {} - virtual ~ILogger() {} - - /** - * @brief Logs given message with given severity, file name and line number. - * @param level Severity of the log message. - * @param file File name where the log message was recorded. - * @param line Line number in the file where the log message was recorded. - * @param message The log message. - * - * Every class implementing the ILogger interface must implement the member function. - * Default implementation does nothing. - */ - virtual void LogMessage(LogLevel level, std::string_view file, int line, std::string_view message) {} - - /** - * @brief Returns current minimum log level of the logger. - * @return Minimum log level. - */ - LogLevel GetMinLogLevel() const noexcept { return minLogLevel; } - - /** - * @brief Sets minimum log level for the logger. - * @param level minimum level to log. - * - * Sets minimum level of log messages to log. For example, if the minimum log level is set - * to LogLevelInfo (default), then LogLevelFatal, LogLevelError, LogLevelWarning and LogLevelInfo - * messages are logged, but not LogLevelDebug or LogLevelTrace messages. - */ - void SetMinLogLevel(LogLevel level) noexcept { minLogLevel = level; } - - /** - * @brief Adds ILogger implementation to logging queue. - * - * This function does not take ownership of the logger's instance. - * It is up to the caller to free the resources of the logger's instance and - * keep it alive until removed from the queue. - * - * @param logger Logger's instance to be added. - * @return Unique cookie identifying the logger's instance in the logging queue. - */ - static int addLogger(ILogger* logger); - - /** - * @brief Removes logger's instance from the logging queue. - * @param cookie Unique cookie returned by the add_logger function when the logger was added. - * @return Pointer to ILogger object that is removed. It's up to user to free the resources. - */ - static ILogger* removeLogger(int cookie); - - /** - * @brief Returns global logger's instance. - * @return Global logger's instance. - */ - static ILogger* getLogger(); - - static void setLogger(ILogger *logger); - -protected: - /** - * @brief Minimum level of log messages to log. - */ - LogLevel minLogLevel; -}; - -#ifndef SWIG -template -static inline void LogFormat(ILogger::LogLevel level, std::string_view file, int line, fmt::format_string fmt, Args&&... args) -{ - auto msg = fmt::format(fmt, std::forward(args)...); - ILogger::getLogger()->LogMessage(level, file, line, msg); -} - -static inline void LogFormat(ILogger::LogLevel level, std::string_view file, int line, std::string_view msg) -{ - ILogger::getLogger()->LogMessage(level, file, line, msg); -} -#endif - -#define LOG(l,...) LogFormat((l), __FILE__, __LINE__, __VA_ARGS__) -#define LOG_ERROR(...) LogFormat(libcdoc::ILogger::LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_WARN(...) LogFormat(libcdoc::ILogger::LEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_INFO(...) LogFormat(libcdoc::ILogger::LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_DBG(...) LogFormat(libcdoc::ILogger::LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__) - -#ifdef NDEBUG -#define LOG_TRACE(...) -#define LOG_TRACE_KEY(MSG, KEY) -#else -#define LOG_TRACE(...) LogFormat(libcdoc::ILogger::LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__) -#define LOG_TRACE_KEY(MSG, KEY) LogFormat(libcdoc::ILogger::LEVEL_TRACE, __FILE__, __LINE__, MSG, toHex(KEY)) -#endif - -} - -#endif diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Io.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Io.h index dfc04199..5bc5eecf 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Io.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Io.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace libcdoc { @@ -209,45 +210,6 @@ struct CDOC_EXPORT MultiDataSource : public DataSource { result_t next(FileInfo& info) { return next(info.name, info.size); } }; -struct CDOC_EXPORT ChainedConsumer : public DataConsumer { - ChainedConsumer(DataConsumer *dst, bool take_ownership) : _dst(dst), _owned(take_ownership) {} - ~ChainedConsumer() { - if (_owned) delete _dst; - } - result_t write(const uint8_t *src, size_t size) noexcept override { - return _dst->write(src, size); - } - result_t close() noexcept override { - if (_owned) return _dst->close(); - return OK; - } - bool isError() noexcept override { - return _dst->isError(); - } -protected: - DataConsumer *_dst; - bool _owned; -}; - -struct CDOC_EXPORT ChainedSource : public DataSource { - ChainedSource(DataSource *src, bool take_ownership) : _src(src), _owned(take_ownership) {} - ~ChainedSource() { - if (_owned) delete _src; - } - result_t read(uint8_t *dst, size_t size) noexcept override { - return _src->read(dst, size); - } - bool isError() noexcept override { - return _src->isError(); - } - bool isEof() noexcept override { - return _src->isEof(); - } -protected: - DataSource *_src; - bool _owned; -}; - struct CDOC_EXPORT IStreamSource : public DataSource { IStreamSource(std::istream *ifs, bool take_ownership = false) : _ifs(ifs), _owned(take_ownership) {} IStreamSource(const std::string& path); @@ -259,7 +221,7 @@ struct CDOC_EXPORT IStreamSource : public DataSource { if(_ifs->bad()) return INPUT_STREAM_ERROR; _ifs->clear(); _ifs->seekg(pos); - return bool(_ifs->bad()) ? INPUT_STREAM_ERROR : OK; + return _ifs->bad() ? INPUT_STREAM_ERROR : OK; } result_t read(uint8_t *dst, size_t size) noexcept override try { @@ -302,7 +264,7 @@ struct CDOC_EXPORT OStreamConsumer : public DataConsumer { }; struct CDOC_EXPORT VectorSource : public DataSource { - VectorSource(const std::vector& data) : _data(data), _ptr(0) {} + VectorSource(const std::vector& data) : _data(data) {} result_t seek(size_t pos) override { if (pos > _data.size()) return INPUT_STREAM_ERROR; @@ -321,7 +283,7 @@ struct CDOC_EXPORT VectorSource : public DataSource { bool isEof() noexcept override { return _ptr >= _data.size(); } protected: const std::vector& _data; - size_t _ptr; + size_t _ptr{0}; }; struct CDOC_EXPORT VectorConsumer : public DataConsumer { @@ -333,7 +295,7 @@ struct CDOC_EXPORT VectorConsumer : public DataConsumer { return OUTPUT_STREAM_ERROR; } result_t close() noexcept final { return OK; } - virtual bool isError() noexcept final { return false; } + bool isError() noexcept final { return false; } protected: std::vector& _data; }; @@ -355,25 +317,7 @@ struct CDOC_EXPORT FileListConsumer : public MultiDataConsumer { bool isError() noexcept final { return ofs.bad(); } - result_t open(const std::string& name, int64_t size) override final { - std::string fileName; - if (ofs.is_open()) { - ofs.close(); - } - size_t lastSlashPos = name.find_last_of("\\/"); - if (lastSlashPos != std::string::npos) - { - fileName = name.substr(lastSlashPos + 1); - } - else - { - fileName = name; - } - std::filesystem::path path(base); - path /= fileName; - ofs.open(path.string(), std::ios_base::binary); - return ofs.bad() ? OUTPUT_STREAM_ERROR : OK; - } + result_t open(const std::string &name, int64_t size) final; protected: std::filesystem::path base; @@ -390,7 +334,7 @@ struct CDOC_EXPORT FileListSource : public MultiDataSource { protected: std::filesystem::path _base; const std::vector& _files; - int64_t _current; + int64_t _current = -1; std::ifstream _ifs; }; diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Lock.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Lock.h index 3011f871..c46cea21 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Lock.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Lock.h @@ -19,7 +19,7 @@ #ifndef __LOCK_H__ #define __LOCK_H__ -#include +#include "CDoc.h" #include #include @@ -42,7 +42,7 @@ struct CDOC_EXPORT Lock /** * @brief The lock type */ - enum Type : unsigned char { + enum Type : unsigned char { /** * @brief Valid capsule but not supported by this library version * @@ -51,7 +51,7 @@ struct CDOC_EXPORT Lock /** * @brief Symmetric AES key */ - SYMMETRIC_KEY, + SYMMETRIC_KEY, /** * @brief PBKDF key (derived from password) */ @@ -68,30 +68,18 @@ struct CDOC_EXPORT Lock * @brief Public key stored on keyserver */ SERVER, +#ifdef HAS_KEYSHARES /** * @brief Symmetric key distributed on several servers */ SHARE_SERVER - }; - - /** - * @brief The public key type - */ - enum PKType : unsigned char { - /** - * Elliptic curve - */ - ECC, - /** - * RSA - */ - RSA - }; +#endif + }; /** * @brief Extra parameters depending on key type */ - enum Params : unsigned int { + enum Params : unsigned int { /** * @brief HKDF salt (SYMMETRIC_KEY, PASSWORD and SHARE_SERVER) */ @@ -128,10 +116,12 @@ struct CDOC_EXPORT Lock * @brief Keyshare recipient ID */ RECIPIENT_ID, +#ifdef HAS_KEYSHARES /** * @brief Keyshare server urls (separated by ';') */ SHARE_URLS, +#endif /** * @brief CDoc1 specific */ @@ -152,7 +142,7 @@ struct CDOC_EXPORT Lock * @brief CDoc1 specific */ PARTY_VINFO - }; + }; /** * @brief get lock parameter value @@ -176,20 +166,20 @@ struct CDOC_EXPORT Lock /** * @brief The lock type */ - Type type = Type::UNKNOWN; + Type type = Type::UNKNOWN; /** * @brief algorithm type for public key based locks */ - PKType pk_type = PKType::ECC; + PKType pk_type = PKType::ECC; /** * @brief the lock label */ - std::string label; + std::string label; /** * @brief encrypted FMK (File Master Key) */ - std::vector encrypted_fmk; + std::vector encrypted_fmk; /** * @brief check whether lock is valid @@ -206,11 +196,6 @@ struct CDOC_EXPORT Lock * @return true if type is CDOC1, PUBLIC_KEY or SERVER */ constexpr bool isPKI() const noexcept { return (type == Type::CDOC1) || (type == Type::PUBLIC_KEY) || (type == Type::SERVER); } - /** - * @brief check whether lock is based on certificate - * @return true if type is CDOC1 - */ - constexpr bool isCertificate() const noexcept { return (type == Type::CDOC1); } /** * @brief check whether lock is CDoc1 version * @return true if type is CDOC1 @@ -222,40 +207,21 @@ struct CDOC_EXPORT Lock */ constexpr bool isRSA() const noexcept { return pk_type == PKType::RSA; } - /** - * @brief check whether two locks have the same public key - * - * This convenience method checks whether both locks are public key based, and if they are, - * whether the RCPT_KEY parameters are identical (i.e. both can be decrypted by the same private key) - * @param other the other lock - * @return true if both have the same public key - */ - bool hasTheSameKey(const Lock &other) const; - /** - * @brief check whether lock has the given public key - * - * This convenience method checks whether lock is public key based, and if it is, - * whether the RCPT_KEY parameters is identical to ptovided key(i.e. it can be decrypted by the corresponding private key) - * @param public_key the public key (short format) - * @return true if lock has the same public key - */ - bool hasTheSameKey(const std::vector& public_key) const; - - Lock() noexcept = default; - Lock(Type _type) noexcept : type(_type) {}; + Lock() noexcept = default; + Lock(Type _type) noexcept : type(_type) {}; /** * @brief Set lock parameter value * @param param a parameter type * @param val the value */ - void setBytes(Params param, const std::vector& val) { params[param] = val; } + void setBytes(Params param, std::vector val) { params[param] = std::move(val); } /** * @brief Set lock parameter value from string * @param param a parameter type * @param val the value */ - void setString(Params param, const std::string& val) { params[param] = std::vector(val.cbegin(), val.cend()); } + void setString(Params param, const std::string& val) { setBytes(param, {val.cbegin(), val.cend()}); } /** * @brief Set lock parameter value from integer * @param param a parameter type @@ -264,15 +230,16 @@ struct CDOC_EXPORT Lock void setInt(Params param, int32_t val); /** - * @brief A convenience method to initialize CERTIFICATE, RCPT_KEY and PK_TYPE values from given certificate - * @param cert the certificate (der-encoded) + * @brief parse machine-readable CDoc2 label + * @param label the label + * @return a map of key-value pairs */ - void setCertificate(const std::vector& cert); + static std::map parseLabel(const std::string& label); - bool operator== (const Lock& other) const = default; + bool operator== (const Lock& other) const noexcept = default; private: - std::map> params; + std::map> params; }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Logger.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Logger.h new file mode 100644 index 00000000..a3d27234 --- /dev/null +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Logger.h @@ -0,0 +1,79 @@ +/* + * libcdoc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +#include + +namespace libcdoc +{ + +/** + * @brief Generic interface to implement a logger. + */ +class CDOC_EXPORT Logger +{ +public: + virtual ~Logger() noexcept = default; + + /** + * @brief Logs given message with given severity, file name and line number. + * + * It tests the log level and if <= min_level invokes logMessage + * + * @param level Severity of the log message. + * @param file File name where the log message was recorded. + * @param line Line number in the file where the log message was recorded. + * @param msg The log message. + */ + void log(LogLevel level, std::string_view file, int line, std::string_view msg) { + if (level <= min_level) logMessage(level, file, line, msg); + } + + /** + * @brief Sets minimum log level for the logger. + * @param level minimum level to log. + * + * Sets minimum level of log messages to log. For example, if the minimum log level is set + * to LEVEL_INFO (default), then LEVEL_FATAL, LEVEL_ERROR, LEVEL_WARNING and LEVEL_INFO + * messages are logged, but not LEVEL_DEBUG or LEVEL_TRACE messages. + */ + constexpr void setMinLogLevel(LogLevel level) noexcept { min_level = level; } + +protected: + /** + * @brief Logs given message with given severity, file name and line number. + * + * Every class implementing the ILogger interface must implement this member function. + * The efault implementation does nothing. + * The level should be checked by caller, thus the implementation should expect that level <= min_level + * + * @param level Severity of the log message. + * @param file File name where the log message was recorded. + * @param line Line number in the file where the log message was recorded. + * @param msg The log message. + */ + virtual void logMessage(LogLevel level, std::string_view file, int line, std::string_view msg) {} + + /** + * @brief Minimum level of log messages to log. + */ + LogLevel min_level = LEVEL_WARNING; +}; + +} diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/NetworkBackend.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/NetworkBackend.h index 6c082240..4d1dc3d9 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/NetworkBackend.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/NetworkBackend.h @@ -29,6 +29,7 @@ struct CDOC_EXPORT NetworkBackend { * */ static constexpr int NETWORK_ERROR = -300; +#ifdef HAS_KEYSHARES // MID/SID error codes // User refused the session static constexpr int MIDSID_USER_REFUSED = -350; @@ -62,9 +63,10 @@ struct CDOC_EXPORT NetworkBackend { static constexpr int MIDSID_DELIVERY_ERROR = -364; // Invalid response from card static constexpr int MIDSID_SIM_ERROR = -365; +#endif /** - * @brief Share information returned by server + * @brief Capsule information returned by capsule server * */ struct CapsuleInfo { @@ -79,8 +81,9 @@ struct CDOC_EXPORT NetworkBackend { */ uint64_t expiry_time; }; +#ifdef HAS_KEYSHARES /** - * @brief Share information returned by server + * @brief Share information returned by share server * */ struct ShareInfo { @@ -95,6 +98,7 @@ struct CDOC_EXPORT NetworkBackend { */ std::string recipient; }; +#endif /** * @brief Proxy credentials used for network access @@ -146,6 +150,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t sendKey (CapsuleInfo& dst, const std::string& url, const std::vector& rcpt_key, const std::vector &key_material, const std::string& type, uint64_t expiry_ts); +#ifdef HAS_KEYSHARES /** * @brief send key share to server * @@ -157,6 +162,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t sendShare(std::vector& dst, const std::string& url, const std::string& recipient, const std::vector& share); +#endif /** * @brief fetch key material from keyserver * @@ -167,6 +173,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t fetchKey (std::vector& dst, const std::string& url, const std::string& transaction_id); +#ifdef HAS_KEYSHARES /** * @brief fetch authentication nonce from share server * @param dst a destination container for nonce @@ -185,7 +192,7 @@ struct CDOC_EXPORT NetworkBackend { * @return error code or OK */ virtual result_t fetchShare(ShareInfo& share, const std::string& url, const std::string& share_id, const std::string& ticket, const std::vector& cert); - +#endif /** * @brief get client TLS certificate in der format @@ -234,6 +241,7 @@ struct CDOC_EXPORT NetworkBackend { return NOT_IMPLEMENTED; } +#ifdef HAS_KEYSHARES /** * @brief show MID/SID verification code * @@ -277,9 +285,6 @@ struct CDOC_EXPORT NetworkBackend { result_t signMID(std::vector& dst, std::vector& cert, const std::string& url, const std::string& rp_uuid, const std::string& rp_name, const std::string& phone, const std::string& rcpt_id, const std::vector& digest, CryptoBackend::HashAlgorithm algo); - -#if LIBCDOC_TESTING - virtual int64_t test(std::vector> &dst); #endif }; diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Recipient.h b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Recipient.h index 0b04755b..8374bc4b 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Recipient.h +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Headers/Recipient.h @@ -19,15 +19,17 @@ #ifndef __RECIPIENT_H__ #define __RECIPIENT_H__ -#include +#include "CDoc.h" -#include #include #include +#include #include namespace libcdoc { +struct Lock; + /** * @brief A descriptor of encryption method and key to be used in container * @@ -50,24 +52,12 @@ struct CDOC_EXPORT Recipient { * @brief Public key */ PUBLIC_KEY, +#ifdef HAS_KEYSHARES /** * @brief n of n shared symmetric key */ KEYSHARE - }; - - /** - * @brief The public key type - */ - enum PKType : uint8_t { - /** - * Elliptic curve - */ - ECC, - /** - * RSA - */ - RSA +#endif }; Recipient() = default; @@ -96,10 +86,12 @@ struct CDOC_EXPORT Recipient { * @brief The recipient's certificate (if present) */ std::vector cert; +#ifdef HAS_KEYSHARES /** * @brief The recipient id for share server (PNOEE-XXXXXXXXXXX) */ std::string id; +#endif /** * @brief The keyserver or share server list id (if present) */ @@ -109,16 +101,6 @@ struct CDOC_EXPORT Recipient { * */ uint64_t expiry_ts = 0; - /** - * @brief key/certificate filename for machine-readable label - * - */ - std::string file_name; - /** - * @brief public key/password name for machine-readable label - * - */ - std::string key_name; /** * @brief test whether the Recipient structure is initialized @@ -145,11 +127,13 @@ struct CDOC_EXPORT Recipient { * @return true if type is SERVER */ bool isKeyServer() const { return (type == Type::PUBLIC_KEY) && !server_id.empty(); } +#ifdef HAS_KEYSHARES /** * @brief check whether Recipient is keyshare * @return true if type is KEYSHARE */ bool isKeyShare() const { return type == Type::KEYSHARE; } +#endif /** * @brief Clear all values and set type to NONE @@ -184,6 +168,12 @@ struct CDOC_EXPORT Recipient { * @return a new Recipient structure */ static Recipient makePublicKey(std::string label, std::vector public_key, PKType pk_type); + /** + * @brief Create a new public key based Recipient + * @param lock Lock to derive parameters from + * @return a new Recipient structure + */ + static Recipient makePublicKey(const Lock &lock); /** * @brief Create a new certificate based Recipient * @param label the label text @@ -215,6 +205,16 @@ struct CDOC_EXPORT Recipient { */ static Recipient makeServer(std::string label, std::vector cert, std::string server_id); + /** + * @brief Create a new capsule server based Recipient + * + * @param lock Lock to derive parameters from + * @param server_id the keyserver id + * @return a new Recipient structure + */ + static Recipient makeServer(const Lock &lock, std::string server_id); + +#ifdef HAS_KEYSHARES /** * @brief Create new keyshare recipient * @@ -224,6 +224,7 @@ struct CDOC_EXPORT Recipient { * @return Recipient a new Recipient structure */ static Recipient makeShare(std::string label, std::string server_id, std::string recipient_id); +#endif /** * @brief Get the label for this recipient @@ -233,18 +234,30 @@ struct CDOC_EXPORT Recipient { * @param extra additional parameter values to use * @return a label value */ - std::string getLabel(const std::vector> &extra) const; + std::string getLabel(std::map extra) const; + + /** + * @brief Set a property for automatic label generation + * + * @param key the property name + * @param value the property value + */ + void setLabelValue(std::string_view key, std::string_view value) { + lbl_parts[std::string(key)] = value; + } /** - * @brief parse machine-readable CDoc2 label - * @param label the label - * @return a map of key-value pairs + * @brief Validate recipient record + * + * @return true if Recipient is valid */ - static std::map parseLabel(const std::string& label); + bool validate() const; bool operator== (const Recipient& other) const = default; protected: Recipient(Type _type) : type(_type) {}; +private: + std::map lbl_parts; }; } // namespace libcdoc diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Info.plist b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Info.plist index f1db506c..3f02ba10 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Info.plist +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Info.plist @@ -12,17 +12,19 @@ ee.ria.cdoc CFBundleInfoDictionaryVersion 6.0 + CFBundleName + CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.8 + 0.5.0 CFBundleSignature ???? CFBundleVersion - 0 + 32 CSResourcesFileMapped MinimumOSVersion - 15.0 + 16.3 diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Modules/module.modulemap b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Modules/module.modulemap index db570a56..68872550 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Modules/module.modulemap +++ b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/Modules/module.modulemap @@ -10,8 +10,7 @@ framework module cdoc { header "CryptoBackend.h" header "NetworkBackend.h" header "PKCS11Backend.h" - header "ILogger.h" - header "ConsoleLogger.h" + header "Logger.h" export * requires cplusplus } \ No newline at end of file diff --git a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/cdoc b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/cdoc index e0c30e51..8edfd1ba 100755 Binary files a/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/cdoc and b/Modules/CryptoLib/Sources/CryptoObjC/Libs/cdoc.xcframework/ios-arm64_x86_64-simulator/cdoc.framework/cdoc differ diff --git a/Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm b/Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm index 4d30bd1b..eae30f28 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm +++ b/Modules/CryptoLib/Sources/CryptoObjC/include/Decrypt.mm @@ -31,7 +31,7 @@ @implementation Addressee (label) - (instancetype)initWithLabel:(const std::string &)label pub:(NSData*)pub concatKDFAlgorithmURI:(NSString *)concatKDFAlgorithmURI { - std::map info = libcdoc::Recipient::parseLabel(label); + std::map info = libcdoc::Lock::parseLabel(label); id cn = info.contains("cn") ? [NSString stringWithStdString:info["cn"]] : [NSString stringWithStdString:label]; id type = info.contains("type") ? [NSString stringWithStdString:info["type"]] : nil; id serial = info.contains("serial_number") ? [NSString stringWithStdString:info["serial_number"]] : nil; @@ -102,7 +102,7 @@ + (CdocInfo*)cdocInfo:(NSString *)fullPath error:(NSError**)error { NSMutableArray *addressees = [[NSMutableArray alloc] init]; for(const libcdoc::Lock &lock: reader->getLocks()) { - if(lock.isCertificate()) { + if(lock.isCDoc1()) { NSString* concatKDFAlgorithmURI = @""; if (!lock.isRSA()) { concatKDFAlgorithmURI = [NSString stringWithStdString:lock.getString(libcdoc::Lock::CONCAT_DIGEST)]; diff --git a/Modules/CryptoLib/Sources/CryptoObjC/include/Encrypt.mm b/Modules/CryptoLib/Sources/CryptoObjC/include/Encrypt.mm index 7c185fd8..e8999b74 100644 --- a/Modules/CryptoLib/Sources/CryptoObjC/include/Encrypt.mm +++ b/Modules/CryptoLib/Sources/CryptoObjC/include/Encrypt.mm @@ -25,7 +25,8 @@ #include #include -#include +#include + @implementation Encrypt + (void)setCerts:(nullable NSArray *)certs { @@ -66,14 +67,14 @@ + (void)setProxy:(nonnull NSString *)host port:(NSInteger)port username:(nonnull encoding:NSUTF8StringEncoding] ?: @""; } -static inline NSString *NSStringFromLogLevel(libcdoc::ILogger::LogLevel level) { +static inline NSString *NSStringFromLogLevel(libcdoc::LogLevel level) { switch (level) { - case libcdoc::ILogger::LEVEL_FATAL: return @"FATAL"; - case libcdoc::ILogger::LEVEL_ERROR: return @"ERROR"; - case libcdoc::ILogger::LEVEL_WARNING: return @"WARN"; - case libcdoc::ILogger::LEVEL_INFO: return @"INFO"; - case libcdoc::ILogger::LEVEL_DEBUG: return @"DEBUG"; - case libcdoc::ILogger::LEVEL_TRACE: return @"TRACE"; + case libcdoc::LEVEL_FATAL: return @"FATAL"; + case libcdoc::LEVEL_ERROR: return @"ERROR"; + case libcdoc::LEVEL_WARNING: return @"WARN"; + case libcdoc::LEVEL_INFO: return @"INFO"; + case libcdoc::LEVEL_DEBUG: return @"DEBUG"; + case libcdoc::LEVEL_TRACE: return @"TRACE"; } return @"UNKNOWN"; } @@ -91,9 +92,9 @@ + (void)setProxy:(nonnull NSString *)host port:(NSInteger)port username:(nonnull return path; } -class ObjCLogger final : public libcdoc::ILogger { -public: - void LogMessage(libcdoc::ILogger::LogLevel level, +class ObjCLogger final : public libcdoc::Logger { +protected: + void logMessage(libcdoc::LogLevel level, std::string_view file, int line, std::string_view message) override @@ -132,8 +133,8 @@ + (void)enableLogging:(bool)enabled { // Install only once, even if enableLogging:YES is called many times static std::once_flag once; std::call_once(once, [] { - libcdoc::ILogger::setLogger(&gLogger); - gLogger.SetMinLogLevel(libcdoc::ILogger::LEVEL_TRACE); + libcdoc::setLogger(&gLogger); + gLogger.setMinLogLevel(libcdoc::LEVEL_TRACE); }); }