mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
[9.18] fix: usr: Fix rndc-confgen aborting on HMAC-SHA-384/512 keys above 512 bits
`rndc-confgen -A hmac-sha384` and `-A hmac-sha512` documented a `-b` range of 1..1024, but any value above 512 aborted on hardened builds instead of producing a key. The full advertised range now works. Closes #5903 Backport of MR !11903 Merge branch 'backport-5903-hmac-generate-stack-overflow-9.18' into 'bind-9.18' See merge request isc-projects/bind9!11911
This commit is contained in:
commit
739e79592d
3 changed files with 51 additions and 2 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#include <isc/base64.h>
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/file.h>
|
||||
#include <isc/md.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
|
|
@ -97,7 +98,7 @@ generate_key(isc_mem_t *mctx, dns_secalg_t alg, int keysize,
|
|||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_buffer_t key_rawbuffer;
|
||||
isc_region_t key_rawregion;
|
||||
char key_rawsecret[64];
|
||||
char key_rawsecret[ISC_MAX_BLOCK_SIZE];
|
||||
dst_key_t *key = NULL;
|
||||
|
||||
switch (alg) {
|
||||
|
|
|
|||
48
bin/tests/system/rndc_confgen/tests_rndc_confgen.py
Normal file
48
bin/tests/system/rndc_confgen/tests_rndc_confgen.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
import base64
|
||||
import os
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
import isctest
|
||||
|
||||
|
||||
def _extract_secret(stdout: bytes) -> bytes:
|
||||
match = re.search(rb'secret\s+"([^"]+)"', stdout)
|
||||
assert match is not None, f"no secret in output: {stdout!r}"
|
||||
return base64.b64decode(match.group(1))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"algorithm,bits",
|
||||
[
|
||||
("hmac-sha256", 1),
|
||||
("hmac-sha256", 256),
|
||||
("hmac-sha256", 512),
|
||||
("hmac-sha384", 1),
|
||||
("hmac-sha384", 384),
|
||||
("hmac-sha384", 513),
|
||||
("hmac-sha384", 768),
|
||||
("hmac-sha384", 1024),
|
||||
("hmac-sha512", 1),
|
||||
("hmac-sha512", 512),
|
||||
("hmac-sha512", 513),
|
||||
("hmac-sha512", 1024),
|
||||
],
|
||||
)
|
||||
def test_rndc_confgen_hmac_keysize(algorithm, bits):
|
||||
cmd = isctest.run.cmd([os.environ["RNDCCONFGEN"], "-A", algorithm, "-b", str(bits)])
|
||||
secret = _extract_secret(cmd.proc.stdout)
|
||||
assert len(secret) == (bits + 7) // 8
|
||||
assert f"algorithm {algorithm};".encode() in cmd.proc.stdout
|
||||
|
|
@ -280,7 +280,7 @@ hmac_generate(const isc_md_type_t *type, dst_key_t *key) {
|
|||
isc_buffer_t b;
|
||||
isc_result_t ret;
|
||||
unsigned int bytes, len;
|
||||
unsigned char data[ISC_MAX_MD_SIZE] = { 0 };
|
||||
unsigned char data[ISC_MAX_BLOCK_SIZE] = { 0 };
|
||||
|
||||
len = isc_md_type_get_block_size(type);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue