# HG changeset patch
# User Kai Engert <kaie@kuix.de>
# Date 1411493325 -7200
# Node ID 4e90910ad2f9741978820ec2314b12a504d78c4e
# Parent ad411fb64046d987272043f311ca477022c6fef4
Fix bug 1064636, patch part 3, r=rrelyea
diff --git a/lib/softoken/pkcs11c.c b/lib/softoken/pkcs11c.c
--- a/lib/softoken/pkcs11c.c
+++ b/lib/softoken/pkcs11c.c
@@ -18,16 +18,17 @@
* that created or generated them.
*/
#include "seccomon.h"
#include "secitem.h"
#include "secport.h"
#include "blapi.h"
#include "pkcs11.h"
#include "pkcs11i.h"
+#include "pkcs1sig.h"
#include "lowkeyi.h"
#include "secder.h"
#include "secdig.h"
#include "lowpbe.h" /* We do PBE below */
#include "pkcs11t.h"
#include "secoid.h"
#include "alghmac.h"
#include "softoken.h"
@@ -2851,75 +2852,52 @@ sftk_hashCheckSign(SFTKHashVerifyInfo *i
return SECFailure;
}
return RSA_HashCheckSign(info->hashOid, info->key, sig, sigLen, digest,
digestLen);
}
SECStatus
-RSA_HashCheckSign(SECOidTag hashOid, NSSLOWKEYPublicKey *key,
+RSA_HashCheckSign(SECOidTag digestOid, NSSLOWKEYPublicKey *key,
const unsigned char *sig, unsigned int sigLen,
- const unsigned char *hash, unsigned int hashLen)
+ const unsigned char *digestData, unsigned int digestLen)
{
- SECItem it;
- SGNDigestInfo *di = NULL;
- SECStatus rv = SECSuccess;
-
- it.data = NULL;
- it.len = nsslowkey_PublicModulusLen(key);
- if (!it.len) {
- goto loser;
- }
-
- it.data = (unsigned char *)PORT_Alloc(it.len);
- if (it.data == NULL) {
- goto loser;
- }
-
+ unsigned char *pkcs1DigestInfoData;
+ SECItem pkcs1DigestInfo;
+ SECItem digest;
+ unsigned int bufferSize;
+ SECStatus rv;
+
+ /* pkcs1DigestInfo.data must be less than key->u.rsa.modulus.len */
+ bufferSize = key->u.rsa.modulus.len;
+ pkcs1DigestInfoData = PORT_ZAlloc(bufferSize);
+ if (!pkcs1DigestInfoData) {
+ PORT_SetError(SEC_ERROR_NO_MEMORY);
+ return SECFailure;
+ }
+
+ pkcs1DigestInfo.data = pkcs1DigestInfoData;
+ pkcs1DigestInfo.len = bufferSize;
+
/* decrypt the block */
- rv = RSA_CheckSignRecover(&key->u.rsa, it.data, &it.len, it.len, sig,
- sigLen);
+ rv = RSA_CheckSignRecover(&key->u.rsa, pkcs1DigestInfo.data,
+ &pkcs1DigestInfo.len, pkcs1DigestInfo.len,
+ sig, sigLen);
if (rv != SECSuccess) {
- goto loser;
- }
-
- di = SGN_DecodeDigestInfo(&it);
- if (di == NULL) {
- goto loser;
- }
- if (di->digest.len != hashLen) {
- goto loser;
- }
-
- /* make sure the tag is OK */
- if (SECOID_GetAlgorithmTag(&di->digestAlgorithm) != hashOid) {
- goto loser;
- }
- /* make sure the "parameters" are not too bogus. */
- if (di->digestAlgorithm.parameters.len > 2) {
- goto loser;
- }
- /* Now check the signature */
- if (PORT_Memcmp(hash, di->digest.data, di->digest.len) == 0) {
- goto done;
- }
-
- loser:
- PORT_SetError(SEC_ERROR_BAD_SIGNATURE);
- rv = SECFailure;
-
- done:
- if (it.data != NULL) {
- PORT_Free(it.data);
- }
- if (di != NULL) {
- SGN_DestroyDigestInfo(di);
- }
-
+ PORT_SetError(SEC_ERROR_BAD_SIGNATURE);
+ } else {
+ digest.data = (PRUint8*) digestData;
+ digest.len = digestLen;
+ rv = _SGN_VerifyPKCS1DigestInfo(
+ digestOid, &digest, &pkcs1DigestInfo,
+ PR_TRUE /*XXX: unsafeAllowMissingParameters*/);
+ }
+
+ PORT_Free(pkcs1DigestInfoData);
return rv;
}
static SECStatus
sftk_RSACheckSign(NSSLOWKEYPublicKey *key, const unsigned char *sig,
unsigned int sigLen, const unsigned char *digest,
unsigned int digestLen)
{