Mercurial > hg > nginx
comparison src/event/ngx_event_openssl.c @ 7732:59e1c73fe02b
SSL: ssl_reject_handshake directive (ticket #195).
In some cases it might be needed to reject SSL handshake based on SNI
server name provided, for example, to make sure an invalid certificate
is not returned to clients trying to contact a name-based virtual server
without SSL configured. Previously, a "ssl_ciphers aNULL;" was used for
this. This workaround, however, is not compatible with TLSv1.3, in
particular, when using BoringSSL, where it is not possible to configure
TLSv1.3 ciphers at all.
With this change, the ssl_reject_handshake directive is introduced,
which instructs nginx to reject SSL handshakes with an "unrecognized_name"
alert in a particular server block.
For example, to reject handshake with names other than example.com,
one can use the following configuration:
server {
listen 443 ssl;
ssl_reject_handshake on;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate example.com.crt;
ssl_certificate_key example.com.key;
}
The following configuration can be used to reject all SSL handshakes
without SNI server name provided:
server {
listen 443 ssl;
ssl_reject_handshake on;
}
server {
listen 443 ssl;
server_name ~^;
ssl_certificate example.crt;
ssl_certificate_key example.key;
}
Additionally, the ssl_reject_handshake directive makes configuring
certificates for the default server block optional. If no certificates
are configured in the default server for a given listening socket,
certificates must be defined in all non-default server blocks with
the listening socket in question.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 22 Oct 2020 18:02:28 +0300 |
parents | 3bff3f397c05 |
children | a46fcf101cfc 71b7453fb11f |
comparison
equal
deleted
inserted
replaced
7731:fd0b2226919b | 7732:59e1c73fe02b |
---|---|
1787 c->read->eof = 1; | 1787 c->read->eof = 1; |
1788 | 1788 |
1789 if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) { | 1789 if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) { |
1790 ngx_connection_error(c, err, | 1790 ngx_connection_error(c, err, |
1791 "peer closed connection in SSL handshake"); | 1791 "peer closed connection in SSL handshake"); |
1792 | |
1793 return NGX_ERROR; | |
1794 } | |
1795 | |
1796 if (c->ssl->handshake_rejected) { | |
1797 ngx_connection_error(c, err, "handshake rejected"); | |
1798 ERR_clear_error(); | |
1792 | 1799 |
1793 return NGX_ERROR; | 1800 return NGX_ERROR; |
1794 } | 1801 } |
1795 | 1802 |
1796 c->read->error = 1; | 1803 c->read->error = 1; |
3352 "EVP_DigestUpdate() failed"); | 3359 "EVP_DigestUpdate() failed"); |
3353 goto failed; | 3360 goto failed; |
3354 } | 3361 } |
3355 } | 3362 } |
3356 | 3363 |
3357 if (SSL_CTX_get_ex_data(ssl->ctx, ngx_ssl_certificate_index) == NULL) { | 3364 if (SSL_CTX_get_ex_data(ssl->ctx, ngx_ssl_certificate_index) == NULL |
3358 | 3365 && certificates != NULL) |
3366 { | |
3359 /* | 3367 /* |
3360 * If certificates are loaded dynamically, we use certificate | 3368 * If certificates are loaded dynamically, we use certificate |
3361 * names as specified in the configuration (with variables). | 3369 * names as specified in the configuration (with variables). |
3362 */ | 3370 */ |
3363 | 3371 |