sim: Actually test invalid signatures
Currently, the tests that appear to be testing for invalid signatures
are actually just testing that images aren't used if the entire TLV
block is missing. Fix this by being more subtle about our corruptions.
If there is no signature, corrupt that data being used to generate the
hash. Otherwise, modify the data before it goes into the signature, but
generate a valid SHA256 in the TLV. This way, we exercise the signature
itself being corrupt.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/image.rs b/sim/src/image.rs
index bc4c444..cfb5198 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -1149,12 +1149,10 @@
}
// Build the TLV itself.
- let mut b_tlv = if bad_sig {
- let good_sig = &mut tlv.make_tlv();
- vec![0; good_sig.len()]
- } else {
- tlv.make_tlv()
- };
+ if bad_sig {
+ tlv.corrupt_sig();
+ }
+ let mut b_tlv = tlv.make_tlv();
let dev = flash.get_mut(&dev_id).unwrap();