esp-signed-updater-mqtt/include/signedUpdatesHelper.h

36 lines
1.2 KiB
C

/* ----------------------------------------------------------------------------
* "THE TSCHUNK LICENSE" (Revision 42):
* <christian@staudte.it> wrote this file. As long as you retain this notice
* you can do whatever you want with this stuff. If we meet some day, and you
* think this stuff is worth it, you can buy me a Tschunk in return.
* ---------------------------------------------------------------------------*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#ifdef PUBLIC_SIGN_KEY
const char pubkey[] PROGMEM = PUBLIC_SIGN_KEY;
BearSSL::PublicKey *signPubKey = nullptr;
BearSSL::HashSHA256 *hash;
BearSSL::SigningVerifier *sign;
void signedUpdatesHelperInit() {
signPubKey = new BearSSL::PublicKey(pubkey);
hash = new BearSSL::HashSHA256();
sign = new BearSSL::SigningVerifier(signPubKey);
Update.installSignature(hash, sign);
}
String signedUpdatesHelperRun(WiFiClient& wifi, const String& url, const String& currentVersion = "") {
t_httpUpdate_return ret = ESPhttpUpdate.update(wifi, url, currentVersion);
if (ret == HTTP_UPDATE_FAILED)
return ESPhttpUpdate.getLastErrorString();
return String();
}
#endif