-
Notifications
You must be signed in to change notification settings - Fork 205
Add scipts to monitor nginx ssl session ticket keys and session ticket r... #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
3eb5acd
bba6a34
3ffd8e8
76600fd
4a1b448
3878abd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ Table of Contents | |
* [ngx-orig-resp-body-len](#ngx-orig-resp-body-len) | ||
* [zlib-deflate-chunk-size](#zlib-deflate-chunk-size) | ||
* [lj-str-tab](#lj-str-tab) | ||
* [ngx-ssl-session-ticket-keys](#ngx-ssl-session-ticket-keys) | ||
* [ngx-ssl-session-ticket-resumption-stats](#ngx-ssl-session-ticket-resumption-stats) | ||
* [Installation](#installation) | ||
* [Author](#author) | ||
* [Copyright and License](#copyright-and-license) | ||
|
@@ -1453,7 +1455,67 @@ value |-------------------------------------------------- count | |
lj-str-tab | ||
---------- | ||
|
||
Analayzing the structure and various statistics of the global Lua string hash table in the LuaJIT v2.1 VM. | ||
Analyzing the structure and various statistics of the global Lua string hash table in the LuaJIT v2.1 VM. | ||
|
||
[Back to TOC](#table-of-contents) | ||
|
||
ngx-ssl-session-ticket-keys | ||
---------- | ||
|
||
Dumping ssl session ticket keys of a nginx worker. It will exit on the first | ||
time it captures the ticket keys. It can be utilized as a cron job to monitor if | ||
session ticket rotation actually happends. | ||
|
||
```bash | ||
# making the ./stap++ tool visible in PATH: | ||
$ export PATH=$PWD:$PATH | ||
|
||
# assuming one nginx worker process has the pid 3781. | ||
$ ./samples/ngx-ssl-session-ticket-keys.sxx -x 3781 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you add some sample outputs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, please add sample outputs here in its docs and also some brief explanation if not too obvious. |
||
Tracing process 3781 (/etc/nginx/sbin/nginx). | ||
Exit on first capture. Or hit Ctrl-C to end. | ||
keys len 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "keys len" looks confusing, how about "Number of keys" or "Key count"? |
||
enc key: | ||
key name: 5589398e87a104dd30691fbc3c8446c6 | ||
dec key: | ||
key name: f14c1d6611ad4802eccf6332f3b356f5 | ||
dec key: | ||
key name: b9cb4fb269a4148cc7c19c71d9e8554d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still no indentation in the output? It's hard to look ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, still miss that. |
||
``` | ||
|
||
[Back to TOC](#table-of-contents) | ||
|
||
ngx-ssl-session-ticket-resumption-stats | ||
---------- | ||
|
||
Analyzing the statistics of nginx SSL/TLS session ticket resumption. | ||
It counts the total number of session ticket encryption/decryption events | ||
Then it calculates the ratio of session ticket resumption attempts versus | ||
session ticket eligible connections and the ratio of successful session ticket | ||
resumption versus total number of session ticket resumption attemtps. Finally, | ||
it calculates the session ticket resumption rate as the product of the above | ||
two ratio. | ||
|
||
Here is an example on monitoring session ticket resumption statistics | ||
on a local nginx instance for 30 seconds. | ||
|
||
```bash | ||
# making the ./stap++ tool visible in PATH: | ||
$ export PATH=$PWD:$PATH | ||
|
||
# assuming one nginx worker process has the pid 3781. | ||
$ ./samples/ngx-ssl-session-ticket-resumption-stats.sxx -x 3781 --arg time=30 | ||
Tracing process 3781 (/etc/nginx/sbin/nginx). | ||
Pleasese wait for 30 seconds... | ||
Stop tracing NGX OPENSSL ticket key callback | ||
Total sessions: 11 | ||
Total session tickets: 10 | ||
Total resumed session ticket: 10 | ||
Total re-encrypted session ticket: 0 | ||
Session ticket resumption attempts ratio: 90 percent | ||
Session ticket resumption success ratio: 100 percent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
Total session ticket resumption rate: 90 percent | ||
``` | ||
|
||
[Back to TOC](#table-of-contents) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env stap++ | ||
|
||
# Capture ssl session tickets. | ||
|
||
@use nginx.array | ||
@use openssl | ||
|
||
probe begin { | ||
printf("Tracing process %d ($^exec_path).\nExit on first capture. Or hit Ctrl-C to end.\n", target()) | ||
} | ||
|
||
// print 16-byte key name | ||
function print_key_name(name) { | ||
printf("key name: "); | ||
$*n := @cast(name, "unsigned char", "$^exec_path") | ||
for (i=0; i<16; i++) { | ||
printf("%02x", $*n[i]) | ||
} | ||
printf("\n") | ||
} | ||
|
||
// print session ticket content | ||
function print_session_ticket_key(key) { | ||
$*k := @cast(key, "ngx_ssl_session_ticket_key_t", "$^exec_path") | ||
print_key_name($*k->name) | ||
// could be extended to print out other cipher states | ||
} | ||
|
||
probe @pfunc(ngx_ssl_session_ticket_key_callback).return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use this probe. This C function is seldom or never called in production. Alas. |
||
keys_index = @var("ngx_ssl_session_ticket_keys_index@src/event/ngx_event_openssl.c") | ||
num = get_ssl_ex_data_len($ssl_conn->ctx) | ||
if (keys_index > num) { | ||
printf("Error: ticket key list is not supported") | ||
|
||
} else { | ||
keys = get_ssl_ex_data_item($ssl_conn->ctx, keys_index) | ||
keys_len = get_ngx_array_len(keys) | ||
if (keys_len <= 0) { | ||
printf("Error: empty key list") | ||
|
||
} else { | ||
key_ptr = get_ngx_array_elts(keys) | ||
printf("keys len %d\n", keys_len) | ||
for (i=0; i<keys_len; i++) { | ||
key = &@cast(key_ptr, "ngx_ssl_session_ticket_key_t", | ||
"$^exec_path")[i] | ||
if (i == 0) { | ||
printf("enc key:\n") | ||
} else { | ||
printf("dec key:\n") | ||
} | ||
print_session_ticket_key(key) | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this tool should exit here as soon as it dumps the first key set. Thoughts? |
||
exit() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env stap++ | ||
|
||
# Capture ssl session resumption statistics. | ||
|
||
global total | ||
global tickets | ||
global resumed | ||
global reencrypted | ||
|
||
probe begin { | ||
printf("Tracing process %d ($^exec_path).\n", target()) | ||
%( "$^arg_time :default()" != "" %? | ||
printf("Please wait for $^arg_time seconds...\n") | ||
%: | ||
printf("Hit Ctrl-C to end.\n") | ||
%) | ||
} | ||
|
||
probe @pfunc(ngx_ssl_session_ticket_key_callback).return { | ||
total++; | ||
# record client session ticket decryption calls | ||
if ($enc == 0) { | ||
tickets++; | ||
if ($return > 0) resumed++; | ||
if ($return > 1) reencrypted++; | ||
} | ||
} | ||
|
||
%( "$^arg_time" != "" %? | ||
probe timer.s($^arg_time) { | ||
exit() | ||
} | ||
%) | ||
|
||
probe end { | ||
printf("Stop tracing NGX OPENSSL ticket key callback\n"); | ||
printf("Total sessions: %d\n", total); | ||
printf("Total session tickets: %d\n", tickets); | ||
printf("Total resumed session ticket: %d\n", resumed); | ||
printf("Total re-encrypted session ticket: %d\n", reencrypted); | ||
|
||
if (total > 0) { | ||
ratio1 = (tickets * 100) / total; | ||
|
||
} else { | ||
ratio1 = 0; | ||
} | ||
|
||
if (tickets > 0) { | ||
ratio2 = (resumed * 100) / tickets; | ||
|
||
} else { | ||
ratio2 = 0; | ||
} | ||
printf("Session ticket resumption attempts ratio: %d percent\n", ratio1) | ||
printf("Session ticket resumption success ratio: %d percent\n", ratio2) | ||
printf("Total session ticket resumption rate: %d percent\n", | ||
ratio1 * ratio2 / 100) | ||
exit(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// module nginx.array | ||
|
||
function get_ngx_array_len(ngx_arr) { | ||
$*arr := @cast(ngx_arr, "ngx_array_t", "$^exec_path") | ||
return $*arr->nelts | ||
|
||
} | ||
|
||
function get_ngx_array_elts(ngx_arr) { | ||
$*arr := @cast(ngx_arr, "ngx_array_t", "$^exec_path") | ||
return $*arr->elts | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// module openssl | ||
|
||
// extract ex_data pointer from openssl SSL_CTX | ||
function get_ssl_ex_data(ssl_ctx) { | ||
$*ctx := @cast(ssl_ctx, "SSL_CTX", "$^exec_path") | ||
return &$*ctx->ex_data | ||
} | ||
|
||
// extract number of items in SSL_CTX ex_data | ||
function get_ssl_ex_data_len(ssl_ctx) { | ||
ex_data = get_ssl_ex_data(ssl_ctx) | ||
$*data := @cast(ex_data, "CRYPTO_EX_DATA", "$^exec_path") | ||
return $*data->sk->stack->num | ||
} | ||
|
||
// extract the item specified by idx in SSL_CTX ex_data | ||
function get_ssl_ex_data_item(ssl_ctx, idx) { | ||
ex_data = get_ssl_ex_data(ssl_ctx) | ||
$*data := @cast(ex_data, "CRYPTO_EX_DATA", "$^exec_path") | ||
return $*data->sk->stack->data[idx] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case you add these manually, we usually use the
markdown-toc.pl
script to generate the TOC links and "Back to TOC" links automatically. Seehttps://github.com/openresty/nginx-devel-utils/blob/master/markdown-toc.pl