-
Notifications
You must be signed in to change notification settings - Fork 40
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
[wicketd] Fall back to old behavior if SP is too old to support reading RoT CMPA/CFPA #4326
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1608,90 +1608,131 @@ impl UpdateContext { | |
page.copy_from_slice(&output_buf[..n]); | ||
Ok(page) | ||
}; | ||
let cmpa = self | ||
|
||
// We may be talking to an SP / RoT that doesn't yet know how to give us | ||
// its CMPA. If we hit a protocol version error here, we can fall back | ||
// to our old behavior of requiring exactly 1 RoT artifact. | ||
let mut artifact_to_apply = None; | ||
|
||
let cmpa = match self | ||
.mgs_client | ||
.sp_rot_cmpa_get( | ||
self.sp.type_, | ||
self.sp.slot, | ||
SpComponent::ROT.const_as_str(), | ||
) | ||
.await | ||
.map_err(|err| UpdateTerminalError::GetRotCmpaFailed { | ||
error: err.into(), | ||
}) | ||
.and_then(|response| { | ||
{ | ||
Ok(response) => { | ||
let data = response.into_inner().base64_data; | ||
base64_decode_rot_page(data).map_err(|error| { | ||
Some(base64_decode_rot_page(data).map_err(|error| { | ||
UpdateTerminalError::GetRotCmpaFailed { error } | ||
}) | ||
})?; | ||
let cfpa = self | ||
.mgs_client | ||
.sp_rot_cfpa_get( | ||
self.sp.type_, | ||
self.sp.slot, | ||
SpComponent::ROT.const_as_str(), | ||
&gateway_client::types::GetCfpaParams { | ||
slot: RotCfpaSlot::Active, | ||
}, | ||
) | ||
.await | ||
.map_err(|err| UpdateTerminalError::GetRotCfpaFailed { | ||
error: err.into(), | ||
}) | ||
.and_then(|response| { | ||
let data = response.into_inner().base64_data; | ||
base64_decode_rot_page(data).map_err(|error| { | ||
UpdateTerminalError::GetRotCfpaFailed { error } | ||
}) | ||
})?; | ||
|
||
// Loop through our possible artifacts and find the first (we only | ||
// expect one!) that verifies against the RoT's CMPA/CFPA. | ||
let mut artifact_to_apply = None; | ||
for artifact in available_artifacts { | ||
let image = artifact | ||
.data | ||
.reader_stream() | ||
.and_then(|stream| async { | ||
let mut buf = Vec::with_capacity(artifact.data.file_size()); | ||
StreamReader::new(stream) | ||
.read_to_end(&mut buf) | ||
.await | ||
.context("I/O error reading extracted archive")?; | ||
Ok(buf) | ||
}) | ||
.await | ||
.map_err(|error| { | ||
UpdateTerminalError::FailedFindingSignedRotImage { error } | ||
})?; | ||
let archive = RawHubrisArchive::from_vec(image).map_err(|err| { | ||
UpdateTerminalError::FailedFindingSignedRotImage { | ||
error: anyhow::Error::new(err).context(format!( | ||
"failed to read hubris archive for {:?}", | ||
artifact.id | ||
)), | ||
} | ||
})?; | ||
match archive.verify(&cmpa, &cfpa) { | ||
Ok(()) => { | ||
})?) | ||
} | ||
// TODO is there a better way to check the _specific_ error response | ||
// we get here? We only have a couple of strings; we could check the | ||
// error string contents for something like "WrongVersion", but | ||
// that's pretty fragile. Instead we'll treat any error response | ||
// here as a "fallback to previous behavior". | ||
Err(err @ gateway_client::Error::ErrorResponse(_)) => { | ||
if available_artifacts.len() == 1 { | ||
info!( | ||
self.log, "RoT archive verification success"; | ||
"name" => artifact.id.name.as_str(), | ||
"version" => %artifact.id.version, | ||
"kind" => ?artifact.id.kind, | ||
self.log, | ||
"Failed to get RoT CMPA page; \ | ||
using only available RoT artifact"; | ||
"err" => %err, | ||
); | ||
artifact_to_apply = Some(artifact.clone()); | ||
break; | ||
artifact_to_apply = Some(available_artifacts[0].clone()); | ||
None | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some logging here, since it's a weird corner case |
||
return Err(UpdateTerminalError::GetRotCmpaFailed { | ||
error: err.into(), | ||
}); | ||
} | ||
Err(err) => { | ||
// We log this but don't fail - we want to continue looking | ||
// for a verifiable artifact. | ||
info!( | ||
self.log, "RoT archive verification failed"; | ||
"artifact" => ?artifact.id, | ||
"err" => %DisplayErrorChain::new(&err), | ||
); | ||
} | ||
Err(err) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here that this covers communication errors, etc? |
||
return Err(UpdateTerminalError::GetRotCmpaFailed { | ||
error: err.into(), | ||
}); | ||
} | ||
}; | ||
|
||
// If we were able to fetch the CMPA, we also need to fetch the CFPA and | ||
// then find the correct RoT artifact. If we weren't able to fetch the | ||
// CMPA, we either already set `artifact_to_apply` to the one-and-only | ||
// RoT artifact available, or we returned a terminal error. | ||
if let Some(cmpa) = cmpa { | ||
let cfpa = self | ||
.mgs_client | ||
.sp_rot_cfpa_get( | ||
self.sp.type_, | ||
self.sp.slot, | ||
SpComponent::ROT.const_as_str(), | ||
&gateway_client::types::GetCfpaParams { | ||
slot: RotCfpaSlot::Active, | ||
}, | ||
) | ||
.await | ||
.map_err(|err| UpdateTerminalError::GetRotCfpaFailed { | ||
error: err.into(), | ||
}) | ||
.and_then(|response| { | ||
let data = response.into_inner().base64_data; | ||
base64_decode_rot_page(data).map_err(|error| { | ||
UpdateTerminalError::GetRotCfpaFailed { error } | ||
}) | ||
})?; | ||
|
||
// Loop through our possible artifacts and find the first (we only | ||
// expect one!) that verifies against the RoT's CMPA/CFPA. | ||
for artifact in available_artifacts { | ||
let image = artifact | ||
.data | ||
.reader_stream() | ||
.and_then(|stream| async { | ||
let mut buf = | ||
Vec::with_capacity(artifact.data.file_size()); | ||
StreamReader::new(stream) | ||
.read_to_end(&mut buf) | ||
.await | ||
.context("I/O error reading extracted archive")?; | ||
Ok(buf) | ||
}) | ||
.await | ||
.map_err(|error| { | ||
UpdateTerminalError::FailedFindingSignedRotImage { | ||
error, | ||
} | ||
})?; | ||
let archive = | ||
RawHubrisArchive::from_vec(image).map_err(|err| { | ||
UpdateTerminalError::FailedFindingSignedRotImage { | ||
error: anyhow::Error::new(err).context(format!( | ||
"failed to read hubris archive for {:?}", | ||
artifact.id | ||
)), | ||
} | ||
})?; | ||
match archive.verify(&cmpa, &cfpa) { | ||
Ok(()) => { | ||
info!( | ||
self.log, "RoT archive verification success"; | ||
"name" => artifact.id.name.as_str(), | ||
"version" => %artifact.id.version, | ||
"kind" => ?artifact.id.kind, | ||
); | ||
artifact_to_apply = Some(artifact.clone()); | ||
break; | ||
} | ||
Err(err) => { | ||
// We log this but don't fail - we want to continue | ||
// looking for a verifiable artifact. | ||
info!( | ||
self.log, "RoT archive verification failed"; | ||
"artifact" => ?artifact.id, | ||
"err" => %DisplayErrorChain::new(&err), | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine; it's no worse than before!