Skip to content

Commit

Permalink
ircd/listener: return a fatal TLS alert for early rejected TLS clients
Browse files Browse the repository at this point in the history
This is in furtherance of commit 3fdf26a which added
functionality to reply with a TLS record layer alert for D-Lined TLS
clients. It turns out that there are other plaintext error messages
in this same function that should receive the same treatment.

Also move another error string to a variable and use a compile-time
optimised-out strlen for it too, to use the same approach as an
existing error string.

Finally, use a different alert (internal_error) for the case where
IRCd is simply unable to accept more connections.
  • Loading branch information
aaronmdjones committed Jul 1, 2023
1 parent d1c028f commit beecb81
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions ircd/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,19 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
static time_t last_oper_notice = 0;
int len;

static const char *allinuse = "ERROR :All connections in use\r\n";
static const char *toofast = "ERROR :Reconnecting too fast, throttled.\r\n";

static const unsigned char sslerrcode[] = {
static const unsigned char ssldeniederrcode[] = {
// SSLv3.0 Fatal Alert: Access Denied
0x15, 0x03, 0x00, 0x00, 0x02, 0x02, 0x31
};

static const unsigned char sslinternalerrcode[] = {
// SSLv3.0 Fatal Alert: Internal Error
0x15, 0x03, 0x00, 0x00, 0x02, 0x02, 0x50
};

if(listener->ssl && (!ircd_ssl_ok || !get_ssld_count()))
{
rb_close(F);
Expand All @@ -608,7 +614,11 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi
last_oper_notice = rb_current_time();
}

rb_write(F, "ERROR :All connections in use\r\n", 31);
if(listener->ssl)
rb_write(F, sslinternalerrcode, sizeof(sslinternalerrcode));
else
rb_write(F, allinuse, strlen(allinuse));

rb_close(F);
return 0;
}
Expand All @@ -625,7 +635,7 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi

if(listener->ssl)
{
rb_write(F, sslerrcode, sizeof(sslerrcode));
rb_write(F, ssldeniederrcode, sizeof(ssldeniederrcode));
}
else if(ConfigFileEntry.dline_with_reason)
{
Expand Down Expand Up @@ -656,7 +666,11 @@ accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, voi

if(throttle_add(addr))
{
rb_write(F, toofast, strlen(toofast));
if(listener->ssl)
rb_write(F, ssldeniederrcode, sizeof(ssldeniederrcode));
else
rb_write(F, toofast, strlen(toofast));

rb_close(F);
return 0;
}
Expand Down

0 comments on commit beecb81

Please sign in to comment.