добавил sha256 для файла обновления
This commit is contained in:
parent
0dcc562b7d
commit
eda26319c4
@ -9,9 +9,12 @@
|
|||||||
|
|
||||||
|
|
||||||
std::string http::utils::sha256(const std::string &payload) {
|
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];
|
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;
|
std::stringstream ss;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
namespace http::utils {
|
namespace http::utils {
|
||||||
std::string sha256(const std::string& payload);
|
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 sha256AsB64(const std::string& payload);
|
||||||
|
|
||||||
std::string b64Encode(const char* data, size_t size);
|
std::string b64Encode(const char* data, size_t size);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "terminal_api_driver.h"
|
#include "terminal_api_driver.h"
|
||||||
#include "auth/resources.h"
|
#include "auth/resources.h"
|
||||||
#include "auth/jwt.h"
|
#include "auth/jwt.h"
|
||||||
|
#include "auth/utils.h"
|
||||||
|
|
||||||
|
|
||||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
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)});
|
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||||
std::string result = R"({"status":"ok","fwsize":)";
|
std::string result = R"({"status":"ok","fwsize":)";
|
||||||
result += std::to_string(req.payload.size());
|
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());
|
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "../../dependencies/control_system/common/protocol_commands.h"
|
|
||||||
|
|
||||||
static void loadFile(const std::string& path, std::vector<char>& content) {
|
static void loadFile(const std::string& path, std::vector<char>& content) {
|
||||||
std::ifstream is(path, std::ios::in | std::ios::binary);
|
std::ifstream is(path, std::ios::in | std::ios::binary);
|
||||||
if (!is) {
|
if (!is) {
|
||||||
|
@ -619,6 +619,7 @@
|
|||||||
<label>
|
<label>
|
||||||
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
||||||
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
<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>
|
</label>
|
||||||
<button class="dangerous-button" @click="settingsUploadUpdate()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
<button class="dangerous-button" @click="settingsUploadUpdate()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
||||||
</div>
|
</div>
|
||||||
@ -954,7 +955,8 @@
|
|||||||
|
|
||||||
uploadFw: {
|
uploadFw: {
|
||||||
progress: null,
|
progress: null,
|
||||||
filename: null
|
filename: null,
|
||||||
|
sha256: null
|
||||||
},
|
},
|
||||||
|
|
||||||
testState: false,
|
testState: false,
|
||||||
@ -1313,6 +1315,8 @@
|
|||||||
});
|
});
|
||||||
xhr.addEventListener("loadend", () => {
|
xhr.addEventListener("loadend", () => {
|
||||||
this.uploadFw.progress = 100
|
this.uploadFw.progress = 100
|
||||||
|
const rep = JSON.parse(xhr.responseText);
|
||||||
|
this.uploadFw.sha256 = rep['sha256']
|
||||||
resolve(xhr.readyState === 4 && xhr.status === 200);
|
resolve(xhr.readyState === 4 && xhr.status === 200);
|
||||||
});
|
});
|
||||||
xhr.open("PUT", "/api/firmwareUpdate", true);
|
xhr.open("PUT", "/api/firmwareUpdate", true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user