Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

Commit 54ba022

Browse files
committed
Expose SNI to ircd code; OpenSSL only for now
1 parent 673fd77 commit 54ba022

File tree

7 files changed

+75
-0
lines changed

7 files changed

+75
-0
lines changed

include/client.h

+2
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ struct LocalUser
291291
unsigned int sasl_messages;
292292
unsigned int sasl_failures;
293293
time_t sasl_next_retry;
294+
295+
char *sni;
294296
};
295297

296298
#define AUTHC_F_DEFERRED 0x01

ircd/sslproc.c

+25
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,28 @@ ssl_process_certfp(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
535535
client_p->certfp = certfp_string;
536536
}
537537

538+
539+
static void
540+
ssl_process_sni(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf)
541+
{
542+
struct Client *client_p;
543+
int32_t fd;
544+
char *sni_string;
545+
int i;
546+
547+
if(ctl_buf->buflen > 5 + RB_SSL_SNI_LEN)
548+
return;
549+
550+
fd = buf_to_uint32(&ctl_buf->buf[1]);
551+
client_p = find_cli_connid_hash(fd);
552+
if(client_p == NULL)
553+
return;
554+
rb_free(client_p->localClient->sni);
555+
sni_string = rb_malloc(ctl_buf->buflen - 4);
556+
rb_strlcpy(sni_string, &ctl_buf->buf[5], ctl_buf->buflen - 0);
557+
client_p->localClient->sni = sni_string;
558+
}
559+
538560
static void
539561
ssl_process_cmd_recv(ssl_ctl_t * ctl)
540562
{
@@ -590,6 +612,9 @@ ssl_process_cmd_recv(ssl_ctl_t * ctl)
590612
case 'z':
591613
ircd_zlib_ok = 0;
592614
break;
615+
case 'n':
616+
ssl_process_sni(ctl, ctl_buf);
617+
break;
593618
default:
594619
ilog(L_MAIN, "Received invalid command from ssld: %s", ctl_buf->buf);
595620
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Received invalid command from ssld");

librb/include/rb_commio.h

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void rb_note(rb_fde_t *, const char *);
117117
#define RB_SSL_CERTFP_LEN_SHA256 32
118118
#define RB_SSL_CERTFP_LEN_SHA512 64
119119

120+
#define RB_SSL_SNI_LEN 250
121+
120122
int rb_set_nb(rb_fde_t *);
121123
int rb_set_buffers(rb_fde_t *, int);
122124

@@ -165,6 +167,7 @@ rb_platform_fd_t rb_get_fd(rb_fde_t *F);
165167
const char *rb_get_ssl_strerror(rb_fde_t *F);
166168
int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN], int method);
167169
int rb_get_ssl_certfp_file(const char *filename, uint8_t certfp[RB_SSL_CERTFP_LEN], int method);
170+
int rb_get_ssl_sni(rb_fde_t *F, uint8_t sni[static RB_SSL_SNI_LEN]);
168171

169172
rb_fde_t *rb_get_fde(rb_platform_fd_t fd);
170173

librb/src/export-syms.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ rb_get_random
6262
rb_get_sockerr
6363
rb_get_ssl_certfp
6464
rb_get_ssl_certfp_file
65+
rb_get_ssl_sni
6566
rb_get_ssl_strerror
6667
rb_get_type
6768
rb_getmaxconnect

librb/src/openssl.c

+21
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,27 @@ rb_get_ssl_strerror(rb_fde_t *const F)
521521
return rb_ssl_strerror(F->ssl_errno);
522522
}
523523

524+
int
525+
rb_get_ssl_sni(rb_fde_t *F, uint8_t sni[static RB_SSL_SNI_LEN])
526+
{
527+
const char *openssl_sni;
528+
size_t n;
529+
530+
if (F == NULL || F->ssl == NULL)
531+
return 0;
532+
533+
openssl_sni = SSL_get_servername(F->ssl, TLSEXT_NAMETYPE_host_name);
534+
if (openssl_sni == NULL)
535+
return 0;
536+
537+
n = snprintf((char *)sni, RB_SSL_SNI_LEN, "%s", openssl_sni);
538+
539+
if (n == 0 || n > RB_SSL_SNI_LEN || n > INT_MAX)
540+
return 0;
541+
542+
return (int)n;
543+
}
544+
524545
int
525546
rb_get_ssl_certfp(rb_fde_t *const F, uint8_t certfp[const RB_SSL_CERTFP_LEN], const int method)
526547
{

modules/m_whois.c

+7
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
344344
sendto_one_numeric(source_p, RPL_WHOISCERTFP,
345345
form_str(RPL_WHOISCERTFP),
346346
target_p->name, target_p->certfp);
347+
348+
if((source_p == target_p || IsOper(source_p)) &&
349+
target_p->localClient != NULL &&
350+
target_p->localClient->sni != NULL)
351+
sendto_one_numeric(source_p, RPL_WHOISCERTFP,
352+
"%s %s :Connected to hostname",
353+
target_p->name, target_p->localClient->sni);
347354
}
348355

349356
if(MyClient(target_p))

ssld/ssld.c

+16
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,21 @@ ssl_send_certfp(conn_t *conn)
695695
mod_cmd_write_queue(conn->ctl, buf, 13 + len);
696696
}
697697

698+
static void
699+
ssl_send_sni(conn_t *conn)
700+
{
701+
uint8_t buf[5 + RB_SSL_SNI_LEN];
702+
703+
int len = rb_get_ssl_sni(conn->mod_fd, &buf[5]);
704+
if (len == 0)
705+
return;
706+
707+
lrb_assert(len <= RB_SSL_SNI_LEN);
708+
buf[0] = 'n';
709+
uint32_to_buf(&buf[1], conn->id);
710+
mod_cmd_write_queue(conn->ctl, buf, 5 + len);
711+
}
712+
698713
static void
699714
ssl_send_open(conn_t *conn)
700715
{
@@ -714,6 +729,7 @@ ssl_process_accept_cb(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen
714729
{
715730
ssl_send_cipher(conn);
716731
ssl_send_certfp(conn);
732+
ssl_send_sni(conn);
717733
ssl_send_open(conn);
718734
conn_mod_read_cb(conn->mod_fd, conn);
719735
conn_plain_read_cb(conn->plain_fd, conn);

0 commit comments

Comments
 (0)