Skip to content

Commit

Permalink
fix: Include certificate time checks for read_subnet_state too (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity authored Feb 29, 2024
1 parent b434eec commit 66246e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

* Timestamps are now being checked in `Agent::verify`. If you were using it with old certificates, increase the expiry timeout to continue to verify them.
* Timestamps are now being checked in `Agent::verify` and `Agent::verify_for_subnet`. If you were using it with old certificates, increase the expiry timeout to continue to verify them.
* Added ECDSA and Bitcoin functions to `MgmtMethod`. There are no new wrappers in `ManagementCanister` because only canisters can call these functions.
* Added `FetchCanisterLogs` function to `MgmtMethod` and a corresponding wrapper to `ManagementCanister`.

Expand Down
30 changes: 24 additions & 6 deletions ic-agent/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@ impl Agent {
&self,
cert: &Certificate,
effective_canister_id: Principal,
) -> Result<(), AgentError> {
self.verify_cert(cert, effective_canister_id)?;
self.verify_cert_timestamp(cert)?;
Ok(())
}

fn verify_cert(
&self,
cert: &Certificate,
effective_canister_id: Principal,
) -> Result<(), AgentError> {
let sig = &cert.signature;

Expand All @@ -851,9 +861,6 @@ impl Agent {

ic_verify_bls_signature::verify_bls_signature(sig, &msg, &key)
.map_err(|_| AgentError::CertificateVerificationFailed())?;

self.verify_cert_timestamp(cert)?;

Ok(())
}

Expand All @@ -863,6 +870,16 @@ impl Agent {
&self,
cert: &Certificate,
subnet_id: Principal,
) -> Result<(), AgentError> {
self.verify_cert_for_subnet(cert, subnet_id)?;
self.verify_cert_timestamp(cert)?;
Ok(())
}

fn verify_cert_for_subnet(
&self,
cert: &Certificate,
subnet_id: Principal,
) -> Result<(), AgentError> {
let sig = &cert.signature;

Expand All @@ -875,7 +892,8 @@ impl Agent {
let key = extract_der(der_key)?;

ic_verify_bls_signature::verify_bls_signature(sig, &msg, &key)
.map_err(|_| AgentError::CertificateVerificationFailed())
.map_err(|_| AgentError::CertificateVerificationFailed())?;
Ok(())
}

fn verify_cert_timestamp(&self, cert: &Certificate) -> Result<(), AgentError> {
Expand Down Expand Up @@ -903,7 +921,7 @@ impl Agent {
if cert.delegation.is_some() {
return Err(AgentError::CertificateHasTooManyDelegations);
}
self.verify(&cert, effective_canister_id)?;
self.verify_cert(&cert, effective_canister_id)?;
let canister_range_lookup = [
"subnet".as_bytes(),
delegation.subnet_id.as_ref(),
Expand Down Expand Up @@ -940,7 +958,7 @@ impl Agent {
if cert.delegation.is_some() {
return Err(AgentError::CertificateHasTooManyDelegations);
}
self.verify_for_subnet(&cert, subnet_id)?;
self.verify_cert_for_subnet(&cert, subnet_id)?;
let public_key_path = [
"subnet".as_bytes(),
delegation.subnet_id.as_ref(),
Expand Down

0 comments on commit 66246e9

Please sign in to comment.