MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / verify_download_checksum

Function verify_download_checksum

src/cli/cli.c:6969–7043  ·  view source on GitHub ↗

Download checksums.txt and verify the archive integrity. Every non-zero * result is a fail-closed refusal; verification is never optional. */

Source from the content-addressed store, hash-verified

6967/* Download checksums.txt and verify the archive integrity. Every non-zero
6968 * result is a fail-closed refusal; verification is never optional. */
6969static int verify_download_checksum(const char *archive_path, const char *archive_name) {
6970 char checksum_file[CLI_BUF_256];
6971 int checksum_path_length =
6972 snprintf(checksum_file, sizeof(checksum_file), "%s/cbm-checksums-XXXXXX", cbm_tmpdir());
6973 if (checksum_path_length <= 0 || (size_t)checksum_path_length >= sizeof(checksum_file)) {
6974 return CLI_ERR;
6975 }
6976 int checksum_descriptor = cbm_mkstemp(checksum_file);
6977 if (checksum_descriptor < 0) {
6978 return CLI_ERR;
6979 }
6980#ifdef _WIN32
6981 int checksum_close_status = _close(checksum_descriptor);
6982#else
6983 int checksum_close_status = close(checksum_descriptor);
6984#endif
6985 if (checksum_close_status != 0) {
6986 cbm_unlink(checksum_file);
6987 return CLI_ERR;
6988 }
6989
6990 char dl_base_buf[CLI_BUF_512];
6991 const char *dl_base =
6992 cbm_safe_getenv("CBM_DOWNLOAD_URL", dl_base_buf, sizeof(dl_base_buf), NULL);
6993 char checksum_url[CLI_BUF_512];
6994 int checksum_url_length;
6995 if (dl_base && dl_base[0]) {
6996 checksum_url_length =
6997 snprintf(checksum_url, sizeof(checksum_url), "%s/checksums.txt", dl_base);
6998 } else {
6999 checksum_url_length =
7000 snprintf(checksum_url, sizeof(checksum_url), "%s",
7001 "https://github.com/DeusData/codebase-memory-mcp/releases/latest/"
7002 "download/checksums.txt");
7003 }
7004 if (checksum_url_length <= 0 || (size_t)checksum_url_length >= sizeof(checksum_url)) {
7005 cbm_unlink(checksum_file);
7006 return CLI_ERR;
7007 }
7008 int rc = cbm_download_to_file_quiet(checksum_url, checksum_file);
7009 if (rc != 0) {
7010 (void)fprintf(stderr, "error: could not download checksums.txt for mandatory "
7011 "verification\n");
7012 cbm_unlink(checksum_file);
7013 return CLI_ERR;
7014 }
7015
7016 char expected[SHA256_BUF_SIZE] = {0};
7017 int manifest_status =
7018 cbm_cli_checksum_manifest_digest(checksum_file, archive_name, expected, sizeof(expected));
7019 cbm_unlink(checksum_file);
7020 if (manifest_status != CLI_OK) {
7021 (void)fprintf(stderr,
7022 "error: checksums.txt has no single valid SHA-256 entry "
7023 "for exact artifact %s\n",
7024 archive_name);
7025 return CLI_ERR;
7026 }

Callers 1

download_verify_installFunction · 0.85

Calls 7

cbm_tmpdirFunction · 0.85
cbm_mkstempFunction · 0.85
cbm_unlinkFunction · 0.85
cbm_safe_getenvFunction · 0.85
cbm_cli_sha256_fileFunction · 0.85

Tested by

no test coverage detected