Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set multiple service certificates #419

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake
1 change: 1 addition & 0 deletions libdigidocpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ extern "C"
// ignore X509Cert and implement later cert as ByteVector
%ignore digidoc::Conf::TSLCerts;
%ignore digidoc::ConfV2::verifyServiceCert;
%ignore digidoc::ConfV4::verifyServiceCerts;
%ignore digidoc::Signer::cert;
%ignore digidoc::Signature::signingCertificate;
%ignore digidoc::Signature::OCSPCertificate;
Expand Down
18 changes: 14 additions & 4 deletions src/libdigidocpp.i.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class SWIGEXPORT DigiDocConf: public digidoc::XmlConfCurrent
std::string TSLCache() const override { return cache.empty() ? digidoc::XmlConfCurrent::TSLCache() : cache; }
std::vector<X509Cert> TSLCerts() const override { return tslCerts.empty() ? digidoc::XmlConfCurrent::TSLCerts() : tslCerts; };
std::string TSLUrl() const override { return tslUrl.empty() ? digidoc::XmlConfCurrent::TSLUrl() : tslUrl; }
X509Cert verifyServiceCert() const override { return !serviceCert ? digidoc::XmlConfCurrent::verifyServiceCert() : serviceCert; }
X509Cert verifyServiceCert() const override { return serviceCerts.empty() ? digidoc::XmlConfCurrent::verifyServiceCert() : serviceCerts.front(); }
std::vector<X509Cert> verifyServiceCerts() const override { return serviceCerts.empty() ? digidoc::XmlConfCurrent::verifyServiceCerts() : serviceCerts; }
std::string verifyServiceUri() const override { return serviceUrl.empty() ? digidoc::XmlConfCurrent::verifyServiceUri() : serviceUrl; }
std::string xsdPath() const override { return cache.empty() ? digidoc::XmlConfCurrent::xsdPath() : cache; }

Expand All @@ -68,7 +69,7 @@ class SWIGEXPORT DigiDocConf: public digidoc::XmlConfCurrent
void addTSLCert(const std::vector<unsigned char> &cert)
{
if(!cert.empty())
tslCerts.push_back(X509Cert(cert, X509Cert::Der));
tslCerts.emplace_back(cert, X509Cert::Der);
}
void setTSLUrl(std::string url) { tslUrl = std::move(url); }
void setOCSPUrls(std::map<std::string,std::string> urls) { OCSPUrls = urls; }
Expand All @@ -79,7 +80,16 @@ class SWIGEXPORT DigiDocConf: public digidoc::XmlConfCurrent
if(_TMProfiles.empty())
TMProfiles.clear();
}
void setVerifyServiceCert(const std::vector<unsigned char> &cert) { serviceCert = X509Cert(cert.data(), cert.size(), X509Cert::Der); }
void setVerifyServiceCert(const std::vector<unsigned char> &cert)
{
if(cert.empty()) serviceCerts.clear();
else serviceCerts = { X509Cert(cert, X509Cert::Der) };
}
void addVerifyServiceCert(const std::vector<unsigned char> &cert)
{
if(!cert.empty())
serviceCerts.emplace_back(cert, X509Cert::Der);
}
void setVerifyServiceUri(std::string url) { serviceUrl = std::move(url); }

private:
Expand All @@ -88,7 +98,7 @@ class SWIGEXPORT DigiDocConf: public digidoc::XmlConfCurrent
std::vector<X509Cert> tslCerts;
std::set<std::string> TMProfiles;
std::map<std::string,std::string> OCSPUrls;
X509Cert serviceCert;
std::vector<X509Cert> serviceCerts;
};

static void initializeLib(const std::string &appName, const std::string &path)
Expand Down