forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement pgp signature validation
Uses the pgp crate to validate signatures on downloaded artifacts when they are available and warns if those are not valid. Ref rust-lang#2028
- Loading branch information
1 parent
3929244
commit 597953e
Showing
18 changed files
with
831 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ pub mod manifest; | |
pub mod manifestation; | ||
pub mod notifications; | ||
pub mod prefix; | ||
pub mod signatures; |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Signature verification support for Rustup. | ||
// TODO: Determine whether we want external keyring support | ||
|
||
use pgp::types::KeyTrait; | ||
use pgp::{Deserializable, StandaloneSignature}; | ||
|
||
use crate::config::PgpPublicKey; | ||
use crate::errors::*; | ||
|
||
use std::io::Read; | ||
|
||
fn squish_internal_err<E: std::fmt::Display>(err: E) -> Error { | ||
ErrorKind::SignatureVerificationInternalError(format!("{}", err)).into() | ||
} | ||
|
||
pub fn verify_signature<T: Read>( | ||
mut content: T, | ||
signature: &str, | ||
keys: &[PgpPublicKey], | ||
) -> Result<bool> { | ||
let mut content_buf = Vec::new(); | ||
content.read_to_end(&mut content_buf)?; | ||
let (signatures, _) = | ||
StandaloneSignature::from_string_many(signature).map_err(squish_internal_err)?; | ||
|
||
for signature in signatures { | ||
let signature = signature.map_err(squish_internal_err)?; | ||
|
||
for key in keys { | ||
let actual_key = key.key(); | ||
if actual_key.is_signing_key() && signature.verify(actual_key, &content_buf).is_ok() { | ||
return Ok(true); | ||
} | ||
|
||
for sub_key in &actual_key.public_subkeys { | ||
if sub_key.is_signing_key() && signature.verify(sub_key, &content_buf).is_ok() { | ||
return Ok(true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(false) | ||
} |
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
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
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
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
Oops, something went wrong.