Skip to content

Add cryptographically signed update support #5213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
71bf243
Add cryptographically signed update support
earlephilhower Oct 6, 2018
ac25877
Add a simple example
earlephilhower Oct 6, 2018
882e546
Make verifier EC/RSA compatible at any bit length
earlephilhower Oct 6, 2018
29d8c63
Make certain hash bits constant
earlephilhower Oct 7, 2018
e33eb7d
Merge branch 'master' into signedupdates
d-a-v Oct 8, 2018
d9ce799
Merge branch 'master' into signedupdates
earlephilhower Oct 8, 2018
5fb8cd5
When update signed, don't do MD5 work or checking
earlephilhower Oct 10, 2018
b9344f6
Add python automatic signing if keys present
Oct 15, 2018
0ae91ae
Automatically include validation in updater
Oct 15, 2018
dd5c2b0
Merge branch 'master' into signedupdates
earlephilhower Oct 26, 2018
68f703e
Merge branch 'master' into signedupdates
earlephilhower Nov 5, 2018
9823290
Add documentation on signing process
Nov 5, 2018
3de43d6
Update documentation formatting
earlephilhower Nov 6, 2018
3f1013e
Merge branch 'master' into signedupdates
earlephilhower Nov 9, 2018
b3b7477
Move to new BearSSL:: namespace for classes
Nov 9, 2018
2b4016e
Merge branch 'master' into signedupdates
earlephilhower Nov 19, 2018
31b22fb
Move 2 strings into PROGMEM
earlephilhower Nov 29, 2018
b3ed528
Merge branch 'master' into signedupdates
earlephilhower Nov 29, 2018
4164bce
Add openssl return code error checking
earlephilhower Nov 29, 2018
5b2a882
Merge branch 'signedupdates' of https://github.com/earlephilhower/Ard…
earlephilhower Nov 29, 2018
e530a8a
Completely silence normal unsigned builds
earlephilhower Nov 29, 2018
5b243e2
Move debug strings to PMEM
earlephilhower Nov 29, 2018
f1eca3f
Merge branch 'master' into signedupdates
earlephilhower Nov 30, 2018
30e9d9b
Fix prebuild numbering, typo in docs
Nov 30, 2018
15ca564
Warn about Windows incompatibility in build and docs
earlephilhower Nov 30, 2018
d61a8ff
Merge branch 'master' into signedupdates
earlephilhower Dec 1, 2018
f9d340c
Merge branch 'master' into signedupdates
devyte Dec 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add python automatic signing if keys present
  • Loading branch information
Earle F. Philhower, III authored and Earle F. Philhower, III committed Oct 15, 2018
commit b9344f6f00bdf8a3de06e90601c96d2c166760c3
6 changes: 5 additions & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version=2.5.0-dev

runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf
runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
runtime.tools.signing={runtime.platform.path}/tools/signing.py

compiler.warning_flags=-w
compiler.warning_flags.none=-w
Expand Down Expand Up @@ -74,6 +75,8 @@ compiler.elf2hex.extra_flags=
## needs bash, git, and echo
recipe.hooks.core.prebuild.1.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_VER 0x`git --git-dir {runtime.platform.path}/.git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff` >{build.path}/core/core_version.h"
recipe.hooks.core.prebuild.2.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_DESC `cd "{runtime.platform.path}"; git describe --tags 2>/dev/null || echo unix-{version}` >>{build.path}/core/core_version.h"
recipe.hooks.core.prebuild.2.pattern="{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"

## windows-compatible version without git
recipe.hooks.core.prebuild.1.pattern.windows=cmd.exe /c mkdir {build.path}\core & (echo #define ARDUINO_ESP8266_GIT_VER 0x00000000 & echo #define ARDUINO_ESP8266_GIT_DESC win-{version} ) > {build.path}\core\core_version.h
recipe.hooks.core.prebuild.2.pattern.windows=
Expand Down Expand Up @@ -102,7 +105,8 @@ recipe.objcopy.eep.pattern=
## Create hex
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

recipe.objcopy.hex.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.1.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.2.pattern="{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"

## Save hex
recipe.output.tmp_file={build.project_name}.bin
Expand Down
63 changes: 63 additions & 0 deletions tools/signing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
import argparse
import subprocess
import hashlib

def parse_args():
parser = argparse.ArgumentParser(description='Binary signing tool')
parser.add_argument('-m', '--mode', help='Mode (header, sign)')
parser.add_argument('-b', '--bin', help='Unsigned binary')
parser.add_argument('-o', '--out', help='Output file');
parser.add_argument('-p', '--publickey', help='Public key file');
parser.add_argument('-s', '--privatekey', help='Private(secret) key file');
return parser.parse_args()


def main():
args = parse_args()
if args.mode == "header":
val = ""
try:
with open(args.publickey, "rb") as f:
pub = f.read()
val += "#include <pgmspace.h>\n"
val += "#define ARDUINO_SIGNING 1\n"
val += "static const char signing_pubkey[] PROGMEM = {\n"
for i in pub:
val += "0x%02x, \n" % ord(i)
val = val[:-3]
val +="\n};\n"
print "Enabling binary signing\n"
except:
print "Not enabling binary signing\n"
val += "#define ARDUINO_SIGNING 0\n"
with open(args.out, "w") as f:
f.write(val)
return 0
elif args.mode == "sign":
val = ""
try:
with open(args.bin, "rb") as b:
bin = b.read()
sha256 = hashlib.sha256(bin)
print "Binary SHA256 = " + sha256.hexdigest()
signcmd = [ 'openssl', 'rsautl', '-sign', '-inkey', args.privatekey ]
proc = subprocess.Popen(signcmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
signout = proc.communicate(input=sha256.digest())[0]
with open(args.out, "wb") as out:
out.write(bin)
out.write(signout)
out.write(b'\x00\x01\x00\x00')
print "Signed binary: " + args.out
except:
print "Not signing the generated binary\n"
return 0
else:
print "ERROR: Mode not specified as header or sign\n"

if __name__ == '__main__':
sys.exit(main())