Skip to content

Commit

Permalink
<fix>(security): fix dataEncrtption decode bug. (FISCO-BCOS#4561)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Aug 1, 2024
1 parent 6f62fad commit cc2483e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions bcos-executor/src/vm/gas_meter/Metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace bcos
{
namespace wasm
{
using bcos::wasm::Instruction;
InstructionTable GetInstructionTable()
{
auto defaultInstructionTable = InstructionTable{};
Expand Down
26 changes: 10 additions & 16 deletions bcos-security/bcos-security/DataEncryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ std::shared_ptr<bytes> DataEncryption::decryptContents(const std::shared_ptr<byt
if (m_compatibilityVersion >=
static_cast<uint32_t>(bcos::protocol::BlockVersion::V3_3_VERSION))
{
random_bytes_engine rbe;
std::vector<unsigned char> ivData(16);
std::generate(std::begin(ivData), std::end(ivData), std::ref(rbe));

size_t const offsetIv = encFileBytes.size() - 16;
size_t const cipherDataSize = encFileBytes.size() - 16;
decFileBytesBase64Ptr = m_symmetricEncrypt->symmetricDecrypt(
(const unsigned char*)encFileBytes.data(), encFileBytes.size(),
(const unsigned char*)m_dataKey.data(), m_dataKey.size(), ivData.data(), 16);
decFileBytesBase64Ptr->insert(
decFileBytesBase64Ptr->end(), ivData.begin(), ivData.end());
reinterpret_cast<const unsigned char*>(encFileBytes.data()), cipherDataSize,
reinterpret_cast<const unsigned char*>(m_dataKey.data()), m_dataKey.size(),
reinterpret_cast<const unsigned char*>(encFileBytes.data() + offsetIv), 16);
}
else
{
Expand Down Expand Up @@ -143,15 +140,12 @@ std::shared_ptr<bytes> DataEncryption::decryptFile(const std::string& filename)
if (m_compatibilityVersion >=
static_cast<uint32_t>(bcos::protocol::BlockVersion::V3_3_VERSION))
{
random_bytes_engine rbe;
std::vector<unsigned char> ivData(16);
std::generate(std::begin(ivData), std::end(ivData), std::ref(rbe));

size_t const offsetIv = encFileBytes.size() - 16;
size_t const cipherDataSize = encFileBytes.size() - 16;
decFileBytesBase64Ptr = m_symmetricEncrypt->symmetricDecrypt(
(const unsigned char*)encFileBytes.data(), encFileBytes.size(),
(const unsigned char*)m_dataKey.data(), m_dataKey.size(), ivData.data(), 16);
decFileBytesBase64Ptr->insert(
decFileBytesBase64Ptr->end(), ivData.begin(), ivData.end());
reinterpret_cast<const unsigned char*>(encFileBytes.data()), cipherDataSize,
reinterpret_cast<const unsigned char*>(m_dataKey.data()), m_dataKey.size(),
reinterpret_cast<const unsigned char*>(encFileBytes.data() + offsetIv), 16);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class BaselineScheduler : public scheduler::SchedulerInterface
callback(nullptr);
}

void stop() override {};
void stop() override{};

void registerTransactionNotifier(std::function<void(bcos::protocol::BlockNumber,
bcos::protocol::TransactionSubmitResultsPtr, std::function<void(Error::Ptr)>)>
Expand Down

0 comments on commit cc2483e

Please sign in to comment.