Skip to content

Commit 5a576b2

Browse files
Jakujenwalfield
andcommitted
PubKeyLint: Return NotTrusted for disabled algorithms
The RPM needs to distinguish between completely broken keys and keys that are "just" untrusted by the policy. Similarly with signatures on RPMs we can return the NonTrusted return value, that can be used by RPM to differentiate these errors and allow filtering valid certificates when a file contains more of them. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Co-authored-by: Neal H. Walfield <neal@sequoia-pgp.org>
1 parent c036745 commit 5a576b2

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,9 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17261726
let pkts = check_slice!(pkts, pktslen);
17271727
let explanation = check_mut!(explanation);
17281728

1729+
// Whether the key relies on legacy cryptography.
1730+
let mut legacy = false;
1731+
17291732
// Make sure we always set explanation to something.
17301733
*explanation = std::ptr::null_mut();
17311734

@@ -1743,6 +1746,11 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17431746
Err(err) => {
17441747
lint(&format!("Policy rejects {}: {}",
17451748
cert.keyid(), error_chain_display(&err)));
1749+
// If the signatures are valid, then assume it failed
1750+
// due to the use of legacy cryptography.
1751+
if let Ok(_) = cert.with_policy(NP, None) {
1752+
legacy = true;
1753+
}
17461754
break 'done false;
17471755
}
17481756
Ok(vc) => {
@@ -1790,6 +1798,11 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17901798
Err(err) => {
17911799
lint(&format!("Policy rejects subkey {}: {}",
17921800
keyid, error_chain_display(&err)));
1801+
// If the signatures are valid, then assume it
1802+
// failed due to the use of legacy cryptography.
1803+
if let Ok(_) = ka.with_policy(NP, None) {
1804+
legacy = true;
1805+
}
17931806
continue;
17941807
}
17951808
Ok(ka) => {
@@ -1873,6 +1886,9 @@ fn _pgpPubKeyLint(pkts: *const c_char,
18731886

18741887
if usable {
18751888
Ok(())
1889+
} else if legacy {
1890+
Err(Error::NotTrusted(
1891+
format!("Certificate {} relies on legacy crypto", cert.keyid())))
18761892
} else {
18771893
Err(Error::Fail(format!("Certificate {} is unusable", cert.keyid())))
18781894
}

0 commit comments

Comments
 (0)