Share signed job core and verify native Linux then Windows contracts
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
//! Fixed Ed25519 verification; no algorithm negotiation or trust-key discovery.
|
||||
use anyhow::Result;
|
||||
use ed25519_dalek::{Signature, VerifyingKey};
|
||||
|
||||
pub trait Ed25519Verifier {
|
||||
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct DalekVerifier;
|
||||
|
||||
impl Ed25519Verifier for DalekVerifier {
|
||||
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool> {
|
||||
let Ok(raw): Result<&[u8; 32], _> = public_key.try_into() else {
|
||||
return Ok(false);
|
||||
};
|
||||
let Ok(key) = VerifyingKey::from_bytes(raw) else {
|
||||
return Ok(false);
|
||||
};
|
||||
let Ok(signature) = Signature::from_slice(signature) else {
|
||||
return Ok(false);
|
||||
};
|
||||
// Reject weak points and scalar/point malleability. This is raw Ed25519,
|
||||
// never Ed25519ph: the exact stored bytes are the signed message.
|
||||
Ok(key.verify_strict(message, &signature).is_ok())
|
||||
}
|
||||
}
|
||||
|
||||
/// Existing Linux verifier semantics, retained explicitly during extraction.
|
||||
#[cfg(all(unix, feature = "openssl-verifier"))]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct OpenSslVerifier;
|
||||
|
||||
#[cfg(all(unix, feature = "openssl-verifier"))]
|
||||
impl Ed25519Verifier for OpenSslVerifier {
|
||||
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool> {
|
||||
use openssl::{
|
||||
pkey::{Id, PKey},
|
||||
sign::Verifier,
|
||||
};
|
||||
if public_key.len() != 32 || signature.len() != 64 {
|
||||
return Ok(false);
|
||||
}
|
||||
let key = PKey::public_key_from_raw_bytes(public_key, Id::ED25519)?;
|
||||
Ok(Verifier::new_without_digest(&key)?.verify_oneshot(signature, message)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Preserve the existing Linux OpenSSL profile when selected by its adapter;
|
||||
/// Windows never depends on OpenSSL, including workspace feature unification.
|
||||
#[cfg(all(unix, feature = "openssl-verifier"))]
|
||||
pub type DefaultVerifier = OpenSslVerifier;
|
||||
#[cfg(not(all(unix, feature = "openssl-verifier")))]
|
||||
pub type DefaultVerifier = DalekVerifier;
|
||||
Reference in New Issue
Block a user