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

[TOB] DEV-3784: ID-5 #20

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
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 .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
[submodule "lib/automata-on-chain-pccs"]
path = lib/automata-on-chain-pccs
url = https://github.com/automata-network/automata-on-chain-pccs
branch = main
branch = DEV-3784
32 changes: 22 additions & 10 deletions contracts/bases/X509ChainBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@
bool verified;
bool certChainCanBeTrusted;
for (uint256 i = 0; i < n; i++) {
X509CertObj memory current = certs[i];
X509CertObj memory issuer;
bytes memory crl;

Check warning

Code scanning / Slither

Uninitialized local variables Medium

if (i == n - 1) {
// rootCA
issuer = certs[i];
issuer = current;
} else {
issuer = certs[i + 1];
bytes memory crl;
if (i == n - 2) {
(, crl) = pccsRouter.getCrl(CA.ROOT);
} else if (i == 0) {
string memory issuerName = certs[i].issuerCommonName;
string memory issuerName = current.issuerCommonName;
if (LibString.eq(issuerName, PLATFORM_ISSUER_NAME)) {
(, crl) = pccsRouter.getCrl(CA.PLATFORM);
} else if (LibString.eq(issuerName, PROCESSOR_ISSUER_NAME)) {
Expand All @@ -88,21 +89,32 @@
return false;
}
}
if (crl.length > 0) {
certRevoked = crlHelper.serialNumberIsRevoked(certs[i].serialNumber, crl);
}
if (certRevoked) {
break;
}

bytes memory issuerSubjectKeyIdentifier = issuer.subjectKeyIdentifier;

if (crl.length > 0) {
// check issuer subject key identifier against crl authority key identifier
bytes memory crlAuthorityKeyIdentifier = crlHelper.getAuthorityKeyIdentifier(crl);
if (!BytesUtils.compareBytes(issuerSubjectKeyIdentifier, crlAuthorityKeyIdentifier)) {
return false;
}
certRevoked = crlHelper.serialNumberIsRevoked(current.serialNumber, crl);
}
if (certRevoked) {
break;
}

certNotExpired = block.timestamp > certs[i].validityNotBefore && block.timestamp < certs[i].validityNotAfter;
certNotExpired = block.timestamp > current.validityNotBefore && block.timestamp < current.validityNotAfter;
if (!certNotExpired) {
break;
}

{
verified = ecdsaVerify(sha256(certs[i].tbs), certs[i].signature, issuer.subjectPublicKey);
bytes memory currentAuthorityKeyIdentifier = current.authorityKeyIdentifier;
if (BytesUtils.compareBytes(issuerSubjectKeyIdentifier, currentAuthorityKeyIdentifier)) {
verified = ecdsaVerify(sha256(current.tbs), current.signature, issuer.subjectPublicKey);
}
if (!verified) {
break;
}
Expand Down