为了便于调试, 将 ssl service cache 的 hash key 都转化成 16 进制格式,并增加 debug 日志

This commit is contained in:
lwp
2019-08-16 14:51:43 +08:00
committed by luwenpeng
parent 1f7a32f7f5
commit f589f0e433

View File

@@ -318,18 +318,32 @@ static long app_st_write_cb(void * data, const uchar * key, uint size, void * us
int ssl_service_cache_read(struct ssl_service_cache* svc_cache, const struct ssl_chello* chello, const struct tfe_stream_addr * addr, struct ssl_service_status* result)
{
long cli_st_cb_ret=0, svr_st_cb_ret=0, app_st_cb_ret=0;
char hash_key[2048];
char temp_key[2048];
unsigned char hash_key[4096]; // Size must be twice the size of temp_key
size_t temp_key_sz=0;
size_t hash_key_sz=0;
if(chello->sni==NULL)
{
return 0;
}
hash_key_sz=ssl_svc_client_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->cli_st_hash, (unsigned char*) hash_key, (unsigned int) hash_key_sz, cli_st_read_cb, result, &cli_st_cb_ret);
hash_key_sz=ssl_svc_server_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->srv_st_hash, (unsigned char*) hash_key, (unsigned int) hash_key_sz, srv_st_read_cb, result, &svr_st_cb_ret);
hash_key_sz=ssl_svc_app_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->app_st_hash, (unsigned char*) hash_key, (unsigned int) hash_key_sz, app_st_read_cb, result, &app_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_client_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc read client table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->cli_st_hash, hash_key, (unsigned int) hash_key_sz, cli_st_read_cb, result, &cli_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_server_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc read server table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->srv_st_hash, hash_key, (unsigned int) hash_key_sz, srv_st_read_cb, result, &svr_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_app_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc read app table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->app_st_hash, hash_key, (unsigned int) hash_key_sz, app_st_read_cb, result, &app_st_cb_ret);
if(cli_st_cb_ret||svr_st_cb_ret||app_st_cb_ret)
{
@@ -344,7 +358,9 @@ int ssl_service_cache_read(struct ssl_service_cache* svc_cache, const struct ssl
void ssl_service_cache_write(struct ssl_service_cache* svc_cache, const struct ssl_chello* chello, const struct tfe_stream_addr * addr, const struct ssl_service_status* status)
{
long cli_st_cb_ret=0, svr_st_cb_ret=0;
char hash_key[2048];
char temp_key[2048];
unsigned char hash_key[4096]; // Size must be twice the size of temp_key
size_t temp_key_sz=0;
size_t hash_key_sz=0;
if(chello == NULL || chello->sni==NULL)
@@ -354,18 +370,27 @@ void ssl_service_cache_write(struct ssl_service_cache* svc_cache, const struct s
struct ssl_service_write_args write_args={svc_cache, status};
if(status->is_mutual_auth||status->cli_pinning_status!=PINNING_ST_NOT_PINNING||status->has_protocol_errors)
{
hash_key_sz=ssl_svc_client_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->cli_st_hash, (unsigned char*)hash_key, (unsigned int) hash_key_sz, cli_st_write_cb, &write_args, &cli_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_client_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc write client table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->cli_st_hash, hash_key, (unsigned int) hash_key_sz, cli_st_write_cb, &write_args, &cli_st_cb_ret);
}
if(status->is_ct||status->is_ev)
{
hash_key_sz=ssl_svc_server_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->srv_st_hash, (unsigned char*)hash_key, (unsigned int) hash_key_sz, srv_st_write_cb, &write_args, &svr_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_server_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc write server table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->srv_st_hash, hash_key, (unsigned int) hash_key_sz, srv_st_write_cb, &write_args, &svr_st_cb_ret);
}
if(status->is_app_not_pinning)
{
hash_key_sz=ssl_svc_app_st_mk_key(chello, addr, hash_key, sizeof(hash_key));
MESA_htable_search_cb(svc_cache->app_st_hash, (unsigned char*)hash_key, (unsigned int) hash_key_sz, app_st_write_cb, &write_args, &svr_st_cb_ret);
memset(hash_key, 0, sizeof(hash_key));
temp_key_sz = ssl_svc_app_st_mk_key(chello, addr, temp_key, sizeof(temp_key));
hash_key_sz = tfe_hexdump(hash_key, (unsigned char *)temp_key, temp_key_sz) - hash_key;
TFE_LOG_DEBUG(g_default_logger, "ssl svc write app table, hash:%s, ori_len:%lu hash_len:%lu\n", hash_key, temp_key_sz, hash_key_sz);
MESA_htable_search_cb(svc_cache->app_st_hash, hash_key, (unsigned int) hash_key_sz, app_st_write_cb, &write_args, &svr_st_cb_ret);
}
}
struct ssl_service_cache* ssl_service_cache_create(unsigned int slot_size, unsigned int expire_seconds, int fail_as_pinning_cnt, int fail_as_proto_err_cnt, int fail_time_win)