mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Use DER encoding for AVB1 ECDSA signatures
The AVB 1.0 BootSignature format comes from AOSP's BootSignature.java, which signs and verifies with Java's SHA256withECDSA family. Those produce and expect ASN.1 DER encoded (r, s) signatures. magiskboot wrote and parsed the fixed width r || s form instead. An image signed by AOSP with an EC key was therefore not recognized by `magiskboot verify` (nor flagged AVB1_SIGNED by unpack), and an image signed by `magiskboot sign-avb1` with an EC key was rejected by AOSP's verifier with "Invalid encoding for signature". Encode and decode ECDSA signatures as DER. RSA is unchanged. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -133,15 +133,15 @@ impl Verifier {
|
||||
key.verify_prehash(hash.as_ref(), &sig).log()
|
||||
}
|
||||
VerifyingKey::SHA256withECDSA(key) => {
|
||||
let sig = P256Signature::from_slice(signature)?;
|
||||
let sig = P256Signature::from_der(signature)?;
|
||||
key.verify_prehash(hash.as_ref(), &sig).log()
|
||||
}
|
||||
VerifyingKey::SHA384withECDSA(key) => {
|
||||
let sig = P384Signature::from_slice(signature)?;
|
||||
let sig = P384Signature::from_der(signature)?;
|
||||
key.verify_prehash(hash.as_ref(), &sig).log()
|
||||
}
|
||||
VerifyingKey::SHA521withECDSA(key) => {
|
||||
let sig = P521Signature::from_slice(signature)?;
|
||||
let sig = P521Signature::from_der(signature)?;
|
||||
key.verify_prehash(hash.as_ref(), &sig).log()
|
||||
}
|
||||
}
|
||||
@@ -199,15 +199,15 @@ impl Signer {
|
||||
}
|
||||
SigningKey::SHA256withECDSA(key) => {
|
||||
let sig: P256Signature = key.sign_prehash(hash.as_ref())?;
|
||||
sig.to_vec()
|
||||
sig.to_der().as_bytes().to_vec()
|
||||
}
|
||||
SigningKey::SHA384withECDSA(key) => {
|
||||
let sig: P384Signature = key.sign_prehash(hash.as_ref())?;
|
||||
sig.to_vec()
|
||||
sig.to_der().as_bytes().to_vec()
|
||||
}
|
||||
SigningKey::SHA521withECDSA(key) => {
|
||||
let sig: P521Signature = key.sign_prehash(hash.as_ref())?;
|
||||
sig.to_vec()
|
||||
sig.to_der().as_bytes().to_vec()
|
||||
}
|
||||
};
|
||||
Ok(v)
|
||||
|
||||
Reference in New Issue
Block a user