mirror of
https://github.com/nmap/nmap.git
synced 2025-12-25 00:49:01 +00:00
Return RSA exponent from parsed SSL certificates, as a bignum
This commit is contained in:
@@ -128,6 +128,7 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/ssl.h>
|
||||
@@ -146,6 +147,12 @@ struct cert_userdata {
|
||||
int attributes_table;
|
||||
};
|
||||
|
||||
/* from nse_openssl.cc */
|
||||
typedef struct bignum_data {
|
||||
BIGNUM * bn;
|
||||
} bignum_data_t;
|
||||
|
||||
|
||||
SSL *nse_nsock_get_ssl(lua_State *L);
|
||||
|
||||
/* This is a reference to a table that will be used as the metatable for
|
||||
@@ -546,6 +553,14 @@ static int parse_ssl_cert(lua_State *L, X509 *cert)
|
||||
if (pkey_type == EVP_PKEY_EC) {
|
||||
lua_push_ecdhparams(L, pubkey);
|
||||
}
|
||||
else if (pkey_type == EVP_PKEY_RSA) {
|
||||
RSA *rsa = EVP_PKEY_get1_RSA(pubkey);
|
||||
bignum_data_t * data = (bignum_data_t *) lua_newuserdata( L, sizeof(bignum_data_t));
|
||||
luaL_getmetatable( L, "BIGNUM" );
|
||||
lua_setmetatable( L, -2 );
|
||||
data->bn = rsa->e;
|
||||
lua_setfield(L, -2, "exponent");
|
||||
}
|
||||
lua_pushstring(L, pkey_type_to_string(pkey_type));
|
||||
lua_setfield(L, -2, "type");
|
||||
lua_pushnumber(L, EVP_PKEY_bits(pubkey));
|
||||
|
||||
@@ -732,6 +732,12 @@ function pcap_close()
|
||||
-- pem = "-----BEGIN CERTIFICATE-----\nMIIFxzCCBK+gAwIBAgIQX02QuADDB7CVj..."
|
||||
-- </code>
|
||||
--
|
||||
-- If the <code>pubkey</code> is type <code>"rsa"</code>, it will also have an
|
||||
-- <code>exponent</code> member, containing the public exponent as a bignum. If
|
||||
-- the type is <code>"ec"</code>, it will have an <code>ecdhparams</code>
|
||||
-- member, containing a table with <code>ec_curve_type</code> and
|
||||
-- <code>curve</code> keys as strings.
|
||||
--
|
||||
-- It also has the following member functions:
|
||||
--
|
||||
-- * <code>digest(algorithm)</code> returns the digest of the certificate using the given digest algorithm, which is any of the strings returned by <code>openssl.supported_digests</code>, typically something like <code>"md5"</code> or <code>"sha1"</code>.
|
||||
|
||||
Reference in New Issue
Block a user