Skip to content

Commit a78bfbb

Browse files
committed
버전 - 1.19.0 업데이트
*) 기능 : OCSP 클라이언트 인증서 검사기능 추가 *) 버그 : gRPC 백엔드로 구동시 close stream에 대한 upstream 전송 프레임 오류가 발생한 문제 *) 버그 : resolver를 지정하지 않으면 OCSP 스테이플링이 작동하지 않던 문제 *) 버그 : HTTP/2에서 잘못된 서문이 전송되면 로그가 남지 않던 문제
1 parent 126a86b commit a78bfbb

13 files changed

+1777
-640
lines changed

CHANGES

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11

2-
Changes with nginx 1.18.0 21 Apr 2020
2+
Changes with nginx 1.19.0 26 May 2020
33

4-
*) 1.18.x stable branch.
4+
*) Feature: client certificate validation with OCSP.
5+
6+
*) Bugfix: "upstream sent frame for closed stream" errors might occur
7+
when working with gRPC backends.
8+
9+
*) Bugfix: OCSP stapling might not work if the "resolver" directive was
10+
not specified.
11+
12+
*) Bugfix: connections with incorrect HTTP/2 preface were not logged.
513

614

715
Changes with nginx 1.17.10 14 Apr 2020

CHANGES.ru

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11

2-
Изменения в nginx 1.18.0 21.04.2020
2+
Изменения в nginx 1.19.0 26.05.2020
33

4-
*) Стабильная ветка 1.18.x.
4+
*) Добавление: проверка клиентских сертификатов с помощью OCSP.
5+
6+
*) Исправление: при работе с gRPC-бэкендами могли возникать ошибки
7+
"upstream sent frame for closed stream".
8+
9+
*) Исправление: OCSP stapling мог не работать, если не была указана
10+
директива resolver.
11+
12+
*) Исправление: соединения с некорректным HTTP/2 preface не
13+
логгировались.
514

615

716
Изменения в nginx 1.17.10 14.04.2020

src/core/nginx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define _NGINX_H_INCLUDED_
1010

1111

12-
#define nginx_version 1018000
13-
#define NGINX_VERSION "1.18.0"
12+
#define nginx_version 1019000
13+
#define NGINX_VERSION "1.19.0"
1414
#define NGINX_VER "HostLSH SERVER/" NGINX_VERSION
1515

1616
#ifdef NGX_BUILD

src/event/ngx_event_openssl.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ int ngx_ssl_connection_index;
130130
int ngx_ssl_server_conf_index;
131131
int ngx_ssl_session_cache_index;
132132
int ngx_ssl_session_ticket_keys_index;
133+
int ngx_ssl_ocsp_index;
133134
int ngx_ssl_certificate_index;
134135
int ngx_ssl_next_certificate_index;
135136
int ngx_ssl_certificate_name_index;
@@ -213,6 +214,13 @@ ngx_ssl_init(ngx_log_t *log)
213214
return NGX_ERROR;
214215
}
215216

217+
ngx_ssl_ocsp_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL, NULL);
218+
if (ngx_ssl_ocsp_index == -1) {
219+
ngx_ssl_error(NGX_LOG_ALERT, log, 0,
220+
"SSL_CTX_get_ex_new_index() failed");
221+
return NGX_ERROR;
222+
}
223+
216224
ngx_ssl_certificate_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL,
217225
NULL);
218226
if (ngx_ssl_certificate_index == -1) {
@@ -1594,13 +1602,18 @@ ngx_ssl_handshake(ngx_connection_t *c)
15941602
{
15951603
int n, sslerr;
15961604
ngx_err_t err;
1605+
ngx_int_t rc;
15971606

15981607
#ifdef SSL_READ_EARLY_DATA_SUCCESS
15991608
if (c->ssl->try_early_data) {
16001609
return ngx_ssl_try_early_data(c);
16011610
}
16021611
#endif
16031612

1613+
if (c->ssl->in_ocsp) {
1614+
return ngx_ssl_ocsp_validate(c);
1615+
}
1616+
16041617
ngx_ssl_clear_error(c->log);
16051618

16061619
n = SSL_do_handshake(c->ssl->connection);
@@ -1621,8 +1634,6 @@ ngx_ssl_handshake(ngx_connection_t *c)
16211634
ngx_ssl_handshake_log(c);
16221635
#endif
16231636

1624-
c->ssl->handshaked = 1;
1625-
16261637
c->recv = ngx_ssl_recv;
16271638
c->send = ngx_ssl_write;
16281639
c->recv_chain = ngx_ssl_recv_chain;
@@ -1641,6 +1652,20 @@ ngx_ssl_handshake(ngx_connection_t *c)
16411652
#endif
16421653
#endif
16431654

1655+
rc = ngx_ssl_ocsp_validate(c);
1656+
1657+
if (rc == NGX_ERROR) {
1658+
return NGX_ERROR;
1659+
}
1660+
1661+
if (rc == NGX_AGAIN) {
1662+
c->read->handler = ngx_ssl_handshake_handler;
1663+
c->write->handler = ngx_ssl_handshake_handler;
1664+
return NGX_AGAIN;
1665+
}
1666+
1667+
c->ssl->handshaked = 1;
1668+
16441669
return NGX_OK;
16451670
}
16461671

@@ -1710,6 +1735,7 @@ ngx_ssl_try_early_data(ngx_connection_t *c)
17101735
u_char buf;
17111736
size_t readbytes;
17121737
ngx_err_t err;
1738+
ngx_int_t rc;
17131739

17141740
ngx_ssl_clear_error(c->log);
17151741

@@ -1744,14 +1770,27 @@ ngx_ssl_try_early_data(ngx_connection_t *c)
17441770
c->ssl->early_buf = buf;
17451771
c->ssl->early_preread = 1;
17461772

1747-
c->ssl->handshaked = 1;
17481773
c->ssl->in_early = 1;
17491774

17501775
c->recv = ngx_ssl_recv;
17511776
c->send = ngx_ssl_write;
17521777
c->recv_chain = ngx_ssl_recv_chain;
17531778
c->send_chain = ngx_ssl_send_chain;
17541779

1780+
rc = ngx_ssl_ocsp_validate(c);
1781+
1782+
if (rc == NGX_ERROR) {
1783+
return NGX_ERROR;
1784+
}
1785+
1786+
if (rc == NGX_AGAIN) {
1787+
c->read->handler = ngx_ssl_handshake_handler;
1788+
c->write->handler = ngx_ssl_handshake_handler;
1789+
return NGX_AGAIN;
1790+
}
1791+
1792+
c->ssl->handshaked = 1;
1793+
17551794
return NGX_OK;
17561795
}
17571796

