Skip to content

Commit

Permalink
2.2.6 overclocking and fix in version string processing
Browse files Browse the repository at this point in the history
- overclock in ota_set_verify=ON fixes tighter timeout applied by GitHub

- version string malloc was 1 byte short

- keyid now uint16_t
  • Loading branch information
HomeACcessoryKid committed Dec 31, 2023
1 parent 1d87872 commit bff6b52
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.2.6 overclocking and fix in version string processing
- overclock in ota_set_verify=ON fixes tighter timeout applied by GitHub
- version string malloc was 1 byte short
- keyid now uint16_t

## 2.2.5 updated certificates to be identical across all versions
- contains DigiCertGlobalRootCA and DigiCertHighAssuranceEVRootCA
- EC support put back in place
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Life-Cycle-Manager (LCM)
Initial install, WiFi settings and over the air firmware upgrades for any esp-open-rtos repository on GitHub
(c) 2018-2022 HomeAccessoryKid
(c) 2018-2024 HomeAccessoryKid

## Update December 2023
It looks like GitHub has put a 10s timeout on their TLS stack.
When verifying the server certificate, we take >15s and the server finishes the connection.
Version 2.2.6 tries to fix this by using overclock during this phase.

## Update season 16 April 2022
After 14 months, version 2.1.2 will get upgraded to version 2.2.5. So be aware your own app update will take extra long.
Expand Down
49 changes: 29 additions & 20 deletions deploy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(c) 2018-2022 HomeAccessoryKid
(c) 2018-2024 HomeAccessoryKid

### Instructions for end users:
TBD
Expand All @@ -10,33 +10,42 @@ cd life-cycle-manager
- initial steps to be expanded

