@@ -170,7 +170,41 @@ bool VerifyDownloadSignature(const std::string& file, const std::string& expecte
170170 return success;
171171}
172172#else
173- static bool VerifyDownloadSignature (const std::string&, const std::string&) { return true ; }
173+ #include < openssl/evp.h>
174+ #include < cstdio>
175+
176+ static bool VerifyDownloadSignature (const std::string& filePath, const std::string& expectedHex)
177+ {
178+ FILE * f = fopen (filePath.c_str (), " rb" );
179+ if (!f) return false ;
180+
181+ EVP_MD_CTX * ctx = EVP_MD_CTX_new ();
182+ if (!ctx) { fclose (f); return false ; }
183+
184+ bool success = false ;
185+ if (EVP_DigestInit_ex (ctx, EVP_sha256 (), nullptr )) {
186+ unsigned char buf[65536 ];
187+ size_t n;
188+ bool ok = true ;
189+ while ((n = fread (buf, 1 , sizeof (buf), f)) > 0 ) {
190+ if (!EVP_DigestUpdate (ctx, buf, n)) { ok = false ; break ; }
191+ }
192+ if (ok && !ferror (f)) {
193+ unsigned char hash[EVP_MAX_MD_SIZE ];
194+ unsigned int hashLen = 0 ;
195+ if (EVP_DigestFinal_ex (ctx, hash, &hashLen)) {
196+ char hexStr[65 ] = {};
197+ for (unsigned int i = 0 ; i < hashLen; i++)
198+ snprintf (hexStr + i * 2 , 3 , " %02x" , hash[i]);
199+ success = (expectedHex == hexStr);
200+ }
201+ }
202+ }
203+
204+ EVP_MD_CTX_free (ctx);
205+ fclose (f);
206+ return success;
207+ }
174208#endif
175209
176210TaskScheduler::TaskResult DownloadReleaseAssets (std::unique_ptr<double >& progress, const nlohmann::json& releaseInfo, const nlohmann::json& osReleaseInfo)
0 commit comments