feat: add Updater

This commit is contained in:
MaxPlays35 2023-07-23 03:08:13 +03:00
parent ec0e949bae
commit 7864a0b6ea
3 changed files with 12 additions and 31 deletions

View file

@ -49,9 +49,9 @@ inline const char *cGUIDStr() {
static const char *UpdatesPublicKey = "\ static const char *UpdatesPublicKey = "\
-----BEGIN RSA PUBLIC KEY-----\n\ -----BEGIN RSA PUBLIC KEY-----\n\
MIGJAoGBAMA4ViQrjkPZ9xj0lrer3r23JvxOnrtE8nI69XLGSr+sRERz9YnUptnU\n\ MIGJAoGBAOIENxe1sfT2t7b+HUMpnT6RnN/sCqY0JjK7/1A/59daDc6i/K4023jw\n\
BZpkIfKaRcl6XzNJiN28cVwO1Ui5JSa814UAiDHzWUqCaXUiUEQ6NmNTneiGx2sQ\n\ Us+187Pa2VSaPh3kDywp9PfLDFgFiPTD9BsBvpaSK9p3zyG8k6an3+GbUTlUgmFv\n\
+9PKKlb8mmr3BB9A45ZNwLT6G9AK3+qkZLHojeSA+m84/a6GP4svAgMBAAE=\n\ eI0pg7vmceIl0Lcy9nndfEx27UQId3Y3dQTMuwwFYGtjJAMHNNq5AgMBAAE=\n\
-----END RSA PUBLIC KEY-----\ -----END RSA PUBLIC KEY-----\
"; ";

View file

@ -308,9 +308,7 @@ bool UnpackUpdate(const QString &filepath) {
RSA *pbKey = [] { RSA *pbKey = [] {
const auto bio = MakeBIO( const auto bio = MakeBIO(
const_cast<char*>( const_cast<char*>(
AppBetaVersion UpdatesPublicKey),
? UpdatesPublicBetaKey
: UpdatesPublicKey),
-1); -1);
return PEM_read_bio_RSAPublicKey(bio.get(), 0, 0, 0); return PEM_read_bio_RSAPublicKey(bio.get(), 0, 0, 0);
}(); }();
@ -319,27 +317,9 @@ bool UnpackUpdate(const QString &filepath) {
return false; return false;
} }
if (RSA_verify(NID_sha1, (const uchar*)(compressed.constData() + hSigLen), hShaLen, (const uchar*)(compressed.constData()), hSigLen, pbKey) != 1) { // verify signature if (RSA_verify(NID_sha1, (const uchar*)(compressed.constData() + hSigLen), hShaLen, (const uchar*)(compressed.constData()), hSigLen, pbKey) != 1) { // verify signature
RSA_free(pbKey); RSA_free(pbKey);
LOG(("Update Error: bad RSA signature of update file!"));
// try other public key, if we update from beta to stable or vice versa return false;
pbKey = [] {
const auto bio = MakeBIO(
const_cast<char*>(
AppBetaVersion
? UpdatesPublicKey
: UpdatesPublicBetaKey),
-1);
return PEM_read_bio_RSAPublicKey(bio.get(), 0, 0, 0);
}();
if (!pbKey) {
LOG(("Update Error: cant read public rsa key!"));
return false;
}
if (RSA_verify(NID_sha1, (const uchar*)(compressed.constData() + hSigLen), hShaLen, (const uchar*)(compressed.constData()), hSigLen, pbKey) != 1) { // verify signature
RSA_free(pbKey);
LOG(("Update Error: bad RSA signature of update file!"));
return false;
}
} }
RSA_free(pbKey); RSA_free(pbKey);

View file

@ -558,7 +558,7 @@ const QString &readAutoupdatePrefixRaw() {
return AutoupdatePrefix(value); return AutoupdatePrefix(value);
} }
} }
return AutoupdatePrefix("https://td.telegram.org"); return AutoupdatePrefix("https://update.ayugram.one/");
} }
void writeAutoupdatePrefix(const QString &prefix) { void writeAutoupdatePrefix(const QString &prefix) {
@ -567,11 +567,12 @@ void writeAutoupdatePrefix(const QString &prefix) {
} }
const auto current = readAutoupdatePrefixRaw(); const auto current = readAutoupdatePrefixRaw();
if (current != prefix) { const auto fixedPrefix = QString::fromStdString("https://update.ayugram.one/");
AutoupdatePrefix(prefix); if (current != fixedPrefix) {
AutoupdatePrefix(fixedPrefix);
QFile f(autoupdatePrefixFile()); QFile f(autoupdatePrefixFile());
if (f.open(QIODevice::WriteOnly)) { if (f.open(QIODevice::WriteOnly)) {
f.write(prefix.toUtf8()); f.write(fixedPrefix.toUtf8());
f.close(); f.close();
} }
if (cAutoUpdate()) { if (cAutoUpdate()) {