Bug 1642687 - land NSS 2bd2f3267dc5 UPGRADE_NSS_RELEASE, r=jcj

2020-06-22  Kevin Jacobs  <kjacobs@mozilla.com>

	* lib/util/quickder.c:
	Bug 1646520 - Stricter leading-zero checks for ASN.1 INTEGER values.
	r=jcj

	This patch adjusts QuickDER to strictly enforce INTEGER encoding
	with respect to leading zeros:
	- If the MSB of the first (value) octet is set, a single zero byte MAY
	be present to make the value positive. This singular pad byte is
	removed.
	- Otherwise, the first octet must not be zero.

	[2bd2f3267dc5] [tip]

Differential Revision: https://phabricator.services.mozilla.com/D80543
This commit is contained in:
Kevin Jacobs 2020-06-22 22:24:10 +00:00
Родитель 7fb8c3b457
Коммит 34be3870be
3 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -1 +1 @@
699541a7793b
2bd2f3267dc5

Просмотреть файл

@ -10,3 +10,4 @@
*/
#error "Do not include this header file."

Просмотреть файл

@ -742,15 +742,18 @@ DecodeItem(void* dest,
switch (tagnum) {
/* special cases of primitive types */
case SEC_ASN1_INTEGER: {
/* remove leading zeroes if the caller requested
siUnsignedInteger
This is to allow RSA key operations to work */
SECItem* destItem = (SECItem*)((char*)dest +
templateEntry->offset);
if (destItem && (siUnsignedInteger == destItem->type)) {
while (temp.len > 1 && temp.data[0] == 0) { /* leading 0 */
/* A leading 0 is only allowed when a value
* would otherwise be interpreted as negative. */
if (temp.len > 1 && temp.data[0] == 0) {
temp.data++;
temp.len--;
if (!(temp.data[0] & 0x80)) {
PORT_SetError(SEC_ERROR_BAD_DER);
rv = SECFailure;
}
}
}
break;