File indexing completed on 2026-01-07 10:14:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef SIGNATUREBACKEND_H
0011 #define SIGNATUREBACKEND_H
0012
0013 #include <vector>
0014 #include <memory>
0015 #include <chrono>
0016 #include <variant>
0017 #include <functional>
0018 #include <optional>
0019 #include "Error.h"
0020 #include "HashAlgorithm.h"
0021 #include "CertificateInfo.h"
0022 #include "SignatureInfo.h"
0023 #include "poppler_private_export.h"
0024
0025 namespace CryptoSign {
0026
0027 enum class SignatureType
0028 {
0029 adbe_pkcs7_sha1,
0030 adbe_pkcs7_detached,
0031 ETSI_CAdES_detached,
0032 g10c_pgp_signature_detached,
0033 unknown_signature_type,
0034 unsigned_signature_field
0035 };
0036
0037 SignatureType signatureTypeFromString(std::string_view data);
0038
0039 std::string toStdString(SignatureType type);
0040
0041
0042
0043
0044 static const int maxSupportedSignatureSize = 10000;
0045
0046 enum class SigningError
0047 {
0048 GenericError ,
0049 InternalError ,
0050 WriteFailed ,
0051 UserCancelled ,
0052 KeyMissing,
0053 BadPassphrase,
0054
0055 };
0056
0057 struct SigningErrorMessage
0058 {
0059 SigningError type;
0060 ErrorString message;
0061 };
0062
0063
0064
0065 class VerificationInterface
0066 {
0067 public:
0068 virtual void addData(unsigned char *data_block, int data_len) = 0;
0069 virtual SignatureValidationStatus validateSignature() = 0;
0070 virtual std::chrono::system_clock::time_point getSigningTime() const = 0;
0071 virtual std::string getSignerName() const = 0;
0072 virtual std::string getSignerSubjectDN() const = 0;
0073 virtual HashAlgorithm getHashAlgorithm() const = 0;
0074
0075
0076 virtual CertificateValidationStatus validateCertificateResult() = 0;
0077 virtual void validateCertificateAsync(std::chrono::system_clock::time_point validation_time, bool ocspRevocationCheck, bool useAIACertFetch, const std::function<void()> &doneCallback) = 0;
0078 virtual std::unique_ptr<X509CertificateInfo> getCertificateInfo() const = 0;
0079 virtual ~VerificationInterface();
0080 VerificationInterface() = default;
0081 VerificationInterface(const VerificationInterface &other) = delete;
0082 VerificationInterface &operator=(const VerificationInterface &other) = delete;
0083 };
0084
0085 class SigningInterface
0086 {
0087 public:
0088 virtual void addData(unsigned char *data_block, int data_len) = 0;
0089 virtual SignatureType signatureType() const = 0;
0090 virtual std::unique_ptr<X509CertificateInfo> getCertificateInfo() const = 0;
0091 virtual std::variant<std::vector<unsigned char>, SigningErrorMessage> signDetached(const std::string &password) = 0;
0092 virtual ~SigningInterface();
0093 SigningInterface() = default;
0094 SigningInterface(const SigningInterface &other) = delete;
0095 SigningInterface &operator=(const SigningInterface &other) = delete;
0096 };
0097
0098 class Backend
0099 {
0100 public:
0101 enum class Type
0102 {
0103 NSS3,
0104 GPGME
0105 };
0106 virtual std::unique_ptr<VerificationInterface> createVerificationHandler(std::vector<unsigned char> &&pkcs7, SignatureType type) = 0;
0107 virtual std::unique_ptr<SigningInterface> createSigningHandler(const std::string &certID, HashAlgorithm digestAlgTag) = 0;
0108 virtual std::vector<std::unique_ptr<X509CertificateInfo>> getAvailableSigningCertificates() = 0;
0109 virtual ~Backend();
0110 Backend() = default;
0111 Backend(const Backend &other) = delete;
0112 Backend &operator=(const Backend &other) = delete;
0113 };
0114
0115 class POPPLER_PRIVATE_EXPORT Factory
0116 {
0117 public:
0118
0119 static void setPreferredBackend(Backend::Type backend);
0120
0121
0122
0123
0124 static std::optional<Backend::Type> getActive();
0125 static std::vector<Backend::Type> getAvailable();
0126 static std::unique_ptr<Backend> createActive();
0127 static std::unique_ptr<Backend> create(Backend::Type);
0128 static std::optional<Backend::Type> typeFromString(std::string_view string);
0129 Factory() = delete;
0130
0131
0132 private:
0133 static std::optional<Backend::Type> preferredBackend;
0134 };
0135
0136 }
0137
0138 #endif