mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 19:53:13 +02:00
Fix verification of SSL certificates by calling gnutls verify callback (patch #7459)
This commit is contained in:
committed by
Sebastien Helleu
parent
bf2f7d33ef
commit
c265cad1c9
+36
-2
@@ -1700,7 +1700,40 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy, const char *ad
|
||||
}
|
||||
|
||||
/*
|
||||
* hook_connect_gnutls_set_certificates: set gnutls
|
||||
* hook_connect_gnutls_verify_certificates: verify certificates
|
||||
*/
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
int
|
||||
hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session)
|
||||
{
|
||||
struct t_hook *ptr_hook;
|
||||
int rc;
|
||||
|
||||
rc = -1;
|
||||
ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT];
|
||||
while (ptr_hook)
|
||||
{
|
||||
/* looking for the right hook using to the gnutls session pointer */
|
||||
if (!ptr_hook->deleted
|
||||
&& HOOK_CONNECT(ptr_hook, gnutls_sess)
|
||||
&& (*(HOOK_CONNECT(ptr_hook, gnutls_sess)) == tls_session))
|
||||
{
|
||||
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
|
||||
(ptr_hook->callback_data, tls_session, NULL, 0,
|
||||
NULL, 0, NULL,
|
||||
WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT);
|
||||
break;
|
||||
}
|
||||
ptr_hook = ptr_hook->next_hook;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* hook_connect_gnutls_set_certificates: set certificates
|
||||
*/
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
@@ -1725,7 +1758,8 @@ hook_connect_gnutls_set_certificates (gnutls_session_t tls_session,
|
||||
{
|
||||
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
|
||||
(ptr_hook->callback_data, tls_session, req_ca, nreq,
|
||||
pk_algos, pk_algos_len, answer);
|
||||
pk_algos, pk_algos_len, answer,
|
||||
WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT);
|
||||
break;
|
||||
}
|
||||
ptr_hook = ptr_hook->next_hook;
|
||||
|
||||
+3
-1
@@ -205,7 +205,8 @@ typedef int (t_hook_callback_connect)(void *data, int status,
|
||||
typedef int (gnutls_callback_t)(void *data, gnutls_session_t tls_session,
|
||||
const gnutls_datum_t *req_ca, int nreq,
|
||||
const gnutls_pk_algorithm_t *pk_algos,
|
||||
int pk_algos_len, gnutls_retr_st *answer);
|
||||
int pk_algos_len, gnutls_retr_st *answer,
|
||||
int action);
|
||||
#endif
|
||||
|
||||
struct t_hook_connect
|
||||
@@ -411,6 +412,7 @@ extern struct t_hook *hook_connect (struct t_weechat_plugin *plugin,
|
||||
t_hook_callback_connect *callback,
|
||||
void *callback_data);
|
||||
#ifdef HAVE_GNUTLS
|
||||
extern int hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session);
|
||||
extern int hook_connect_gnutls_set_certificates (gnutls_session_t tls_session,
|
||||
const gnutls_datum_t *req_ca, int nreq,
|
||||
const gnutls_pk_algorithm_t *pk_algos,
|
||||
|
||||
@@ -94,6 +94,8 @@ network_init ()
|
||||
}
|
||||
free (ca_path);
|
||||
}
|
||||
gnutls_certificate_set_verify_function (gnutls_xcred,
|
||||
&hook_connect_gnutls_verify_certificates);
|
||||
gnutls_certificate_client_set_retrieve_function (gnutls_xcred,
|
||||
&hook_connect_gnutls_set_certificates);
|
||||
network_init_ok = 1;
|
||||
|
||||
Reference in New Issue
Block a user