feat: response authentication (certificate verification, root key lookup, delegations)#86
feat: response authentication (certificate verification, root key lookup, delegations)#86
Conversation
ic-agent/src/agent/mod.rs
Outdated
|
|
||
| static INIT_BLS: Once = Once::new(); | ||
|
|
||
| // todo: do not merge until this is the actual Sodium key |
ic-agent/src/agent/mod.rs
Outdated
| } | ||
| } | ||
|
|
||
| fn initialize_bls() -> Result<(), AgentError> { |
There was a problem hiding this comment.
This file is getting big, does it make sense to move this, extract_der, and the lookup functions to a different file?
ic-agent/src/agent/agent_error.rs
Outdated
| DerPrefixMismatch { expected: Vec<u8>, actual: Vec<u8> }, | ||
|
|
||
| #[error("The status response did not contain a root key")] | ||
| NoRootKeyInStatus(), |
There was a problem hiding this comment.
should we also print the status here (may be useful)
ic-agent/src/agent/mod.rs
Outdated
| } | ||
|
|
||
| /// Fetch the root key from the status endpoint. | ||
| /// It is not necessary to call this when communicating with "the" Internet Computer. |
There was a problem hiding this comment.
nit: maybe reword to affirm the positive "Only an agent communicating with a local/custom instance of the Internet Computer should call this method. It is not necessary to call this when communicating with the DFINITY foundation managed Internet Computer."
ic-agent/src/agent/mod.rs
Outdated
| let mut write_guard = self.root_key.write().unwrap(); | ||
| *write_guard = root_key; |
There was a problem hiding this comment.
| let mut write_guard = self.root_key.write().unwrap(); | |
| *write_guard = root_key; | |
| if let Ok(mut write_guard) = self.root_key.write() { | |
| *write_guard = root_key; | |
| } |
There was a problem hiding this comment.
getting rid of the unwraps
There was a problem hiding this comment.
Ok, I applied these changes. The reason I had them as unwrap() is because the RwLock poisoning condition that would cause them to fail can't happen in the code as is, because the writer can't panic.
ic-agent/src/agent/mod.rs
Outdated
| let root_key = self.root_key.read().unwrap().clone(); | ||
| Ok(root_key) |
There was a problem hiding this comment.
| let root_key = self.root_key.read().unwrap().clone(); | |
| Ok(root_key) | |
| if let Ok(read_lock) = self.root_key.read() { | |
| let root_key = *read_lock; | |
| Ok(root_key) | |
| } else { | |
| Err(AgentError::CouldntReadRootKey) | |
| } |
There was a problem hiding this comment.
getting rid of unwraps and adding some new AgentError
Implements from doc:
See also companion PR sdk #1197