fix: critical security issues from code review
All checks were successful
CI / build (pull_request) Successful in 1m10s
All checks were successful
CI / build (pull_request) Successful in 1m10s
- Thread safety: Add @Synchronized methods for ECDH buffer access - Crypto: Use X509EncodedKeySpec instead of hard-coded EC curve params - Sensitive data: Make aes_key/shared_secret private in CryptoECDH - Credential storage: Migrate PSK/UUID to EncryptedSharedPreferences
This commit is contained in:
parent
ec310c1bcb
commit
e0b2750c2e
6 changed files with 105 additions and 46 deletions
|
|
@ -260,7 +260,7 @@ static bool performEcdhHandshake(NimBLERemoteService *pSvc) {
|
|||
return false;
|
||||
}
|
||||
|
||||
memcpy(aesKey, ecdh.aes_key, AES_KEY_LEN);
|
||||
memcpy(aesKey, ecdh.getAesKey(), AES_KEY_LEN);
|
||||
ecdh.free();
|
||||
ecdhReady = true;
|
||||
ESP_LOGI(TAG, "ECDH: handshake complete");
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ private:
|
|||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
bool initialized = false;
|
||||
|
||||
uint8_t shared_secret[32];
|
||||
uint8_t aes_key[AES_KEY_LEN];
|
||||
|
||||
CryptoECDH(const CryptoECDH&) = delete;
|
||||
CryptoECDH& operator=(const CryptoECDH&) = delete;
|
||||
|
||||
|
|
@ -29,8 +32,9 @@ public:
|
|||
|
||||
uint8_t public_key[ECDH_PUBKEY_LEN];
|
||||
size_t pub_len = 0;
|
||||
uint8_t shared_secret[32];
|
||||
uint8_t aes_key[AES_KEY_LEN];
|
||||
|
||||
const uint8_t* getAesKey() const { return aes_key; }
|
||||
size_t getAesKeyLen() const { return AES_KEY_LEN; }
|
||||
|
||||
bool init() {
|
||||
mbedtls_ecdh_init(&ecdh);
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@ class EcdhCharacteristicCallbacks : public NimBLECharacteristicCallbacks {
|
|||
return;
|
||||
}
|
||||
|
||||
memcpy(clients[idx].aesKey, clients[idx].ecdh.aes_key, AES_KEY_LEN);
|
||||
memcpy(clients[idx].aesKey, clients[idx].ecdh.getAesKey(), AES_KEY_LEN);
|
||||
|
||||
uint8_t resp[ECDH_PKT_SIZE];
|
||||
memcpy(resp, clients[idx].ecdh.public_key, ECDH_PUBKEY_LEN);
|
||||
|
|
|
|||
Loading…
Reference in a new issue