Commit 7e701d8c authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Add RSA signature verification to simulator

Using the published debug keypair, generate a signature with it, to add
to the TLV.  This verifies that signature verification works as
expected.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 1e158599
Loading
Loading
Loading
Loading
+106
Changes for sim/Cargo.lock: 106 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,10 +8,12 @@ dependencies = [
 "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "pem 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
 "simflash 0.1.0",
 "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -22,6 +24,14 @@ dependencies = [
 "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "aho-corasick"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "backtrace"
version = "0.3.2"
@@ -45,11 +55,24 @@ dependencies = [
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "base64"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "byteorder"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "cfg-if"
version = "0.1.2"
@@ -106,6 +129,14 @@ dependencies = [
 "backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "error-chain"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "futures"
version = "0.1.14"
@@ -148,6 +179,14 @@ dependencies = [
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "memchr"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "num_cpus"
version = "1.6.2"
@@ -156,6 +195,17 @@ dependencies = [
 "libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "pem"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rand"
version = "0.3.15"
@@ -197,11 +247,28 @@ dependencies = [
 "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "regex"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "regex-syntax"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "regex-syntax"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "ring"
version = "0.11.0"
@@ -258,6 +325,23 @@ dependencies = [
 "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "thread_local"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "untrusted"
version = "0.5.0"
@@ -268,6 +352,16 @@ name = "utf8-ranges"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "utf8-ranges"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi"
version = "0.2.8"
@@ -280,15 +374,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
"checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76"
"checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff"
"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7ef30445607f6fc8720f0a0a2c7442284b629cf0d049286860fae23e71c4d9"
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
"checksum error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "318cb3c71ee4cdea69fdc9e15c173b245ed6063e1709029e8fd32525a881120f"
"checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a"
"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a"
@@ -297,12 +395,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "30885bcb161cf67054244d10d4a7f4835ffd58773bc72e07d35fecf472295503"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
"checksum pem 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b8ecfb4eb6b5ec9f5ca17667a5d451275630bbf53c25eb1ae76e235bbf8bf26"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a"
"checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
"checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724"
"checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
@@ -310,7 +412,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "67f84c44fbb2f91db7fef94554e6b2ac05909c9c0b0bc23bb98d3a1aebfe7f7c"
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
"checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673"
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+3 −1
Changes for sim/Cargo.toml: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@ log = "0.3"
env_logger = "0.3"
simflash = { path = "simflash" }
bitflags = "0.9"
ring = "0.11"
ring = { version = "0.11", features = ["rsa_signing"] }
untrusted = "0.5"
pem = "0.4"

[profile.test]
opt-level = 1
+8
Changes for sim/build.rs: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ fn main() {
    conf.file("../boot/bootutil/src/caps.c");
    conf.file("../boot/bootutil/src/bootutil_misc.c");
    conf.file("../boot/bootutil/src/image_validate.c");
    conf.file("../boot/bootutil/src/image_rsa.c");
    conf.file("../boot/zephyr/keys.c");
    conf.file("csupport/run.c");
    conf.include("../boot/bootutil/include");
    conf.include("../boot/zephyr/include");
@@ -28,8 +30,14 @@ fn main() {
    conf.include("mbedtls/include");
    conf.file("mbedtls/library/sha256.c");

    // Code for RSA.
    conf.file("mbedtls/library/rsa.c");
    conf.file("mbedtls/library/bignum.c");
    conf.file("mbedtls/library/asn1parse.c");

    // Test that signature/hashes are present.
    conf.define("MCUBOOT_VALIDATE_SLOT0", None);
    conf.define("MCUBOOT_SIGN_RSA", None);

    conf.compile("libbootutil.a");
    walk_dir("../boot").unwrap();
+6
Changes for sim/csupport/run.c: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -42,11 +42,17 @@ struct area_desc {

static struct area_desc *flash_areas;

void *(*mbedtls_calloc)(size_t n, size_t size);
void (*mbedtls_free)(void *ptr);

int invoke_boot_go(struct area_desc *adesc)
{
    int res;
    struct boot_rsp rsp;

    mbedtls_calloc = calloc;
    mbedtls_free = free;

    flash_areas = adesc;
    if (setjmp(boot_jmpbuf) == 0) {
        res = boot_go(&rsp);
+3 −1
Changes for sim/src/main.rs: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -4,9 +4,11 @@ extern crate env_logger;
#[macro_use] extern crate bitflags;
extern crate docopt;
extern crate libc;
extern crate pem;
extern crate rand;
extern crate rustc_serialize;
extern crate simflash;
extern crate untrusted;

use docopt::Docopt;
use rand::{Rng, SeedableRng, XorShiftRng};
@@ -601,7 +603,7 @@ fn show_flash(flash: &Flash) {
fn install_image(flash: &mut Flash, offset: usize, len: usize) -> Vec<u8> {
    let offset0 = offset;

    let mut tlv = TlvGen::new_hash_only();
    let mut tlv = TlvGen::new_rsa_pss();

    // Generate a boot header.  Note that the size doesn't include the header.
    let header = ImageHeader {
Loading