@@ -2735,6 +2774,8 @@ ngx_ssl_shutdown(ngx_connection_t *c)
27352774
int n, sslerr, mode;
27362775
ngx_err_t err;
27372776

2777+
ngx_ssl_ocsp_cleanup(c);
2778+
27382779
if (SSL_in_init(c->ssl->connection)) {
27392780
/*
27402781
* OpenSSL 1.0.2f complains if SSL_shutdown() is called during
@@ -4894,11 +4935,14 @@ ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
48944935
rc = SSL_get_verify_result(c->ssl->connection);
48954936

48964937
if (rc == X509_V_OK) {
4897-
ngx_str_set(s, "SUCCESS");
4898-
return NGX_OK;
4899-
}
4938+
if (ngx_ssl_ocsp_get_status(c, &str) == NGX_OK) {
4939+
ngx_str_set(s, "SUCCESS");
4940+
return NGX_OK;
4941+
}
49004942

4901-
str = X509_verify_cert_error_string(rc);
4943+
} else {
4944+
str = X509_verify_cert_error_string(rc);
4945+
}
49024946

49034947
s->data = ngx_pnalloc(pool, sizeof("FAILED:") - 1 + ngx_strlen(str));
49044948
if (s->data == NULL) {

src/event/ngx_event_openssl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
#endif
6565

6666

67+
typedef struct ngx_ssl_ocsp_s ngx_ssl_ocsp_t;
68+
69+
6770
struct ngx_ssl_s {
6871
SSL_CTX *ctx;
6972
ngx_log_t *log;
@@ -87,6 +90,8 @@ struct ngx_ssl_connection_s {
8790
ngx_event_handler_pt saved_read_handler;
8891
ngx_event_handler_pt saved_write_handler;
8992

93+
ngx_ssl_ocsp_t *ocsp;
94+
9095
u_char early_buf;
9196

9297
unsigned handshaked:1;
@@ -97,6 +102,7 @@ struct ngx_ssl_connection_s {
97102
unsigned handshake_buffer_set:1;
98103
unsigned try_early_data:1;
99104
unsigned in_early:1;
105+
unsigned in_ocsp:1;
100106
unsigned early_preread:1;
101107
unsigned write_blocked:1;
102108
};
@@ -180,6 +186,14 @@ ngx_int_t ngx_ssl_stapling(ngx_conf_t *cf, ngx_ssl_t *ssl,
180186
ngx_str_t *file, ngx_str_t *responder, ngx_uint_t verify);
181187
ngx_int_t ngx_ssl_stapling_resolver(ngx_conf_t *cf, ngx_ssl_t *ssl,
182188
ngx_resolver_t *resolver, ngx_msec_t resolver_timeout);
189+
ngx_int_t ngx_ssl_ocsp(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *responder,
190+
ngx_uint_t depth, ngx_shm_zone_t *shm_zone);
191+
ngx_int_t ngx_ssl_ocsp_resolver(ngx_conf_t *cf, ngx_ssl_t *ssl,
192+
ngx_resolver_t *resolver, ngx_msec_t resolver_timeout);
193+
ngx_int_t ngx_ssl_ocsp_validate(ngx_connection_t *c);
194+
ngx_int_t ngx_ssl_ocsp_get_status(ngx_connection_t *c, const char **s);
195+
void ngx_ssl_ocsp_cleanup(ngx_connection_t *c);
196+
ngx_int_t ngx_ssl_ocsp_cache_init(ngx_shm_zone_t *shm_zone, void *data);
183197
RSA *ngx_ssl_rsa512_key_callback(ngx_ssl_conn_t *ssl_conn, int is_export,
184198
int key_length);
185199
ngx_array_t *ngx_ssl_read_password_file(ngx_conf_t *cf, ngx_str_t *file);
@@ -281,6 +295,7 @@ extern int ngx_ssl_connection_index;
281295
extern int ngx_ssl_server_conf_index;
282296
extern int ngx_ssl_session_cache_index;
283297
extern int ngx_ssl_session_ticket_keys_index;
298+
extern int ngx_ssl_ocsp_index;
284299
extern int ngx_ssl_certificate_index;
285300
extern int ngx_ssl_next_certificate_index;
286301
extern int ngx_ssl_certificate_name_index;

0 commit comments

Comments
 (0)