[nginx] SSL: $ssl_client_fingerprint variable.

Sergey Budnevitch sb at waeme.net
Tue May 20 10:03:48 UTC 2014


details:   http://hg.nginx.org/nginx/rev/5e892d40e5cc
branches:  
changeset: 5700:5e892d40e5cc
user:      Sergey Budnevitch <sb at waeme.net>
date:      Tue May 20 14:03:03 2014 +0400
description:
SSL: $ssl_client_fingerprint variable.

diffstat:

 src/event/ngx_event_openssl.c          |  34 ++++++++++++++++++++++++++++++++++
 src/event/ngx_event_openssl.h          |   2 ++
 src/http/modules/ngx_http_ssl_module.c |   3 +++
 3 files changed, 39 insertions(+), 0 deletions(-)

diffs (69 lines):

diff -r e9dbffc18a77 -r 5e892d40e5cc src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c	Mon May 19 22:45:35 2014 +0400
+++ b/src/event/ngx_event_openssl.c	Tue May 20 14:03:03 2014 +0400
@@ -2957,6 +2957,40 @@ ngx_ssl_get_serial_number(ngx_connection
 
 
 ngx_int_t
+ngx_ssl_get_fingerprint(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
+{
+    X509          *cert;
+    unsigned int   len;
+    u_char         buf[EVP_MAX_MD_SIZE];
+
+    s->len = 0;
+
+    cert = SSL_get_peer_certificate(c->ssl->connection);
+    if (cert == NULL) {
+        return NGX_OK;
+    }
+
+    if (!X509_digest(cert, EVP_sha1(), buf, &len)) {
+        X509_free(cert);
+        return NGX_ERROR;
+    }
+
+    s->len = 2 * len;
+    s->data = ngx_pnalloc(pool, 2 * len);
+    if (s->data == NULL) {
+        X509_free(cert);
+        return NGX_ERROR;
+    }
+
+    ngx_hex_dump(s->data, buf, len);
+
+    X509_free(cert);
+
+    return NGX_OK;
+}
+
+
+ngx_int_t
 ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
 {
     X509  *cert;
diff -r e9dbffc18a77 -r 5e892d40e5cc src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h	Mon May 19 22:45:35 2014 +0400
+++ b/src/event/ngx_event_openssl.h	Tue May 20 14:03:03 2014 +0400
@@ -173,6 +173,8 @@ ngx_int_t ngx_ssl_get_issuer_dn(ngx_conn
     ngx_str_t *s);
 ngx_int_t ngx_ssl_get_serial_number(ngx_connection_t *c, ngx_pool_t *pool,
     ngx_str_t *s);
+ngx_int_t ngx_ssl_get_fingerprint(ngx_connection_t *c, ngx_pool_t *pool,
+    ngx_str_t *s);
 ngx_int_t ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool,
     ngx_str_t *s);
 
diff -r e9dbffc18a77 -r 5e892d40e5cc src/http/modules/ngx_http_ssl_module.c
--- a/src/http/modules/ngx_http_ssl_module.c	Mon May 19 22:45:35 2014 +0400
+++ b/src/http/modules/ngx_http_ssl_module.c	Tue May 20 14:03:03 2014 +0400
@@ -292,6 +292,9 @@ static ngx_http_variable_t  ngx_http_ssl
     { ngx_string("ssl_client_serial"), NULL, ngx_http_ssl_variable,
       (uintptr_t) ngx_ssl_get_serial_number, NGX_HTTP_VAR_CHANGEABLE, 0 },
 
+    { ngx_string("ssl_client_fingerprint"), NULL, ngx_http_ssl_variable,
+      (uintptr_t) ngx_ssl_get_fingerprint, NGX_HTTP_VAR_CHANGEABLE, 0 },
+
     { ngx_string("ssl_client_verify"), NULL, ngx_http_ssl_variable,
       (uintptr_t) ngx_ssl_get_client_verify, NGX_HTTP_VAR_CHANGEABLE, 0 },
 



More information about the nginx-devel mailing list