Browse code

tls_wolfssl: add timestamp and sni info for a session

- ref: commit c0c1dcc100 for tls

S-P Chan authored on 19/08/2022 14:01:08
Showing 1 changed files
... ...
@@ -115,6 +115,9 @@ static void tls_list(rpc_t* rpc, void* c)
115 115
 	struct tls_extra_data* tls_d;
116 116
 	struct tcp_connection* con;
117 117
 	int i, len, timeout;
118
+	struct tm timestamp;
119
+	char timestamp_s[128];
120
+	const char* sni;
118 121
 
119 122
 	TCPCONN_LOCK;
120 123
 	for(i = 0; i < TCP_ID_HASH_SIZE; i++) {
... ...
@@ -132,8 +135,29 @@ static void tls_list(rpc_t* rpc, void* c)
132 135
 				BUG("failed to convert destination ip");
133 136
 			dst_ip[len] = 0;
134 137
 			timeout = TICKS_TO_S(con->timeout - get_ticks_raw());
135
-			rpc->struct_add(handle, "ddsdsd",
138
+			timestamp = *localtime(&con->timestamp);
139
+			if (snprintf(timestamp_s, 128, "%d-%02d-%02d %02d:%02d:%02d", timestamp.tm_year + 1900,
140
+					timestamp.tm_mon + 1, timestamp.tm_mday, timestamp.tm_hour,
141
+					timestamp.tm_min, timestamp.tm_sec) < 0) {
142
+				timestamp_s[0] = 'N';
143
+				timestamp_s[1] = '/';
144
+				timestamp_s[2] = 'A';
145
+				timestamp_s[3] = '\0';
146
+			}
147
+
148
+			if (tls_d) {
149
+				sni = wolfSSL_get_servername(tls_d->ssl, TLSEXT_NAMETYPE_host_name);
150
+				if (sni == NULL) {
151
+					sni = "N/A";
152
+				}
153
+			} else {
154
+				sni = "N/A";
155
+			}
156
+
157
+			rpc->struct_add(handle, "dssdsdsd",
136 158
 					"id", con->id,
159
+					"sni", sni,
160
+					"timestamp", timestamp_s,
137 161
 					"timeout", timeout,
138 162
 					"src_ip", src_ip,
139 163
 					"src_port", con->rcv.src_port,