ssl,dtls: split init/cleanup routines

Minor functional change: instead of an empty hash table, now the
ssl_session_hash and ssl_crandom_hash structures point will be set to
NULL when files are closed.

API change: drop the ssl_keylog_file parameter from ssl_common_init,
add a new ssl_common_cleanup parameter instead.

Change-Id: I65efe71f8347fe9685359f8ed70cfb9673712421
Reviewed-on: https://code.wireshark.org/review/9226
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Peter Wu 2015-06-28 07:31:18 -07:00 committed by Michael Mann
parent ba9aa3015f
commit 3ad976896a
4 changed files with 47 additions and 32 deletions

View File

@ -184,7 +184,7 @@ dtls_init(void)
module_t *dtls_module = prefs_find_module("dtls");
pref_t *keys_list_pref;
ssl_common_init(&dtls_master_key_map, &dtls_keylog_file,
ssl_common_init(&dtls_master_key_map,
&dtls_decrypted_data, &dtls_compressed_data);
reassembly_table_init (&dtls_reassembly_table, &addresses_ports_reassembly_table_functions);
@ -197,6 +197,14 @@ dtls_init(void)
}
}
static void
dtls_cleanup(void)
{
reassembly_table_destroy(&dtls_reassembly_table);
ssl_common_cleanup(&dtls_master_key_map, &dtls_keylog_file,
&dtls_decrypted_data, &dtls_compressed_data);
}
/* parse dtls related preferences (private keys and ports association strings) */
static void
dtls_parse_uat(void)
@ -1934,6 +1942,7 @@ proto_register_dtls(void)
dtls_associations = g_tree_new(ssl_association_cmp);
register_init_routine(dtls_init);
register_cleanup_routine(dtls_cleanup);
ssl_lib_init();
dtls_tap = register_tap("dtls");
ssl_debug_printf("proto_register_dtls: registered tap %s:%d\n",

View File

@ -4367,34 +4367,28 @@ ssl_get_data_info(int proto, packet_info *pinfo, gint key)
/* initialize/reset per capture state data (ssl sessions cache) */
void
ssl_common_init(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
ssl_common_init(ssl_master_key_map_t *mk_map,
StringInfo *decrypted_data, StringInfo *compressed_data)
{
if (mk_map->session)
g_hash_table_remove_all(mk_map->session);
else
mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
ssl_data_alloc(decrypted_data, 32);
ssl_data_alloc(compressed_data, 32);
}
if (mk_map->crandom)
g_hash_table_remove_all(mk_map->crandom);
else
mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
if (mk_map->pre_master)
g_hash_table_remove_all(mk_map->pre_master);
else
mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
if (mk_map->pms)
g_hash_table_remove_all(mk_map->pms);
else
mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
void
ssl_common_cleanup(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
StringInfo *decrypted_data, StringInfo *compressed_data)
{
g_hash_table_destroy(mk_map->session);
g_hash_table_destroy(mk_map->crandom);
g_hash_table_destroy(mk_map->pre_master);
g_hash_table_destroy(mk_map->pms);
g_free(decrypted_data->data);
ssl_data_alloc(decrypted_data, 32);
g_free(compressed_data->data);
ssl_data_alloc(compressed_data, 32);
/* close the previous keylog file now that the cache are cleared, this
* allows the cache to be filled with the full keylog file contents. */

View File

@ -601,8 +601,11 @@ ssl_get_data_info(int proto, packet_info *pinfo, gint key);
/* initialize/reset per capture state data (ssl sessions cache) */
extern void
ssl_common_init(ssl_master_key_map_t *master_key_map, FILE **ssl_keylog_file,
ssl_common_init(ssl_master_key_map_t *master_key_map,
StringInfo *decrypted_data, StringInfo *compressed_data);
extern void
ssl_common_cleanup(ssl_master_key_map_t *master_key_map, FILE **ssl_keylog_file,
StringInfo *decrypted_data, StringInfo *compressed_data);
/* tries to update the secrets cache from the given filename */
extern void

View File

@ -333,12 +333,6 @@ void proto_reg_handoff_ssl(void);
/* Desegmentation of SSL streams */
/* table to hold defragmented SSL streams */
static reassembly_table ssl_reassembly_table;
static void
ssl_fragment_init(void)
{
reassembly_table_init(&ssl_reassembly_table,
&addresses_ports_reassembly_table_functions);
}
/* initialize/reset per capture state data (ssl sessions cache) */
static void
@ -347,9 +341,10 @@ ssl_init(void)
module_t *ssl_module = prefs_find_module("ssl");
pref_t *keys_list_pref;
ssl_common_init(&ssl_master_key_map, &ssl_keylog_file,
ssl_common_init(&ssl_master_key_map,
&ssl_decrypted_data, &ssl_compressed_data);
ssl_fragment_init();
reassembly_table_init(&ssl_reassembly_table,
&addresses_ports_reassembly_table_functions);
ssl_debug_flush();
/* for "Export SSL Session Keys" */
@ -365,6 +360,19 @@ ssl_init(void)
}
}
static void
ssl_cleanup(void)
{
reassembly_table_destroy(&ssl_reassembly_table);
ssl_common_cleanup(&ssl_master_key_map, &ssl_keylog_file,
&ssl_decrypted_data, &ssl_compressed_data);
/* should not be needed since the UI code prevents this from being accessed
* when no file is open. Clear it anyway just to be sure. */
ssl_session_hash = NULL;
ssl_crandom_hash = NULL;
}
/* parse ssl related preferences (private keys and ports association strings) */
static void
ssl_parse_uat(void)
@ -4208,6 +4216,7 @@ proto_register_ssl(void)
ssl_associations = g_tree_new(ssl_association_cmp);
register_init_routine(ssl_init);
register_cleanup_routine(ssl_cleanup);
ssl_lib_init();
ssl_tap = register_tap("ssl");
ssl_debug_printf("proto_register_ssl: registered tap %s:%d\n",