добавил sha256 для файла обновления

This commit is contained in:
Vladislav Ostapov 2024-11-14 11:34:28 +03:00
parent 0dcc562b7d
commit eda26319c4
5 changed files with 15 additions and 6 deletions

View File

@ -9,9 +9,12 @@
std::string http::utils::sha256(const std::string &payload) {
// Вычисляем SHA256 хеш
return sha256(payload.c_str(), payload.size());
}
std::string http::utils::sha256(const char* data, size_t size) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256(reinterpret_cast<const unsigned char *>(payload.c_str()), payload.length(), hash);
SHA256(reinterpret_cast<const unsigned char *>(data), size, hash);
// Преобразуем хеш в шестнадцатеричную строку
std::stringstream ss;

View File

@ -6,6 +6,7 @@
namespace http::utils {
std::string sha256(const std::string& payload);
std::string sha256(const char* data, size_t size);
std::string sha256AsB64(const std::string& payload);
std::string b64Encode(const char* data, size_t size);

View File

@ -19,6 +19,7 @@
#include "terminal_api_driver.h"
#include "auth/resources.h"
#include "auth/jwt.h"
#include "auth/utils.h"
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
@ -347,7 +348,9 @@ public:
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
std::string result = R"({"status":"ok","fwsize":)";
result += std::to_string(req.payload.size());
result += "}";
result += ",\"sha256\":\"";
result += http::utils::sha256(req.payload.data(), req.payload.size());
result += "\"}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}));
}

View File

@ -3,8 +3,6 @@
#include <fstream>
#include <utility>
#include "../../dependencies/control_system/common/protocol_commands.h"
static void loadFile(const std::string& path, std::vector<char>& content) {
std::ifstream is(path, std::ios::in | std::ios::binary);
if (!is) {

View File

@ -619,6 +619,7 @@
<label>
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
</label>
<button class="dangerous-button" @click="settingsUploadUpdate()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
</div>
@ -954,7 +955,8 @@
uploadFw: {
progress: null,
filename: null
filename: null,
sha256: null
},
testState: false,
@ -1313,6 +1315,8 @@
});
xhr.addEventListener("loadend", () => {
this.uploadFw.progress = 100
const rep = JSON.parse(xhr.responseText);
this.uploadFw.sha256 = rep['sha256']
resolve(xhr.readyState === 4 && xhr.status === 200);
});
xhr.open("PUT", "/api/firmwareUpdate", true);