Index: net/third_party/nss/ssl/sslplatf.c |
=================================================================== |
--- net/third_party/nss/ssl/sslplatf.c (revision 202696) |
+++ net/third_party/nss/ssl/sslplatf.c (working copy) |
@@ -212,9 +212,8 @@ |
DWORD dwFlags = 0; |
VOID *pPaddingInfo = NULL; |
- /* Always encode using PKCS#1 block type, with no OID/encoded DigestInfo */ |
+ /* Always encode using PKCS#1 block type. */ |
BCRYPT_PKCS1_PADDING_INFO rsaPaddingInfo; |
- rsaPaddingInfo.pszAlgId = NULL; |
if (key->dwKeySpec != CERT_NCRYPT_KEY_SPEC) { |
PR_SetError(SEC_ERROR_LIBRARY_FAILURE, 0); |
@@ -227,8 +226,29 @@ |
switch (keyType) { |
case rsaKey: |
- hashItem.data = hash->md5; |
- hashItem.len = sizeof(SSL3Hashes); |
+ switch (hash->hashAlg) { |
+ case SEC_OID_UNKNOWN: |
+ /* No OID/encoded DigestInfo. */ |
+ rsaPaddingInfo.pszAlgId = NULL; |
+ break; |
+ case SEC_OID_SHA1: |
+ rsaPaddingInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM; |
+ break; |
+ case SEC_OID_SHA256: |
+ rsaPaddingInfo.pszAlgId = BCRYPT_SHA256_ALGORITHM; |
+ break; |
+ case SEC_OID_SHA384: |
+ rsaPaddingInfo.pszAlgId = BCRYPT_SHA384_ALGORITHM; |
+ break; |
+ case SEC_OID_SHA512: |
+ rsaPaddingInfo.pszAlgId = BCRYPT_SHA512_ALGORITHM; |
+ break; |
+ default: |
+ PORT_SetError(SSL_ERROR_UNSUPPORTED_HASH_ALGORITHM); |
+ return SECFailure; |
+ } |
+ hashItem.data = hash->u.raw; |
+ hashItem.len = hash->len; |
dwFlags = BCRYPT_PAD_PKCS1; |
pPaddingInfo = &rsaPaddingInfo; |
break; |
@@ -239,8 +259,13 @@ |
} else { |
doDerEncode = isTLS; |
} |
- hashItem.data = hash->sha; |
- hashItem.len = sizeof(hash->sha); |
+ if (hash->hashAlg == SEC_OID_UNKNOWN) { |
+ hashItem.data = hash->u.s.sha; |
+ hashItem.len = sizeof(hash->u.s.sha); |
+ } else { |
+ hashItem.data = hash->u.raw; |
+ hashItem.len = hash->len; |
+ } |
break; |
default: |
PORT_SetError(SEC_ERROR_INVALID_KEY); |
@@ -315,11 +340,34 @@ |
buf->data = NULL; |
+ switch (hash->hashAlg) { |
+ case SEC_OID_UNKNOWN: |
+ hashAlg = 0; |
+ break; |
+ case SEC_OID_SHA1: |
+ hashAlg = CALG_SHA1; |
+ break; |
+ case SEC_OID_SHA256: |
+ hashAlg = CALG_SHA_256; |
+ break; |
+ case SEC_OID_SHA384: |
+ hashAlg = CALG_SHA_384; |
+ break; |
+ case SEC_OID_SHA512: |
+ hashAlg = CALG_SHA_512; |
+ break; |
+ default: |
+ PORT_SetError(SSL_ERROR_UNSUPPORTED_HASH_ALGORITHM); |
+ return SECFailure; |
+ } |
+ |
switch (keyType) { |
case rsaKey: |
- hashAlg = CALG_SSL3_SHAMD5; |
- hashItem.data = hash->md5; |
- hashItem.len = sizeof(SSL3Hashes); |
+ if (hashAlg == 0) { |
+ hashAlg = CALG_SSL3_SHAMD5; |
+ } |
+ hashItem.data = hash->u.raw; |
+ hashItem.len = hash->len; |
break; |
case dsaKey: |
case ecKey: |
@@ -328,9 +376,14 @@ |
} else { |
doDerEncode = isTLS; |
} |
- hashAlg = CALG_SHA1; |
- hashItem.data = hash->sha; |
- hashItem.len = sizeof(hash->sha); |
+ if (hashAlg == 0) { |
+ hashAlg = CALG_SHA1; |
+ hashItem.data = hash->u.s.sha; |
+ hashItem.len = sizeof(hash->u.s.sha); |
+ } else { |
+ hashItem.data = hash->u.raw; |
+ hashItem.len = hash->len; |
+ } |
break; |
default: |
PORT_SetError(SEC_ERROR_INVALID_KEY); |
@@ -468,11 +521,36 @@ |
goto done; /* error code was set. */ |
sigAlg = cssmKey->KeyHeader.AlgorithmId; |
+ if (keyType == rsaKey) { |
+ PORT_Assert(sigAlg == CSSM_ALGID_RSA); |
+ switch (hash->hashAlg) { |
+ case SEC_OID_UNKNOWN: |
+ break; |
+ case SEC_OID_SHA1: |
+ sigAlg = CSSM_ALGID_SHA1WithRSA; |
+ break; |
+ case SEC_OID_SHA224: |
+ sigAlg = CSSM_ALGID_SHA224WithRSA; |
+ break; |
+ case SEC_OID_SHA256: |
+ sigAlg = CSSM_ALGID_SHA256WithRSA; |
+ break; |
+ case SEC_OID_SHA384: |
+ sigAlg = CSSM_ALGID_SHA384WithRSA; |
+ break; |
+ case SEC_OID_SHA512: |
+ sigAlg = CSSM_ALGID_SHA512WithRSA; |
+ break; |
+ default: |
+ PORT_SetError(SSL_ERROR_UNSUPPORTED_HASH_ALGORITHM); |
+ goto done; |
+ } |
+ } |
+ |
switch (keyType) { |
case rsaKey: |
- PORT_Assert(sigAlg == CSSM_ALGID_RSA); |
- hashData.Data = hash->md5; |
- hashData.Length = sizeof(SSL3Hashes); |
+ hashData.Data = hash->u.raw; |
+ hashData.Length = hash->len; |
break; |
case dsaKey: |
case ecKey: |
@@ -483,8 +561,13 @@ |
PORT_Assert(sigAlg == CSSM_ALGID_DSA); |
doDerEncode = isTLS; |
} |
- hashData.Data = hash->sha; |
- hashData.Length = sizeof(hash->sha); |
+ if (hash->hashAlg == SEC_OID_UNKNOWN) { |
+ hashData.Data = hash->u.s.sha; |
+ hashData.Length = sizeof(hash->u.s.sha); |
+ } else { |
+ hashData.Data = hash->u.raw; |
+ hashData.Length = hash->len; |
+ } |
break; |
default: |
PORT_SetError(SEC_ERROR_INVALID_KEY); |