Skip to content

Commit

Permalink
Allow to set multiple service certificates (#419)
Browse files Browse the repository at this point in the history
IB-7091

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored Jul 1, 2021
1 parent a2fea2d commit fe7da1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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

0 comments on commit fe7da1b

Please sign in to comment.