-
Notifications
You must be signed in to change notification settings - Fork 74
Security callbacks #2901
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
Merged
Merged
Security callbacks #2901
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
477dc4c
initial implementation of security callbacks
jreidinger 3d4cca5
Merge remote-tracking branch 'origin/api-v2' into security_callbacks
jreidinger 6bee4ad
add helper to properly ask question and use it
jreidinger d9976dd
add yes_no_action helper as QoL improvement
jreidinger 2000ad1
change trait to pass string as it is what we construct from libzypp a…
jreidinger 1d44098
changes from review
jreidinger 6942f30
cargo fmt
jreidinger e8e5049
Apply suggestions from code review
jreidinger 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,17 @@ | ||
| pub mod commit_download; | ||
| mod commit_download; | ||
| use agama_utils::{ | ||
| actor::Handler, | ||
| api::question::{Answer, QuestionSpec}, | ||
| question::{self, ask_question, AskError}, | ||
| }; | ||
| pub use commit_download::CommitDownload; | ||
| mod security; | ||
| pub use security::Security; | ||
| use tokio::runtime::Handle; | ||
|
|
||
| fn ask_software_question( | ||
| handler: &Handler<question::Service>, | ||
| question: QuestionSpec, | ||
| ) -> Result<Answer, AskError> { | ||
| Handle::current().block_on(async move { ask_question(handler, question).await }) | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| use agama_utils::{ | ||
| actor::Handler, | ||
| api::question::QuestionSpec, | ||
| question::{self, ask_question}, | ||
| }; | ||
| use gettextrs::gettext; | ||
| use tokio::runtime::Handle; | ||
| use zypp_agama::callbacks::security; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct Security { | ||
| questions: Handler<question::Service>, | ||
| } | ||
|
|
||
| impl Security { | ||
| pub fn new(questions: Handler<question::Service>) -> Self { | ||
| Self { questions } | ||
| } | ||
| } | ||
|
|
||
| impl security::Callback for Security { | ||
| fn unsigned_file(&self, file: String, repository_alias: String) -> bool { | ||
| // TODO: support for extra_repositories with allow_unsigned config | ||
| // TODO: localization for text when parameters in gextext will be solved | ||
| let text = if repository_alias.is_empty() { | ||
| format!( | ||
| "The file {file} is not digitally signed. The origin \ | ||
| and integrity of the file cannot be verified. Use it anyway?" | ||
| ) | ||
| } else { | ||
| format!( | ||
| "The file {file} from {repository_alias} is not digitally signed. The origin \ | ||
| and integrity of the file cannot be verified. Use it anyway?" | ||
| ) | ||
| }; | ||
| let question = QuestionSpec::new(&text, "software.unsigned_file") | ||
| .with_yes_no_actions() | ||
| .with_data(&[("filename", file.as_str())]); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
|
|
||
| fn accept_key( | ||
| &self, | ||
| key_id: String, | ||
| key_name: String, | ||
| key_fingerprint: String, | ||
| _repository_alias: String, | ||
| ) -> security::GpgKeyTrust { | ||
| // TODO: support for extra_repositories with specified gpg key checksum | ||
| // TODO: localization with params | ||
| let text = format!( | ||
| "The key {key_id} ({key_name}) with fingerprint {key_fingerprint} is unknown. \ | ||
| Do you want to trust this key?" | ||
| ); | ||
| let labels = [gettext("Trust"), gettext("Skip")]; | ||
| let actions = [("Trust", labels[0].as_str()), ("Skip", labels[1].as_str())]; | ||
| let question = QuestionSpec::new(&text, "software.import_gpg") | ||
| .with_actions(&actions) | ||
| .with_data(&[ | ||
| ("id", key_id.as_str()), | ||
| ("name", key_name.as_str()), | ||
| ("fingerprint", key_fingerprint.as_str()), | ||
| ]) | ||
| .with_default_action("Skip"); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return security::GpgKeyTrust::Reject; | ||
| }; | ||
|
|
||
| answer | ||
| .action | ||
| .as_str() | ||
| .parse::<security::GpgKeyTrust>() | ||
| .unwrap_or(security::GpgKeyTrust::Reject) | ||
| } | ||
|
|
||
| fn unknown_key(&self, file: String, key_id: String, repository_alias: String) -> bool { | ||
| // TODO: localization for text when parameters in gextext will be solved | ||
| let text = if repository_alias.is_empty() { | ||
| format!( | ||
| "The file {file} is digitally signed with \ | ||
| the following unknown GnuPG key: {key_id}. Use it anyway?" | ||
| ) | ||
| } else { | ||
| format!( | ||
| "The file {file} from {repository_alias} is digitally signed with \ | ||
| the following unknown GnuPG key: {key_id}. Use it anyway?" | ||
| ) | ||
| }; | ||
| let question = QuestionSpec::new(&text, "software.unknown_gpg") | ||
| .with_yes_no_actions() | ||
| .with_data(&[("filename", file.as_str()), ("id", key_id.as_str())]); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
|
|
||
| fn verification_failed( | ||
| &self, | ||
| file: String, | ||
| key_id: String, | ||
| key_name: String, | ||
| _key_fingerprint: String, | ||
| repository_alias: String, | ||
| ) -> bool { | ||
| // TODO: localization for text when parameters in gextext will be solved | ||
| let text = if repository_alias.is_empty() { | ||
| format!( | ||
| "The file {file} is digitally signed with the \ | ||
| following GnuPG key, but the integrity check failed: {key_id} ({key_name}). \ | ||
| Use it anyway?" | ||
| ) | ||
| } else { | ||
| // TODO: Originally it uses repository url and not alias. Does it matter? | ||
| format!( | ||
| "The file {file} from {repository_alias} is digitally signed with the \ | ||
| following GnuPG key, but the integrity check failed: {key_id} ({key_name}). \ | ||
| Use it anyway?" | ||
| ) | ||
| }; | ||
| let question = QuestionSpec::new(&text, "software.verification_failed") | ||
| .with_yes_no_actions() | ||
| .with_data(&[("filename", file.as_str())]); | ||
| let result = Handle::current() | ||
jreidinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
|
|
||
| fn checksum_missing(&self, file: String) -> bool { | ||
| // TODO: localization for text when parameters in gextext will be solved | ||
| let text = format!( | ||
| "No checksum for the file {file} was found in the repository. This means that \ | ||
| although the file is part of the signed repository, the list of checksums \ | ||
| does not mention this file. Use it anyway?" | ||
| ); | ||
| let question = QuestionSpec::new(&text, "software.digest.no_digest").with_yes_no_actions(); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
|
|
||
| fn checksum_unknown(&self, file: String, checksum: String) -> bool { | ||
| let text = format!( | ||
| "The checksum of the file {file} is \"{checksum}\" but the expected checksum is \ | ||
| unknown. This means that the origin and integrity of the file cannot be verified. \ | ||
| Use it anyway?" | ||
| ); | ||
| let question = | ||
| QuestionSpec::new(&text, "software.digest.unknown_digest").with_yes_no_actions(); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
|
|
||
| fn checksum_wrong(&self, file: String, expected: String, actual: String) -> bool { | ||
| let text = format!( | ||
| "The expected checksum of file %{file} is \"%{actual}\" but it was expected to be \ | ||
| \"%{expected}\". The file has changed by accident or by an attacker since the \ | ||
| creater signed it. Use it anyway?" | ||
| ); | ||
|
|
||
| let question = | ||
| QuestionSpec::new(&text, "software.digest.unknown_digest").with_yes_no_actions(); | ||
| let result = Handle::current() | ||
| .block_on(async move { ask_question(&self.questions, question).await }); | ||
| let Ok(answer) = result else { | ||
| tracing::warn!("Failed to ask question {:?}", result); | ||
| return false; | ||
| }; | ||
|
|
||
| answer.action == "Yes" | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.