Skip to content

Commit

Permalink
Allow only qualified TimeStamp-s
Browse files Browse the repository at this point in the history
IB-8250

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Nov 15, 2024
1 parent 82729b4 commit b2b92a8
Show file tree
Hide file tree
Showing 17 changed files with 10,084 additions and 569 deletions.
6 changes: 1 addition & 5 deletions src/crypto/TSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,13 @@ constexpr array SERVICESTATUS_END {

constexpr array SERVICES_SUPPORTED {
"http://uri.etsi.org/TrstSvc/Svctype/CA/QC",
//"http://uri.etsi.org/TrstSvc/Svctype/CA/PKC", //???
//"http://uri.etsi.org/TrstSvc/Svctype/NationalRootCA-QC", //???
"http://uri.etsi.org/TrstSvc/Svctype/Certstatus/OCSP",
"http://uri.etsi.org/TrstSvc/Svctype/Certstatus/OCSP/QC",
"http://uri.etsi.org/TrstSvc/Svctype/TSA",
"http://uri.etsi.org/TrstSvc/Svctype/TSA/QTST",
"http://uri.etsi.org/TrstSvc/Svctype/TSA/TSS-QC", //???
"http://uri.etsi.org/TrstSvc/Svctype/TSA/TSS-AdESQCandQES", //???
};

template<typename C, typename T>
[[nodiscard]]
constexpr bool contains(const C &list, const T &value)
{
return find(list.begin(), list.end(), value) != list.end();
Expand Down
41 changes: 20 additions & 21 deletions src/crypto/X509CertStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@
using namespace digidoc;
using namespace std;

template<typename C, typename T>
[[nodiscard]]
constexpr bool contains(const C &list, const T &value)
{
return find(list.begin(), list.end(), std::forward<decltype(value)>(value)) != list.end();
};

const X509CertStore::Type X509CertStore::CA {
"http://uri.etsi.org/TrstSvc/Svctype/CA/QC",
};

const X509CertStore::Type X509CertStore::TSA {
"http://uri.etsi.org/TrstSvc/Svctype/TSA",
"http://uri.etsi.org/TrstSvc/Svctype/TSA/QTST",
"http://uri.etsi.org/TrstSvc/Svctype/TSA/TSS-QC",
"http://uri.etsi.org/TrstSvc/Svctype/TSA/TSS-AdESQCandQES",
};

const X509CertStore::Type X509CertStore::OCSP {
Expand Down Expand Up @@ -240,29 +244,24 @@ bool X509CertStore::verify(const X509Cert &cert, bool noqscd) const
const vector<string> policies = cert.certificatePolicies();
const vector<string> qcstatement = cert.qcStatements();
const vector<X509Cert::KeyUsage> keyUsage = cert.keyUsage();
auto containsPolicy = [&policies](const string &policy) {
return find(policies.cbegin(), policies.cend(), policy) != policies.cend();
};
auto containsQCStatement = [&qcstatement](const string &statement) {
return find(qcstatement.cbegin(), qcstatement.cend(), statement) != qcstatement.cend();
};

bool isQCCompliant = containsQCStatement(X509Cert::QC_COMPLIANT);
bool isQCCompliant = contains(qcstatement, X509Cert::QC_COMPLIANT);
bool isQSCD =
containsPolicy(X509Cert::QCP_PUBLIC_WITH_SSCD) ||
containsPolicy(X509Cert::QCP_LEGAL_QSCD) ||
containsPolicy(X509Cert::QCP_NATURAL_QSCD) ||
containsQCStatement(X509Cert::QC_SSCD);
contains(policies, X509Cert::QCP_PUBLIC_WITH_SSCD) ||
contains(policies, X509Cert::QCP_LEGAL_QSCD) ||
contains(policies, X509Cert::QCP_NATURAL_QSCD) ||
contains(qcstatement, X509Cert::QC_SSCD);

bool isESeal = // Special treamtent for E-Seals
containsPolicy(X509Cert::QCP_LEGAL) ||
containsQCStatement(X509Cert::QCT_ESEAL);
auto matchPolicySet = [&containsPolicy](const vector<string> &policySet){
return all_of(policySet.cbegin(), policySet.cend(), containsPolicy);
bool isESeal = // Special treamtent for E-Seals
contains(policies, X509Cert::QCP_LEGAL) ||
contains(qcstatement, X509Cert::QCT_ESEAL);
auto matchPolicySet = [&policies](const vector<string> &policySet){
return all_of(policySet.cbegin(), policySet.cend(), [&policies](const string &policy) {
return contains(policies, policy);
});
};
auto matchKeyUsageSet = [&keyUsage](const map<X509Cert::KeyUsage,bool> &keyUsageSet){
return all_of(keyUsageSet.cbegin(), keyUsageSet.cend(), [&keyUsage](pair<X509Cert::KeyUsage, bool> keyUsageBit){
return (find(keyUsage.cbegin(), keyUsage.cend(), keyUsageBit.first) != keyUsage.cend()) == keyUsageBit.second;
return contains(keyUsage, keyUsageBit.first) == keyUsageBit.second;
});
};

Expand Down
671 changes: 635 additions & 36 deletions test/data/EE_T-CA-invalid-type.xml

Large diffs are not rendered by default.

669 changes: 634 additions & 35 deletions test/data/EE_T-CA-non-qa.xml

Large diffs are not rendered by default.

790 changes: 753 additions & 37 deletions test/data/EE_T-CA-withdrawn-granted-before.xml

Large diffs are not rendered by default.

790 changes: 753 additions & 37 deletions test/data/EE_T-CA-withdrawn-granted-later.xml

Large diffs are not rendered by default.

712 changes: 678 additions & 34 deletions test/data/EE_T-CA-withdrawn.xml

Large diffs are not rendered by default.

671 changes: 635 additions & 36 deletions test/data/EE_T-OCSP-invalid-type.xml

Large diffs are not rendered by default.

717 changes: 679 additions & 38 deletions test/data/EE_T-OCSP-withdrawn-granted-before.xml

Large diffs are not rendered by default.

717 changes: 679 additions & 38 deletions test/data/EE_T-OCSP-withdrawn-granted-later.xml

Large diffs are not rendered by default.

714 changes: 679 additions & 35 deletions test/data/EE_T-OCSP-withdrawn.xml

Large diffs are not rendered by default.

665 changes: 632 additions & 33 deletions test/data/EE_T-TSA-invalid-type.xml

Large diffs are not rendered by default.

725 changes: 680 additions & 45 deletions test/data/EE_T-TSA-withdrawn-granted-before.xml

Large diffs are not rendered by default.

725 changes: 680 additions & 45 deletions test/data/EE_T-TSA-withdrawn-granted-later.xml

Large diffs are not rendered by default.

726 changes: 690 additions & 36 deletions test/data/EE_T-TSA-withdrawn.xml

Large diffs are not rendered by default.

665 changes: 632 additions & 33 deletions test/data/EE_T-no_QCSD.xml

Large diffs are not rendered by default.

649 changes: 624 additions & 25 deletions test/data/EE_T-no_QCStatement.xml

Large diffs are not rendered by default.

0 comments on commit b2b92a8

Please sign in to comment.