Get rid of hardcoded numbers used for quic handshake errors.

This commit is contained in:
Sergey Kandaurov 2020-06-23 11:57:00 +03:00
parent fc0036bdd6
commit 3d27c55ae3
3 changed files with 13 additions and 7 deletions

View File

@ -421,7 +421,7 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
if (client_params_len == 0) {
/* quic-tls 8.2 */
qc->error = 0x100 + SSL_AD_MISSING_EXTENSION;
qc->error = NGX_QUIC_ERR_CRYPTO(SSL_AD_MISSING_EXTENSION);
qc->error_reason = "missing transport parameters";
ngx_log_error(NGX_LOG_INFO, c->log, 0,
@ -552,7 +552,9 @@ ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, enum ssl_encryption_level_t level,
return 1;
}
if (ngx_quic_send_cc(c, level, 0x100 + alert, 0, "TLS alert") != NGX_OK) {
if (ngx_quic_send_cc(c, level, NGX_QUIC_ERR_CRYPTO(alert), 0, "TLS alert")
!= NGX_OK)
{
return 0;
}

View File

@ -104,8 +104,6 @@ static char *ngx_quic_errors[] = {
"APPLICATION_ERROR",
"CRYPTO_BUFFER_EXCEEDED",
"KEY_UPDATE_ERROR",
"unknown error 0xF",
"CRYPTO_ERROR",
};
@ -218,6 +216,9 @@ ngx_quic_build_int(u_char **pos, uint64_t value)
u_char *
ngx_quic_error_text(uint64_t error_code)
{
if (error_code >= NGX_QUIC_ERR_CRYPTO_ERROR) {
return (u_char *) "handshake error";
}
if (error_code >= NGX_QUIC_ERR_LAST) {
return (u_char *) "unknown error";

View File

@ -75,6 +75,7 @@
#define NGX_QUIC_FT_HANDSHAKE_DONE 0x1E
/* 22.4. QUIC Transport Error Codes Registry */
/* Keep in sync with ngx_quic_errors[] */
#define NGX_QUIC_ERR_NO_ERROR 0x00
#define NGX_QUIC_ERR_INTERNAL_ERROR 0x01
#define NGX_QUIC_ERR_CONNECTION_REFUSED 0x02
@ -90,10 +91,12 @@
#define NGX_QUIC_ERR_APPLICATION_ERROR 0x0C
#define NGX_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED 0x0D
#define NGX_QUIC_ERR_KEY_UPDATE_ERROR 0x0E
/* 0xF is not defined */
#define NGX_QUIC_ERR_CRYPTO_ERROR 0x10
#define NGX_QUIC_ERR_LAST NGX_QUIC_ERR_CRYPTO_ERROR
#define NGX_QUIC_ERR_LAST 0x0F
#define NGX_QUIC_ERR_CRYPTO_ERROR 0x100
#define NGX_QUIC_ERR_CRYPTO(e) (NGX_QUIC_ERR_CRYPTO_ERROR + (e))
/* Transport parameters */
#define NGX_QUIC_TP_ORIGINAL_DCID 0x00