Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3

This commit is contained in:
Sebastien L
2022-01-20 13:45:36 -05:00
77 changed files with 823 additions and 320 deletions

View File

@@ -7,8 +7,6 @@ option(BELL_DISABLE_CODECS "Disable libhelix AAC and MP3 codecs" OFF)
#set(BELL_EXTERNAL_CJSON "" CACHE STRING "External cJSON library target name, optional")
#set(BELL_EXTERNAL_TREMOR "" CACHE STRING "External tremor library target name, optional")
add_definitions(-DPB_ENABLE_MALLOC)
# Include nanoPB library
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/nanopb/extra)
find_package(Nanopb REQUIRED)
@@ -98,3 +96,4 @@ message(${NANOPB_INCLUDE_DIRS})
# PUBLIC to propagate esp-idf includes to bell dependents
target_link_libraries(bell PUBLIC ${EXTRA_LIBS})
target_include_directories(bell PUBLIC "include" ${EXTRA_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(bell PUBLIC PB_ENABLE_MALLOC)

View File

@@ -56,7 +56,7 @@ public:
std::vector<uint8_t> sha1HMAC(const std::vector<uint8_t>& inputKey, const std::vector<uint8_t>& message);
// AES CTR
void aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, std::vector<uint8_t>& data);
void aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, uint8_t* data, size_t nbytes);
// AES ECB
void aesECBdecrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& data);

View File

@@ -63,7 +63,7 @@ public:
std::vector<uint8_t> sha1HMAC(const std::vector<uint8_t>& inputKey, const std::vector<uint8_t>& message);
// AES CTR
void aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, std::vector<uint8_t>& data);
void aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, uint8_t* buffer, size_t nbytes);
// AES ECB
void aesECBdecrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& data);

View File

@@ -42,6 +42,10 @@ void pbDecode(T &result, const pb_msgdesc_t *fields, std::vector<uint8_t> &data)
}
}
void pbPutString(const std::string &stringToPack, char* dst);
void pbPutCharArray(const char * stringToPack, char* dst);
void pbPutBytes(const std::vector<uint8_t> &data, pb_bytes_array_t &dst);
const char* pb_encode_to_string(const pb_msgdesc_t *fields, const void *data);
pb_istream_t pb_istream_from_http(bell::HTTPClient::HTTPResponse *response, size_t length = 0);

View File

@@ -29,7 +29,7 @@ namespace bell
#ifdef ESP_PLATFORM
this->xStack = NULL;
this->priority = CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + priority;
if (this->priority < 0) this->priority = ESP_TASK_PRIO_MIN;
if (this->priority <= ESP_TASK_PRIO_MIN) this->priority = ESP_TASK_PRIO_MIN + 1;
if (runOnPSRAM) {
this->xStack = (StackType_t*) heap_caps_malloc(this->stackSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

View File

@@ -88,7 +88,7 @@ std::vector<uint8_t> CryptoMbedTLS::sha1HMAC(const std::vector<uint8_t> &inputKe
}
// AES CTR
void CryptoMbedTLS::aesCTRXcrypt(const std::vector<uint8_t> &key, std::vector<uint8_t> &iv, std::vector<uint8_t> &data)
void CryptoMbedTLS::aesCTRXcrypt(const std::vector<uint8_t> &key, std::vector<uint8_t> &iv, uint8_t* buffer, size_t nbytes)
{
// needed for internal cache
size_t off = 0;
@@ -99,12 +99,12 @@ void CryptoMbedTLS::aesCTRXcrypt(const std::vector<uint8_t> &key, std::vector<ui
// Perform decrypt
mbedtls_aes_crypt_ctr(&aesCtx,
data.size(),
nbytes,
&off,
iv.data(),
streamBlock,
data.data(),
data.data());
buffer,
buffer);
}
void CryptoMbedTLS::aesECBdecrypt(const std::vector<uint8_t> &key, std::vector<uint8_t> &data)
@@ -115,7 +115,7 @@ void CryptoMbedTLS::aesECBdecrypt(const std::vector<uint8_t> &key, std::vector<u
// Mbedtls's decrypt only works on 16 byte blocks
for (unsigned int x = 0; x < data.size() / 16; x++)
{
// Perform decrypt
// Perform finalize
mbedtls_aes_crypt_ecb(&aesCtx,
MBEDTLS_AES_DECRYPT,
data.data() + (x * 16),

View File

@@ -99,7 +99,7 @@ std::vector<uint8_t> CryptoOpenSSL::sha1HMAC(const std::vector<uint8_t>& inputKe
}
// AES CTR
void CryptoOpenSSL::aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, std::vector<uint8_t> &data)
void CryptoOpenSSL::aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<uint8_t>& iv, uint8_t* buffer, size_t nbytes)
{
// Prepare AES_KEY
auto cryptoKey = AES_KEY();
@@ -110,9 +110,9 @@ void CryptoOpenSSL::aesCTRXcrypt(const std::vector<uint8_t>& key, std::vector<ui
unsigned int offsetInBlock = 0;
CRYPTO_ctr128_encrypt(
data.data(),
data.data(),
data.size(),
buffer,
buffer,
nbytes,
&cryptoKey,
iv.data(),
ecountBuf,

View File

@@ -287,7 +287,7 @@ std::string HTTPClient::HTTPResponse::readToString() {
return result;
}
std::string result;
char buffer[BUF_SIZE];
char buffer[BUF_SIZE+1]; // make space for null-terminator
size_t len;
do {
len = this->read(buffer, BUF_SIZE);

View File

@@ -47,6 +47,22 @@ pb_bytes_array_t* vectorToPbArray(const std::vector<uint8_t>& vectorToPack)
return result;
}
void pbPutString(const std::string &stringToPack, char* dst) {
stringToPack.copy(dst, stringToPack.size());
dst[stringToPack.size()] = '\0';
}
void pbPutCharArray(const char * stringToPack, char* dst) {
// copy stringToPack into dst
strcpy(dst, stringToPack);
//dst[sizeof(stringToPack)-1] = '\0';
}
void pbPutBytes(const std::vector<uint8_t> &data, pb_bytes_array_t &dst) {
dst.size = data.size();
std::copy(data.begin(), data.end(), dst.bytes);
}
std::vector<uint8_t> pbArrayToVector(pb_bytes_array_t* pbArray) {
return std::vector<uint8_t>(pbArray->bytes, pbArray->bytes + pbArray->size);
}