Skip to content

Commit

Permalink
Fix sha256 file digest (#37)
Browse files Browse the repository at this point in the history
* Always initialize sha256_out_length variable
* Return true if processing was interrupted and false if not, this was erroneously inverted before
* Bump version to 0.4.2

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Jan 30, 2024
1 parent f95a98c commit 5afe436
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(everest-evse_security VERSION 0.4.1
project(everest-evse_security VERSION 0.4.2
DESCRIPTION "Implementation of EVSE related security operations"
LANGUAGES CXX C
)
Expand Down
10 changes: 5 additions & 5 deletions lib/evse_security/crypto/openssl/openssl_supplier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ bool OpenSSLSupplier::digest_file_sha256(const fs::path& path, std::vector<std::

bool digest_error = false;

unsigned int sha256_out_length;
unsigned int sha256_out_length = 0;
std::byte sha256_out[EVP_MAX_MD_SIZE];

// calculate sha256 of file
Expand All @@ -778,7 +778,7 @@ bool OpenSSLSupplier::digest_file_sha256(const fs::path& path, std::vector<std::
if (EVP_DigestUpdate(md_context_ptr.get(), bytes, read) == 0) {
EVLOG_error << "Error during EVP_DigestUpdate";
digest_error = true;
return false;
return true;
}
}

Expand All @@ -787,11 +787,11 @@ bool OpenSSLSupplier::digest_file_sha256(const fs::path& path, std::vector<std::
&sha256_out_length) == 0) {
EVLOG_error << "Error during EVP_DigestFinal_ex";
digest_error = true;
return false;
return true;
}
}

return true;
return false;
});

if ((processed_file == false) || (digest_error == true)) {
Expand Down Expand Up @@ -843,4 +843,4 @@ bool OpenSSLSupplier::decode_base64_signature(const std::string& signature, std:
return true;
}

} // namespace evse_security
} // namespace evse_security
5 changes: 3 additions & 2 deletions lib/evse_security/utils/evse_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ bool process_file(const fs::path& file_path, size_t buffer_size,
while (file.read(reinterpret_cast<char*>(buffer.data()), buffer_size)) {
interupted = func(buffer.data(), buffer_size, false);

if (interupted)
if (interupted) {
break;
}
}

// Process the remaining bytes
Expand Down Expand Up @@ -117,4 +118,4 @@ std::string get_random_file_name(const std::string& extension) {
return buff.str();
}

} // namespace evse_security::filesystem_utils
} // namespace evse_security::filesystem_utils

0 comments on commit 5afe436

Please sign in to comment.