security(server): bind grant revocation state (revoked_at) to integrity hash
This commit is contained in:
@@ -394,6 +394,7 @@ mod tests {
|
||||
chain: CHAIN_ID,
|
||||
valid_from: None,
|
||||
valid_until: None,
|
||||
revoked_at: None,
|
||||
max_gas_fee_per_gas: None,
|
||||
max_priority_fee_per_gas: None,
|
||||
rate_limit: None,
|
||||
@@ -596,4 +597,24 @@ mod tests {
|
||||
assert!(violations.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_settings_hash_changes_when_revoked_at_changes() {
|
||||
use arbiter_crypto::hashing::Hashable;
|
||||
use sha2::Digest;
|
||||
|
||||
let active = shared_settings();
|
||||
let revoked = SharedGrantSettings {
|
||||
revoked_at: Some(Utc::now()),
|
||||
..shared_settings()
|
||||
};
|
||||
|
||||
let mut active_hash = sha2::Sha256::new();
|
||||
active.hash(&mut active_hash);
|
||||
|
||||
let mut revoked_hash = sha2::Sha256::new();
|
||||
revoked.hash(&mut revoked_hash);
|
||||
|
||||
assert_ne!(active_hash.finalize(), revoked_hash.finalize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ pub struct SharedGrantSettings {
|
||||
|
||||
pub valid_from: Option<DateTime<Utc>>,
|
||||
pub valid_until: Option<DateTime<Utc>>,
|
||||
pub revoked_at: Option<DateTime<Utc>>,
|
||||
|
||||
pub max_gas_fee_per_gas: Option<U256>,
|
||||
pub max_priority_fee_per_gas: Option<U256>,
|
||||
@@ -160,6 +161,7 @@ impl SharedGrantSettings {
|
||||
chain: model.chain_id as u64, // safe because chain_id is stored as i32 but is guaranteed to be a valid ChainId by the API when creating grants
|
||||
valid_from: model.valid_from.map(Into::into),
|
||||
valid_until: model.valid_until.map(Into::into),
|
||||
revoked_at: model.revoked_at.map(Into::into),
|
||||
max_gas_fee_per_gas: model
|
||||
.max_gas_fee_per_gas
|
||||
.map(|b| utils::try_bytes_to_u256(&b))
|
||||
|
||||
@@ -78,6 +78,7 @@ fn shared() -> SharedGrantSettings {
|
||||
chain: CHAIN_ID,
|
||||
valid_from: None,
|
||||
valid_until: None,
|
||||
revoked_at: None,
|
||||
max_gas_fee_per_gas: None,
|
||||
max_priority_fee_per_gas: None,
|
||||
rate_limit: None,
|
||||
|
||||
@@ -95,6 +95,7 @@ fn shared() -> SharedGrantSettings {
|
||||
chain: CHAIN_ID,
|
||||
valid_from: None,
|
||||
valid_until: None,
|
||||
revoked_at: None,
|
||||
max_gas_fee_per_gas: None,
|
||||
max_priority_fee_per_gas: None,
|
||||
rate_limit: None,
|
||||
|
||||
@@ -87,6 +87,7 @@ impl TryConvert for ProtoSharedSettings {
|
||||
.valid_until
|
||||
.map(ProtoTimestamp::try_convert)
|
||||
.transpose()?,
|
||||
revoked_at: None,
|
||||
max_gas_fee_per_gas: self
|
||||
.max_gas_fee_per_gas
|
||||
.as_deref()
|
||||
|
||||
Reference in New Issue
Block a user