Index: nse_ssl_cert.cc =================================================================== --- nse_ssl_cert.cc (revision 35207) +++ nse_ssl_cert.cc (working copy) @@ -426,6 +426,48 @@ } } +void lua_push_ecdhparams(lua_State *L, EVP_PKEY *pubkey) { + EC_KEY *ec_key = EVP_PKEY_get1_EC_KEY(pubkey); + const EC_GROUP *group = EC_KEY_get0_group(ec_key); + int nid; + if ((nid = EC_GROUP_get_curve_name(group)) != 0) { + lua_newtable(L); + lua_newtable(L); + lua_pushstring(L, OBJ_nid2sn(nid)); + lua_setfield(L, -2, "curve"); + lua_pushstring(L, "namedcurve"); + lua_setfield(L, -2, "ec_curve_type"); + lua_setfield(L, -2, "curve_params"); + lua_setfield(L, -2, "ecdhparams"); + } + else { + /* According to RFC 5480 section 2.1.1, explicit curves must not be used with + X.509. This may change in the future, but for now it doesn't seem worth it + to add in code to extract the extra parameters. */ + nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); + if (nid == NID_X9_62_prime_field) { + lua_newtable(L); + lua_newtable(L); + lua_pushstring(L, "explicit_prime"); + lua_setfield(L, -2, "ec_curve_type"); + lua_setfield(L, -2, "curve_params"); + lua_setfield(L, -2, "ecdhparams"); + } + else if (nid == NID_X9_62_characteristic_two_field) { + lua_newtable(L); + lua_newtable(L); + lua_pushstring(L, "explicit_char2"); + lua_setfield(L, -2, "ec_curve_type"); + lua_setfield(L, -2, "curve_params"); + lua_setfield(L, -2, "ecdhparams"); + } + else { + /* Something wierd happened. */ + } + } + EC_KEY_free(ec_key); +} + static int parse_ssl_cert(lua_State *L, X509 *cert); int l_parse_ssl_certificate(lua_State *L) @@ -467,6 +509,7 @@ struct cert_userdata *udata; X509_NAME *subject, *issuer; EVP_PKEY *pubkey; + int pkey_type; udata = (struct cert_userdata *) lua_newuserdata(L, sizeof(*udata)); udata->cert = cert; @@ -497,6 +540,10 @@ pubkey = X509_get_pubkey(cert); lua_newtable(L); + pkey_type = EVP_PKEY_type(pubkey->type); + if (pkey_type == EVP_PKEY_EC) { + lua_push_ecdhparams(L, pubkey); + } lua_pushstring(L, pkey_type_to_string(pubkey->type)); lua_setfield(L, -2, "type"); lua_pushnumber(L, EVP_PKEY_bits(pubkey)); Index: scripts/ssl-enum-ciphers.nse =================================================================== --- scripts/ssl-enum-ciphers.nse (revision 35207) +++ scripts/ssl-enum-ciphers.nse (working copy) @@ -526,7 +526,15 @@ scores.warnings["Weak certificate signature: SHA1"] = true end kex_strength = tls.rsa_equiv(kex.pubkey, c.pubkey.bits) - extra = string.format("%s %d", kex.pubkey, c.pubkey.bits) + if c.pubkey.ecdhparams then + if c.pubkey.ecdhparams.curve_params.ec_curve_type == "namedcurve" then + extra = c.pubkey.ecdhparams.curve_params.curve + else + extra = string.format("%s %d", c.pubkey.ecdhparams.curve_params.ec_curve_type, c.pubkey.bits) + end + else + extra = string.format("%s %d", kex.pubkey, c.pubkey.bits) + end end end end @@ -540,7 +548,15 @@ scores.warnings["Key exchange parameters of lower strength than certificate key"] = true end kex_strength = kex_strength or rsa_bits - extra = string.format("%s %d", kex.type, kex_info.strength) + if kex_info.ecdhparams then + if kex_info.ecdhparams.curve_params.ec_curve_type == "namedcurve" then + extra = kex_info.ecdhparams.curve_params.curve + else + extra = string.format("%s %d", kex_info.ecdhparams.curve_params.ec_curve_type, kex_info.strength) + end + else + extra = string.format("%s %d", kex.type, kex_info.strength) + end end end end