Skip to content

Commit

Permalink
nghttpx: Add $tls_client_serial log variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Nov 16, 2017
1 parent 4720c5c commit eca0a30
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions gennghttpxfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"tls_client_fingerprint_sha1",
"tls_client_subject_name",
"tls_client_issuer_name",
"tls_client_serial",
"backend_host",
"backend_port",
]
Expand Down
2 changes: 2 additions & 0 deletions src/shrpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,8 @@ HTTP/2 and SPDY:
certificate.
* $tls_client_issuer_name: issuer name in client
certificate.
* $tls_client_serial: serial number in client
certificate.
* $tls_protocol: protocol for SSL/TLS connection.
* $tls_session_id: session ID for SSL/TLS connection.
* $tls_session_reused: "r" if SSL/TLS session was
Expand Down
9 changes: 9 additions & 0 deletions src/shrpx_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,15 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
break;
}
break;
case 17:
switch (name[16]) {
case 'l':
if (util::strieq_l("tls_client_seria", name, 16)) {
return SHRPX_LOGF_TLS_CLIENT_SERIAL;
}
break;
}
break;
case 18:
switch (name[17]) {
case 'd':
Expand Down
19 changes: 19 additions & 0 deletions src/shrpx_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,25 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy(name, p, last);
break;
}
case SHRPX_LOGF_TLS_CLIENT_SERIAL: {
if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last);
break;
}
auto x = SSL_get_peer_certificate(lgsp.ssl);
if (!x) {
std::tie(p, last) = copy('-', p, last);
break;
}
auto sn = tls::get_x509_serial(balloc, x);
X509_free(x);
if (sn.empty()) {
std::tie(p, last) = copy('-', p, last);
break;
}
std::tie(p, last) = copy(sn, p, last);
break;
}
case SHRPX_LOGF_BACKEND_HOST:
if (!downstream_addr) {
std::tie(p, last) = copy('-', p, last);
Expand Down
1 change: 1 addition & 0 deletions src/shrpx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ enum LogFragmentType {
SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA1,
SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA256,
SHRPX_LOGF_TLS_CLIENT_ISSUER_NAME,
SHRPX_LOGF_TLS_CLIENT_SERIAL,
SHRPX_LOGF_TLS_CLIENT_SUBJECT_NAME,
SHRPX_LOGF_BACKEND_HOST,
SHRPX_LOGF_BACKEND_PORT,
Expand Down

0 comments on commit eca0a30

Please sign in to comment.