Skip to content

Commit

Permalink
Remove deprecated SHA1 functions on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsanches committed Dec 8, 2024
1 parent 573d1e8 commit 504d4a1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
4 changes: 4 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

- Support to new sensor with milliseconds delay and legacy sensors

## Code

- Updated to stop using deprecated OpenSSL functions for computing SHA1

# Version 0.9.0

## General Features
Expand Down
2 changes: 1 addition & 1 deletion src/BrokerLib/dcc/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace dcclite::broker
}

dcclite::Log::Trace("[Device::{}] [Load] stored config token {}", this->GetName(), storedConfigToken);
dcclite::Log::Trace("[Device::{}] [Load] config token {}", this->GetName(), m_ConfigToken);
dcclite::Log::Trace("[Device::{}] [Load] currently config token {}", this->GetName(), m_ConfigToken);
dcclite::Log::Trace("[Device::{}] [Load] reading config {}", this->GetName(), m_pathConfigFile.string());

rapidjson::IStreamWrapper isw(configFile);
Expand Down
14 changes: 9 additions & 5 deletions src/BrokerLib/sys/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace dcclite::broker
dcclite::Sha1 currentFileHash;
currentFileHash.ComputeForFile(this->GetFilePath(fileName));

//dcclite::Log::Trace("hash {} -> {}", filePath.string(), currentFileHash.ToString());
dcclite::Log::Trace("[Project::GetFileToken] {} hash is {}", fileName, currentFileHash.ToString());

dcclite::Guid token;
dcclite::Sha1 storedHash;
Expand Down Expand Up @@ -95,13 +95,13 @@ namespace dcclite::broker
}
else
{
dcclite::Log::Info("[Project::GetFileToken] Project state file for {} not found", fileName);
dcclite::Log::Info("[Project::GetFileToken] {} Project state file not found", fileName);
}

SKIP_LOAD:
if (storedHash != currentFileHash)
{
dcclite::Log::Info("[Project::GetFileToken] Project config file {} modified", fileName);
dcclite::Log::Info("[Project::GetFileToken] {} Project config file modified", fileName);

token = dcclite::GuidCreate();

Expand All @@ -113,7 +113,7 @@ namespace dcclite::broker

if (ec)
{
dcclite::Log::Error("[Project::GetFileToken] Cannot create app path for storing state for {}, system error: {}", fileName, ec.message());
dcclite::Log::Error("[Project::GetFileToken] {} Cannot create app path for storing state, system error: {}", fileName, ec.message());
}
else
{
Expand All @@ -129,9 +129,13 @@ namespace dcclite::broker

newStateFile << responseWriter.GetString();

dcclite::Log::Info("[Project::GetFileToken] Stored {} state data on {}", fileName, stateFilePath.string());
dcclite::Log::Info("[Project::GetFileToken] {} state data on {}", fileName, stateFilePath.string());
}
}
else
{
dcclite::Log::Info("[Project::GetFileToken] {} Stored hash on state match {}", fileName, storedHash.ToString());
}
}

return token;
Expand Down
42 changes: 20 additions & 22 deletions src/Common/Sha1_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,49 @@
// defined by the Mozilla Public License, v. 2.0.


#include <openssl/sha.h>
#include <openssl/evp.h>
#include <cassert>

#include "Sha1.h"


class Hasher : public dcclite::detail::NonCopyable
{
public:
Hasher()
{
assert(dcclite::SHA1_LENGTH == SHA_DIGEST_LENGTH);
{
m_pContext = EVP_MD_CTX_new();
if(m_pContext == nullptr)
{
throw std::runtime_error("[Hasher] Cannot create SSL context");
}

if(!EVP_DigestInit(m_pContext, EVP_sha1()))
{
EVP_MD_CTX_free(m_pContext);

SHA1_Init(&m_Context);
throw std::runtime_error("[Hasher] Cannot init SSL digest");
}
}

~Hasher()
{
if (!m_fFinalized)
{
unsigned char hash[dcclite::SHA1_LENGTH];

SHA1_Final(hash, &m_Context);
}
{
EVP_MD_CTX_free(m_pContext);
}

void Compute(const void* data, size_t length)
{
assert(!m_fFinalized);

SHA1_Update(&m_Context, data, length);
EVP_DigestUpdate(m_pContext, data, length);
}

void Finalize(unsigned char hash[dcclite::SHA1_LENGTH])
{
assert(!m_fFinalized);
unsigned int s = dcclite::SHA1_LENGTH;

SHA1_Final(hash, &m_Context);
m_fFinalized = true;
EVP_DigestFinal_ex(m_pContext, hash, &s);
}

private:
bool m_fFinalized = false;

SHA_CTX m_Context;
private:
EVP_MD_CTX *m_pContext;
};

void dcclite::Sha1::ComputeForFile(const dcclite::fs::path &fileName)
Expand Down
2 changes: 0 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ DCCLite

- update route section to know next section and avoid re-ocupying the block

- remove deprecate SHA1 usage on Linux

LitePanelSDL
------------

Expand Down

0 comments on commit 504d4a1

Please sign in to comment.