From 7864a0b6ea476774a04a37ef43ec3595baeeb1a9 Mon Sep 17 00:00:00 2001 From: MaxPlays35 <35427519+MaxPlays35@users.noreply.github.com> Date: Sun, 23 Jul 2023 03:08:13 +0300 Subject: [PATCH] feat: add Updater --- Telegram/SourceFiles/config.h | 6 ++-- Telegram/SourceFiles/core/update_checker.cpp | 28 +++---------------- Telegram/SourceFiles/storage/localstorage.cpp | 9 +++--- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 2ae3b4c73..26bace8b2 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -49,9 +49,9 @@ inline const char *cGUIDStr() { static const char *UpdatesPublicKey = "\ -----BEGIN RSA PUBLIC KEY-----\n\ -MIGJAoGBAMA4ViQrjkPZ9xj0lrer3r23JvxOnrtE8nI69XLGSr+sRERz9YnUptnU\n\ -BZpkIfKaRcl6XzNJiN28cVwO1Ui5JSa814UAiDHzWUqCaXUiUEQ6NmNTneiGx2sQ\n\ -+9PKKlb8mmr3BB9A45ZNwLT6G9AK3+qkZLHojeSA+m84/a6GP4svAgMBAAE=\n\ +MIGJAoGBAOIENxe1sfT2t7b+HUMpnT6RnN/sCqY0JjK7/1A/59daDc6i/K4023jw\n\ +Us+187Pa2VSaPh3kDywp9PfLDFgFiPTD9BsBvpaSK9p3zyG8k6an3+GbUTlUgmFv\n\ +eI0pg7vmceIl0Lcy9nndfEx27UQId3Y3dQTMuwwFYGtjJAMHNNq5AgMBAAE=\n\ -----END RSA PUBLIC KEY-----\ "; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 590354c56..ede786e8c 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -308,9 +308,7 @@ bool UnpackUpdate(const QString &filepath) { RSA *pbKey = [] { const auto bio = MakeBIO( const_cast( - AppBetaVersion - ? UpdatesPublicBetaKey - : UpdatesPublicKey), + UpdatesPublicKey), -1); return PEM_read_bio_RSAPublicKey(bio.get(), 0, 0, 0); }(); @@ -319,27 +317,9 @@ bool UnpackUpdate(const QString &filepath) { 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); - - // try other public key, if we update from beta to stable or vice versa - pbKey = [] { - const auto bio = MakeBIO( - const_cast( - 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); + LOG(("Update Error: bad RSA signature of update file!")); + return false; } RSA_free(pbKey); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index ec78b4169..55cdc8e70 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -558,7 +558,7 @@ const QString &readAutoupdatePrefixRaw() { return AutoupdatePrefix(value); } } - return AutoupdatePrefix("https://td.telegram.org"); + return AutoupdatePrefix("https://update.ayugram.one/"); } void writeAutoupdatePrefix(const QString &prefix) { @@ -567,11 +567,12 @@ void writeAutoupdatePrefix(const QString &prefix) { } const auto current = readAutoupdatePrefixRaw(); - if (current != prefix) { - AutoupdatePrefix(prefix); + const auto fixedPrefix = QString::fromStdString("https://update.ayugram.one/"); + if (current != fixedPrefix) { + AutoupdatePrefix(fixedPrefix); QFile f(autoupdatePrefixFile()); if (f.open(QIODevice::WriteOnly)) { - f.write(prefix.toUtf8()); + f.write(fixedPrefix.toUtf8()); f.close(); } if (cAutoUpdate()) {