{"id":365414,"date":"2024-05-21T02:37:36","date_gmt":"2024-05-21T02:37:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=365414"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=365414","title":{"rendered":"<span>TLS Client Hello \u2014 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438 \u043f\u0430\u0440\u0441\u0438\u043c \u2014 Nginx + Lua \/ Go<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0430 \u0434\u043d\u044f\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u043a\u0430 &#8212; \u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0443 \u0441\u0430\u0439\u0442\u0430 <a href=\"https:\/\/www.howsmyssl.com\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.howsmyssl.com\/<\/u><\/a> \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435 \u0441\u043f\u0438\u0441\u043e\u043a Cipher Suites \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438 TLS Handshake \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0432 \u0441\u0432\u043e\u0435\u043c Client hello.<\/p>\n<p>\u0410 \u0437\u0430\u043e\u0434\u043d\u043e \u043e\u0431\u0434\u0443\u043c\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 &#8212; Proxy-Connection.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0438\u043c\u0435\u044e \u0434\u0435\u043b\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 Nginx, \u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0433\u043e \u0441\u0431\u043e\u0440\u043a\u0430 Openresty \u0441 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u043c LuaJIT \u0434\u043b\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 Lua.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e\u0435 \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 TLS Handshake.<br \/>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0445\u0435\u043d\u0434\u0448\u0435\u0439\u043a\u0430 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/p>\n<p>\u041d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u043e Session ID \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f Session ID \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ngx.var.ssl_session_id<\/code><\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0438 \u043f\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0443\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0447\u0435\u0440\u0435\u0437 Tshark \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u043d\u0430 Python:<br \/><code>tshark -i eth0 -Y 'ssl.handshake.type == 1 or ssl.handshake.type == 2 ' -l -V | python3 tcpparse.py<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u0435\u043b.<br \/>\u0412\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u043c \u0438 \u0441\u0435\u0432\u0435\u0440\u043d\u044b\u043c \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e Acknowledgment number \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d Sequence Number \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430. \u0418\u0437 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0431\u0440\u0430\u0442\u044c Session ID \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c. <\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0430 \u043d\u0435\u043a\u0438\u0439 \u0437\u0430\u0434\u0435\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c tshark, \u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c stream \u0432 Nginx:  <\/p>\n<pre><code class=\"nginx\">stream {     server {         listen 443;         content_by_lua_file \"\/lua\/simpleproxy.lua\";     }  }<\/code><\/pre>\n<pre><code class=\"lua\">local function proxy_data(client_sock, server_sock)     local ok1, err = ngx.thread.spawn(read_from_socket_client, client_sock, server_sock)     if not ok1 then         ngx.log(ngx.ERR, \"failed to spawn read_from_socket_client thread: \", err)         return     end     local ok2, err = ngx.thread.spawn(read_from_socket_server, server_sock, client_sock)     if not ok2 then         ngx.log(ngx.ERR, \"failed to spawn read_from_socket_server thread: \", err)         return     end     ngx.thread.wait(ok1, ok2) end  local function proxy_handler_stream()     local client_sock, err = ngx.req.socket(true)     if not client_sock then         ngx.log(ngx.ERR, \"failed to get client socket: \", err)         return ngx.exit(ngx.ERROR)     end     local server_sock = ngx.socket.tcp()     local ok, err = server_sock:connect(\"127.0.0.1\", 8443)     if not ok then         ngx.log(ngx.ERR, \"failed to connect to the server: \", err)         return ngx.exit(ngx.ERROR)     end     proxy_data(client_sock, server_sock) end  proxy_handler_stream()<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f proxy_handler_stream \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0435\u043a\u0435\u043d\u0434\u043e\u043c, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 proxy_data, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c &#171;Light threads&#187; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0432 Lua<\/p>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e, \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>read_from_socket_client<\/code> \u0438 <code>read_from_socket_server<\/code>:<\/p>\n<pre><code class=\"lua\">local function read_from_socket_client(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end  local function read_from_socket_server(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0431\u0443\u0431\u043d\u044b \u0441 \u0442\u0430\u043d\u0446\u0430\u043c\u0438.<br \/>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c <code>read_from_socket_client<\/code> \u0438 <code>read_from_socket_server<\/code>. \u0418\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u043a\u0435\u0442\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0431\u0430\u0439\u0442 (\u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e &#8212; \u044f \u043d\u0435 \u043f\u043e\u043c\u043d\u044e \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u0438, \u0441\u043e\u0440\u0440\u0438). 6 \u0431\u0430\u0439\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 (01 &#8212; \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 hello, 02 &#8212; \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442), \u0434\u0430\u043b\u0435\u0435 &#8212; 3 \u0431\u0430\u0439\u0442\u0430 \u0434\u043b\u0438\u043d\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u043a\u0443:<\/p>\n<pre><code class=\"lua\">local accumulated_data_client = \"\" local accumulated_data_server = \"\" local counter_client = -5 local counter_client_stop = 4096 local counter_server = -5 local counter_server_stop = 4096  local function read_from_socket_client(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             counter_client = counter_client + 1             if counter_client > 0 and counter_client &lt;= counter_client_stop then                 accumulated_data_client = accumulated_data_client .. data                 if counter_client == 4 then                     local last_three_bytes = accumulated_data_client:sub(2, 4)                     local result = 0                     for i = 1, #last_three_bytes do                         result = result * 256 + last_three_bytes:byte(i)                     end                     counter_client_stop = result + 4                 end             end             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end  local function read_from_socket_server(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             counter_server = counter_server + 1             if counter_server > 0 and counter_server &lt;= counter_server_stop then                 accumulated_data_server = accumulated_data_server .. data                 if counter_server == 4 then                     local last_three_bytes = accumulated_data_server:sub(2, 4)                     local result = 0                     for i = 1, #last_three_bytes do                         result = result * 256 + last_three_bytes:byte(i)                     end                     counter_server_stop = result + 4                 end             end             if counter_server == counter_server_stop then                 infoFromHandshake(accumulated_data_client, accumulated_data_server)             end             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 <code>counter_server<\/code> \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>infoFromHandshake<\/code>. \u041e\u043d\u0430 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e.\u00a0<\/p>\n<p>\u0425\u043e\u0442\u044f \u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f SessionID \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e Cipher Suites \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u0418 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u0437 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 cryptobyte, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Go.\u00a0<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430\u043c\u0435\u0441\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0439\u043f \u043d\u0430\u0448\u0435\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 Go, \u043e\u0442\u0432\u0435\u0442 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432 Redis \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043c Lua \u0432 \u043f\u043e\u043a\u043e\u0435:<\/p>\n<pre><code class=\"lua\">local function infoFromHandshake(data_client, data_server)      local timestamp = os.time()     local randomPart = math.random(10000, 99999)     local tempInputClientFileName = string.format(\"\/tmp\/hs_client_input_%d_%d.txt\", timestamp, randomPart)     local tempInputServerFileName = string.format(\"\/tmp\/hs_server_input_%d_%d.txt\", timestamp, randomPart)      local tempInputClientFile = io.open(tempInputClientFileName, \"w\")     tempInputClientFile:write(data_client)     tempInputClientFile:close()      local tempInputServerFile = io.open(tempInputServerFileName, \"w\")     tempInputServerFile:write(data_server)     tempInputServerFile:close()      local go_program_client = assert(io.popen(\"\/ciphersuites\/clienthello &lt; \" .. tempInputClientFileName, \"r\"))     local clienthello = assert(go_program_client:read(\"*a\"))     go_program_client:close()     os.remove(tempInputClientFileName)      local go_program_server = assert(io.popen(\"\/ciphersuites\/clienthello &lt; \" .. tempInputServerFileName, \"r\"))     local sessionid = assert(go_program_server:read(\"*a\"))     go_program_server:close()     os.remove(tempInputServerFileName)      if sessionid and clienthello then         setRedisKeys(sessionid, clienthello)     else         return     end  end<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044e <code>setRedisKeys<\/code> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443, \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0434\u043e \u0431\u0435\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u044f.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0430 Go \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u0439\u043f\u0430, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u0443 \u0442\u0438\u043f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"go\">package main  import ( \"bytes\" \"encoding\/json\" \"fmt\" \"io\" \"os\" )  func main() { var buf bytes.Buffer _, err := io.Copy(&amp;buf, os.Stdin) if err != nil { fmt.Fprintln(os.Stderr, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438:\", err) return } data := buf.Bytes() if len(data) &lt; 1 { fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\") return } switch data[0] { case 0x01: ClientDecode(data) case 0x02: ServerDecode(data) default: fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\") } }  func ClientDecode(data []byte) { clientInfo := UnmarshalClientHello(data) clientInfoJson, err := json.Marshal(clientInfo) if err != nil { fmt.Println(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 JSON:\", err) return } fmt.Printf(string(clientInfoJson)) } func ServerDecode(data []byte) { server_info := UnmarshalServerResponse(data) serverSessionID := server_info.SessionIDHex fmt.Printf(string(serverSessionID)) }<\/code><\/pre>\n<p>\u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u043a\u043e\u0434\u0430 \u043d\u0430 Go \u0434\u043b\u044f \u0434\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0438 \u0432\u0437\u044f\u0442\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f: <a href=\"https:\/\/www.agwa.name\/blog\/post\/parsing_tls_client_hello_with_cryptobyte\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.agwa.name\/blog\/post\/parsing_tls_client_hello_with_cryptobyte<\/u><\/a><\/p>\n<pre><code class=\"go\">package main import ( \"bytes\" \"encoding\/json\"     \"encoding\/hex\"     \"crypto\/cryptobyte\"   \"fmt\" \"io\" \"os\" ) func main() { var buf bytes.Buffer _, err := io.Copy(&amp;buf, os.Stdin) if err != nil { fmt.Fprintln(os.Stderr, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438:\", err) return } data := buf.Bytes() if len(data) &lt; 1 { fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\") return } switch data[0] { case 0x01: ClientDecode(data) case 0x02: ServerDecode(data) default: fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\") } } func ClientDecode(data []byte) { clientInfo := UnmarshalClientHello(data) clientInfoJson, err := json.Marshal(clientInfo) if err != nil { fmt.Println(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 JSON:\", err) return } fmt.Printf(string(clientInfoJson)) } func ServerDecode(data []byte) { server_info := UnmarshalServerResponse(data) serverSessionID := server_info.SessionIDHex fmt.Printf(string(serverSessionID)) }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f <code>ServerHelloInfo<\/code> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e SessionID \/ SessionIDHex, \u0430 <code>ClientHelloInfo<\/code> \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c, \u043d\u043e \u043a\u0430\u043a \u0437\u0430\u0434\u0435\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442. <br \/>\u041c\u0430\u0441\u0441\u0438\u0432 CipherSuites \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 MakeCipherSuite \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u043e\u043c csv \u0438\u0437 <code>https:\/\/www.iana.org\/assignments\/tls-parameters\/tls-parameters-4.csv<\/code>, \u043f\u0440\u0438\u043c\u0435\u0440 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 &#171;Parsing a TLS Client Hello with Go&#8217;s cryptobyte Package&#187;. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043f\u043e\u0434 \u043c\u043e\u0438 \u043d\u0443\u0436\u0434\u044b:<\/p>\n<pre><code class=\"go\">type ProtocolVersion uint16  func (v ProtocolVersion) Hi() uint8 { return uint8(v >> 8) }  func (v ProtocolVersion) Lo() uint8 { return uint8(v) }  func (v ProtocolVersion) MarshalJSON() ([]byte, error) { return json.Marshal([2]uint8{v.Hi(), v.Lo()}) }  type CompressionMethod uint8  func (m CompressionMethod) MarshalJSON() ([]byte, error) { return json.Marshal(uint16(m)) }  type CipherSuite struct { Code   [2]uint8 `json:\"code\"` Name   string   `json:\"name,omitempty\"` Grease bool     `json:\"grease,omitempty\"` }  func (c CipherSuite) CodeUint16() uint16 { return (uint16(c.Code[0]) &lt;&lt; 8) | uint16(c.Code[1]) }  func MakeCipherSuite(code uint16) CipherSuite { hi := uint8(code >> 8) lo := uint8(code)  return CipherSuite{ Code:   [2]uint8{hi, lo}, Name:   CipherSuites[code].Name, Grease: CipherSuites[code].Grease, } }  type ClientHelloInfo struct { Raw []byte `json:\"raw\"`  Version            ProtocolVersion     `json:\"version\"` Random             []byte              `json:\"random\"` SessionID          []byte              `json:\"session_id\"` CipherSuites       []CipherSuite       `json:\"cipher_suites\"` CompressionMethods []CompressionMethod `json:\"compression_methods\"` Extensions         []Extension         `json:\"extensions\"`  Info struct { ServerName     *string  `json:\"server_name\"` SCTs           bool     `json:\"scts\"` Protocols      []string `json:\"protocols\"` JA3String      string   `json:\"ja3_string\"` JA3Fingerprint string   `json:\"ja3_fingerprint\"` } `json:\"info\"` }  type ServerHelloInfo struct { Raw []byte `json:\"raw\"`  Version           ProtocolVersion   `json:\"version\"` Random            []byte            `json:\"random\"` SessionID         []byte            `json:\"session_id_string\"` SessionIDHex      string            `json:\"session_id\"` CipherSuite       CipherSuite       `json:\"cipher_suite\"` CompressionMethod CompressionMethod `json:\"compression_method\"` Extensions        []Extension       `json:\"extensions\"`  Info struct { SelectedProtocol *string `json:\"selected_protocol\"` SCTs             bool    `json:\"scts\"` } `json:\"info\"` }<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0440\u0430\u0437\u0431\u043e\u0440 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432:<\/p>\n<pre><code class=\"go\">func UnmarshalClientHello(handshakeBytes []byte) *ClientHelloInfo { info := &amp;ClientHelloInfo{Raw: handshakeBytes} handshakeMessage := cryptobyte.String(handshakeBytes)  var messageType uint8 if !handshakeMessage.ReadUint8(&amp;messageType) || messageType != 1 { return nil } var clientHello cryptobyte.String if !handshakeMessage.ReadUint24LengthPrefixed(&amp;clientHello) || !handshakeMessage.Empty() { return nil }  if !clientHello.ReadUint16((*uint16)(&amp;info.Version)) { return nil }  if !clientHello.ReadBytes(&amp;info.Random, 32) { return nil }  if !clientHello.ReadUint8LengthPrefixed((*cryptobyte.String)(&amp;info.SessionID)) { return nil }  var cipherSuites cryptobyte.String if !clientHello.ReadUint16LengthPrefixed(&amp;cipherSuites) { return nil } info.CipherSuites = []CipherSuite{} for !cipherSuites.Empty() { var suite uint16 if !cipherSuites.ReadUint16(&amp;suite) { return nil } info.CipherSuites = append(info.CipherSuites, MakeCipherSuite(suite)) }   if !clientHello.Empty() { return nil }  return info }  func UnmarshalServerResponse(handshakeBytes []byte) *ServerHelloInfo { info := &amp;ServerHelloInfo{Raw: handshakeBytes} handshakeMessage := cryptobyte.String(handshakeBytes)  var messageType uint8 if !handshakeMessage.ReadUint8(&amp;messageType) || messageType != 2 { return nil }  \/\/ \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (3 \u0431\u0430\u0439\u0442\u0430) if !handshakeMessage.Skip(3) { return nil }  \/\/ \u0427\u0442\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 (2 \u0431\u0430\u0439\u0442\u0430) if !handshakeMessage.Skip(2) { \/\/ \u0432\u0435\u0440\u0441\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f return nil }  \/\/ \u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 (32 \u0431\u0430\u0439\u0442\u0430) if !handshakeMessage.Skip(32) { return nil }  var sessionIDBytes cryptobyte.String if !handshakeMessage.ReadUint8LengthPrefixed(&amp;sessionIDBytes) { return nil } info.SessionIDHex = hex.EncodeToString(sessionIDBytes)  return info }<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u0440\u043a\u0430\u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0430\u0439\u043f\u0430 \u0431\u0430\u0439\u0442\u043e\u0432 \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 <code>clientInfoJson<\/code> \u0438 <code>serverSessionID<\/code><\/p>\n<p>\u0412 Nginx \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c:<br \/><code>ssl_session_cache   none;<\/code> <code>ssl_session_tickets off;<\/code> <code>keepalive_timeout 0;<br \/><\/code>\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0442\u0438\u043a\u0435\u0442\u043e\u0432 \u0432 \u0441\u0435\u0441\u0441\u0438\u044f\u0445 ssl \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0441 curl \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0430 \u0432\u043e\u0442 \u0441\u043a\u0430\u0436\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 Chrome \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u0447\u0438\u0442\u0441\u044f \u0437\u0430 favicon \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Session ID \u043c\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u043c.<br \/>\u0414\u0430\u043b\u0435\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430\u044f \u043c\u0430\u043b\u043e\u0441\u0442\u044c &#8212; \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Redis: \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u043b\u043e\u043a\u0435\u0439\u0448\u043d \u043d\u0430\u0448\u0435\u0433\u043e http server \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e ssl \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c <code>content_by_lua_block<\/code> \u0438\u043b\u0438 <code>content_by_lua_file<\/code> \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"lua\">local function getclientinfo()     local redis_key = ngx.var.ssl_session_id     local clientinfo     local redis_err     local ok, red = pcall(redis.connect, { host = redis_local_server, port = redis_local_port, timeout = redis_local_connect_timeout })     if not ok then         redis_err = true     end     if not redis_err then         local res, err = red:get(redis_key)         if err then         elseif not res then         else             clientinfo = res         end     end      local jsonData = json.decode(clientinfo)     ngx.header.content_type = 'application\/json; charset=utf-8'     ngx.say(jsonData)     ngx.exit(200)  end  getclientinfo()<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043b\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>ngx.say(jsonData.cipher_suites)<\/code><\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043e\u0442 \u0438 \u0432\u0441\u0435. \u041f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u0438. \u041a\u043e\u0434 \u043f\u0438\u0441\u0430\u043b\u0441\u044f \u043d\u0430 \u0441\u043a\u043e\u0440\u0443\u044e \u0440\u0443\u043a\u0443 \u0438 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u043d\u0438\u0438 &#8212; \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u044d\u0441\u043a\u0438\u0437\u043d\u043e\u0435. \u041d\u043e \u043f\u0440\u0438 \u0440\u0435\u0441\u0435\u0440\u0447\u0435 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u0442\u044c\u0438 Andrew Ayer, \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043c\u0430\u043b\u043e \u0445\u043e\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \/ \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f. <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/786670\/\"> https:\/\/habr.com\/ru\/articles\/786670\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0430 \u0434\u043d\u044f\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u043a\u0430 &#8212; \u043f\u043e \u043e\u0431\u0440\u0430\u0437\u0443 \u0441\u0430\u0439\u0442\u0430 <a href=\"https:\/\/www.howsmyssl.com\/\" rel=\"noopener noreferrer nofollow\"><u>https:\/\/www.howsmyssl.com\/<\/u><\/a> \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435 \u0441\u043f\u0438\u0441\u043e\u043a Cipher Suites \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438 TLS Handshake \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0432 \u0441\u0432\u043e\u0435\u043c Client hello.<\/p>\n<p>\u0410 \u0437\u0430\u043e\u0434\u043d\u043e \u043e\u0431\u0434\u0443\u043c\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 &#8212; Proxy-Connection.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0438\u043c\u0435\u044e \u0434\u0435\u043b\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 Nginx, \u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0433\u043e \u0441\u0431\u043e\u0440\u043a\u0430 Openresty \u0441 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u043c LuaJIT \u0434\u043b\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 Lua.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e\u0435 \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0435 TLS Handshake.<br \/>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0445\u0435\u043d\u0434\u0448\u0435\u0439\u043a\u0430 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/p>\n<p>\u041d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0442\u043e Session ID \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f Session ID \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ngx.var.ssl_session_id<\/code><\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0438 \u043f\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u043f\u0443\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0447\u0435\u0440\u0435\u0437 Tshark \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u043d\u0430 Python:<br \/><code>tshark -i eth0 -Y 'ssl.handshake.type == 1 or ssl.handshake.type == 2 ' -l -V | python3 tcpparse.py<\/code><\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 Python \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u0435\u043b.<br \/>\u0412\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u043c \u0438 \u0441\u0435\u0432\u0435\u0440\u043d\u044b\u043c \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e Acknowledgment number \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d Sequence Number \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430. \u0418\u0437 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0431\u0440\u0430\u0442\u044c Session ID \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c. <\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0430 \u043d\u0435\u043a\u0438\u0439 \u0437\u0430\u0434\u0435\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c tshark, \u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c stream \u0432 Nginx:  <\/p>\n<pre><code class=\"nginx\">stream {     server {         listen 443;         content_by_lua_file \"\/lua\/simpleproxy.lua\";     }  }<\/code><\/pre>\n<pre><code class=\"lua\">local function proxy_data(client_sock, server_sock)     local ok1, err = ngx.thread.spawn(read_from_socket_client, client_sock, server_sock)     if not ok1 then         ngx.log(ngx.ERR, \"failed to spawn read_from_socket_client thread: \", err)         return     end     local ok2, err = ngx.thread.spawn(read_from_socket_server, server_sock, client_sock)     if not ok2 then         ngx.log(ngx.ERR, \"failed to spawn read_from_socket_server thread: \", err)         return     end     ngx.thread.wait(ok1, ok2) end  local function proxy_handler_stream()     local client_sock, err = ngx.req.socket(true)     if not client_sock then         ngx.log(ngx.ERR, \"failed to get client socket: \", err)         return ngx.exit(ngx.ERROR)     end     local server_sock = ngx.socket.tcp()     local ok, err = server_sock:connect(\"127.0.0.1\", 8443)     if not ok then         ngx.log(ngx.ERR, \"failed to connect to the server: \", err)         return ngx.exit(ngx.ERROR)     end     proxy_data(client_sock, server_sock) end  proxy_handler_stream()<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f proxy_handler_stream \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0435\u043a\u0435\u043d\u0434\u043e\u043c, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 proxy_data, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c &#171;Light threads&#187; \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0432 Lua<\/p>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e, \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>read_from_socket_client<\/code> \u0438 <code>read_from_socket_server<\/code>:<\/p>\n<pre><code class=\"lua\">local function read_from_socket_client(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end  local function read_from_socket_server(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0447\u043d\u0435\u043c \u0431\u0443\u0431\u043d\u044b \u0441 \u0442\u0430\u043d\u0446\u0430\u043c\u0438.<br \/>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c <code>read_from_socket_client<\/code> \u0438 <code>read_from_socket_server<\/code>. \u0418\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u043a\u0435\u0442\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u0431\u0430\u0439\u0442 (\u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e &#8212; \u044f \u043d\u0435 \u043f\u043e\u043c\u043d\u044e \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u0438, \u0441\u043e\u0440\u0440\u0438). 6 \u0431\u0430\u0439\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 (01 &#8212; \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 hello, 02 &#8212; \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442), \u0434\u0430\u043b\u0435\u0435 &#8212; 3 \u0431\u0430\u0439\u0442\u0430 \u0434\u043b\u0438\u043d\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u043a\u0443:<\/p>\n<pre><code class=\"lua\">local accumulated_data_client = \"\" local accumulated_data_server = \"\" local counter_client = -5 local counter_client_stop = 4096 local counter_server = -5 local counter_server_stop = 4096  local function read_from_socket_client(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             counter_client = counter_client + 1             if counter_client > 0 and counter_client &lt;= counter_client_stop then                 accumulated_data_client = accumulated_data_client .. data                 if counter_client == 4 then                     local last_three_bytes = accumulated_data_client:sub(2, 4)                     local result = 0                     for i = 1, #last_three_bytes do                         result = result * 256 + last_three_bytes:byte(i)                     end                     counter_client_stop = result + 4                 end             end             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end  local function read_from_socket_server(from_sock, to_sock)     from_sock:settimeout(0)     to_sock:settimeout(0)     while true do         local data, err, partial = from_sock:receive(\"1\")         if not data and err == \"closed\" then             break         end         data = data or partial         if data and #data > 0 then             counter_server = counter_server + 1             if counter_server > 0 and counter_server &lt;= counter_server_stop then                 accumulated_data_server = accumulated_data_server .. data                 if counter_server == 4 then                     local last_three_bytes = accumulated_data_server:sub(2, 4)                     local result = 0                     for i = 1, #last_three_bytes do                         result = result * 256 + last_three_bytes:byte(i)                     end                     counter_server_stop = result + 4                 end             end             if counter_server == counter_server_stop then                 infoFromHandshake(accumulated_data_client, accumulated_data_server)             end             local bytes, send_err = to_sock:send(data)             if not bytes then                 return false, \"failed to send data: \" .. send_err             end         end     end end<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 <code>counter_server<\/code> \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>infoFromHandshake<\/code>. \u041e\u043d\u0430 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e.\u00a0<\/p>\n<p>\u0425\u043e\u0442\u044f \u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f SessionID \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e Cipher Suites \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u0418 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u0437 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u043d\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 cryptobyte, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Go.\u00a0<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430\u043c\u0435\u0441\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0439\u043f \u043d\u0430\u0448\u0435\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 Go, \u043e\u0442\u0432\u0435\u0442 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432 Redis \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043c Lua \u0432 \u043f\u043e\u043a\u043e\u0435:<\/p>\n<pre><code class=\"lua\">local function infoFromHandshake(data_client, data_server)      local timestamp = os.time()     local randomPart = math.random(10000, 99999)     local tempInputClientFileName = string.format(\"\/tmp\/hs_client_input_%d_%d.txt\", timestamp, randomPart)     local tempInputServerFileName = string.format(\"\/tmp\/hs_server_input_%d_%d.txt\", timestamp, randomPart)      local tempInputClientFile = io.open(tempInputClientFileName, \"w\")     tempInputClientFile:write(data_client)     tempInputClientFile:close()      local tempInputServerFile = io.open(tempInputServerFileName, \"w\")     tempInputServerFile:write(data_server)     tempInputServerFile:close()      local go_program_client = assert(io.popen(\"\/ciphersuites\/clienthello &lt; \" .. tempInputClientFileName, \"r\"))     local clienthello = assert(go_program_client:read(\"*a\"))     go_program_client:close()     os.remove(tempInputClientFileName)      local go_program_server = assert(io.popen(\"\/ciphersuites\/clienthello &lt; \" .. tempInputServerFileName, \"r\"))     local sessionid = assert(go_program_server:read(\"*a\"))     go_program_server:close()     os.remove(tempInputServerFileName)      if sessionid and clienthello then         setRedisKeys(sessionid, clienthello)     else         return     end  end<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044e <code>setRedisKeys<\/code> \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443, \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0434\u043e \u0431\u0435\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u044f.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0430 Go \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u0439\u043f\u0430, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u0443 \u0442\u0438\u043f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"go\">package main  import ( \"bytes\" \"encoding\/json\" \"fmt\" \"io\" \"os\" )  func main() { var buf bytes.Buffer _, err := io.Copy(&amp;buf, os.Stdin) if err != nil { fmt.Fprintln(os.Stderr, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438:\", err) return } data := buf.Bytes() if len(data) &lt; 1 { fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\") return } switch data[0] { case 0x01: ClientDecode(data) case 0x02: ServerDecode(data) default: fmt.Fprintln(os.Stderr, \"\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\") } }  func ClientDecode(data []byte) { clientInfo := UnmarshalClientHello(data) clientInfoJson, err := json.Marshal(clientInfo) if err != nil { fmt.Println(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 JSON:\", err) return } fmt.Printf(string(clientInfoJson)) } func ServerDecode(data []byte) {<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-365414","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/365414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=365414"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/365414\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=365414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=365414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=365414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}