Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the validity of hash algo #3416

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/rpmvs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ int rpmIsValidHex(const char *str, size_t slen)
return valid;
}

static int hashalgoValid(int algo)
{
int rc = 0;

switch(algo) {
case RPM_HASH_MD5:
case RPM_HASH_SHA1:
case RPM_HASH_RIPEMD160:
case RPM_HASH_MD2:
case RPM_HASH_TIGER192:
case RPM_HASH_HAVAL_5_160:
case RPM_HASH_SHA256:
case RPM_HASH_SHA384:
case RPM_HASH_SHA512:
case RPM_HASH_SHA224:
rc = 1;
break;
default:
break;
}

return rc;
}

static void rpmsinfoInit(const struct vfyinfo_s *vinfo,
const struct vfytag_s *tinfo,
rpmtd td, const char *origin,
Expand Down Expand Up @@ -213,6 +237,12 @@ static void rpmsinfoInit(const struct vfyinfo_s *vinfo,
free(lints);
}
sinfo->hashalgo = pgpDigParamsAlgo(sinfo->sig, PGPVAL_HASHALGO);
if (!hashalgoValid(sinfo->hashalgo)) {
rasprintf(&sinfo->msg,
_("%s tag %u: invalid hash algorithm"),
origin, td->tag);
goto exit;
}
sinfo->keyid = rpmhex(pgpDigParamsSignID(sinfo->sig), PGP_KEYID_LEN);
} else if (sinfo->type == RPMSIG_DIGEST_TYPE) {
if (td->type == RPM_BIN_TYPE) {
Expand Down
Loading