Skip to content

Commit

Permalink
Updated libdigidocpp
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Apr 26, 2024
1 parent 8a5f2dc commit 0502bbf
Show file tree
Hide file tree
Showing 62 changed files with 7,546 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* libdigidocpp
*
* 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 Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#pragma once

#include "Exports.h"

#include <set>
#include <string>
#include <vector>

namespace digidoc
{
class X509Cert;
class DIGIDOCPP_EXPORT Conf
{
public:
Conf();
virtual ~Conf();
static void init(Conf *conf);
static Conf* instance();

virtual int logLevel() const;
virtual std::string logFile() const;
DIGIDOCPP_DEPRECATED virtual std::string libdigidocConf() const;
DIGIDOCPP_DEPRECATED virtual std::string certsPath() const;
virtual std::string xsdPath() const;
virtual std::string PKCS11Driver() const;

virtual std::string proxyHost() const;
virtual std::string proxyPort() const;
virtual std::string proxyUser() const;
virtual std::string proxyPass() const;
virtual bool proxyForceSSL() const;
virtual bool proxyTunnelSSL() const;

virtual std::string digestUri() const;
virtual std::string signatureDigestUri() const;
virtual std::string ocsp(const std::string &issuer) const;
virtual std::string TSUrl() const;
virtual std::string verifyServiceUri() const;

DIGIDOCPP_DEPRECATED virtual std::string PKCS12Cert() const;
DIGIDOCPP_DEPRECATED virtual std::string PKCS12Pass() const;
DIGIDOCPP_DEPRECATED virtual bool PKCS12Disable() const;

virtual bool TSLAllowExpired() const;
virtual bool TSLAutoUpdate() const;
virtual std::string TSLCache() const;
virtual std::vector<X509Cert> TSLCerts() const;
virtual bool TSLOnlineDigest() const;
virtual int TSLTimeOut() const;
virtual std::string TSLUrl() const;

private:
DISABLE_COPY(Conf);

static Conf *INSTANCE;
};

class DIGIDOCPP_EXPORT ConfV2: public Conf
{
public:
ConfV2();
~ConfV2() override;
static ConfV2* instance();

virtual X509Cert verifyServiceCert() const;

private:
DISABLE_COPY(ConfV2);
};

class DIGIDOCPP_EXPORT ConfV3: public ConfV2
{
public:
ConfV3();
~ConfV3() override;
static ConfV3* instance();

virtual std::set<std::string> OCSPTMProfiles() const;

private:
DISABLE_COPY(ConfV3);
};

class DIGIDOCPP_EXPORT ConfV4: public ConfV3
{
public:
ConfV4();
~ConfV4() override;
static ConfV4* instance();

virtual std::vector<X509Cert> verifyServiceCerts() const;

private:
DISABLE_COPY(ConfV4);
};

class DIGIDOCPP_EXPORT ConfV5: public ConfV4
{
public:
ConfV5();
~ConfV5() override;
static ConfV5* instance();

virtual std::vector<X509Cert> TSCerts() const;

private:
DISABLE_COPY(ConfV5);
};

using ConfCurrent = ConfV5;
#define CONF(method) (ConfCurrent::instance() ? ConfCurrent::instance()->method() : ConfCurrent().method())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* libdigidocpp
*
* 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 Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#pragma once

#include "Exports.h"

#include <memory>
#include <string>
#include <vector>

namespace digidoc
{
class DataFile;
class Exception;
class Signature;
class Signer;
using initCallBack = void (*)(const Exception *e);

DIGIDOCPP_EXPORT std::string appInfo();
DIGIDOCPP_EXPORT void initialize(const std::string &appInfo = "libdigidocpp", initCallBack callBack = nullptr);
DIGIDOCPP_EXPORT void initialize(const std::string &appInfo, const std::string &userAgent, initCallBack callBack = nullptr);
DIGIDOCPP_EXPORT void terminate();
DIGIDOCPP_EXPORT std::string userAgent();
DIGIDOCPP_EXPORT std::string version();

struct ContainerOpenCB {
virtual ~ContainerOpenCB() = default;
virtual bool validateOnline() const { return true; }
};

class DIGIDOCPP_EXPORT Container
{
public:
virtual ~Container();

virtual void save(const std::string &path = "") = 0;
virtual std::string mediaType() const = 0;

virtual void addDataFile(const std::string &path, const std::string &mediaType) = 0;
DIGIDOCPP_DEPRECATED virtual void addDataFile(std::istream *is, const std::string &fileName, const std::string &mediaType);
virtual std::vector<DataFile*> dataFiles() const = 0;
virtual void removeDataFile(unsigned int index) = 0;

void addAdESSignature(const std::vector<unsigned char> &signature);
virtual void addAdESSignature(std::istream &signature) = 0;
virtual Signature* prepareSignature(Signer *signer) = 0;
virtual std::vector<Signature*> signatures() const = 0;
virtual void removeSignature(unsigned int index) = 0;
virtual Signature* sign(Signer *signer) = 0;

virtual void addDataFile(std::unique_ptr<std::istream> is, const std::string &fileName, const std::string &mediaType);

DIGIDOCPP_DEPRECATED static Container* create(const std::string &path);
static std::unique_ptr<Container> createPtr(const std::string &path);
DIGIDOCPP_DEPRECATED static Container* open(const std::string &path);
static std::unique_ptr<Container> openPtr(const std::string &path);
static std::unique_ptr<Container> openPtr(const std::string &path, digidoc::ContainerOpenCB *cb);
template<class T>
static void addContainerImplementation();

protected:
Container();
unsigned int newSignatureId() const;

private:
DISABLE_COPY(Container);
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* libdigidocpp
*
* 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 Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#pragma once

#include "Exports.h"

#include <string>
#include <vector>

namespace digidoc
{
class DIGIDOCPP_EXPORT DataFile
{

public:
virtual ~DataFile();
virtual std::string id() const = 0;
virtual std::string fileName() const = 0;
virtual unsigned long fileSize() const = 0;
virtual std::string mediaType() const = 0;

virtual std::vector<unsigned char> calcDigest(const std::string &method) const = 0;
virtual void saveAs(std::ostream &os) const = 0;
virtual void saveAs(const std::string& path) const = 0;

protected:
DataFile();

private:
DISABLE_COPY(DataFile);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* libdigidocpp
*
* 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 Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#pragma once

#include "Exports.h"

#include <string>
#include <vector>

namespace digidoc
{
class DIGIDOCPP_EXPORT Exception
{
public:
/**
* Exception code
*/
enum ExceptionCode {
General = 0,
NetworkError = 20,
HostNotFound = 101,
InvalidUrl = 102,
//Verification errors
CertificateIssuerMissing = 10,
CertificateRevoked = 5,
CertificateUnknown = 6,
OCSPBeforeTimeStamp = 19,
OCSPResponderMissing = 8,
OCSPCertMissing = 9,
OCSPTimeSlot = 7,
OCSPRequestUnauthorized = 11,
TSForbidden = 21,
TSTooManyRequests = 18,
//Pin exceptions
PINCanceled = 2,
PINFailed = 4,
PINIncorrect = 1,
PINLocked = 3,
//Warnings
ReferenceDigestWeak = 12,
SignatureDigestWeak = 13,
DataFileNameSpaceWarning = 14,
IssuerNameSpaceWarning = 15,
ProducedATLateWarning = 16,
MimeTypeWarning = 17,
//DDoc error codes
DDocError = 512 //DIGIDOCPP_DEPRECATED
};
using Causes = std::vector<Exception>;

Exception(const std::string& file, int line, const std::string& msg);
Exception(const std::string& file, int line, const std::string& msg, const Exception& cause);
Exception(const Exception &other);
Exception(Exception &&other) DIGIDOCPP_NOEXCEPT;
virtual ~Exception();
Exception &operator=(const Exception &other);
Exception &operator=(Exception &&other) DIGIDOCPP_NOEXCEPT;

std::string file() const;
int line() const;
ExceptionCode code() const;
std::string msg() const;
Causes causes() const;
void addCause(const Exception& cause);
void setCode( ExceptionCode Code );

static void addWarningIgnore(ExceptionCode code);
static void setWarningIgnoreList(const std::vector<ExceptionCode> &list);
static bool hasWarningIgnore(ExceptionCode code);

private:
std::string m_file;
std::string m_msg;
int m_line;
Causes m_causes;
ExceptionCode m_code;

static std::vector<ExceptionCode> ignores;
};

}
Loading

0 comments on commit 0502bbf

Please sign in to comment.