mirror of
https://github.com/nmap/nmap.git
synced 2025-12-19 22:19:02 +00:00
Correct conversion of DH key size to RSA bit strength equivalent
This commit is contained in:
@@ -654,7 +654,7 @@ local cipher_info_cache = {
|
|||||||
local function unpack_dhparams (blob, pos)
|
local function unpack_dhparams (blob, pos)
|
||||||
local p, g, y
|
local p, g, y
|
||||||
pos, p, g, y = bin.unpack(">PPP", blob)
|
pos, p, g, y = bin.unpack(">PPP", blob)
|
||||||
return pos, {p=p, g=g, y=y}, rsa_equiv("dh", #p)
|
return pos, {p=p, g=g, y=y}, #p
|
||||||
end
|
end
|
||||||
|
|
||||||
local function unpack_ecdhparams (blob, pos)
|
local function unpack_ecdhparams (blob, pos)
|
||||||
@@ -665,7 +665,7 @@ local function unpack_ecdhparams (blob, pos)
|
|||||||
if eccurvetype == 1 then
|
if eccurvetype == 1 then
|
||||||
local p, a, b, base, order, cofactor
|
local p, a, b, base, order, cofactor
|
||||||
pos, p, a, b, base, order, cofactor = bin.unpack("pppppp", blob, pos)
|
pos, p, a, b, base, order, cofactor = bin.unpack("pppppp", blob, pos)
|
||||||
strength = rsa_equiv("ec", #p)
|
strength = #p
|
||||||
ret.curve_params = {
|
ret.curve_params = {
|
||||||
ec_curve_type = "explicit_prime",
|
ec_curve_type = "explicit_prime",
|
||||||
prime_p=p, curve={a=a, b=b}, base=base, order=order, cofactor=cofactor
|
prime_p=p, curve={a=a, b=b}, base=base, order=order, cofactor=cofactor
|
||||||
@@ -674,7 +674,7 @@ local function unpack_ecdhparams (blob, pos)
|
|||||||
local p = {}
|
local p = {}
|
||||||
local m, basis
|
local m, basis
|
||||||
pos, m, basis = bin.unpack(">SC", blob, pos)
|
pos, m, basis = bin.unpack(">SC", blob, pos)
|
||||||
strength = rsa_equiv("ec", m)
|
strength = m
|
||||||
if basis == 1 then -- ec_trinomial
|
if basis == 1 then -- ec_trinomial
|
||||||
pos, p.k = bin.unpack("p", blob, pos)
|
pos, p.k = bin.unpack("p", blob, pos)
|
||||||
elseif basis == 2 then -- ec_pentanomial
|
elseif basis == 2 then -- ec_pentanomial
|
||||||
@@ -695,7 +695,7 @@ local function unpack_ecdhparams (blob, pos)
|
|||||||
}
|
}
|
||||||
local size = ret.curve_params.curve:match("(%d+)[rk]%d$")
|
local size = ret.curve_params.curve:match("(%d+)[rk]%d$")
|
||||||
if size then
|
if size then
|
||||||
strength = rsa_equiv("ec", tonumber(size))
|
strength = tonumber(size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pos, ret.public = bin.unpack("p", blob, pos)
|
pos, ret.public = bin.unpack("p", blob, pos)
|
||||||
@@ -723,9 +723,9 @@ end
|
|||||||
-- @param bits Size of key in bits
|
-- @param bits Size of key in bits
|
||||||
-- @return Size in bits of RSA key with equivalent strength
|
-- @return Size in bits of RSA key with equivalent strength
|
||||||
function rsa_equiv (ktype, bits)
|
function rsa_equiv (ktype, bits)
|
||||||
if ktype == "rsa" or ktype == "dsa" or ktype == "dh" then
|
if ktype == "rsa" or ktype == "dsa" then
|
||||||
return bits
|
return bits
|
||||||
elseif ktype == "ec" then
|
elseif ktype == "ec" or ktype == "dh" then
|
||||||
if bits < 160 then
|
if bits < 160 then
|
||||||
return 512 -- Possibly down to 0, but details not published
|
return 512 -- Possibly down to 0, but details not published
|
||||||
elseif bits < 224 then
|
elseif bits < 224 then
|
||||||
@@ -765,7 +765,7 @@ KEX_ALGORITHMS.DH_anon_EXPORT = {
|
|||||||
}
|
}
|
||||||
KEX_ALGORITHMS.ECDH_anon = {
|
KEX_ALGORITHMS.ECDH_anon = {
|
||||||
anon=true,
|
anon=true,
|
||||||
type = "ecdh",
|
type = "ec",
|
||||||
server_key_exchange = function (blob, protocol)
|
server_key_exchange = function (blob, protocol)
|
||||||
local pos
|
local pos
|
||||||
local ret = {}
|
local ret = {}
|
||||||
@@ -776,7 +776,7 @@ KEX_ALGORITHMS.ECDH_anon = {
|
|||||||
KEX_ALGORITHMS.ECDH_anon_EXPORT = {
|
KEX_ALGORITHMS.ECDH_anon_EXPORT = {
|
||||||
anon=true,
|
anon=true,
|
||||||
export=true,
|
export=true,
|
||||||
type = "ecdh",
|
type = "ec",
|
||||||
server_key_exchange = KEX_ALGORITHMS.ECDH_anon.server_key_exchange
|
server_key_exchange = KEX_ALGORITHMS.ECDH_anon.server_key_exchange
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -846,7 +846,7 @@ KEX_ALGORITHMS.DH_RSA_EXPORT={
|
|||||||
|
|
||||||
KEX_ALGORITHMS.ECDHE_RSA={
|
KEX_ALGORITHMS.ECDHE_RSA={
|
||||||
pubkey="rsa",
|
pubkey="rsa",
|
||||||
type = "ecdh",
|
type = "dh",
|
||||||
server_key_exchange = function (blob, protocol)
|
server_key_exchange = function (blob, protocol)
|
||||||
local pos
|
local pos
|
||||||
local ret = {}
|
local ret = {}
|
||||||
@@ -857,7 +857,7 @@ KEX_ALGORITHMS.ECDHE_RSA={
|
|||||||
}
|
}
|
||||||
KEX_ALGORITHMS.ECDHE_ECDSA={
|
KEX_ALGORITHMS.ECDHE_ECDSA={
|
||||||
pubkey="ec",
|
pubkey="ec",
|
||||||
type = "ecdh",
|
type = "dh",
|
||||||
server_key_exchange = KEX_ALGORITHMS.ECDHE_RSA.server_key_exchange
|
server_key_exchange = KEX_ALGORITHMS.ECDHE_RSA.server_key_exchange
|
||||||
}
|
}
|
||||||
KEX_ALGORITHMS.ECDH_ECDSA={
|
KEX_ALGORITHMS.ECDH_ECDSA={
|
||||||
@@ -913,7 +913,7 @@ KEX_ALGORITHMS.PSK_DHE = KEX_ALGORITHMS.DHE_PSK
|
|||||||
|
|
||||||
--rfc5489
|
--rfc5489
|
||||||
KEX_ALGORITHMS.ECDHE_PSK={
|
KEX_ALGORITHMS.ECDHE_PSK={
|
||||||
type = "ecdh",
|
type = "dh",
|
||||||
server_key_exchange = function (blob, protocol)
|
server_key_exchange = function (blob, protocol)
|
||||||
local pos
|
local pos
|
||||||
local ret = {}
|
local ret = {}
|
||||||
|
|||||||
@@ -518,11 +518,12 @@ local function find_ciphers_group(host, port, protocol, group, scores)
|
|||||||
if kex.server_key_exchange and ske then
|
if kex.server_key_exchange and ske then
|
||||||
local kex_info = kex.server_key_exchange(ske.data)
|
local kex_info = kex.server_key_exchange(ske.data)
|
||||||
if kex_info.strength then
|
if kex_info.strength then
|
||||||
if kex_strength and kex_strength > kex_info.strength then
|
local rsa_bits = tls.rsa_equiv(kex.type, kex_info.strength)
|
||||||
kex_strength = kex_info.strength
|
if kex_strength and kex_strength > rsa_bits then
|
||||||
|
kex_strength = rsa_bits
|
||||||
scores.warnings["Key exchange parameters of lower strength than certificate key"] = true
|
scores.warnings["Key exchange parameters of lower strength than certificate key"] = true
|
||||||
end
|
end
|
||||||
kex_strength = kex_strength or kex_info.strength
|
kex_strength = kex_strength or rsa_bits
|
||||||
extra = string.format("%s %d", kex.type, kex_info.strength)
|
extra = string.format("%s %d", kex.type, kex_info.strength)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user