Redirect to the TLS port if a STS profile exists.

This commit is contained in:
Sadie Powell 2021-05-29 20:10:24 +01:00
parent 1d65bfdf08
commit ade78e84f1
5 changed files with 51 additions and 0 deletions

View File

@ -54,6 +54,7 @@
#include "proto-irc.h"
#include "servlist.h"
#include "server.h"
#include "sts.h"
#ifdef USE_OPENSSL
#include <openssl/ssl.h> /* SSL_() */
@ -1544,8 +1545,22 @@ server_connect (server *serv, char *hostname, int port, int no_login)
{
int pid, read_des[2];
session *sess = serv->server_session;
struct sts_profile *sts = NULL;
#ifdef USE_OPENSSL
if (!serv->use_ssl)
{
sts = sts_find (hostname);
if (sts)
{
EMIT_SIGNAL (XP_TE_STSREDIR, sess, hostname, NULL, NULL, NULL, 0);
hostname = sts->host;
port = sts->port;
serv->accept_invalid_cert = FALSE;
serv->use_ssl = TRUE;
}
}
if (!serv->ctx && serv->use_ssl)
{
if (!(serv->ctx = _SSL_context_init (ssl_cb_info)))

View File

@ -28,6 +28,28 @@
GSList *profiles = NULL;
struct sts_profile *
sts_find (const char* host)
{
time_t now;
GList *next;
struct sts_profile *nextprofile;
now = time (NULL);
for (next = profiles; next; next = next->next)
{
nextprofile = (struct sts_profile *)next->data;
if (now >= nextprofile->expiry)
continue; /* Profile has expired. */
if (!g_strcmp0 (host, nextprofile->host))
return nextprofile; /* We found the right profile! */
}
/* No profile for this host. */
return NULL;
}
void
sts_load (void)
{

View File

@ -40,6 +40,10 @@ struct sts_profile
time_t expiry;
};
/* Searches for a STS profile that matches the specified hostname */
struct sts_profile *sts_find (const char *host);
/* Loads STS profiles from sts.conf */
void sts_load (void);

View File

@ -1289,6 +1289,10 @@ static char * const pevt_sslmessage_help[] = {
N_("Server Name")
};
static char * const pevt_stsredir_help[] = {
N_("Server Name"),
};
static char * const pevt_invited_help[] = {
N_("Channel Name"),
N_("Nick of person who invited you"),

View File

@ -784,6 +784,12 @@ pevt_sslmessage_help
%C29*%O$t$1
n2
STS Redirection
XP_TE_STSREDIR
pevt_stsredir_help
%C29*%O$tUsing the previously saved STS profile for %C29$1%O
n2
Stop Connection
XP_TE_STOPCONNECT
pevt_sconnect_help