#### These are the steps if not introducing a new key pair
- create/update the file versions1/latest-pre-release without new-line and setup 2.2.5 version folder
- create/update the file versions1/latest-pre-release without new-line and setup 2.2.6 version folder
```
mkdir versions1/2.2.5v
echo -n 2.2.5 > versions1/2.2.5v/latest-pre-release
cp versions1/certs.sector versions1/certs.sector.sig versions1/2.2.5v
cp versions1/public*key* versions1/2.2.5v
mkdir versions1/2.2.6v
echo -n 2.2.6 > versions1/2.2.6v/latest-pre-release
cp versions1/certs.sector versions1/certs.sector.sig versions1/2.2.6v
cp versions1/public*key* versions1/2.2.6v
```
- set local.mk to the ota-main program
```
make -j6 rebuild OTAVERSION=2.2.5
mv firmware/otamain.bin versions1/2.2.5v
make -j6 rebuild OTAVERSION=2.2.6
mv firmware/otamain.bin versions1/2.2.6v
```
- set local.mk back to ota-boot program
```
make -j6 rebuild OTAVERSION=2.2.5
mv firmware/otaboot.bin versions1/2.2.5v
make -j6 rebuild OTAVERSION=2.2.5 OTABETA=1
cp firmware/otaboot.bin versions1/2.2.5v/otabootbeta.bin
make -j6 rebuild OTAVERSION=2.2.6
mv firmware/otaboot.bin versions1/2.2.6v
make -j6 rebuild OTAVERSION=2.2.6 OTABETA=1
cp firmware/otaboot.bin versions1/2.2.6v/otabootbeta.bin
```
- remove the older version files
#
- update Changelog
- if you can sign the binaries locally, do so, else follow later steps
```
~/bin/ecc_signer otaboot.bin ../secp384r1prv.der ../secp384r1pub.der
printf "%08x" `cat otaboot.bin | wc -c`| xxd -r -p > len
cat hash len sign > otaboot.bin.sig
~/bin/ecc_signer otamain.bin ../secp384r1prv.der ../secp384r1pub.der
printf "%08x" `cat otamain.bin | wc -c`| xxd -r -p > len
cat hash len sign > otamain.bin.sig
rm hash len sign
```
- test otaboot for basic behaviour
- commit and sync submodules
- commit and sync this as version 2.2.5
- set up a new github release 2.2.5 as a pre-release using the just commited master...
- commit and sync this as version 2.2.6
- set up a new github release 2.2.6 as a pre-release using the just commited master...
- upload the certs and binaries to the pre-release assets on github
#
- erase the flash and upload the privatekey
Expand All @@ -46,18 +55,18 @@ esptool.py -p /dev/cu.usbserial-* --baud 230400 write_flash 0xf9000 versions1-pr
```
- upload the ota-boot BETA program to the device that contains the private key
```
make flash OTAVERSION=2.2.5 OTABETA=1
make flash OTAVERSION=2.2.6 OTABETA=1
```
- power cycle to prevent the bug for software reset after flash
- setup wifi and select the ota-demo repo without pre-release checkbox
- create the 2 signature files next to the bin file and upload to github one by one
- verify the hashes on the computer
```
openssl sha384 versions1/2.2.5v/otamain.bin
xxd versions1/2.2.5v/otamain.bin.sig
openssl sha384 versions1/2.2.6v/otamain.bin
xxd versions1/2.2.6v/otamain.bin.sig
```

- upload the file versions1/2.2.5v/latest-pre-release to the 'latest release' assets on github
- upload the file versions1/2.2.6v/latest-pre-release to the 'latest release' assets on github

#### Testing

Expand Down Expand Up @@ -110,14 +119,14 @@ esptool.py -p /dev/cu.usbserial-* --baud 230400 write_flash 0xf9000 versionsN-1-
```
- collect public-1.key.sig and store it in the new version folder and copy it to versions1
```
cp versions1/2.2.5v/public-1.key.sig versions1
cp versions1/2.2.6v/public-1.key.sig versions1
```
- then flash the new private key
```
esptool.py -p /dev/cu.usbserial-* --baud 230400 write_flash 0xf9000 versions1-privatekey.der
```
- collect cert.sector.sig and store it in the new version folder and copy it to versions1
```
cp versions1/2.2.5v/certs.sector.sig versions1
cp versions1/2.2.6v/certs.sector.sig versions1
```
- continue with a normal deployment to create the 2 signature files next to the bin files
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void ota_task(void *arg) {
#ifdef OTABOOT
int have_private_key=0;
#endif
int keyid,foundkey=0;
uint16_t keyid;
int foundkey=0;
char keyname[KEYNAMELEN];

ota_init();
Expand Down
13 changes: 9 additions & 4 deletions ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include <udplogger.h>

#include <FreeRTOS.h>
#include <esplibs/libmain.h> //for overclocking functions

static int verify = 1;
static byte file_first_byte[]={0xff};
ecc_key prvecckey;
Expand Down Expand Up @@ -582,12 +585,14 @@ void ota_set_verify(int onoff) {
UDPLGP("TIME: %s", ctime(&ts)); //we need to have the clock right to check certificates

wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
sdk_system_overclock(); //With verification, we are to slow for the 10s timeout of GitHub (end 2023)
}
} else {
UDPLGP("OFF\n");
if (verify==1) {
verify= 0;
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
sdk_system_restoreclock();
}
}
}
Expand Down Expand Up @@ -619,7 +624,7 @@ char* ota_get_btl_version() {

spiflash_read(SECTORSIZE-MAXVERSIONLEN, (byte *)versionbuff, MAXVERSIONLEN);
if (versionbuff[0]!=0xff) { //TODO: make this more error resistant
version=malloc(strlen(versionbuff));
version=malloc(strlen(versionbuff)+1);
strcpy(version,versionbuff);
} else {
version=malloc(6);
Expand Down Expand Up @@ -696,7 +701,7 @@ char* ota_get_version(char * repo) {
strchr(recv_buf,'\r')[0]=0;
found_ptr=ota_strstr(recv_buf,"releases/tag/");
if (found_ptr[13]=='v' || found_ptr[13]=='V') found_ptr++;
version=malloc(strlen(found_ptr+13));
version=malloc(strlen(found_ptr+13)+1);
strcpy(version,found_ptr+13);
printf("%s@version:\"%s\" according to latest release\n",repo,version);
} else {
Expand Down Expand Up @@ -853,7 +858,7 @@ int ota_get_file_ex(char * repo, char * version, char * file, int sector, byte
strcat(found_ptr, REQUESTTAIL);
slash=strchr(found_ptr,'/')-found_ptr;
found_ptr[slash]=0; //cut behind the hostname
char * host2=malloc(strlen(found_ptr));
char * host2=malloc(strlen(found_ptr)+1);
strcpy(host2,found_ptr);
//printf("next host: %s\n",host2);

Expand All @@ -862,7 +867,7 @@ int ota_get_file_ex(char * repo, char * version, char * file, int sector, byte
strcat(strcat(found_ptr+slash+1,host2),RANGE); //append hostname and range to URI
found_ptr+=slash-4;
memcpy(found_ptr,REQUESTHEAD,5);
char * getlinestart=malloc(strlen(found_ptr));
char * getlinestart=malloc(strlen(found_ptr)+1);
strcpy(getlinestart,found_ptr);
//printf("request:\n%s\n",getlinestart);
//if (!retc) {
Expand Down
2 changes: 1 addition & 1 deletion ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define SIGNSIZE 104 //ECDSA r+s in ASN1 format secP384r1
#define PKEYSIZE 120 //size of a pub key
#define KEYNAME "public-%d.key"
#define KEYNAMELEN 16 //allows for 9999 keys
#define KEYNAMELEN 17 //allows for 65535 keys with uint16_t

typedef unsigned char byte;

Expand Down
1 change: 0 additions & 1 deletion versions1/2.2.5v/latest-pre-release

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions versions1/2.2.6v/latest-pre-release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.2.6
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit bff6b52

Please sign in to comment.