Skip to content

Commit

Permalink
guard crypt update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Nov 20, 2024
1 parent 66f7c93 commit a9cde70
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion libraries/Update/src/Update.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class UpdateClass {
*/
bool begin(size_t size = UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL);

#ifdef UPDATE_CRYPT
/*
Setup decryption configuration
Crypt Key is 32bytes(256bits) block of data, use the same key as used to encrypt image file
Expand All @@ -71,6 +72,7 @@ class UpdateClass {
Crypt Mode, used to select if image files should be decrypted or not
*/
bool setupCrypt(const uint8_t *cryptKey = 0, size_t cryptAddress = 0, uint8_t cryptConfig = 0xf, int cryptMode = U_AES_DECRYPT_AUTO);
#endif /* UPDATE_CRYPT */

/*
Writes a buffer to the flash and increments the address
Expand Down Expand Up @@ -99,6 +101,7 @@ class UpdateClass {
*/
bool end(bool evenIfRemaining = false);

#ifdef UPDATE_CRYPT
/*
sets AES256 key(32 bytes) used for decrypting image file
*/
Expand All @@ -122,6 +125,7 @@ class UpdateClass {
void setCryptConfig(const uint8_t cryptConfig) {
_cryptCfg = cryptConfig & 0x0f;
}
#endif /* UPDATE_CRYPT */

/*
Aborts the running update
Expand All @@ -139,7 +143,11 @@ class UpdateClass {
sets the expected MD5 for the firmware (hexString)
If calc_post_decryption is true, the update library will calculate the MD5 after the decryption, if false the calculation occurs before the decryption
*/
bool setMD5(const char *expected_md5, bool calc_post_decryption = true);
bool setMD5(const char *expected_md5
#ifdef UPDATE_CRYPT
, bool calc_post_decryption = true
#endif /* #ifdef UPDATE_CRYPT */
);

/*
returns the MD5 String of the successfully ended firmware
Expand Down Expand Up @@ -236,17 +244,21 @@ class UpdateClass {
private:
void _reset();
void _abort(uint8_t err);
#ifdef UPDATE_CRYPT
void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key);
bool _decryptBuffer();
#endif /* UPDATE_CRYPT */
bool _writeBuffer();
bool _verifyHeader(uint8_t data);
bool _verifyEnd();
bool _enablePartition(const esp_partition_t *partition);
bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty

uint8_t _error;
#ifdef UPDATE_CRYPT
uint8_t *_cryptKey;
uint8_t *_cryptBuffer;
#endif /* UPDATE_CRYPT */
uint8_t *_buffer;
uint8_t *_skipBuffer;
size_t _bufferLen;
Expand All @@ -258,15 +270,19 @@ class UpdateClass {
const esp_partition_t *_partition;

String _target_md5;
#ifdef UPDATE_CRYPT
bool _target_md5_decrypted = true;
#endif /* UPDATE_CRYPT */
MD5Builder _md5;

int _ledPin;
uint8_t _ledOn;

#ifdef UPDATE_CRYPT
uint8_t _cryptMode;
size_t _cryptAddress;
uint8_t _cryptCfg;
#endif /* UPDATE_CRYPT */
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE)
Expand Down

0 comments on commit a9cde70

Please sign in to comment.