check that there are no extra bytes in the checksum and that the
parameters are NULL or the NULL-type. All to avoid having excess data that can be used to fake the signature. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18031 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -130,7 +130,7 @@ rsa_verify_signature(const struct signature_alg *sig_alg,
|
|||||||
const SubjectPublicKeyInfo *spi;
|
const SubjectPublicKeyInfo *spi;
|
||||||
DigestInfo di;
|
DigestInfo di;
|
||||||
unsigned char *to;
|
unsigned char *to;
|
||||||
int tosize;
|
int tosize, retsize;
|
||||||
int ret;
|
int ret;
|
||||||
RSA *rsa;
|
RSA *rsa;
|
||||||
RSAPublicKey pk;
|
RSAPublicKey pk;
|
||||||
@@ -167,21 +167,27 @@ rsa_verify_signature(const struct signature_alg *sig_alg,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = RSA_public_decrypt(sig->length, (unsigned char *)sig->data,
|
retsize = RSA_public_decrypt(sig->length, (unsigned char *)sig->data,
|
||||||
to, rsa, RSA_PKCS1_PADDING);
|
to, rsa, RSA_PKCS1_PADDING);
|
||||||
if (ret == -1) {
|
if (retsize == -1) {
|
||||||
ret = HX509_CRYPTO_SIG_INVALID_FORMAT;
|
ret = HX509_CRYPTO_SIG_INVALID_FORMAT;
|
||||||
free(to);
|
free(to);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (ret > tosize)
|
if (retsize > tosize)
|
||||||
_hx509_abort("internal rsa decryption failure: ret > tosize");
|
_hx509_abort("internal rsa decryption failure: ret > tosize");
|
||||||
ret = decode_DigestInfo(to, ret, &di, &size);
|
ret = decode_DigestInfo(to, retsize, &di, &size);
|
||||||
free(to);
|
free(to);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for extra data inside the sigature */
|
||||||
|
if (size != retsize) {
|
||||||
|
ret = HX509_CRYPTO_SIG_INVALID_FORMAT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (sig_alg->digest_oid &&
|
if (sig_alg->digest_oid &&
|
||||||
heim_oid_cmp(&di.digestAlgorithm.algorithm,
|
heim_oid_cmp(&di.digestAlgorithm.algorithm,
|
||||||
(*sig_alg->digest_oid)()) != 0)
|
(*sig_alg->digest_oid)()) != 0)
|
||||||
@@ -190,6 +196,15 @@ rsa_verify_signature(const struct signature_alg *sig_alg,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* verify that the parameters are NULL or the NULL-type */
|
||||||
|
if (di.digestAlgorithm.parameters != NULL &&
|
||||||
|
(di.digestAlgorithm.parameters->length != 2 ||
|
||||||
|
memcmp(di.digestAlgorithm.parameters->data, "\x05\x00", 2) != 0))
|
||||||
|
{
|
||||||
|
ret = HX509_CRYPTO_SIG_INVALID_FORMAT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
ret = _hx509_verify_signature(NULL,
|
ret = _hx509_verify_signature(NULL,
|
||||||
&di.digestAlgorithm,
|
&di.digestAlgorithm,
|
||||||
data,
|
data,
|
||||||
|
Reference in New Issue
Block a user