static int cli_cvdverify(FILE *fs, struct cl_cvd *cvdpt, unsigned int skipsig) { struct cl_cvd *cvd; char *md5, head[513]; int i; fseek(fs, 0, SEEK_SET); if(fread(head, 1, 512, fs) != 512) { cli_errmsg("cli_cvdverify: Can't read CVD header\n"); return CL_ECVD; } head[512] = 0; for(i = 511; i > 0 && (head[i] == ' ' || head[i] == 10); head[i] = 0, i--); if((cvd = cl_cvdparse(head)) == NULL) return CL_ECVD; if(cvdpt) memcpy(cvdpt, cvd, sizeof(struct cl_cvd)); if(skipsig) { cl_cvdfree(cvd); return CL_SUCCESS; } md5 = cli_hashstream(fs, NULL, 1); if (md5 == NULL) { cli_dbgmsg("cli_cvdverify: Cannot generate hash, out of memory\n"); cl_cvdfree(cvd); return CL_EMEM; } cli_dbgmsg("MD5(.tar.gz) = %s\n", md5); if(strncmp(md5, cvd->md5, 32)) { cli_dbgmsg("cli_cvdverify: MD5 verification error\n"); free(md5); cl_cvdfree(cvd); return CL_EVERIFY; } if(cli_versig(md5, cvd->dsig)) { cli_dbgmsg("cli_cvdverify: Digital signature verification error\n"); free(md5); cl_cvdfree(cvd); return CL_EVERIFY; } free(md5); cl_cvdfree(cvd); return CL_SUCCESS; }
static int cli_cvdverify(FILE *fs, struct cl_cvd *cvdpt) { struct cl_cvd *cvd; char *md5, head[513]; int i; fseek(fs, 0, SEEK_SET); if(fread(head, 1, 512, fs) != 512) { cli_errmsg("cli_cvdverify: Can't read CVD header\n"); return CL_ECVD; } head[512] = 0; for(i = 511; i > 0 && (head[i] == ' ' || head[i] == 10); head[i] = 0, i--); if((cvd = cl_cvdparse(head)) == NULL) return CL_ECVD; if(cvdpt) memcpy(cvdpt, cvd, sizeof(struct cl_cvd)); md5 = cli_md5stream(fs, NULL); cli_dbgmsg("MD5(.tar.gz) = %s\n", md5); if(strncmp(md5, cvd->md5, 32)) { cli_dbgmsg("cli_cvdverify: MD5 verification error\n"); free(md5); cl_cvdfree(cvd); return CL_EMD5; } #ifdef HAVE_GMP if(cli_versig(md5, cvd->dsig)) { cli_dbgmsg("cli_cvdverify: Digital signature verification error\n"); free(md5); cl_cvdfree(cvd); return CL_EDSIG; } #endif free(md5); cl_cvdfree(cvd); return 0; }