diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-06-28 07:31:18 -0700 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-07-03 23:38:26 +0000 |
commit | 3ad976896a983178fc42a0794f137983f528cde7 (patch) | |
tree | 14da052397719898848caadd0c77facbb416a0a6 /epan | |
parent | ba9aa3015f29f07bf81cdfebdfab54fdc379b94d (diff) |
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>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-dtls.c | 11 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl-utils.c | 38 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl-utils.h | 5 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl.c | 25 |
4 files changed, 47 insertions, 32 deletions
diff --git a/epan/dissectors/packet-dtls.c b/epan/dissectors/packet-dtls.c index cd9da7db20..d5182df09e 100644 --- a/epan/dissectors/packet-dtls.c +++ b/epan/dissectors/packet-dtls.c @@ -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", diff --git a/epan/dissectors/packet-ssl-utils.c b/epan/dissectors/packet-ssl-utils.c index a1fe2903e7..4cd7415e08 100644 --- a/epan/dissectors/packet-ssl-utils.c +++ b/epan/dissectors/packet-ssl-utils.c @@ -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); - - 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); + 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->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. */ diff --git a/epan/dissectors/packet-ssl-utils.h b/epan/dissectors/packet-ssl-utils.h index 722bfa5019..b62915de77 100644 --- a/epan/dissectors/packet-ssl-utils.h +++ b/epan/dissectors/packet-ssl-utils.h @@ -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 diff --git a/epan/dissectors/packet-ssl.c b/epan/dissectors/packet-ssl.c index 742f5673e1..25389627e3 100644 --- a/epan/dissectors/packet-ssl.c +++ b/epan/dissectors/packet-ssl.c @@ -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", |