idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
2,700
hook_add_to_infolist (struct t_infolist *infolist, const char *arguments) { const char *pos_arguments; char *type; int i, type_int; if (!infolist) return 0; type = NULL; pos_arguments = NULL; if (arguments) { pos_arguments = strchr (arguments, ','); if (pos_arguments) { type = string_strndup (arguments, pos_arguments - arguments); pos_arguments++; } else type = strdup (arguments); } type_int = (type) ? hook_search_type (type) : -1; for (i = 0; i < HOOK_NUM_TYPES; i++) { if ((type_int < 0) || (type_int == i)) hook_add_to_infolist_type (infolist, i, pos_arguments); } if (type) free (type); return 1; }
null
0
hook_add_to_infolist (struct t_infolist *infolist, const char *arguments) { const char *pos_arguments; char *type; int i, type_int; if (!infolist) return 0; type = NULL; pos_arguments = NULL; if (arguments) { pos_arguments = strchr (arguments, ','); if (pos_arguments) { type = string_strndup (arguments, pos_arguments - arguments); pos_arguments++; } else type = strdup (arguments); } type_int = (type) ? hook_search_type (type) : -1; for (i = 0; i < HOOK_NUM_TYPES; i++) { if ((type_int < 0) || (type_int == i)) hook_add_to_infolist_type (infolist, i, pos_arguments); } if (type) free (type); return 1; }
@@ -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;
CWE-20
null
null
2,701
hook_add_to_infolist_type (struct t_infolist *infolist, int type, const char *arguments) { struct t_hook *ptr_hook; struct t_infolist_item *ptr_item; char value[64]; int match; for (ptr_hook = weechat_hooks[type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { match = 1; if (arguments && !ptr_hook->deleted) { switch (ptr_hook->type) { case HOOK_TYPE_COMMAND: match = (strcmp (HOOK_COMMAND(ptr_hook, command), arguments) == 0); break; default: break; } } if (!match) continue; ptr_item = infolist_new_item (infolist); if (!ptr_item) return 0; if (!infolist_new_var_pointer (ptr_item, "pointer", ptr_hook)) return 0; if (!infolist_new_var_pointer (ptr_item, "plugin", ptr_hook->plugin)) return 0; if (!infolist_new_var_string (ptr_item, "plugin_name", (ptr_hook->plugin) ? ptr_hook->plugin->name : NULL)) return 0; if (!infolist_new_var_string (ptr_item, "type", hook_type_string[ptr_hook->type])) return 0; if (!infolist_new_var_integer (ptr_item, "deleted", ptr_hook->deleted)) return 0; if (!infolist_new_var_integer (ptr_item, "running", ptr_hook->running)) return 0; if (!infolist_new_var_integer (ptr_item, "priority", ptr_hook->priority)) return 0; switch (ptr_hook->type) { case HOOK_TYPE_COMMAND: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND(ptr_hook, command))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_COMMAND(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_COMMAND(ptr_hook, description) && HOOK_COMMAND(ptr_hook, description)[0]) ? _(HOOK_COMMAND(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args", HOOK_COMMAND(ptr_hook, args))) return 0; if (!infolist_new_var_string (ptr_item, "args_nls", (HOOK_COMMAND(ptr_hook, args) && HOOK_COMMAND(ptr_hook, args)[0]) ? _(HOOK_COMMAND(ptr_hook, args)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_COMMAND(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_COMMAND(ptr_hook, args_description) && HOOK_COMMAND(ptr_hook, args_description)[0]) ? _(HOOK_COMMAND(ptr_hook, args_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "completion", HOOK_COMMAND(ptr_hook, completion))) return 0; } break; case HOOK_TYPE_COMMAND_RUN: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND_RUN(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND_RUN(ptr_hook, command))) return 0; } break; case HOOK_TYPE_TIMER: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_TIMER(ptr_hook, callback))) return 0; snprintf (value, sizeof (value), "%ld", HOOK_TIMER(ptr_hook, interval)); if (!infolist_new_var_string (ptr_item, "interval", value)) return 0; if (!infolist_new_var_integer (ptr_item, "align_second", HOOK_TIMER(ptr_hook, align_second))) return 0; if (!infolist_new_var_integer (ptr_item, "remaining_calls", HOOK_TIMER(ptr_hook, remaining_calls))) return 0; if (!infolist_new_var_buffer (ptr_item, "last_exec", &(HOOK_TIMER(ptr_hook, last_exec)), sizeof (HOOK_TIMER(ptr_hook, last_exec)))) return 0; if (!infolist_new_var_buffer (ptr_item, "next_exec", &(HOOK_TIMER(ptr_hook, next_exec)), sizeof (HOOK_TIMER(ptr_hook, next_exec)))) return 0; } break; case HOOK_TYPE_FD: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FD(ptr_hook, callback))) return 0; if (!infolist_new_var_integer (ptr_item, "fd", HOOK_FD(ptr_hook, fd))) return 0; if (!infolist_new_var_integer (ptr_item, "flags", HOOK_FD(ptr_hook, flags))) return 0; } break; case HOOK_TYPE_PROCESS: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PROCESS(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_PROCESS(ptr_hook, command))) return 0; if (!infolist_new_var_integer (ptr_item, "timeout", HOOK_PROCESS(ptr_hook, timeout))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read_stdout", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write_stdout", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read_stderr", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write_stderr", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_PROCESS(ptr_hook, child_pid))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd_stdout", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd_stderr", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_timer", HOOK_PROCESS(ptr_hook, hook_timer))) return 0; } break; case HOOK_TYPE_CONNECT: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONNECT(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "address", HOOK_CONNECT(ptr_hook, address))) return 0; if (!infolist_new_var_integer (ptr_item, "port", HOOK_CONNECT(ptr_hook, port))) return 0; if (!infolist_new_var_integer (ptr_item, "sock", HOOK_CONNECT(ptr_hook, sock))) return 0; if (!infolist_new_var_integer (ptr_item, "ipv6", HOOK_CONNECT(ptr_hook, ipv6))) return 0; #ifdef HAVE_GNUTLS if (!infolist_new_var_pointer (ptr_item, "gnutls_sess", HOOK_CONNECT(ptr_hook, gnutls_sess))) return 0; if (!infolist_new_var_pointer (ptr_item, "gnutls_cb", HOOK_CONNECT(ptr_hook, gnutls_cb))) return 0; if (!infolist_new_var_integer (ptr_item, "gnutls_dhkey_size", HOOK_CONNECT(ptr_hook, gnutls_dhkey_size))) return 0; #endif if (!infolist_new_var_string (ptr_item, "local_hostname", HOOK_CONNECT(ptr_hook, local_hostname))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read", HOOK_CONNECT(ptr_hook, child_read))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write", HOOK_CONNECT(ptr_hook, child_write))) return 0; if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_CONNECT(ptr_hook, child_pid))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd", HOOK_CONNECT(ptr_hook, hook_fd))) return 0; if (!infolist_new_var_pointer (ptr_item, "handshake_hook_fd", HOOK_CONNECT(ptr_hook, handshake_hook_fd))) return 0; if (!infolist_new_var_pointer (ptr_item, "handshake_hook_timer", HOOK_CONNECT(ptr_hook, handshake_hook_timer))) return 0; if (!infolist_new_var_integer (ptr_item, "handshake_fd_flags", HOOK_CONNECT(ptr_hook, handshake_fd_flags))) return 0; if (!infolist_new_var_string (ptr_item, "handshake_ip_address", HOOK_CONNECT(ptr_hook, handshake_ip_address))) return 0; } break; case HOOK_TYPE_PRINT: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PRINT(ptr_hook, callback))) return 0; if (!infolist_new_var_pointer (ptr_item, "buffer", HOOK_PRINT(ptr_hook, buffer))) return 0; if (!infolist_new_var_integer (ptr_item, "tags_count", HOOK_PRINT(ptr_hook, tags_count))) return 0; if (!infolist_new_var_pointer (ptr_item, "tags_array", HOOK_PRINT(ptr_hook, tags_array))) return 0; if (!infolist_new_var_string (ptr_item, "message", HOOK_PRINT(ptr_hook, message))) return 0; if (!infolist_new_var_integer (ptr_item, "strip_colors", HOOK_PRINT(ptr_hook, strip_colors))) return 0; } break; case HOOK_TYPE_SIGNAL: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_SIGNAL(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "signal", HOOK_SIGNAL(ptr_hook, signal))) return 0; } break; case HOOK_TYPE_HSIGNAL: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HSIGNAL(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "signal", HOOK_HSIGNAL(ptr_hook, signal))) return 0; } break; case HOOK_TYPE_CONFIG: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONFIG(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "option", HOOK_CONFIG(ptr_hook, option))) return 0; } break; case HOOK_TYPE_COMPLETION: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMPLETION(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "completion_item", HOOK_COMPLETION(ptr_hook, completion_item))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_COMPLETION(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_COMPLETION(ptr_hook, description) && HOOK_COMPLETION(ptr_hook, description)[0]) ? _(HOOK_COMPLETION(ptr_hook, description)) : "")) return 0; } break; case HOOK_TYPE_MODIFIER: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_MODIFIER(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "modifier", HOOK_MODIFIER(ptr_hook, modifier))) return 0; } break; case HOOK_TYPE_INFO: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO(ptr_hook, info_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFO(ptr_hook, description) && HOOK_INFO(ptr_hook, description)[0]) ? _(HOOK_INFO(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFO(ptr_hook, args_description) && HOOK_INFO(ptr_hook, args_description)[0]) ? _(HOOK_INFO(ptr_hook, args_description)) : "")) return 0; } break; case HOOK_TYPE_INFO_HASHTABLE: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO_HASHTABLE(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO_HASHTABLE(ptr_hook, info_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO_HASHTABLE(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, description) && HOOK_INFO_HASHTABLE(ptr_hook, description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO_HASHTABLE(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, args_description) && HOOK_INFO_HASHTABLE(ptr_hook, args_description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, args_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "output_description", HOOK_INFO_HASHTABLE(ptr_hook, output_description))) return 0; if (!infolist_new_var_string (ptr_item, "output_description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, output_description) && HOOK_INFO_HASHTABLE(ptr_hook, output_description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, output_description)) : "")) return 0; } break; case HOOK_TYPE_INFOLIST: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFOLIST(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "infolist_name", HOOK_INFOLIST(ptr_hook, infolist_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFOLIST(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFOLIST(ptr_hook, description) && HOOK_INFOLIST(ptr_hook, description)[0]) ? _(HOOK_INFOLIST(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "pointer_description", HOOK_INFOLIST(ptr_hook, pointer_description))) return 0; if (!infolist_new_var_string (ptr_item, "pointer_description_nls", (HOOK_INFOLIST(ptr_hook, pointer_description) && HOOK_INFOLIST(ptr_hook, pointer_description)[0]) ? _(HOOK_INFOLIST(ptr_hook, pointer_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFOLIST(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFOLIST(ptr_hook, args_description) && HOOK_INFOLIST(ptr_hook, args_description)[0]) ? _(HOOK_INFOLIST(ptr_hook, args_description)) : "")) return 0; } break; case HOOK_NUM_TYPES: /* * this constant is used to count types only, * it is never used as type */ break; } } return 1; }
null
0
hook_add_to_infolist_type (struct t_infolist *infolist, int type, const char *arguments) { struct t_hook *ptr_hook; struct t_infolist_item *ptr_item; char value[64]; int match; for (ptr_hook = weechat_hooks[type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { match = 1; if (arguments && !ptr_hook->deleted) { switch (ptr_hook->type) { case HOOK_TYPE_COMMAND: match = (strcmp (HOOK_COMMAND(ptr_hook, command), arguments) == 0); break; default: break; } } if (!match) continue; ptr_item = infolist_new_item (infolist); if (!ptr_item) return 0; if (!infolist_new_var_pointer (ptr_item, "pointer", ptr_hook)) return 0; if (!infolist_new_var_pointer (ptr_item, "plugin", ptr_hook->plugin)) return 0; if (!infolist_new_var_string (ptr_item, "plugin_name", (ptr_hook->plugin) ? ptr_hook->plugin->name : NULL)) return 0; if (!infolist_new_var_string (ptr_item, "type", hook_type_string[ptr_hook->type])) return 0; if (!infolist_new_var_integer (ptr_item, "deleted", ptr_hook->deleted)) return 0; if (!infolist_new_var_integer (ptr_item, "running", ptr_hook->running)) return 0; if (!infolist_new_var_integer (ptr_item, "priority", ptr_hook->priority)) return 0; switch (ptr_hook->type) { case HOOK_TYPE_COMMAND: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND(ptr_hook, command))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_COMMAND(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_COMMAND(ptr_hook, description) && HOOK_COMMAND(ptr_hook, description)[0]) ? _(HOOK_COMMAND(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args", HOOK_COMMAND(ptr_hook, args))) return 0; if (!infolist_new_var_string (ptr_item, "args_nls", (HOOK_COMMAND(ptr_hook, args) && HOOK_COMMAND(ptr_hook, args)[0]) ? _(HOOK_COMMAND(ptr_hook, args)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_COMMAND(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_COMMAND(ptr_hook, args_description) && HOOK_COMMAND(ptr_hook, args_description)[0]) ? _(HOOK_COMMAND(ptr_hook, args_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "completion", HOOK_COMMAND(ptr_hook, completion))) return 0; } break; case HOOK_TYPE_COMMAND_RUN: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND_RUN(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND_RUN(ptr_hook, command))) return 0; } break; case HOOK_TYPE_TIMER: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_TIMER(ptr_hook, callback))) return 0; snprintf (value, sizeof (value), "%ld", HOOK_TIMER(ptr_hook, interval)); if (!infolist_new_var_string (ptr_item, "interval", value)) return 0; if (!infolist_new_var_integer (ptr_item, "align_second", HOOK_TIMER(ptr_hook, align_second))) return 0; if (!infolist_new_var_integer (ptr_item, "remaining_calls", HOOK_TIMER(ptr_hook, remaining_calls))) return 0; if (!infolist_new_var_buffer (ptr_item, "last_exec", &(HOOK_TIMER(ptr_hook, last_exec)), sizeof (HOOK_TIMER(ptr_hook, last_exec)))) return 0; if (!infolist_new_var_buffer (ptr_item, "next_exec", &(HOOK_TIMER(ptr_hook, next_exec)), sizeof (HOOK_TIMER(ptr_hook, next_exec)))) return 0; } break; case HOOK_TYPE_FD: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FD(ptr_hook, callback))) return 0; if (!infolist_new_var_integer (ptr_item, "fd", HOOK_FD(ptr_hook, fd))) return 0; if (!infolist_new_var_integer (ptr_item, "flags", HOOK_FD(ptr_hook, flags))) return 0; } break; case HOOK_TYPE_PROCESS: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PROCESS(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "command", HOOK_PROCESS(ptr_hook, command))) return 0; if (!infolist_new_var_integer (ptr_item, "timeout", HOOK_PROCESS(ptr_hook, timeout))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read_stdout", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write_stdout", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read_stderr", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write_stderr", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_PROCESS(ptr_hook, child_pid))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd_stdout", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDOUT]))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd_stderr", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDERR]))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_timer", HOOK_PROCESS(ptr_hook, hook_timer))) return 0; } break; case HOOK_TYPE_CONNECT: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONNECT(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "address", HOOK_CONNECT(ptr_hook, address))) return 0; if (!infolist_new_var_integer (ptr_item, "port", HOOK_CONNECT(ptr_hook, port))) return 0; if (!infolist_new_var_integer (ptr_item, "sock", HOOK_CONNECT(ptr_hook, sock))) return 0; if (!infolist_new_var_integer (ptr_item, "ipv6", HOOK_CONNECT(ptr_hook, ipv6))) return 0; #ifdef HAVE_GNUTLS if (!infolist_new_var_pointer (ptr_item, "gnutls_sess", HOOK_CONNECT(ptr_hook, gnutls_sess))) return 0; if (!infolist_new_var_pointer (ptr_item, "gnutls_cb", HOOK_CONNECT(ptr_hook, gnutls_cb))) return 0; if (!infolist_new_var_integer (ptr_item, "gnutls_dhkey_size", HOOK_CONNECT(ptr_hook, gnutls_dhkey_size))) return 0; #endif if (!infolist_new_var_string (ptr_item, "local_hostname", HOOK_CONNECT(ptr_hook, local_hostname))) return 0; if (!infolist_new_var_integer (ptr_item, "child_read", HOOK_CONNECT(ptr_hook, child_read))) return 0; if (!infolist_new_var_integer (ptr_item, "child_write", HOOK_CONNECT(ptr_hook, child_write))) return 0; if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_CONNECT(ptr_hook, child_pid))) return 0; if (!infolist_new_var_pointer (ptr_item, "hook_fd", HOOK_CONNECT(ptr_hook, hook_fd))) return 0; if (!infolist_new_var_pointer (ptr_item, "handshake_hook_fd", HOOK_CONNECT(ptr_hook, handshake_hook_fd))) return 0; if (!infolist_new_var_pointer (ptr_item, "handshake_hook_timer", HOOK_CONNECT(ptr_hook, handshake_hook_timer))) return 0; if (!infolist_new_var_integer (ptr_item, "handshake_fd_flags", HOOK_CONNECT(ptr_hook, handshake_fd_flags))) return 0; if (!infolist_new_var_string (ptr_item, "handshake_ip_address", HOOK_CONNECT(ptr_hook, handshake_ip_address))) return 0; } break; case HOOK_TYPE_PRINT: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PRINT(ptr_hook, callback))) return 0; if (!infolist_new_var_pointer (ptr_item, "buffer", HOOK_PRINT(ptr_hook, buffer))) return 0; if (!infolist_new_var_integer (ptr_item, "tags_count", HOOK_PRINT(ptr_hook, tags_count))) return 0; if (!infolist_new_var_pointer (ptr_item, "tags_array", HOOK_PRINT(ptr_hook, tags_array))) return 0; if (!infolist_new_var_string (ptr_item, "message", HOOK_PRINT(ptr_hook, message))) return 0; if (!infolist_new_var_integer (ptr_item, "strip_colors", HOOK_PRINT(ptr_hook, strip_colors))) return 0; } break; case HOOK_TYPE_SIGNAL: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_SIGNAL(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "signal", HOOK_SIGNAL(ptr_hook, signal))) return 0; } break; case HOOK_TYPE_HSIGNAL: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HSIGNAL(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "signal", HOOK_HSIGNAL(ptr_hook, signal))) return 0; } break; case HOOK_TYPE_CONFIG: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONFIG(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "option", HOOK_CONFIG(ptr_hook, option))) return 0; } break; case HOOK_TYPE_COMPLETION: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMPLETION(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "completion_item", HOOK_COMPLETION(ptr_hook, completion_item))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_COMPLETION(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_COMPLETION(ptr_hook, description) && HOOK_COMPLETION(ptr_hook, description)[0]) ? _(HOOK_COMPLETION(ptr_hook, description)) : "")) return 0; } break; case HOOK_TYPE_MODIFIER: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_MODIFIER(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "modifier", HOOK_MODIFIER(ptr_hook, modifier))) return 0; } break; case HOOK_TYPE_INFO: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO(ptr_hook, info_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFO(ptr_hook, description) && HOOK_INFO(ptr_hook, description)[0]) ? _(HOOK_INFO(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFO(ptr_hook, args_description) && HOOK_INFO(ptr_hook, args_description)[0]) ? _(HOOK_INFO(ptr_hook, args_description)) : "")) return 0; } break; case HOOK_TYPE_INFO_HASHTABLE: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO_HASHTABLE(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO_HASHTABLE(ptr_hook, info_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO_HASHTABLE(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, description) && HOOK_INFO_HASHTABLE(ptr_hook, description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO_HASHTABLE(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, args_description) && HOOK_INFO_HASHTABLE(ptr_hook, args_description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, args_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "output_description", HOOK_INFO_HASHTABLE(ptr_hook, output_description))) return 0; if (!infolist_new_var_string (ptr_item, "output_description_nls", (HOOK_INFO_HASHTABLE(ptr_hook, output_description) && HOOK_INFO_HASHTABLE(ptr_hook, output_description)[0]) ? _(HOOK_INFO_HASHTABLE(ptr_hook, output_description)) : "")) return 0; } break; case HOOK_TYPE_INFOLIST: if (!ptr_hook->deleted) { if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFOLIST(ptr_hook, callback))) return 0; if (!infolist_new_var_string (ptr_item, "infolist_name", HOOK_INFOLIST(ptr_hook, infolist_name))) return 0; if (!infolist_new_var_string (ptr_item, "description", HOOK_INFOLIST(ptr_hook, description))) return 0; if (!infolist_new_var_string (ptr_item, "description_nls", (HOOK_INFOLIST(ptr_hook, description) && HOOK_INFOLIST(ptr_hook, description)[0]) ? _(HOOK_INFOLIST(ptr_hook, description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "pointer_description", HOOK_INFOLIST(ptr_hook, pointer_description))) return 0; if (!infolist_new_var_string (ptr_item, "pointer_description_nls", (HOOK_INFOLIST(ptr_hook, pointer_description) && HOOK_INFOLIST(ptr_hook, pointer_description)[0]) ? _(HOOK_INFOLIST(ptr_hook, pointer_description)) : "")) return 0; if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFOLIST(ptr_hook, args_description))) return 0; if (!infolist_new_var_string (ptr_item, "args_description_nls", (HOOK_INFOLIST(ptr_hook, args_description) && HOOK_INFOLIST(ptr_hook, args_description)[0]) ? _(HOOK_INFOLIST(ptr_hook, args_description)) : "")) return 0; } break; case HOOK_NUM_TYPES: /* * this constant is used to count types only, * it is never used as type */ break; } } return 1; }
@@ -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;
CWE-20
null
null
2,702
hook_add_to_list (struct t_hook *new_hook) { struct t_hook *pos_hook; if (weechat_hooks[new_hook->type]) { pos_hook = hook_find_pos (new_hook); if (pos_hook) { /* add hook before "pos_hook" */ new_hook->prev_hook = pos_hook->prev_hook; new_hook->next_hook = pos_hook; if (pos_hook->prev_hook) (pos_hook->prev_hook)->next_hook = new_hook; else weechat_hooks[new_hook->type] = new_hook; pos_hook->prev_hook = new_hook; } else { /* add hook to end of list */ new_hook->prev_hook = last_weechat_hook[new_hook->type]; new_hook->next_hook = NULL; last_weechat_hook[new_hook->type]->next_hook = new_hook; last_weechat_hook[new_hook->type] = new_hook; } } else { new_hook->prev_hook = NULL; new_hook->next_hook = NULL; weechat_hooks[new_hook->type] = new_hook; last_weechat_hook[new_hook->type] = new_hook; } }
null
0
hook_add_to_list (struct t_hook *new_hook) { struct t_hook *pos_hook; if (weechat_hooks[new_hook->type]) { pos_hook = hook_find_pos (new_hook); if (pos_hook) { /* add hook before "pos_hook" */ new_hook->prev_hook = pos_hook->prev_hook; new_hook->next_hook = pos_hook; if (pos_hook->prev_hook) (pos_hook->prev_hook)->next_hook = new_hook; else weechat_hooks[new_hook->type] = new_hook; pos_hook->prev_hook = new_hook; } else { /* add hook to end of list */ new_hook->prev_hook = last_weechat_hook[new_hook->type]; new_hook->next_hook = NULL; last_weechat_hook[new_hook->type]->next_hook = new_hook; last_weechat_hook[new_hook->type] = new_hook; } } else { new_hook->prev_hook = NULL; new_hook->next_hook = NULL; weechat_hooks[new_hook->type] = new_hook; last_weechat_hook[new_hook->type] = new_hook; } }
@@ -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;
CWE-20
null
null
2,703
hook_command (struct t_weechat_plugin *plugin, const char *command, const char *description, const char *args, const char *args_description, const char *completion, t_hook_callback_command *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_command *new_hook_command; int priority; const char *ptr_command; if (!callback) return NULL; if (hook_search_command (plugin, command)) { gui_chat_printf (NULL, _("%sError: another command \"%s\" already exists " "for plugin \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command, plugin_get_name (plugin)); return NULL; } new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_command = malloc (sizeof (*new_hook_command)); if (!new_hook_command) { free (new_hook); return NULL; } hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority, callback_data); new_hook->hook_data = new_hook_command; new_hook_command->callback = callback; new_hook_command->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); new_hook_command->description = strdup ((description) ? description : ""); new_hook_command->args = strdup ((args) ? args : ""); new_hook_command->args_description = strdup ((args_description) ? args_description : ""); new_hook_command->completion = strdup ((completion) ? completion : ""); /* build completion variables for command */ new_hook_command->cplt_num_templates = 0; new_hook_command->cplt_templates = NULL; new_hook_command->cplt_templates_static = NULL; new_hook_command->cplt_template_num_args = NULL; new_hook_command->cplt_template_args = NULL; new_hook_command->cplt_template_num_args_concat = 0; new_hook_command->cplt_template_args_concat = NULL; hook_command_build_completion (new_hook_command); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_command (struct t_weechat_plugin *plugin, const char *command, const char *description, const char *args, const char *args_description, const char *completion, t_hook_callback_command *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_command *new_hook_command; int priority; const char *ptr_command; if (!callback) return NULL; if (hook_search_command (plugin, command)) { gui_chat_printf (NULL, _("%sError: another command \"%s\" already exists " "for plugin \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], command, plugin_get_name (plugin)); return NULL; } new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_command = malloc (sizeof (*new_hook_command)); if (!new_hook_command) { free (new_hook); return NULL; } hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority, callback_data); new_hook->hook_data = new_hook_command; new_hook_command->callback = callback; new_hook_command->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); new_hook_command->description = strdup ((description) ? description : ""); new_hook_command->args = strdup ((args) ? args : ""); new_hook_command->args_description = strdup ((args_description) ? args_description : ""); new_hook_command->completion = strdup ((completion) ? completion : ""); /* build completion variables for command */ new_hook_command->cplt_num_templates = 0; new_hook_command->cplt_templates = NULL; new_hook_command->cplt_templates_static = NULL; new_hook_command->cplt_template_num_args = NULL; new_hook_command->cplt_template_args = NULL; new_hook_command->cplt_template_num_args_concat = 0; new_hook_command->cplt_template_args_concat = NULL; hook_command_build_completion (new_hook_command); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,704
hook_command_build_completion (struct t_hook_command *hook_command) { int i, j, k, length, num_items; struct t_weelist *list; char *pos_completion, *pos_double_pipe, *pos_start, *pos_end; char **items, *last_space, *ptr_template; /* split templates using "||" as separator */ hook_command->cplt_num_templates = 1; pos_completion = hook_command->completion; while ((pos_double_pipe = strstr (pos_completion, "||")) != NULL) { hook_command->cplt_num_templates++; pos_completion = pos_double_pipe + 2; } hook_command->cplt_templates = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_templates)); for (i = 0; i < hook_command->cplt_num_templates; i++) { hook_command->cplt_templates[i] = NULL; } pos_completion = hook_command->completion; i = 0; while (pos_completion) { pos_double_pipe = strstr (pos_completion, "||"); if (!pos_double_pipe) pos_double_pipe = pos_completion + strlen (pos_completion); pos_start = pos_completion; pos_end = pos_double_pipe - 1; if (pos_end < pos_start) { hook_command->cplt_templates[i] = strdup (""); } else { while (pos_start[0] == ' ') { pos_start++; } pos_end = pos_double_pipe - 1; while ((pos_end > pos_start) && (pos_end[0] == ' ')) { pos_end--; } hook_command->cplt_templates[i] = string_strndup (pos_start, pos_end - pos_start + 1); } i++; if (!pos_double_pipe[0]) pos_completion = NULL; else pos_completion = pos_double_pipe + 2; } /* for each template, split/count args */ hook_command->cplt_templates_static = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_templates_static)); hook_command->cplt_template_num_args = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_template_num_args)); hook_command->cplt_template_args = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_template_args)); hook_command->cplt_template_num_args_concat = 0; for (i = 0; i < hook_command->cplt_num_templates; i++) { /* * build static part of template: it's first argument(s) which does not * contain "%" or "|" */ last_space = NULL; ptr_template = hook_command->cplt_templates[i]; while (ptr_template && ptr_template[0]) { if (ptr_template[0] == ' ') last_space = ptr_template; else if ((ptr_template[0] == '%') || (ptr_template[0] == '|')) break; ptr_template = utf8_next_char (ptr_template); } if (last_space) { last_space--; while (last_space > hook_command->cplt_templates[i]) { if (last_space[0] != ' ') break; } if (last_space < hook_command->cplt_templates[i]) last_space = NULL; else last_space++; } if (last_space) hook_command->cplt_templates_static[i] = string_strndup (hook_command->cplt_templates[i], last_space - hook_command->cplt_templates[i]); else hook_command->cplt_templates_static[i] = strdup (hook_command->cplt_templates[i]); /* build arguments for each template */ hook_command->cplt_template_args[i] = string_split (hook_command->cplt_templates[i], " ", 0, 0, &(hook_command->cplt_template_num_args[i])); if (hook_command->cplt_template_num_args[i] > hook_command->cplt_template_num_args_concat) hook_command->cplt_template_num_args_concat = hook_command->cplt_template_num_args[i]; } /* * build strings with concatentaion of items from different templates * for each argument: these strings will be used when completing argument * if we can't find which template to use (for example for first argument) */ if (hook_command->cplt_template_num_args_concat == 0) hook_command->cplt_template_args_concat = NULL; else { hook_command->cplt_template_args_concat = malloc (hook_command->cplt_template_num_args_concat * sizeof (*hook_command->cplt_template_args_concat)); list = weelist_new (); for (i = 0; i < hook_command->cplt_template_num_args_concat; i++) { /* first compute length */ length = 1; for (j = 0; j < hook_command->cplt_num_templates; j++) { if (i < hook_command->cplt_template_num_args[j]) length += strlen (hook_command->cplt_template_args[j][i]) + 1; } /* alloc memory */ hook_command->cplt_template_args_concat[i] = malloc (length); if (hook_command->cplt_template_args_concat[i]) { /* concatene items with "|" as separator */ weelist_remove_all (list); hook_command->cplt_template_args_concat[i][0] = '\0'; for (j = 0; j < hook_command->cplt_num_templates; j++) { if (i < hook_command->cplt_template_num_args[j]) { items = string_split (hook_command->cplt_template_args[j][i], "|", 0, 0, &num_items); for (k = 0; k < num_items; k++) { if (!weelist_search (list, items[k])) { if (hook_command->cplt_template_args_concat[i][0]) strcat (hook_command->cplt_template_args_concat[i], "|"); strcat (hook_command->cplt_template_args_concat[i], items[k]); weelist_add (list, items[k], WEECHAT_LIST_POS_END, NULL); } } string_free_split (items); } } } } weelist_free (list); } }
null
0
hook_command_build_completion (struct t_hook_command *hook_command) { int i, j, k, length, num_items; struct t_weelist *list; char *pos_completion, *pos_double_pipe, *pos_start, *pos_end; char **items, *last_space, *ptr_template; /* split templates using "||" as separator */ hook_command->cplt_num_templates = 1; pos_completion = hook_command->completion; while ((pos_double_pipe = strstr (pos_completion, "||")) != NULL) { hook_command->cplt_num_templates++; pos_completion = pos_double_pipe + 2; } hook_command->cplt_templates = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_templates)); for (i = 0; i < hook_command->cplt_num_templates; i++) { hook_command->cplt_templates[i] = NULL; } pos_completion = hook_command->completion; i = 0; while (pos_completion) { pos_double_pipe = strstr (pos_completion, "||"); if (!pos_double_pipe) pos_double_pipe = pos_completion + strlen (pos_completion); pos_start = pos_completion; pos_end = pos_double_pipe - 1; if (pos_end < pos_start) { hook_command->cplt_templates[i] = strdup (""); } else { while (pos_start[0] == ' ') { pos_start++; } pos_end = pos_double_pipe - 1; while ((pos_end > pos_start) && (pos_end[0] == ' ')) { pos_end--; } hook_command->cplt_templates[i] = string_strndup (pos_start, pos_end - pos_start + 1); } i++; if (!pos_double_pipe[0]) pos_completion = NULL; else pos_completion = pos_double_pipe + 2; } /* for each template, split/count args */ hook_command->cplt_templates_static = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_templates_static)); hook_command->cplt_template_num_args = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_template_num_args)); hook_command->cplt_template_args = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_template_args)); hook_command->cplt_template_num_args_concat = 0; for (i = 0; i < hook_command->cplt_num_templates; i++) { /* * build static part of template: it's first argument(s) which does not * contain "%" or "|" */ last_space = NULL; ptr_template = hook_command->cplt_templates[i]; while (ptr_template && ptr_template[0]) { if (ptr_template[0] == ' ') last_space = ptr_template; else if ((ptr_template[0] == '%') || (ptr_template[0] == '|')) break; ptr_template = utf8_next_char (ptr_template); } if (last_space) { last_space--; while (last_space > hook_command->cplt_templates[i]) { if (last_space[0] != ' ') break; } if (last_space < hook_command->cplt_templates[i]) last_space = NULL; else last_space++; } if (last_space) hook_command->cplt_templates_static[i] = string_strndup (hook_command->cplt_templates[i], last_space - hook_command->cplt_templates[i]); else hook_command->cplt_templates_static[i] = strdup (hook_command->cplt_templates[i]); /* build arguments for each template */ hook_command->cplt_template_args[i] = string_split (hook_command->cplt_templates[i], " ", 0, 0, &(hook_command->cplt_template_num_args[i])); if (hook_command->cplt_template_num_args[i] > hook_command->cplt_template_num_args_concat) hook_command->cplt_template_num_args_concat = hook_command->cplt_template_num_args[i]; } /* * build strings with concatentaion of items from different templates * for each argument: these strings will be used when completing argument * if we can't find which template to use (for example for first argument) */ if (hook_command->cplt_template_num_args_concat == 0) hook_command->cplt_template_args_concat = NULL; else { hook_command->cplt_template_args_concat = malloc (hook_command->cplt_template_num_args_concat * sizeof (*hook_command->cplt_template_args_concat)); list = weelist_new (); for (i = 0; i < hook_command->cplt_template_num_args_concat; i++) { /* first compute length */ length = 1; for (j = 0; j < hook_command->cplt_num_templates; j++) { if (i < hook_command->cplt_template_num_args[j]) length += strlen (hook_command->cplt_template_args[j][i]) + 1; } /* alloc memory */ hook_command->cplt_template_args_concat[i] = malloc (length); if (hook_command->cplt_template_args_concat[i]) { /* concatene items with "|" as separator */ weelist_remove_all (list); hook_command->cplt_template_args_concat[i][0] = '\0'; for (j = 0; j < hook_command->cplt_num_templates; j++) { if (i < hook_command->cplt_template_num_args[j]) { items = string_split (hook_command->cplt_template_args[j][i], "|", 0, 0, &num_items); for (k = 0; k < num_items; k++) { if (!weelist_search (list, items[k])) { if (hook_command->cplt_template_args_concat[i][0]) strcat (hook_command->cplt_template_args_concat[i], "|"); strcat (hook_command->cplt_template_args_concat[i], items[k]); weelist_add (list, items[k], WEECHAT_LIST_POS_END, NULL); } } string_free_split (items); } } } } weelist_free (list); } }
@@ -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;
CWE-20
null
null
2,705
hook_command_run (struct t_weechat_plugin *plugin, const char *command, t_hook_callback_command_run *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_command_run *new_hook_command_run; int priority; const char *ptr_command; if (!callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_command_run = malloc (sizeof (*new_hook_command_run)); if (!new_hook_command_run) { free (new_hook); return NULL; } hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority, callback_data); new_hook->hook_data = new_hook_command_run; new_hook_command_run->callback = callback; new_hook_command_run->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_command_run (struct t_weechat_plugin *plugin, const char *command, t_hook_callback_command_run *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_command_run *new_hook_command_run; int priority; const char *ptr_command; if (!callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_command_run = malloc (sizeof (*new_hook_command_run)); if (!new_hook_command_run) { free (new_hook); return NULL; } hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority, callback_data); new_hook->hook_data = new_hook_command_run; new_hook_command_run->callback = callback; new_hook_command_run->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,706
hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) { struct t_hook *ptr_hook, *next_hook; int rc, hook_matching, length; char *command2; const char *ptr_command; ptr_command = command; command2 = NULL; if (command[0] != '/') { length = strlen (command) + 1; command2 = malloc (length); if (command2) { snprintf (command2, length, "/%s", command + 1); ptr_command = command2; } } ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && HOOK_COMMAND_RUN(ptr_hook, command)) { hook_matching = string_match (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), 0); if (!hook_matching && !strchr (HOOK_COMMAND_RUN(ptr_hook, command), ' ')) { hook_matching = (string_strncasecmp (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), utf8_strlen (HOOK_COMMAND_RUN(ptr_hook, command))) == 0); } if (hook_matching) { ptr_hook->running = 1; rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data, buffer, ptr_command); ptr_hook->running = 0; if (rc == WEECHAT_RC_OK_EAT) { if (command2) free (command2); return rc; } } } ptr_hook = next_hook; } if (command2) free (command2); return WEECHAT_RC_OK; }
null
0
hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) { struct t_hook *ptr_hook, *next_hook; int rc, hook_matching, length; char *command2; const char *ptr_command; ptr_command = command; command2 = NULL; if (command[0] != '/') { length = strlen (command) + 1; command2 = malloc (length); if (command2) { snprintf (command2, length, "/%s", command + 1); ptr_command = command2; } } ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && HOOK_COMMAND_RUN(ptr_hook, command)) { hook_matching = string_match (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), 0); if (!hook_matching && !strchr (HOOK_COMMAND_RUN(ptr_hook, command), ' ')) { hook_matching = (string_strncasecmp (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), utf8_strlen (HOOK_COMMAND_RUN(ptr_hook, command))) == 0); } if (hook_matching) { ptr_hook->running = 1; rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) (ptr_hook->callback_data, buffer, ptr_command); ptr_hook->running = 0; if (rc == WEECHAT_RC_OK_EAT) { if (command2) free (command2); return rc; } } } ptr_hook = next_hook; } if (command2) free (command2); return WEECHAT_RC_OK; }
@@ -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;
CWE-20
null
null
2,707
hook_completion (struct t_weechat_plugin *plugin, const char *completion_item, const char *description, t_hook_callback_completion *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_completion *new_hook_completion; int priority; const char *ptr_completion_item; if (!completion_item || !completion_item[0] || strchr (completion_item, ' ') || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_completion = malloc (sizeof (*new_hook_completion)); if (!new_hook_completion) { free (new_hook); return NULL; } hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item); hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority, callback_data); new_hook->hook_data = new_hook_completion; new_hook_completion->callback = callback; new_hook_completion->completion_item = strdup ((ptr_completion_item) ? ptr_completion_item : completion_item); new_hook_completion->description = strdup ((description) ? description : ""); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_completion (struct t_weechat_plugin *plugin, const char *completion_item, const char *description, t_hook_callback_completion *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_completion *new_hook_completion; int priority; const char *ptr_completion_item; if (!completion_item || !completion_item[0] || strchr (completion_item, ' ') || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_completion = malloc (sizeof (*new_hook_completion)); if (!new_hook_completion) { free (new_hook); return NULL; } hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item); hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority, callback_data); new_hook->hook_data = new_hook_completion; new_hook_completion->callback = callback; new_hook_completion->completion_item = strdup ((ptr_completion_item) ? ptr_completion_item : completion_item); new_hook_completion->description = strdup ((description) ? description : ""); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,708
hook_completion_exec (struct t_weechat_plugin *plugin, const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { struct t_hook *ptr_hook, *next_hook; /* make C compiler happy */ (void) plugin; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_COMPLETION(ptr_hook, completion_item), completion_item) == 0)) { ptr_hook->running = 1; (void) (HOOK_COMPLETION(ptr_hook, callback)) (ptr_hook->callback_data, completion_item, buffer, completion); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_completion_exec (struct t_weechat_plugin *plugin, const char *completion_item, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { struct t_hook *ptr_hook, *next_hook; /* make C compiler happy */ (void) plugin; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_COMPLETION(ptr_hook, completion_item), completion_item) == 0)) { ptr_hook->running = 1; (void) (HOOK_COMPLETION(ptr_hook, callback)) (ptr_hook->callback_data, completion_item, buffer, completion); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,709
hook_completion_get_string (struct t_gui_completion *completion, const char *property) { return gui_completion_get_string (completion, property); }
null
0
hook_completion_get_string (struct t_gui_completion *completion, const char *property) { return gui_completion_get_string (completion, property); }
@@ -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;
CWE-20
null
null
2,710
hook_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where) { gui_completion_list_add (completion, word, nick_completion, where); }
null
0
hook_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where) { gui_completion_list_add (completion, word, nick_completion, where); }
@@ -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;
CWE-20
null
null
2,711
hook_config_exec (const char *option, const char *value) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_CONFIG(ptr_hook, option) || (string_match (option, HOOK_CONFIG(ptr_hook, option), 0)))) { ptr_hook->running = 1; (void) (HOOK_CONFIG(ptr_hook, callback)) (ptr_hook->callback_data, option, value); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_config_exec (const char *option, const char *value) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_CONFIG(ptr_hook, option) || (string_match (option, HOOK_CONFIG(ptr_hook, option), 0)))) { ptr_hook->running = 1; (void) (HOOK_CONFIG(ptr_hook, callback)) (ptr_hook->callback_data, option, value); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,712
hook_connect (struct t_weechat_plugin *plugin, const char *proxy, const char *address, int port, int sock, int ipv6, void *gnutls_sess, void *gnutls_cb, int gnutls_dhkey_size, const char *local_hostname, t_hook_callback_connect *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_connect *new_hook_connect; #ifndef HAVE_GNUTLS /* make C compiler happy */ (void) gnutls_sess; (void) gnutls_cb; (void) gnutls_dhkey_size; #endif if ((sock < 0) || !address || (port <= 0) || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_connect = malloc (sizeof (*new_hook_connect)); if (!new_hook_connect) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_CONNECT, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_connect; new_hook_connect->callback = callback; new_hook_connect->proxy = (proxy) ? strdup (proxy) : NULL; new_hook_connect->address = strdup (address); new_hook_connect->port = port; new_hook_connect->sock = sock; new_hook_connect->ipv6 = ipv6; #ifdef HAVE_GNUTLS new_hook_connect->gnutls_sess = gnutls_sess; new_hook_connect->gnutls_cb = gnutls_cb; new_hook_connect->gnutls_dhkey_size = gnutls_dhkey_size; #endif new_hook_connect->local_hostname = (local_hostname) ? strdup (local_hostname) : NULL; new_hook_connect->child_read = -1; new_hook_connect->child_write = -1; new_hook_connect->child_pid = 0; new_hook_connect->hook_fd = NULL; new_hook_connect->handshake_hook_fd = NULL; new_hook_connect->handshake_hook_timer = NULL; new_hook_connect->handshake_fd_flags = 0; new_hook_connect->handshake_ip_address = NULL; hook_add_to_list (new_hook); network_connect_with_fork (new_hook); return new_hook; }
null
0
hook_connect (struct t_weechat_plugin *plugin, const char *proxy, const char *address, int port, int sock, int ipv6, void *gnutls_sess, void *gnutls_cb, int gnutls_dhkey_size, const char *local_hostname, t_hook_callback_connect *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_connect *new_hook_connect; #ifndef HAVE_GNUTLS /* make C compiler happy */ (void) gnutls_sess; (void) gnutls_cb; (void) gnutls_dhkey_size; #endif if ((sock < 0) || !address || (port <= 0) || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_connect = malloc (sizeof (*new_hook_connect)); if (!new_hook_connect) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_CONNECT, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_connect; new_hook_connect->callback = callback; new_hook_connect->proxy = (proxy) ? strdup (proxy) : NULL; new_hook_connect->address = strdup (address); new_hook_connect->port = port; new_hook_connect->sock = sock; new_hook_connect->ipv6 = ipv6; #ifdef HAVE_GNUTLS new_hook_connect->gnutls_sess = gnutls_sess; new_hook_connect->gnutls_cb = gnutls_cb; new_hook_connect->gnutls_dhkey_size = gnutls_dhkey_size; #endif new_hook_connect->local_hostname = (local_hostname) ? strdup (local_hostname) : NULL; new_hook_connect->child_read = -1; new_hook_connect->child_write = -1; new_hook_connect->child_pid = 0; new_hook_connect->hook_fd = NULL; new_hook_connect->handshake_hook_fd = NULL; new_hook_connect->handshake_hook_timer = NULL; new_hook_connect->handshake_fd_flags = 0; new_hook_connect->handshake_ip_address = NULL; hook_add_to_list (new_hook); network_connect_with_fork (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,713
hook_exec_end () { if (hook_exec_recursion > 0) hook_exec_recursion--; if (hook_exec_recursion == 0) hook_remove_deleted (); }
null
0
hook_exec_end () { if (hook_exec_recursion > 0) hook_exec_recursion--; if (hook_exec_recursion == 0) hook_remove_deleted (); }
@@ -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;
CWE-20
null
null
2,714
hook_exec_start () { hook_exec_recursion++; }
null
0
hook_exec_start () { hook_exec_recursion++; }
@@ -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;
CWE-20
null
null
2,715
hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, int flag_write, int flag_exception, t_hook_callback_fd *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_fd *new_hook_fd; if ((fd < 0) || hook_search_fd (fd) || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_fd = malloc (sizeof (*new_hook_fd)); if (!new_hook_fd) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_fd; new_hook_fd->callback = callback; new_hook_fd->fd = fd; new_hook_fd->flags = 0; if (flag_read) new_hook_fd->flags |= HOOK_FD_FLAG_READ; if (flag_write) new_hook_fd->flags |= HOOK_FD_FLAG_WRITE; if (flag_exception) new_hook_fd->flags |= HOOK_FD_FLAG_EXCEPTION; hook_add_to_list (new_hook); return new_hook; }
null
0
hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, int flag_write, int flag_exception, t_hook_callback_fd *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_fd *new_hook_fd; if ((fd < 0) || hook_search_fd (fd) || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_fd = malloc (sizeof (*new_hook_fd)); if (!new_hook_fd) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_fd; new_hook_fd->callback = callback; new_hook_fd->fd = fd; new_hook_fd->flags = 0; if (flag_read) new_hook_fd->flags |= HOOK_FD_FLAG_READ; if (flag_write) new_hook_fd->flags |= HOOK_FD_FLAG_WRITE; if (flag_exception) new_hook_fd->flags |= HOOK_FD_FLAG_EXCEPTION; hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,716
hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_FD]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) && (FD_ISSET(HOOK_FD(ptr_hook, fd), read_fds))) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) && (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds))) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) && (FD_ISSET(HOOK_FD(ptr_hook, fd), exception_fds))))) { ptr_hook->running = 1; (void) (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data, HOOK_FD(ptr_hook, fd)); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_FD]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) && (FD_ISSET(HOOK_FD(ptr_hook, fd), read_fds))) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) && (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds))) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) && (FD_ISSET(HOOK_FD(ptr_hook, fd), exception_fds))))) { ptr_hook->running = 1; (void) (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data, HOOK_FD(ptr_hook, fd)); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,717
hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook; int max_fd; max_fd = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) { if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) { FD_SET (HOOK_FD(ptr_hook, fd), read_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) { FD_SET (HOOK_FD(ptr_hook, fd), write_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) { FD_SET (HOOK_FD(ptr_hook, fd), exception_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } } } return max_fd; }
null
0
hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook; int max_fd; max_fd = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) { if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) { FD_SET (HOOK_FD(ptr_hook, fd), read_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) { FD_SET (HOOK_FD(ptr_hook, fd), write_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) { FD_SET (HOOK_FD(ptr_hook, fd), exception_fds); if (HOOK_FD(ptr_hook, fd) > max_fd) max_fd = HOOK_FD(ptr_hook, fd); } } } return max_fd; }
@@ -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;
CWE-20
null
null
2,718
hook_find_pos (struct t_hook *hook) { struct t_hook *ptr_hook; int rc_cmp; if (hook->type == HOOK_TYPE_COMMAND) { /* for command hook, sort on command name */ for (ptr_hook = weechat_hooks[hook->type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) { rc_cmp = string_strcasecmp (HOOK_COMMAND(hook, command), HOOK_COMMAND(ptr_hook, command)); if (rc_cmp < 0) return ptr_hook; if ((rc_cmp == 0) && (hook->priority > ptr_hook->priority)) return ptr_hook; } } } else { /* for other types, sort on priority */ for (ptr_hook = weechat_hooks[hook->type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (hook->priority > ptr_hook->priority)) return ptr_hook; } } /* position not found, add at the end */ return NULL; }
null
0
hook_find_pos (struct t_hook *hook) { struct t_hook *ptr_hook; int rc_cmp; if (hook->type == HOOK_TYPE_COMMAND) { /* for command hook, sort on command name */ for (ptr_hook = weechat_hooks[hook->type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) { rc_cmp = string_strcasecmp (HOOK_COMMAND(hook, command), HOOK_COMMAND(ptr_hook, command)); if (rc_cmp < 0) return ptr_hook; if ((rc_cmp == 0) && (hook->priority > ptr_hook->priority)) return ptr_hook; } } } else { /* for other types, sort on priority */ for (ptr_hook = weechat_hooks[hook->type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (hook->priority > ptr_hook->priority)) return ptr_hook; } } /* position not found, add at the end */ return NULL; }
@@ -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;
CWE-20
null
null
2,719
hook_get_priority_and_name (const char *name, int *priority, const char **ptr_name) { char *pos, *str_priority, *error; long number; if (priority) *priority = HOOK_PRIORITY_DEFAULT; if (ptr_name) *ptr_name = name; pos = strchr (name, '|'); if (pos) { str_priority = string_strndup (name, pos - name); if (str_priority) { error = NULL; number = strtol (str_priority, &error, 10); if (error && !error[0]) { if (priority) *priority = number; if (ptr_name) *ptr_name = pos + 1; } free (str_priority); } } }
null
0
hook_get_priority_and_name (const char *name, int *priority, const char **ptr_name) { char *pos, *str_priority, *error; long number; if (priority) *priority = HOOK_PRIORITY_DEFAULT; if (ptr_name) *ptr_name = name; pos = strchr (name, '|'); if (pos) { str_priority = string_strndup (name, pos - name); if (str_priority) { error = NULL; number = strtol (str_priority, &error, 10); if (error && !error[0]) { if (priority) *priority = number; if (ptr_name) *ptr_name = pos + 1; } free (str_priority); } } }
@@ -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;
CWE-20
null
null
2,720
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0))) { ptr_hook->running = 1; (void) (HOOK_HSIGNAL(ptr_hook, callback)) (ptr_hook->callback_data, signal, hashtable); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_hsignal_send (const char *signal, struct t_hashtable *hashtable) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0))) { ptr_hook->running = 1; (void) (HOOK_HSIGNAL(ptr_hook, callback)) (ptr_hook->callback_data, signal, hashtable); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,721
hook_info (struct t_weechat_plugin *plugin, const char *info_name, const char *description, const char *args_description, t_hook_callback_info *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_info *new_hook_info; int priority; const char *ptr_info_name; if (!info_name || !info_name[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_info = malloc (sizeof (*new_hook_info)); if (!new_hook_info) { free (new_hook); return NULL; } hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data); new_hook->hook_data = new_hook_info; new_hook_info->callback = callback; new_hook_info->info_name = strdup ((ptr_info_name) ? ptr_info_name : info_name); new_hook_info->description = strdup ((description) ? description : ""); new_hook_info->args_description = strdup ((args_description) ? args_description : ""); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_info (struct t_weechat_plugin *plugin, const char *info_name, const char *description, const char *args_description, t_hook_callback_info *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_info *new_hook_info; int priority; const char *ptr_info_name; if (!info_name || !info_name[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_info = malloc (sizeof (*new_hook_info)); if (!new_hook_info) { free (new_hook); return NULL; } hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data); new_hook->hook_data = new_hook_info; new_hook_info->callback = callback; new_hook_info->info_name = strdup ((ptr_info_name) ? ptr_info_name : info_name); new_hook_info->description = strdup ((description) ? description : ""); new_hook_info->args_description = strdup ((args_description) ? args_description : ""); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,722
hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name, struct t_hashtable *hashtable) { struct t_hook *ptr_hook, *next_hook; struct t_hashtable *value; /* make C compiler happy */ (void) plugin; if (!info_name || !info_name[0]) return NULL; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name), info_name) == 0)) { ptr_hook->running = 1; value = (HOOK_INFO_HASHTABLE(ptr_hook, callback)) (ptr_hook->callback_data, info_name, hashtable); ptr_hook->running = 0; hook_exec_end (); return value; } ptr_hook = next_hook; } hook_exec_end (); /* info not found */ return NULL; }
null
0
hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name, struct t_hashtable *hashtable) { struct t_hook *ptr_hook, *next_hook; struct t_hashtable *value; /* make C compiler happy */ (void) plugin; if (!info_name || !info_name[0]) return NULL; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name), info_name) == 0)) { ptr_hook->running = 1; value = (HOOK_INFO_HASHTABLE(ptr_hook, callback)) (ptr_hook->callback_data, info_name, hashtable); ptr_hook->running = 0; hook_exec_end (); return value; } ptr_hook = next_hook; } hook_exec_end (); /* info not found */ return NULL; }
@@ -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;
CWE-20
null
null
2,723
hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, const char *description, const char *args_description, const char *output_description, t_hook_callback_info_hashtable *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_info_hashtable *new_hook_info_hashtable; int priority; const char *ptr_info_name; if (!info_name || !info_name[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_info_hashtable = malloc (sizeof (*new_hook_info_hashtable)); if (!new_hook_info_hashtable) { free (new_hook); return NULL; } hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority, callback_data); new_hook->hook_data = new_hook_info_hashtable; new_hook_info_hashtable->callback = callback; new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ? ptr_info_name : info_name); new_hook_info_hashtable->description = strdup ((description) ? description : ""); new_hook_info_hashtable->args_description = strdup ((args_description) ? args_description : ""); new_hook_info_hashtable->output_description = strdup ((output_description) ? output_description : ""); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, const char *description, const char *args_description, const char *output_description, t_hook_callback_info_hashtable *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_info_hashtable *new_hook_info_hashtable; int priority; const char *ptr_info_name; if (!info_name || !info_name[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_info_hashtable = malloc (sizeof (*new_hook_info_hashtable)); if (!new_hook_info_hashtable) { free (new_hook); return NULL; } hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority, callback_data); new_hook->hook_data = new_hook_info_hashtable; new_hook_info_hashtable->callback = callback; new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ? ptr_info_name : info_name); new_hook_info_hashtable->description = strdup ((description) ? description : ""); new_hook_info_hashtable->args_description = strdup ((args_description) ? args_description : ""); new_hook_info_hashtable->output_description = strdup ((output_description) ? output_description : ""); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,724
hook_init () { int type; for (type = 0; type < HOOK_NUM_TYPES; type++) { weechat_hooks[type] = NULL; last_weechat_hook[type] = NULL; } hook_last_system_time = time (NULL); }
null
0
hook_init () { int type; for (type = 0; type < HOOK_NUM_TYPES; type++) { weechat_hooks[type] = NULL; last_weechat_hook[type] = NULL; } hook_last_system_time = time (NULL); }
@@ -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;
CWE-20
null
null
2,725
hook_modifier (struct t_weechat_plugin *plugin, const char *modifier, t_hook_callback_modifier *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_modifier *new_hook_modifier; int priority; const char *ptr_modifier; if (!modifier || !modifier[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_modifier = malloc (sizeof (*new_hook_modifier)); if (!new_hook_modifier) { free (new_hook); return NULL; } hook_get_priority_and_name (modifier, &priority, &ptr_modifier); hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority, callback_data); new_hook->hook_data = new_hook_modifier; new_hook_modifier->callback = callback; new_hook_modifier->modifier = strdup ((ptr_modifier) ? ptr_modifier : modifier); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_modifier (struct t_weechat_plugin *plugin, const char *modifier, t_hook_callback_modifier *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_modifier *new_hook_modifier; int priority; const char *ptr_modifier; if (!modifier || !modifier[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_modifier = malloc (sizeof (*new_hook_modifier)); if (!new_hook_modifier) { free (new_hook); return NULL; } hook_get_priority_and_name (modifier, &priority, &ptr_modifier); hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority, callback_data); new_hook->hook_data = new_hook_modifier; new_hook_modifier->callback = callback; new_hook_modifier->modifier = strdup ((ptr_modifier) ? ptr_modifier : modifier); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,726
hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, const char *modifier_data, const char *string) { struct t_hook *ptr_hook, *next_hook; char *new_msg, *message_modified; /* make C compiler happy */ (void) plugin; if (!modifier || !modifier[0]) return NULL; new_msg = NULL; message_modified = strdup (string); if (!message_modified) return NULL; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier), modifier) == 0)) { ptr_hook->running = 1; new_msg = (HOOK_MODIFIER(ptr_hook, callback)) (ptr_hook->callback_data, modifier, modifier_data, message_modified); ptr_hook->running = 0; /* empty string returned => message dropped */ if (new_msg && !new_msg[0]) { free (message_modified); hook_exec_end (); return new_msg; } /* new message => keep it as base for next modifier */ if (new_msg) { free (message_modified); message_modified = new_msg; } } ptr_hook = next_hook; } hook_exec_end (); return message_modified; }
null
0
hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, const char *modifier_data, const char *string) { struct t_hook *ptr_hook, *next_hook; char *new_msg, *message_modified; /* make C compiler happy */ (void) plugin; if (!modifier || !modifier[0]) return NULL; new_msg = NULL; message_modified = strdup (string); if (!message_modified) return NULL; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier), modifier) == 0)) { ptr_hook->running = 1; new_msg = (HOOK_MODIFIER(ptr_hook, callback)) (ptr_hook->callback_data, modifier, modifier_data, message_modified); ptr_hook->running = 0; /* empty string returned => message dropped */ if (new_msg && !new_msg[0]) { free (message_modified); hook_exec_end (); return new_msg; } /* new message => keep it as base for next modifier */ if (new_msg) { free (message_modified); message_modified = new_msg; } } ptr_hook = next_hook; } hook_exec_end (); return message_modified; }
@@ -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;
CWE-20
null
null
2,727
hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) { struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; int tags_match, tag_found, i, j; if (!line->data->message || !line->data->message[0]) return; prefix_no_color = (line->data->prefix) ? gui_color_decode (line->data->prefix, NULL) : NULL; message_no_color = gui_color_decode (line->data->message, NULL); if (!message_no_color) { if (prefix_no_color) free (prefix_no_color); return; } hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_PRINT]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_PRINT(ptr_hook, buffer) || (buffer == HOOK_PRINT(ptr_hook, buffer))) && (!HOOK_PRINT(ptr_hook, message) || !HOOK_PRINT(ptr_hook, message)[0] || string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message)) || string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message)))) { /* check if tags match */ if (HOOK_PRINT(ptr_hook, tags_array)) { /* if there are tags in message printed */ if (line->data->tags_array) { tags_match = 1; for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++) { /* search for tag in message */ tag_found = 0; for (j = 0; j < line->data->tags_count; j++) { if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i], line->data->tags_array[j]) == 0) { tag_found = 1; break; } } /* tag was asked by hook but not found in message? */ if (!tag_found) { tags_match = 0; break; } } } else tags_match = 0; } else tags_match = 1; /* run callback */ if (tags_match) { ptr_hook->running = 1; (void) (HOOK_PRINT(ptr_hook, callback)) (ptr_hook->callback_data, buffer, line->data->date, line->data->tags_count, (const char **)line->data->tags_array, (int)line->data->displayed, (int)line->data->highlight, (HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix, (HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message); ptr_hook->running = 0; } } ptr_hook = next_hook; } if (prefix_no_color) free (prefix_no_color); if (message_no_color) free (message_no_color); hook_exec_end (); }
null
0
hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) { struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; int tags_match, tag_found, i, j; if (!line->data->message || !line->data->message[0]) return; prefix_no_color = (line->data->prefix) ? gui_color_decode (line->data->prefix, NULL) : NULL; message_no_color = gui_color_decode (line->data->message, NULL); if (!message_no_color) { if (prefix_no_color) free (prefix_no_color); return; } hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_PRINT]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_PRINT(ptr_hook, buffer) || (buffer == HOOK_PRINT(ptr_hook, buffer))) && (!HOOK_PRINT(ptr_hook, message) || !HOOK_PRINT(ptr_hook, message)[0] || string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message)) || string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message)))) { /* check if tags match */ if (HOOK_PRINT(ptr_hook, tags_array)) { /* if there are tags in message printed */ if (line->data->tags_array) { tags_match = 1; for (i = 0; i < HOOK_PRINT(ptr_hook, tags_count); i++) { /* search for tag in message */ tag_found = 0; for (j = 0; j < line->data->tags_count; j++) { if (string_strcasecmp (HOOK_PRINT(ptr_hook, tags_array)[i], line->data->tags_array[j]) == 0) { tag_found = 1; break; } } /* tag was asked by hook but not found in message? */ if (!tag_found) { tags_match = 0; break; } } } else tags_match = 0; } else tags_match = 1; /* run callback */ if (tags_match) { ptr_hook->running = 1; (void) (HOOK_PRINT(ptr_hook, callback)) (ptr_hook->callback_data, buffer, line->data->date, line->data->tags_count, (const char **)line->data->tags_array, (int)line->data->displayed, (int)line->data->highlight, (HOOK_PRINT(ptr_hook, strip_colors)) ? prefix_no_color : line->data->prefix, (HOOK_PRINT(ptr_hook, strip_colors)) ? message_no_color : line->data->message); ptr_hook->running = 0; } } ptr_hook = next_hook; } if (prefix_no_color) free (prefix_no_color); if (message_no_color) free (message_no_color); hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,728
hook_process (struct t_weechat_plugin *plugin, const char *command, int timeout, t_hook_callback_process *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_process *new_hook_process; char *stdout_buffer, *stderr_buffer; if (!command || !command[0] || !callback) return NULL; stdout_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stdout_buffer) return NULL; stderr_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stderr_buffer) { free (stdout_buffer); return NULL; } new_hook = malloc (sizeof (*new_hook)); if (!new_hook) { free (stdout_buffer); free (stderr_buffer); return NULL; } new_hook_process = malloc (sizeof (*new_hook_process)); if (!new_hook_process) { free (stdout_buffer); free (stderr_buffer); free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_PROCESS, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_process; new_hook_process->callback = callback; new_hook_process->command = strdup (command); new_hook_process->timeout = timeout; new_hook_process->child_read[HOOK_PROCESS_STDOUT] = -1; new_hook_process->child_read[HOOK_PROCESS_STDERR] = -1; new_hook_process->child_write[HOOK_PROCESS_STDOUT] = -1; new_hook_process->child_write[HOOK_PROCESS_STDERR] = -1; new_hook_process->child_pid = 0; new_hook_process->hook_fd[HOOK_PROCESS_STDOUT] = NULL; new_hook_process->hook_fd[HOOK_PROCESS_STDERR] = NULL; new_hook_process->hook_timer = NULL; new_hook_process->buffer[HOOK_PROCESS_STDOUT] = stdout_buffer; new_hook_process->buffer[HOOK_PROCESS_STDERR] = stderr_buffer; new_hook_process->buffer_size[HOOK_PROCESS_STDOUT] = 0; new_hook_process->buffer_size[HOOK_PROCESS_STDERR] = 0; hook_add_to_list (new_hook); hook_process_run (new_hook); return new_hook; }
null
0
hook_process (struct t_weechat_plugin *plugin, const char *command, int timeout, t_hook_callback_process *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_process *new_hook_process; char *stdout_buffer, *stderr_buffer; if (!command || !command[0] || !callback) return NULL; stdout_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stdout_buffer) return NULL; stderr_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stderr_buffer) { free (stdout_buffer); return NULL; } new_hook = malloc (sizeof (*new_hook)); if (!new_hook) { free (stdout_buffer); free (stderr_buffer); return NULL; } new_hook_process = malloc (sizeof (*new_hook_process)); if (!new_hook_process) { free (stdout_buffer); free (stderr_buffer); free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_PROCESS, HOOK_PRIORITY_DEFAULT, callback_data); new_hook->hook_data = new_hook_process; new_hook_process->callback = callback; new_hook_process->command = strdup (command); new_hook_process->timeout = timeout; new_hook_process->child_read[HOOK_PROCESS_STDOUT] = -1; new_hook_process->child_read[HOOK_PROCESS_STDERR] = -1; new_hook_process->child_write[HOOK_PROCESS_STDOUT] = -1; new_hook_process->child_write[HOOK_PROCESS_STDERR] = -1; new_hook_process->child_pid = 0; new_hook_process->hook_fd[HOOK_PROCESS_STDOUT] = NULL; new_hook_process->hook_fd[HOOK_PROCESS_STDERR] = NULL; new_hook_process->hook_timer = NULL; new_hook_process->buffer[HOOK_PROCESS_STDOUT] = stdout_buffer; new_hook_process->buffer[HOOK_PROCESS_STDERR] = stderr_buffer; new_hook_process->buffer_size[HOOK_PROCESS_STDOUT] = 0; new_hook_process->buffer_size[HOOK_PROCESS_STDERR] = 0; hook_add_to_list (new_hook); hook_process_run (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,729
hook_process_add_to_buffer (struct t_hook *hook_process, int index_buffer, const char *buffer, int size) { if (HOOK_PROCESS(hook_process, buffer_size[index_buffer]) + size > HOOK_PROCESS_BUFFER_SIZE) hook_process_send_buffers (hook_process, WEECHAT_HOOK_PROCESS_RUNNING); memcpy (HOOK_PROCESS(hook_process, buffer[index_buffer]) + HOOK_PROCESS(hook_process, buffer_size[index_buffer]), buffer, size); HOOK_PROCESS(hook_process, buffer_size[index_buffer]) += size; }
null
0
hook_process_add_to_buffer (struct t_hook *hook_process, int index_buffer, const char *buffer, int size) { if (HOOK_PROCESS(hook_process, buffer_size[index_buffer]) + size > HOOK_PROCESS_BUFFER_SIZE) hook_process_send_buffers (hook_process, WEECHAT_HOOK_PROCESS_RUNNING); memcpy (HOOK_PROCESS(hook_process, buffer[index_buffer]) + HOOK_PROCESS(hook_process, buffer_size[index_buffer]), buffer, size); HOOK_PROCESS(hook_process, buffer_size[index_buffer]) += size; }
@@ -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;
CWE-20
null
null
2,730
hook_process_child (struct t_hook *hook_process) { char *exec_args[4] = { "sh", "-c", NULL, NULL }; /* * close stdin, so that process will fail to read stdin (process reading * stdin should not be run inside WeeChat!) */ close (STDIN_FILENO); /* redirect stdout/stderr to pipe (so that father process can read them) */ close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT])); close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR])); if (dup2 (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]), STDOUT_FILENO) < 0) { _exit (EXIT_FAILURE); } if (dup2 (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]), STDERR_FILENO) < 0) { _exit (EXIT_FAILURE); } /* launch command */ exec_args[2] = HOOK_PROCESS(hook_process, command); execvp (exec_args[0], exec_args); /* should not be executed if execvp was ok */ fprintf (stderr, "Error with command '%s'\n", HOOK_PROCESS(hook_process, command)); _exit (EXIT_FAILURE); }
null
0
hook_process_child (struct t_hook *hook_process) { char *exec_args[4] = { "sh", "-c", NULL, NULL }; /* * close stdin, so that process will fail to read stdin (process reading * stdin should not be run inside WeeChat!) */ close (STDIN_FILENO); /* redirect stdout/stderr to pipe (so that father process can read them) */ close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT])); close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR])); if (dup2 (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]), STDOUT_FILENO) < 0) { _exit (EXIT_FAILURE); } if (dup2 (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]), STDERR_FILENO) < 0) { _exit (EXIT_FAILURE); } /* launch command */ exec_args[2] = HOOK_PROCESS(hook_process, command); execvp (exec_args[0], exec_args); /* should not be executed if execvp was ok */ fprintf (stderr, "Error with command '%s'\n", HOOK_PROCESS(hook_process, command)); _exit (EXIT_FAILURE); }
@@ -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;
CWE-20
null
null
2,731
hook_process_child_read (struct t_hook *hook_process, int fd, int index_buffer, struct t_hook **hook_fd) { char buffer[4096]; int num_read; if (hook_process->deleted) return; num_read = read (fd, buffer, sizeof (buffer) - 1); if (num_read > 0) { hook_process_add_to_buffer (hook_process, index_buffer, buffer, num_read); } else if (num_read == 0) { unhook (*hook_fd); *hook_fd = NULL; } }
null
0
hook_process_child_read (struct t_hook *hook_process, int fd, int index_buffer, struct t_hook **hook_fd) { char buffer[4096]; int num_read; if (hook_process->deleted) return; num_read = read (fd, buffer, sizeof (buffer) - 1); if (num_read > 0) { hook_process_add_to_buffer (hook_process, index_buffer, buffer, num_read); } else if (num_read == 0) { unhook (*hook_fd); *hook_fd = NULL; } }
@@ -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;
CWE-20
null
null
2,732
hook_process_child_read_stderr_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDERR, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]))); return WEECHAT_RC_OK; }
null
0
hook_process_child_read_stderr_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDERR, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]))); return WEECHAT_RC_OK; }
@@ -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;
CWE-20
null
null
2,733
hook_process_child_read_stdout_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDOUT, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]))); return WEECHAT_RC_OK; }
null
0
hook_process_child_read_stdout_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDOUT, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]))); return WEECHAT_RC_OK; }
@@ -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;
CWE-20
null
null
2,734
hook_process_run (struct t_hook *hook_process) { int pipe_stdout[2], pipe_stderr[2], timeout, max_calls; long interval; pid_t pid; /* create pipe for child process (stdout) */ if (pipe (pipe_stdout) < 0) { (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; } if (pipe (pipe_stderr) < 0) { close (pipe_stdout[0]); close (pipe_stdout[1]); (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; } HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]) = pipe_stdout[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = pipe_stdout[1]; HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]) = pipe_stderr[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = pipe_stderr[1]; switch (pid = fork ()) { /* fork failed */ case -1: (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; /* child process */ case 0: setuid (getuid ()); hook_process_child (hook_process); /* never executed */ _exit (EXIT_SUCCESS); break; } /* parent process */ HOOK_PROCESS(hook_process, child_pid) = pid; close (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT])); HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = -1; close (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR])); HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = -1; HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]), 1, 0, 0, &hook_process_child_read_stdout_cb, hook_process); HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]), 1, 0, 0, &hook_process_child_read_stderr_cb, hook_process); timeout = HOOK_PROCESS(hook_process, timeout); interval = 100; max_calls = 0; if (timeout > 0) { if (timeout <= 100) { interval = timeout; max_calls = 1; } else { interval = 100; max_calls = timeout / 100; if (timeout % 100 == 0) max_calls++; } } HOOK_PROCESS(hook_process, hook_timer) = hook_timer (hook_process->plugin, interval, 0, max_calls, &hook_process_timer_cb, hook_process); }
null
0
hook_process_run (struct t_hook *hook_process) { int pipe_stdout[2], pipe_stderr[2], timeout, max_calls; long interval; pid_t pid; /* create pipe for child process (stdout) */ if (pipe (pipe_stdout) < 0) { (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; } if (pipe (pipe_stderr) < 0) { close (pipe_stdout[0]); close (pipe_stdout[1]); (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; } HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]) = pipe_stdout[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = pipe_stdout[1]; HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]) = pipe_stderr[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = pipe_stderr[1]; switch (pid = fork ()) { /* fork failed */ case -1: (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), WEECHAT_HOOK_PROCESS_ERROR, NULL, NULL); unhook (hook_process); return; /* child process */ case 0: setuid (getuid ()); hook_process_child (hook_process); /* never executed */ _exit (EXIT_SUCCESS); break; } /* parent process */ HOOK_PROCESS(hook_process, child_pid) = pid; close (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT])); HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = -1; close (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR])); HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = -1; HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]), 1, 0, 0, &hook_process_child_read_stdout_cb, hook_process); HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]), 1, 0, 0, &hook_process_child_read_stderr_cb, hook_process); timeout = HOOK_PROCESS(hook_process, timeout); interval = 100; max_calls = 0; if (timeout > 0) { if (timeout <= 100) { interval = timeout; max_calls = 1; } else { interval = 100; max_calls = timeout / 100; if (timeout % 100 == 0) max_calls++; } } HOOK_PROCESS(hook_process, hook_timer) = hook_timer (hook_process->plugin, interval, 0, max_calls, &hook_process_timer_cb, hook_process); }
@@ -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;
CWE-20
null
null
2,735
hook_process_send_buffers (struct t_hook *hook_process, int callback_rc) { int i, size; /* add '\0' at end of stdout and stderr */ for (i = 0; i < 2; i++) { size = HOOK_PROCESS(hook_process, buffer_size[i]); if (size > 0) HOOK_PROCESS(hook_process, buffer[i])[size] = '\0'; } /* send buffers to callback */ (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), callback_rc, (HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) > 0) ? HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDOUT]) : NULL, (HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) > 0) ? HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDERR]) : NULL); /* reset size for stdout and stderr */ HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) = 0; HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) = 0; }
null
0
hook_process_send_buffers (struct t_hook *hook_process, int callback_rc) { int i, size; /* add '\0' at end of stdout and stderr */ for (i = 0; i < 2; i++) { size = HOOK_PROCESS(hook_process, buffer_size[i]); if (size > 0) HOOK_PROCESS(hook_process, buffer[i])[size] = '\0'; } /* send buffers to callback */ (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, HOOK_PROCESS(hook_process, command), callback_rc, (HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) > 0) ? HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDOUT]) : NULL, (HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) > 0) ? HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDERR]) : NULL); /* reset size for stdout and stderr */ HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) = 0; HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) = 0; }
@@ -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;
CWE-20
null
null
2,736
hook_remove_from_list (struct t_hook *hook) { struct t_hook *new_hooks; int type; type = hook->type; if (last_weechat_hook[hook->type] == hook) last_weechat_hook[hook->type] = hook->prev_hook; if (hook->prev_hook) { (hook->prev_hook)->next_hook = hook->next_hook; new_hooks = weechat_hooks[hook->type]; } else new_hooks = hook->next_hook; if (hook->next_hook) (hook->next_hook)->prev_hook = hook->prev_hook; free (hook); weechat_hooks[type] = new_hooks; }
null
0
hook_remove_from_list (struct t_hook *hook) { struct t_hook *new_hooks; int type; type = hook->type; if (last_weechat_hook[hook->type] == hook) last_weechat_hook[hook->type] = hook->prev_hook; if (hook->prev_hook) { (hook->prev_hook)->next_hook = hook->next_hook; new_hooks = weechat_hooks[hook->type]; } else new_hooks = hook->next_hook; if (hook->next_hook) (hook->next_hook)->prev_hook = hook->prev_hook; free (hook); weechat_hooks[type] = new_hooks; }
@@ -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;
CWE-20
null
null
2,737
hook_search_fd (int fd) { struct t_hook *ptr_hook; for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (HOOK_FD(ptr_hook, fd) == fd)) return ptr_hook; } /* fd hook not found */ return NULL; }
null
0
hook_search_fd (int fd) { struct t_hook *ptr_hook; for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (HOOK_FD(ptr_hook, fd) == fd)) return ptr_hook; } /* fd hook not found */ return NULL; }
@@ -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;
CWE-20
null
null
2,738
hook_search_type (const char *type) { int i; if (!type) return -1; for (i = 0; i < HOOK_NUM_TYPES; i++) { if (strcmp (hook_type_string[i], type) == 0) return i; } /* type not found */ return -1; }
null
0
hook_search_type (const char *type) { int i; if (!type) return -1; for (i = 0; i < HOOK_NUM_TYPES; i++) { if (strcmp (hook_type_string[i], type) == 0) return i; } /* type not found */ return -1; }
@@ -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;
CWE-20
null
null
2,739
hook_signal (struct t_weechat_plugin *plugin, const char *signal, t_hook_callback_signal *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_signal *new_hook_signal; int priority; const char *ptr_signal; if (!signal || !signal[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_signal = malloc (sizeof (*new_hook_signal)); if (!new_hook_signal) { free (new_hook); return NULL; } hook_get_priority_and_name (signal, &priority, &ptr_signal); hook_init_data (new_hook, plugin, HOOK_TYPE_SIGNAL, priority, callback_data); new_hook->hook_data = new_hook_signal; new_hook_signal->callback = callback; new_hook_signal->signal = strdup ((ptr_signal) ? ptr_signal : signal); hook_add_to_list (new_hook); return new_hook; }
null
0
hook_signal (struct t_weechat_plugin *plugin, const char *signal, t_hook_callback_signal *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_signal *new_hook_signal; int priority; const char *ptr_signal; if (!signal || !signal[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_signal = malloc (sizeof (*new_hook_signal)); if (!new_hook_signal) { free (new_hook); return NULL; } hook_get_priority_and_name (signal, &priority, &ptr_signal); hook_init_data (new_hook, plugin, HOOK_TYPE_SIGNAL, priority, callback_data); new_hook->hook_data = new_hook_signal; new_hook_signal->callback = callback; new_hook_signal->signal = strdup ((ptr_signal) ? ptr_signal : signal); hook_add_to_list (new_hook); return new_hook; }
@@ -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;
CWE-20
null
null
2,740
hook_signal_send (const char *signal, const char *type_data, void *signal_data) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_SIGNAL(ptr_hook, signal), 0))) { ptr_hook->running = 1; (void) (HOOK_SIGNAL(ptr_hook, callback)) (ptr_hook->callback_data, signal, type_data, signal_data); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_signal_send (const char *signal, const char *type_data, void *signal_data) { struct t_hook *ptr_hook, *next_hook; hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_SIGNAL(ptr_hook, signal), 0))) { ptr_hook->running = 1; (void) (HOOK_SIGNAL(ptr_hook, callback)) (ptr_hook->callback_data, signal, type_data, signal_data); ptr_hook->running = 0; } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,741
hook_timer_check_system_clock () { time_t now; long diff_time; struct t_hook *ptr_hook; now = time (NULL); /* * check if difference with previous time is more than 10 seconds: * if it is, then consider it's clock skew and reinitialize all timers */ diff_time = now - hook_last_system_time; if ((diff_time <= -10) || (diff_time >= 10)) { if (weechat_debug_core >= 1) { gui_chat_printf (NULL, _("System clock skew detected (%+ld seconds), " "reinitializing all timers"), diff_time); } /* reinitialize all timers */ for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) hook_timer_init (ptr_hook); } } hook_last_system_time = now; }
null
0
hook_timer_check_system_clock () { time_t now; long diff_time; struct t_hook *ptr_hook; now = time (NULL); /* * check if difference with previous time is more than 10 seconds: * if it is, then consider it's clock skew and reinitialize all timers */ diff_time = now - hook_last_system_time; if ((diff_time <= -10) || (diff_time >= 10)) { if (weechat_debug_core >= 1) { gui_chat_printf (NULL, _("System clock skew detected (%+ld seconds), " "reinitializing all timers"), diff_time); } /* reinitialize all timers */ for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted) hook_timer_init (ptr_hook); } } hook_last_system_time = now; }
@@ -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;
CWE-20
null
null
2,742
hook_timer_exec () { struct timeval tv_time; struct t_hook *ptr_hook, *next_hook; hook_timer_check_system_clock (); gettimeofday (&tv_time, NULL); hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec), &tv_time) <= 0)) { ptr_hook->running = 1; (void) (HOOK_TIMER(ptr_hook, callback)) (ptr_hook->callback_data, (HOOK_TIMER(ptr_hook, remaining_calls) > 0) ? HOOK_TIMER(ptr_hook, remaining_calls) - 1 : -1); ptr_hook->running = 0; if (!ptr_hook->deleted) { HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec; HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec; util_timeval_add (&HOOK_TIMER(ptr_hook, next_exec), HOOK_TIMER(ptr_hook, interval)); if (HOOK_TIMER(ptr_hook, remaining_calls) > 0) { HOOK_TIMER(ptr_hook, remaining_calls)--; if (HOOK_TIMER(ptr_hook, remaining_calls) == 0) unhook (ptr_hook); } } } ptr_hook = next_hook; } hook_exec_end (); }
null
0
hook_timer_exec () { struct timeval tv_time; struct t_hook *ptr_hook, *next_hook; hook_timer_check_system_clock (); gettimeofday (&tv_time, NULL); hook_exec_start (); ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec), &tv_time) <= 0)) { ptr_hook->running = 1; (void) (HOOK_TIMER(ptr_hook, callback)) (ptr_hook->callback_data, (HOOK_TIMER(ptr_hook, remaining_calls) > 0) ? HOOK_TIMER(ptr_hook, remaining_calls) - 1 : -1); ptr_hook->running = 0; if (!ptr_hook->deleted) { HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec; HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec; util_timeval_add (&HOOK_TIMER(ptr_hook, next_exec), HOOK_TIMER(ptr_hook, interval)); if (HOOK_TIMER(ptr_hook, remaining_calls) > 0) { HOOK_TIMER(ptr_hook, remaining_calls)--; if (HOOK_TIMER(ptr_hook, remaining_calls) == 0) unhook (ptr_hook); } } } ptr_hook = next_hook; } hook_exec_end (); }
@@ -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;
CWE-20
null
null
2,743
hook_timer_init (struct t_hook *hook) { time_t time_now; struct tm *local_time, *gm_time; int local_hour, gm_hour, diff_hour; gettimeofday (&HOOK_TIMER(hook, last_exec), NULL); time_now = time (NULL); local_time = localtime(&time_now); local_hour = local_time->tm_hour; gm_time = gmtime(&time_now); gm_hour = gm_time->tm_hour; if ((local_time->tm_year > gm_time->tm_year) || (local_time->tm_mon > gm_time->tm_mon) || (local_time->tm_mday > gm_time->tm_mday)) { diff_hour = (24 - gm_hour) + local_hour; } else if ((gm_time->tm_year > local_time->tm_year) || (gm_time->tm_mon > local_time->tm_mon) || (gm_time->tm_mday > local_time->tm_mday)) { diff_hour = (-1) * ((24 - local_hour) + gm_hour); } else diff_hour = local_hour - gm_hour; if ((HOOK_TIMER(hook, interval) >= 1000) && (HOOK_TIMER(hook, align_second) > 0)) { /* * here we should use 0, but with this value timer is sometimes called * before second has changed, so for displaying time, it may display * 2 times the same second, that's why we use 1000 micro seconds */ HOOK_TIMER(hook, last_exec).tv_usec = 1000; HOOK_TIMER(hook, last_exec).tv_sec = HOOK_TIMER(hook, last_exec).tv_sec - ((HOOK_TIMER(hook, last_exec).tv_sec + (diff_hour * 3600)) % HOOK_TIMER(hook, align_second)); } /* init next call with date of last call */ HOOK_TIMER(hook, next_exec).tv_sec = HOOK_TIMER(hook, last_exec).tv_sec; HOOK_TIMER(hook, next_exec).tv_usec = HOOK_TIMER(hook, last_exec).tv_usec; /* add interval to next call date */ util_timeval_add (&HOOK_TIMER(hook, next_exec), HOOK_TIMER(hook, interval)); }
null
0
hook_timer_init (struct t_hook *hook) { time_t time_now; struct tm *local_time, *gm_time; int local_hour, gm_hour, diff_hour; gettimeofday (&HOOK_TIMER(hook, last_exec), NULL); time_now = time (NULL); local_time = localtime(&time_now); local_hour = local_time->tm_hour; gm_time = gmtime(&time_now); gm_hour = gm_time->tm_hour; if ((local_time->tm_year > gm_time->tm_year) || (local_time->tm_mon > gm_time->tm_mon) || (local_time->tm_mday > gm_time->tm_mday)) { diff_hour = (24 - gm_hour) + local_hour; } else if ((gm_time->tm_year > local_time->tm_year) || (gm_time->tm_mon > local_time->tm_mon) || (gm_time->tm_mday > local_time->tm_mday)) { diff_hour = (-1) * ((24 - local_hour) + gm_hour); } else diff_hour = local_hour - gm_hour; if ((HOOK_TIMER(hook, interval) >= 1000) && (HOOK_TIMER(hook, align_second) > 0)) { /* * here we should use 0, but with this value timer is sometimes called * before second has changed, so for displaying time, it may display * 2 times the same second, that's why we use 1000 micro seconds */ HOOK_TIMER(hook, last_exec).tv_usec = 1000; HOOK_TIMER(hook, last_exec).tv_sec = HOOK_TIMER(hook, last_exec).tv_sec - ((HOOK_TIMER(hook, last_exec).tv_sec + (diff_hour * 3600)) % HOOK_TIMER(hook, align_second)); } /* init next call with date of last call */ HOOK_TIMER(hook, next_exec).tv_sec = HOOK_TIMER(hook, last_exec).tv_sec; HOOK_TIMER(hook, next_exec).tv_usec = HOOK_TIMER(hook, last_exec).tv_usec; /* add interval to next call date */ util_timeval_add (&HOOK_TIMER(hook, next_exec), HOOK_TIMER(hook, interval)); }
@@ -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;
CWE-20
null
null
2,744
hook_valid (struct t_hook *hook) { int type; struct t_hook *ptr_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { for (ptr_hook = weechat_hooks[type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (ptr_hook == hook)) return 1; } } /* hook not found */ return 0; }
null
0
hook_valid (struct t_hook *hook) { int type; struct t_hook *ptr_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { for (ptr_hook = weechat_hooks[type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (ptr_hook == hook)) return 1; } } /* hook not found */ return 0; }
@@ -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;
CWE-20
null
null
2,745
unhook_all () { int type; struct t_hook *ptr_hook, *next_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; while (ptr_hook) { next_hook = ptr_hook->next_hook; unhook (ptr_hook); ptr_hook = next_hook; } } }
null
0
unhook_all () { int type; struct t_hook *ptr_hook, *next_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; while (ptr_hook) { next_hook = ptr_hook->next_hook; unhook (ptr_hook); ptr_hook = next_hook; } } }
@@ -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;
CWE-20
null
null
2,746
unhook_all_plugin (struct t_weechat_plugin *plugin) { int type; struct t_hook *ptr_hook, *next_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (ptr_hook->plugin == plugin) unhook (ptr_hook); ptr_hook = next_hook; } } }
null
0
unhook_all_plugin (struct t_weechat_plugin *plugin) { int type; struct t_hook *ptr_hook, *next_hook; for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (ptr_hook->plugin == plugin) unhook (ptr_hook); ptr_hook = next_hook; } } }
@@ -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;
CWE-20
null
null
2,747
network_connect_child (struct t_hook *hook_connect) { struct t_proxy *ptr_proxy; struct addrinfo hints, *res, *res_local, *ptr_res; char status_str[2], *ptr_address, *status_ok_with_address; char ipv4_address[INET_ADDRSTRLEN + 1], ipv6_address[INET6_ADDRSTRLEN + 1]; char status_ok_without_address[1 + 5 + 1]; int rc, length; res = NULL; res_local = NULL; status_str[1] = '\0'; ptr_proxy = NULL; if (HOOK_CONNECT(hook_connect, proxy) && HOOK_CONNECT(hook_connect, proxy)[0]) { ptr_proxy = proxy_search (HOOK_CONNECT(hook_connect, proxy)); if (!ptr_proxy) { /* proxy not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_PROXY_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } } if (ptr_proxy) { /* get info about peer */ memset (&hints, 0, sizeof (hints)); hints.ai_family = (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; if (getaddrinfo (CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS]), NULL, &hints, &res) !=0) { /* address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } if (!res) { /* adddress not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } if ((CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6]) && (res->ai_family != AF_INET6)) || ((!CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6]) && (res->ai_family != AF_INET)))) { /* IP address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } if (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ((struct sockaddr_in6 *)(res->ai_addr))->sin6_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); else ((struct sockaddr_in *)(res->ai_addr))->sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); /* connect to peer */ if (connect (HOOK_CONNECT(hook_connect, sock), res->ai_addr, res->ai_addrlen) != 0) { /* connection refused */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } if (!network_pass_proxy (HOOK_CONNECT(hook_connect, proxy), HOOK_CONNECT(hook_connect, sock), HOOK_CONNECT(hook_connect, address), HOOK_CONNECT(hook_connect, port))) { /* proxy fails to connect to peer */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_PROXY_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } status_str[0] = '0' + WEECHAT_HOOK_CONNECT_OK; } else { /* set local hostname/IP if asked by user */ if (HOOK_CONNECT(hook_connect, local_hostname) && HOOK_CONNECT(hook_connect, local_hostname[0])) { memset (&hints, 0, sizeof(hints)); hints.ai_family = (HOOK_CONNECT(hook_connect, ipv6)) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; rc = getaddrinfo (HOOK_CONNECT(hook_connect, local_hostname), NULL, &hints, &res_local); if ((rc != 0) || !res_local || (HOOK_CONNECT(hook_connect, ipv6) && (res_local->ai_family != AF_INET6)) || ((!HOOK_CONNECT(hook_connect, ipv6) && (res_local->ai_family != AF_INET)))) { /* fails to set local hostname/IP */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res_local) freeaddrinfo (res_local); return; } if (bind (HOOK_CONNECT(hook_connect, sock), res_local->ai_addr, res_local->ai_addrlen) < 0) { /* fails to set local hostname/IP */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res_local) freeaddrinfo (res_local); return; } } /* get info about peer */ memset (&hints, 0, sizeof(hints)); hints.ai_family = (HOOK_CONNECT(hook_connect, ipv6)) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; rc = getaddrinfo (HOOK_CONNECT(hook_connect, address), NULL, &hints, &res); if ((rc != 0) || !res) { /* address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res) freeaddrinfo (res); if (res_local) freeaddrinfo (res_local); return; } status_str[0] = '0' + WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND; /* try all IP addresses found, stop when connection is ok */ for (ptr_res = res; ptr_res; ptr_res = ptr_res->ai_next) { /* skip IP address if it's not good family */ if ((HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET6)) || ((!HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET)))) continue; /* connect to peer */ if (HOOK_CONNECT(hook_connect, ipv6)) ((struct sockaddr_in6 *)(ptr_res->ai_addr))->sin6_port = htons (HOOK_CONNECT(hook_connect, port)); else ((struct sockaddr_in *)(ptr_res->ai_addr))->sin_port = htons (HOOK_CONNECT(hook_connect, port)); if (connect (HOOK_CONNECT(hook_connect, sock), ptr_res->ai_addr, ptr_res->ai_addrlen) == 0) { status_str[0] = '0' + WEECHAT_HOOK_CONNECT_OK; break; } else status_str[0] = '0' + WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED; } } if (status_str[0] == '0' + WEECHAT_HOOK_CONNECT_OK) { status_ok_with_address = NULL; ptr_address = NULL; if (HOOK_CONNECT(hook_connect, ipv6)) { if (inet_ntop (AF_INET6, &((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr, ipv6_address, INET6_ADDRSTRLEN)) { ptr_address = ipv6_address; } } else { if (inet_ntop (AF_INET, &((struct sockaddr_in *)(res->ai_addr))->sin_addr, ipv4_address, INET_ADDRSTRLEN)) { ptr_address = ipv4_address; } } if (ptr_address) { length = strlen (status_str) + 5 + strlen (ptr_address) + 1; status_ok_with_address = malloc (length); if (status_ok_with_address) { snprintf (status_ok_with_address, length, "%s%05d%s", status_str, (int)strlen (ptr_address), ptr_address); } } if (status_ok_with_address) { write (HOOK_CONNECT(hook_connect, child_write), status_ok_with_address, strlen (status_ok_with_address)); free (status_ok_with_address); } else { snprintf (status_ok_without_address, sizeof (status_ok_without_address), "%s%05d", status_str, 0); write (HOOK_CONNECT(hook_connect, child_write), status_ok_without_address, strlen (status_ok_without_address)); } } else { write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); } if (res) freeaddrinfo (res); if (res_local) freeaddrinfo (res_local); }
null
0
network_connect_child (struct t_hook *hook_connect) { struct t_proxy *ptr_proxy; struct addrinfo hints, *res, *res_local, *ptr_res; char status_str[2], *ptr_address, *status_ok_with_address; char ipv4_address[INET_ADDRSTRLEN + 1], ipv6_address[INET6_ADDRSTRLEN + 1]; char status_ok_without_address[1 + 5 + 1]; int rc, length; res = NULL; res_local = NULL; status_str[1] = '\0'; ptr_proxy = NULL; if (HOOK_CONNECT(hook_connect, proxy) && HOOK_CONNECT(hook_connect, proxy)[0]) { ptr_proxy = proxy_search (HOOK_CONNECT(hook_connect, proxy)); if (!ptr_proxy) { /* proxy not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_PROXY_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } } if (ptr_proxy) { /* get info about peer */ memset (&hints, 0, sizeof (hints)); hints.ai_family = (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; if (getaddrinfo (CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS]), NULL, &hints, &res) !=0) { /* address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } if (!res) { /* adddress not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); return; } if ((CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6]) && (res->ai_family != AF_INET6)) || ((!CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6]) && (res->ai_family != AF_INET)))) { /* IP address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } if (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ((struct sockaddr_in6 *)(res->ai_addr))->sin6_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); else ((struct sockaddr_in *)(res->ai_addr))->sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); /* connect to peer */ if (connect (HOOK_CONNECT(hook_connect, sock), res->ai_addr, res->ai_addrlen) != 0) { /* connection refused */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } if (!network_pass_proxy (HOOK_CONNECT(hook_connect, proxy), HOOK_CONNECT(hook_connect, sock), HOOK_CONNECT(hook_connect, address), HOOK_CONNECT(hook_connect, port))) { /* proxy fails to connect to peer */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_PROXY_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); freeaddrinfo (res); return; } status_str[0] = '0' + WEECHAT_HOOK_CONNECT_OK; } else { /* set local hostname/IP if asked by user */ if (HOOK_CONNECT(hook_connect, local_hostname) && HOOK_CONNECT(hook_connect, local_hostname[0])) { memset (&hints, 0, sizeof(hints)); hints.ai_family = (HOOK_CONNECT(hook_connect, ipv6)) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; rc = getaddrinfo (HOOK_CONNECT(hook_connect, local_hostname), NULL, &hints, &res_local); if ((rc != 0) || !res_local || (HOOK_CONNECT(hook_connect, ipv6) && (res_local->ai_family != AF_INET6)) || ((!HOOK_CONNECT(hook_connect, ipv6) && (res_local->ai_family != AF_INET)))) { /* fails to set local hostname/IP */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res_local) freeaddrinfo (res_local); return; } if (bind (HOOK_CONNECT(hook_connect, sock), res_local->ai_addr, res_local->ai_addrlen) < 0) { /* fails to set local hostname/IP */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res_local) freeaddrinfo (res_local); return; } } /* get info about peer */ memset (&hints, 0, sizeof(hints)); hints.ai_family = (HOOK_CONNECT(hook_connect, ipv6)) ? AF_INET6 : AF_INET; hints.ai_socktype = SOCK_STREAM; rc = getaddrinfo (HOOK_CONNECT(hook_connect, address), NULL, &hints, &res); if ((rc != 0) || !res) { /* address not found */ status_str[0] = '0' + WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND; write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); if (res) freeaddrinfo (res); if (res_local) freeaddrinfo (res_local); return; } status_str[0] = '0' + WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND; /* try all IP addresses found, stop when connection is ok */ for (ptr_res = res; ptr_res; ptr_res = ptr_res->ai_next) { /* skip IP address if it's not good family */ if ((HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET6)) || ((!HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET)))) continue; /* connect to peer */ if (HOOK_CONNECT(hook_connect, ipv6)) ((struct sockaddr_in6 *)(ptr_res->ai_addr))->sin6_port = htons (HOOK_CONNECT(hook_connect, port)); else ((struct sockaddr_in *)(ptr_res->ai_addr))->sin_port = htons (HOOK_CONNECT(hook_connect, port)); if (connect (HOOK_CONNECT(hook_connect, sock), ptr_res->ai_addr, ptr_res->ai_addrlen) == 0) { status_str[0] = '0' + WEECHAT_HOOK_CONNECT_OK; break; } else status_str[0] = '0' + WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED; } } if (status_str[0] == '0' + WEECHAT_HOOK_CONNECT_OK) { status_ok_with_address = NULL; ptr_address = NULL; if (HOOK_CONNECT(hook_connect, ipv6)) { if (inet_ntop (AF_INET6, &((struct sockaddr_in6 *)(res->ai_addr))->sin6_addr, ipv6_address, INET6_ADDRSTRLEN)) { ptr_address = ipv6_address; } } else { if (inet_ntop (AF_INET, &((struct sockaddr_in *)(res->ai_addr))->sin_addr, ipv4_address, INET_ADDRSTRLEN)) { ptr_address = ipv4_address; } } if (ptr_address) { length = strlen (status_str) + 5 + strlen (ptr_address) + 1; status_ok_with_address = malloc (length); if (status_ok_with_address) { snprintf (status_ok_with_address, length, "%s%05d%s", status_str, (int)strlen (ptr_address), ptr_address); } } if (status_ok_with_address) { write (HOOK_CONNECT(hook_connect, child_write), status_ok_with_address, strlen (status_ok_with_address)); free (status_ok_with_address); } else { snprintf (status_ok_without_address, sizeof (status_ok_without_address), "%s%05d", status_str, 0); write (HOOK_CONNECT(hook_connect, child_write), status_ok_without_address, strlen (status_ok_without_address)); } } else { write (HOOK_CONNECT(hook_connect, child_write), status_str, 1); } if (res) freeaddrinfo (res); if (res_local) freeaddrinfo (res_local); }
@@ -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;
CWE-20
null
null
2,748
network_connect_gnutls_handshake_timer_cb (void *arg_hook_connect, int remaining_calls) { struct t_hook *hook_connect; /* make C compiler happy */ (void) remaining_calls; hook_connect = (struct t_hook *)arg_hook_connect; HOOK_CONNECT(hook_connect, handshake_hook_timer) = NULL; (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR, GNUTLS_E_EXPIRED, gnutls_strerror (GNUTLS_E_EXPIRED), HOOK_CONNECT(hook_connect, handshake_ip_address)); unhook (hook_connect); return WEECHAT_RC_OK; }
null
0
network_connect_gnutls_handshake_timer_cb (void *arg_hook_connect, int remaining_calls) { struct t_hook *hook_connect; /* make C compiler happy */ (void) remaining_calls; hook_connect = (struct t_hook *)arg_hook_connect; HOOK_CONNECT(hook_connect, handshake_hook_timer) = NULL; (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR, GNUTLS_E_EXPIRED, gnutls_strerror (GNUTLS_E_EXPIRED), HOOK_CONNECT(hook_connect, handshake_ip_address)); unhook (hook_connect); return WEECHAT_RC_OK; }
@@ -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;
CWE-20
null
null
2,749
network_connect_to (const char *proxy, int sock, unsigned long address, int port) { struct t_proxy *ptr_proxy; struct sockaddr_in addr; struct hostent *hostent; char *ip4; int ret; ptr_proxy = NULL; if (proxy && proxy[0]) { ptr_proxy = proxy_search (proxy); if (!ptr_proxy) return 0; } if (ptr_proxy) { memset (&addr, 0, sizeof (addr)); addr.sin_addr.s_addr = htonl (address); ip4 = inet_ntoa(addr.sin_addr); memset (&addr, 0, sizeof (addr)); addr.sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); addr.sin_family = AF_INET; hostent = gethostbyname (CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS])); if (!hostent) return 0; memcpy(&(addr.sin_addr), *(hostent->h_addr_list), sizeof(struct in_addr)); ret = connect (sock, (struct sockaddr *) &addr, sizeof (addr)); if ((ret == -1) && (errno != EINPROGRESS)) return 0; if (!network_pass_proxy (proxy, sock, ip4, port)) return 0; } else { memset (&addr, 0, sizeof (addr)); addr.sin_port = htons (port); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (address); ret = connect (sock, (struct sockaddr *) &addr, sizeof (addr)); if ((ret == -1) && (errno != EINPROGRESS)) return 0; } return 1; }
null
0
network_connect_to (const char *proxy, int sock, unsigned long address, int port) { struct t_proxy *ptr_proxy; struct sockaddr_in addr; struct hostent *hostent; char *ip4; int ret; ptr_proxy = NULL; if (proxy && proxy[0]) { ptr_proxy = proxy_search (proxy); if (!ptr_proxy) return 0; } if (ptr_proxy) { memset (&addr, 0, sizeof (addr)); addr.sin_addr.s_addr = htonl (address); ip4 = inet_ntoa(addr.sin_addr); memset (&addr, 0, sizeof (addr)); addr.sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); addr.sin_family = AF_INET; hostent = gethostbyname (CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS])); if (!hostent) return 0; memcpy(&(addr.sin_addr), *(hostent->h_addr_list), sizeof(struct in_addr)); ret = connect (sock, (struct sockaddr *) &addr, sizeof (addr)); if ((ret == -1) && (errno != EINPROGRESS)) return 0; if (!network_pass_proxy (proxy, sock, ip4, port)) return 0; } else { memset (&addr, 0, sizeof (addr)); addr.sin_port = htons (port); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (address); ret = connect (sock, (struct sockaddr *) &addr, sizeof (addr)); if ((ret == -1) && (errno != EINPROGRESS)) return 0; } return 1; }
@@ -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;
CWE-20
null
null
2,750
network_connect_with_fork (struct t_hook *hook_connect) { int child_pipe[2]; #ifndef __CYGWIN__ pid_t pid; #endif #ifdef HAVE_GNUTLS /* initialize GnuTLS if SSL asked */ if (HOOK_CONNECT(hook_connect, gnutls_sess)) { if (gnutls_init (HOOK_CONNECT(hook_connect, gnutls_sess), GNUTLS_CLIENT) != 0) { (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR, 0, NULL, NULL); unhook (hook_connect); return; } gnutls_set_default_priority (*HOOK_CONNECT(hook_connect, gnutls_sess)); gnutls_certificate_type_set_priority (*HOOK_CONNECT(hook_connect, gnutls_sess), gnutls_cert_type_prio); gnutls_protocol_set_priority (*HOOK_CONNECT(hook_connect, gnutls_sess), gnutls_prot_prio); gnutls_credentials_set (*HOOK_CONNECT(hook_connect, gnutls_sess), GNUTLS_CRD_CERTIFICATE, gnutls_xcred); gnutls_transport_set_ptr (*HOOK_CONNECT(hook_connect, gnutls_sess), (gnutls_transport_ptr) ((unsigned long) HOOK_CONNECT(hook_connect, sock))); } #endif /* create pipe for child process */ if (pipe (child_pipe) < 0) { (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR, 0, NULL, NULL); unhook (hook_connect); return; } HOOK_CONNECT(hook_connect, child_read) = child_pipe[0]; HOOK_CONNECT(hook_connect, child_write) = child_pipe[1]; #ifdef __CYGWIN__ /* * connection may block under Cygwin, there's no other known way * to do better today, since connect() in child process seems not to work * any suggestion is welcome to improve that! */ network_connect_child (hook_connect); network_connect_child_read_cb (hook_connect, 0); #else switch (pid = fork ()) { /* fork failed */ case -1: (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR, 0, NULL, NULL); unhook (hook_connect); return; /* child process */ case 0: setuid (getuid ()); close (HOOK_CONNECT(hook_connect, child_read)); network_connect_child (hook_connect); _exit (EXIT_SUCCESS); } /* parent process */ HOOK_CONNECT(hook_connect, child_pid) = pid; close (HOOK_CONNECT(hook_connect, child_write)); HOOK_CONNECT(hook_connect, child_write) = -1; HOOK_CONNECT(hook_connect, hook_fd) = hook_fd (hook_connect->plugin, HOOK_CONNECT(hook_connect, child_read), 1, 0, 0, &network_connect_child_read_cb, hook_connect); #endif }
null
0
network_connect_with_fork (struct t_hook *hook_connect) { int child_pipe[2]; #ifndef __CYGWIN__ pid_t pid; #endif #ifdef HAVE_GNUTLS /* initialize GnuTLS if SSL asked */ if (HOOK_CONNECT(hook_connect, gnutls_sess)) { if (gnutls_init (HOOK_CONNECT(hook_connect, gnutls_sess), GNUTLS_CLIENT) != 0) { (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR, 0, NULL, NULL); unhook (hook_connect); return; } gnutls_set_default_priority (*HOOK_CONNECT(hook_connect, gnutls_sess)); gnutls_certificate_type_set_priority (*HOOK_CONNECT(hook_connect, gnutls_sess), gnutls_cert_type_prio); gnutls_protocol_set_priority (*HOOK_CONNECT(hook_connect, gnutls_sess), gnutls_prot_prio); gnutls_credentials_set (*HOOK_CONNECT(hook_connect, gnutls_sess), GNUTLS_CRD_CERTIFICATE, gnutls_xcred); gnutls_transport_set_ptr (*HOOK_CONNECT(hook_connect, gnutls_sess), (gnutls_transport_ptr) ((unsigned long) HOOK_CONNECT(hook_connect, sock))); } #endif /* create pipe for child process */ if (pipe (child_pipe) < 0) { (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR, 0, NULL, NULL); unhook (hook_connect); return; } HOOK_CONNECT(hook_connect, child_read) = child_pipe[0]; HOOK_CONNECT(hook_connect, child_write) = child_pipe[1]; #ifdef __CYGWIN__ /* * connection may block under Cygwin, there's no other known way * to do better today, since connect() in child process seems not to work * any suggestion is welcome to improve that! */ network_connect_child (hook_connect); network_connect_child_read_cb (hook_connect, 0); #else switch (pid = fork ()) { /* fork failed */ case -1: (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, '0' + WEECHAT_HOOK_CONNECT_MEMORY_ERROR, 0, NULL, NULL); unhook (hook_connect); return; /* child process */ case 0: setuid (getuid ()); close (HOOK_CONNECT(hook_connect, child_read)); network_connect_child (hook_connect); _exit (EXIT_SUCCESS); } /* parent process */ HOOK_CONNECT(hook_connect, child_pid) = pid; close (HOOK_CONNECT(hook_connect, child_write)); HOOK_CONNECT(hook_connect, child_write) = -1; HOOK_CONNECT(hook_connect, hook_fd) = hook_fd (hook_connect->plugin, HOOK_CONNECT(hook_connect, child_read), 1, 0, 0, &network_connect_child_read_cb, hook_connect); #endif }
@@ -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;
CWE-20
null
null
2,751
network_end () { #ifdef HAVE_GNUTLS if (network_init_ok) { network_init_ok = 0; gnutls_certificate_free_credentials (gnutls_xcred); gnutls_global_deinit(); } #endif }
null
0
network_end () { #ifdef HAVE_GNUTLS if (network_init_ok) { network_init_ok = 0; gnutls_certificate_free_credentials (gnutls_xcred); gnutls_global_deinit(); } #endif }
@@ -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;
CWE-20
null
null
2,752
network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address, int port) { char buffer[256], authbuf[128], authbuf_base64[196]; int n, m; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { /* authentification */ snprintf (authbuf, sizeof (authbuf), "%s:%s", CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), (CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])) ? CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]) : ""); string_encode_base64 (authbuf, strlen (authbuf), authbuf_base64); n = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n", address, port, authbuf_base64); } else { /* no authentification */ n = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\n\r\n", address, port); } m = send (sock, buffer, n, 0); if (n != m) return 0; n = recv (sock, buffer, sizeof (buffer), 0); /* success result must be like: "HTTP/1.0 200 OK" */ if (n < 12) return 0; if (memcmp (buffer, "HTTP/", 5) || memcmp (buffer + 9, "200", 3)) return 0; /* connection ok */ return 1; }
null
0
network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address, int port) { char buffer[256], authbuf[128], authbuf_base64[196]; int n, m; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { /* authentification */ snprintf (authbuf, sizeof (authbuf), "%s:%s", CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), (CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])) ? CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]) : ""); string_encode_base64 (authbuf, strlen (authbuf), authbuf_base64); n = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n", address, port, authbuf_base64); } else { /* no authentification */ n = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\n\r\n", address, port); } m = send (sock, buffer, n, 0); if (n != m) return 0; n = recv (sock, buffer, sizeof (buffer), 0); /* success result must be like: "HTTP/1.0 200 OK" */ if (n < 12) return 0; if (memcmp (buffer, "HTTP/", 5) || memcmp (buffer + 9, "200", 3)) return 0; /* connection ok */ return 1; }
@@ -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;
CWE-20
null
null
2,753
network_pass_proxy (const char *proxy, int sock, const char *address, int port) { int rc; struct t_proxy *ptr_proxy; rc = 0; ptr_proxy = proxy_search (proxy); if (ptr_proxy) { switch (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_TYPE])) { case PROXY_TYPE_HTTP: rc = network_pass_httpproxy (ptr_proxy, sock, address, port); break; case PROXY_TYPE_SOCKS4: rc = network_pass_socks4proxy (ptr_proxy, sock, address, port); break; case PROXY_TYPE_SOCKS5: rc = network_pass_socks5proxy (ptr_proxy, sock, address, port); break; } } return rc; }
null
0
network_pass_proxy (const char *proxy, int sock, const char *address, int port) { int rc; struct t_proxy *ptr_proxy; rc = 0; ptr_proxy = proxy_search (proxy); if (ptr_proxy) { switch (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_TYPE])) { case PROXY_TYPE_HTTP: rc = network_pass_httpproxy (ptr_proxy, sock, address, port); break; case PROXY_TYPE_SOCKS4: rc = network_pass_socks4proxy (ptr_proxy, sock, address, port); break; case PROXY_TYPE_SOCKS5: rc = network_pass_socks5proxy (ptr_proxy, sock, address, port); break; } } return rc; }
@@ -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;
CWE-20
null
null
2,754
network_pass_socks4proxy (struct t_proxy *proxy, int sock, const char *address, int port) { /* socks4 protocol is explained here: http://en.wikipedia.org/wiki/SOCKS */ struct t_network_socks4 socks4; unsigned char buffer[24]; char ip_addr[NI_MAXHOST]; socks4.version = 4; socks4.method = 1; socks4.port = htons (port); network_resolve (address, ip_addr, NULL); socks4.address = inet_addr (ip_addr); strncpy (socks4.user, CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), sizeof (socks4.user) - 1); send (sock, (char *) &socks4, 8 + strlen (socks4.user) + 1, 0); recv (sock, buffer, sizeof (buffer), 0); /* connection ok */ if ((buffer[0] == 0) && (buffer[1] == 90)) return 1; /* connection failed */ return 0; }
null
0
network_pass_socks4proxy (struct t_proxy *proxy, int sock, const char *address, int port) { /* socks4 protocol is explained here: http://en.wikipedia.org/wiki/SOCKS */ struct t_network_socks4 socks4; unsigned char buffer[24]; char ip_addr[NI_MAXHOST]; socks4.version = 4; socks4.method = 1; socks4.port = htons (port); network_resolve (address, ip_addr, NULL); socks4.address = inet_addr (ip_addr); strncpy (socks4.user, CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), sizeof (socks4.user) - 1); send (sock, (char *) &socks4, 8 + strlen (socks4.user) + 1, 0); recv (sock, buffer, sizeof (buffer), 0); /* connection ok */ if ((buffer[0] == 0) && (buffer[1] == 90)) return 1; /* connection failed */ return 0; }
@@ -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;
CWE-20
null
null
2,755
network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, int port) { /* * socks5 protocol is explained in RFC 1928 * socks5 authentication with username/pass is explained in RFC 1929 */ struct t_network_socks5 socks5; unsigned char buffer[288]; int username_len, password_len, addr_len, addr_buffer_len; unsigned char *addr_buffer; socks5.version = 5; socks5.nmethods = 1; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) socks5.method = 2; /* with authentication */ else socks5.method = 0; /* without authentication */ send (sock, (char *) &socks5, sizeof(socks5), 0); /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { /* * with authentication * -> socks server must respond with : * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 2 => authentication */ if (buffer[0] != 5 || buffer[1] != 2) return 0; /* authentication as in RFC 1929 */ username_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])); password_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])); /* make username/password buffer */ buffer[0] = 1; buffer[1] = (unsigned char) username_len; memcpy(buffer + 2, CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), username_len); buffer[2 + username_len] = (unsigned char) password_len; memcpy (buffer + 3 + username_len, CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]), password_len); send (sock, buffer, 3 + username_len + password_len, 0); /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; /* buffer[1] = auth state, must be 0 for success */ if (buffer[1] != 0) return 0; } else { /* * without authentication * -> socks server must respond with : * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 0 => no authentication */ if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; } /* authentication successful then giving address/port to connect */ addr_len = strlen(address); addr_buffer_len = 4 + 1 + addr_len + 2; addr_buffer = malloc (addr_buffer_len * sizeof(*addr_buffer)); if (!addr_buffer) return 0; addr_buffer[0] = 5; /* version 5 */ addr_buffer[1] = 1; /* command: 1 for connect */ addr_buffer[2] = 0; /* reserved */ addr_buffer[3] = 3; /* address type : ipv4 (1), domainname (3), ipv6 (4) */ addr_buffer[4] = (unsigned char) addr_len; memcpy (addr_buffer + 5, address, addr_len); /* server address */ *((unsigned short *) (addr_buffer + 5 + addr_len)) = htons (port); /* server port */ send (sock, addr_buffer, addr_buffer_len, 0); free (addr_buffer); /* dialog with proxy server */ if (recv (sock, buffer, 4, 0) != 4) return 0; if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; /* buffer[3] = address type */ switch (buffer[3]) { case 1: /* * ipv4 * server socks return server bound address and port * address of 4 bytes and port of 2 bytes (= 6 bytes) */ if (recv (sock, buffer, 6, 0) != 6) return 0; break; case 3: /* * domainname * server socks return server bound address and port */ /* read address length */ if (recv (sock, buffer, 1, 0) != 1) return 0; addr_len = buffer[0]; /* read address + port = addr_len + 2 */ if (recv (sock, buffer, addr_len + 2, 0) != (addr_len + 2)) return 0; break; case 4: /* * ipv6 * server socks return server bound address and port * address of 16 bytes and port of 2 bytes (= 18 bytes) */ if (recv (sock, buffer, 18, 0) != 18) return 0; break; default: return 0; } /* connection ok */ return 1; }
null
0
network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, int port) { /* * socks5 protocol is explained in RFC 1928 * socks5 authentication with username/pass is explained in RFC 1929 */ struct t_network_socks5 socks5; unsigned char buffer[288]; int username_len, password_len, addr_len, addr_buffer_len; unsigned char *addr_buffer; socks5.version = 5; socks5.nmethods = 1; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) socks5.method = 2; /* with authentication */ else socks5.method = 0; /* without authentication */ send (sock, (char *) &socks5, sizeof(socks5), 0); /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { /* * with authentication * -> socks server must respond with : * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 2 => authentication */ if (buffer[0] != 5 || buffer[1] != 2) return 0; /* authentication as in RFC 1929 */ username_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])); password_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])); /* make username/password buffer */ buffer[0] = 1; buffer[1] = (unsigned char) username_len; memcpy(buffer + 2, CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), username_len); buffer[2 + username_len] = (unsigned char) password_len; memcpy (buffer + 3 + username_len, CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]), password_len); send (sock, buffer, 3 + username_len + password_len, 0); /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; /* buffer[1] = auth state, must be 0 for success */ if (buffer[1] != 0) return 0; } else { /* * without authentication * -> socks server must respond with : * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 0 => no authentication */ if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; } /* authentication successful then giving address/port to connect */ addr_len = strlen(address); addr_buffer_len = 4 + 1 + addr_len + 2; addr_buffer = malloc (addr_buffer_len * sizeof(*addr_buffer)); if (!addr_buffer) return 0; addr_buffer[0] = 5; /* version 5 */ addr_buffer[1] = 1; /* command: 1 for connect */ addr_buffer[2] = 0; /* reserved */ addr_buffer[3] = 3; /* address type : ipv4 (1), domainname (3), ipv6 (4) */ addr_buffer[4] = (unsigned char) addr_len; memcpy (addr_buffer + 5, address, addr_len); /* server address */ *((unsigned short *) (addr_buffer + 5 + addr_len)) = htons (port); /* server port */ send (sock, addr_buffer, addr_buffer_len, 0); free (addr_buffer); /* dialog with proxy server */ if (recv (sock, buffer, 4, 0) != 4) return 0; if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; /* buffer[3] = address type */ switch (buffer[3]) { case 1: /* * ipv4 * server socks return server bound address and port * address of 4 bytes and port of 2 bytes (= 6 bytes) */ if (recv (sock, buffer, 6, 0) != 6) return 0; break; case 3: /* * domainname * server socks return server bound address and port */ /* read address length */ if (recv (sock, buffer, 1, 0) != 1) return 0; addr_len = buffer[0]; /* read address + port = addr_len + 2 */ if (recv (sock, buffer, addr_len + 2, 0) != (addr_len + 2)) return 0; break; case 4: /* * ipv6 * server socks return server bound address and port * address of 16 bytes and port of 2 bytes (= 18 bytes) */ if (recv (sock, buffer, 18, 0) != 18) return 0; break; default: return 0; } /* connection ok */ return 1; }
@@ -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;
CWE-20
null
null
2,756
network_resolve (const char *hostname, char *ip, int *version) { char ipbuffer[NI_MAXHOST]; struct addrinfo *res; if (version != NULL) *version = 0; res = NULL; if (getaddrinfo (hostname, NULL, NULL, &res) != 0) return 0; if (!res) return 0; if (getnameinfo (res->ai_addr, res->ai_addrlen, ipbuffer, sizeof(ipbuffer), NULL, 0, NI_NUMERICHOST) != 0) { freeaddrinfo (res); return 0; } if ((res->ai_family == AF_INET) && (version != NULL)) *version = 4; if ((res->ai_family == AF_INET6) && (version != NULL)) *version = 6; strcpy (ip, ipbuffer); freeaddrinfo (res); /* resolution ok */ return 1; }
null
0
network_resolve (const char *hostname, char *ip, int *version) { char ipbuffer[NI_MAXHOST]; struct addrinfo *res; if (version != NULL) *version = 0; res = NULL; if (getaddrinfo (hostname, NULL, NULL, &res) != 0) return 0; if (!res) return 0; if (getnameinfo (res->ai_addr, res->ai_addrlen, ipbuffer, sizeof(ipbuffer), NULL, 0, NI_NUMERICHOST) != 0) { freeaddrinfo (res); return 0; } if ((res->ai_family == AF_INET) && (version != NULL)) *version = 4; if ((res->ai_family == AF_INET6) && (version != NULL)) *version = 6; strcpy (ip, ipbuffer); freeaddrinfo (res); /* resolution ok */ return 1; }
@@ -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;
CWE-20
null
null
2,757
irc_server_add_to_infolist (struct t_infolist *infolist, struct t_irc_server *server) { struct t_infolist_item *ptr_item; if (!infolist || !server) return 0; ptr_item = weechat_infolist_new_item (infolist); if (!ptr_item) return 0; if (!weechat_infolist_new_var_string (ptr_item, "name", server->name)) return 0; if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", server->buffer)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "buffer_name", (server->buffer) ? weechat_buffer_get_string (server->buffer, "name") : "")) return 0; if (!weechat_infolist_new_var_string (ptr_item, "buffer_short_name", (server->buffer) ? weechat_buffer_get_string (server->buffer, "short_name") : "")) return 0; if (!weechat_infolist_new_var_string (ptr_item, "addresses", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_ADDRESSES))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "proxy", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "ssl_cert", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SSL_CERT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_dhkey_size", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_verify", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL_VERIFY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "password", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "sasl_mechanism", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_MECHANISM))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "sasl_username", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_USERNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "sasl_password", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_PASSWORD))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOCONNECT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nicks", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_NICKS))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "username", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "realname", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "local_hostname", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "command", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "command_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "autojoin", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOREJOIN))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "connection_timeout", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "anti_flood_prio_high", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "anti_flood_prio_low", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "away_check", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "away_check_max_nicks", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "default_msg_part", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_PART))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "default_msg_quit", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_QUIT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "temp_server", server->temp_server)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "current_address", server->current_address)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "current_ip", server->current_ip)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "current_port", server->current_port)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", server->is_connected)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", server->ssl_connected)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", server->unterminated_message)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nick", server->nick)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix_modes", server->prefix_modes)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix_chars", server->prefix_chars)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_join", server->reconnect_join)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "is_away", server->is_away)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "away_message", server->away_message)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "away_time", server->away_time)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "lag", server->lag)) return 0; if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &(server->lag_check_time), sizeof (struct timeval))) return 0; if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_user_message", server->last_user_message)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_away_check", server->last_away_check)) return 0; return 1; }
null
0
irc_server_add_to_infolist (struct t_infolist *infolist, struct t_irc_server *server) { struct t_infolist_item *ptr_item; if (!infolist || !server) return 0; ptr_item = weechat_infolist_new_item (infolist); if (!ptr_item) return 0; if (!weechat_infolist_new_var_string (ptr_item, "name", server->name)) return 0; if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", server->buffer)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "buffer_name", (server->buffer) ? weechat_buffer_get_string (server->buffer, "name") : "")) return 0; if (!weechat_infolist_new_var_string (ptr_item, "buffer_short_name", (server->buffer) ? weechat_buffer_get_string (server->buffer, "short_name") : "")) return 0; if (!weechat_infolist_new_var_string (ptr_item, "addresses", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_ADDRESSES))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "proxy", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "ssl_cert", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SSL_CERT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_dhkey_size", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_verify", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL_VERIFY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "password", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "sasl_mechanism", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_MECHANISM))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "sasl_username", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_USERNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "sasl_password", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_PASSWORD))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOCONNECT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nicks", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_NICKS))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "username", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "realname", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "local_hostname", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "command", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "command_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "autojoin", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin", IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOREJOIN))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin_delay", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "connection_timeout", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "anti_flood_prio_high", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "anti_flood_prio_low", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "away_check", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "away_check_max_nicks", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "default_msg_part", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_PART))) return 0; if (!weechat_infolist_new_var_string (ptr_item, "default_msg_quit", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_QUIT))) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "temp_server", server->temp_server)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "current_address", server->current_address)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "current_ip", server->current_ip)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "current_port", server->current_port)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", server->is_connected)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", server->ssl_connected)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", server->unterminated_message)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nick", server->nick)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix_modes", server->prefix_modes)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "prefix_chars", server->prefix_chars)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_join", server->reconnect_join)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "is_away", server->is_away)) return 0; if (!weechat_infolist_new_var_string (ptr_item, "away_message", server->away_message)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "away_time", server->away_time)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "lag", server->lag)) return 0; if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &(server->lag_check_time), sizeof (struct timeval))) return 0; if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_user_message", server->last_user_message)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "last_away_check", server->last_away_check)) return 0; return 1; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,758
irc_server_alloc (const char *name) { struct t_irc_server *new_server; int i, length; char *option_name; if (irc_server_search (name)) return NULL; /* alloc memory for new server */ new_server = malloc (sizeof (*new_server)); if (!new_server) { weechat_printf (NULL, _("%s%s: error when allocating new server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return NULL; } /* add new server to queue */ new_server->prev_server = last_irc_server; new_server->next_server = NULL; if (irc_servers) last_irc_server->next_server = new_server; else irc_servers = new_server; last_irc_server = new_server; /* set name */ new_server->name = strdup (name); /* internal vars */ new_server->temp_server = 0; new_server->reloading_from_config = 0; new_server->reloaded_from_config = 0; new_server->addresses_count = 0; new_server->addresses_array = NULL; new_server->ports_array = NULL; new_server->index_current_address = 0; new_server->current_address = NULL; new_server->current_ip = NULL; new_server->current_port = 0; new_server->sock = -1; new_server->hook_connect = NULL; new_server->hook_fd = NULL; new_server->hook_timer_connection = NULL; new_server->hook_timer_sasl = NULL; new_server->is_connected = 0; new_server->ssl_connected = 0; new_server->unterminated_message = NULL; new_server->nicks_count = 0; new_server->nicks_array = NULL; new_server->nick_first_tried = 0; new_server->nick = NULL; new_server->nick_modes = NULL; new_server->isupport = NULL; new_server->prefix_modes = NULL; new_server->prefix_chars = NULL; new_server->reconnect_delay = 0; new_server->reconnect_start = 0; new_server->command_time = 0; new_server->reconnect_join = 0; new_server->disable_autojoin = 0; new_server->is_away = 0; new_server->away_message = NULL; new_server->away_time = 0; new_server->lag = 0; new_server->lag_check_time.tv_sec = 0; new_server->lag_check_time.tv_usec = 0; new_server->lag_next_check = time (NULL) + weechat_config_integer (irc_config_network_lag_check); new_server->lag_last_refresh = 0; new_server->cmd_list_regexp = NULL; new_server->last_user_message = 0; new_server->last_away_check = 0; for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { new_server->outqueue[i] = NULL; new_server->last_outqueue[i] = NULL; } new_server->redirects = NULL; new_server->last_redirect = NULL; new_server->notify_list = NULL; new_server->last_notify = NULL; new_server->buffer = NULL; new_server->buffer_as_string = NULL; new_server->channels = NULL; new_server->last_channel = NULL; /* create options with null value */ for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { length = strlen (new_server->name) + 1 + strlen (irc_server_option_string[i]) + 1; option_name = malloc (length); if (option_name) { snprintf (option_name, length, "%s.%s", new_server->name, irc_server_option_string[i]); new_server->options[i] = irc_config_server_new_option (irc_config_file, irc_config_section_server, i, option_name, NULL, NULL, 1, &irc_config_server_change_cb, irc_server_option_string[i]); irc_config_server_change_cb (irc_server_option_string[i], new_server->options[i]); free (option_name); } } return new_server; }
null
0
irc_server_alloc (const char *name) { struct t_irc_server *new_server; int i, length; char *option_name; if (irc_server_search (name)) return NULL; /* alloc memory for new server */ new_server = malloc (sizeof (*new_server)); if (!new_server) { weechat_printf (NULL, _("%s%s: error when allocating new server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return NULL; } /* add new server to queue */ new_server->prev_server = last_irc_server; new_server->next_server = NULL; if (irc_servers) last_irc_server->next_server = new_server; else irc_servers = new_server; last_irc_server = new_server; /* set name */ new_server->name = strdup (name); /* internal vars */ new_server->temp_server = 0; new_server->reloading_from_config = 0; new_server->reloaded_from_config = 0; new_server->addresses_count = 0; new_server->addresses_array = NULL; new_server->ports_array = NULL; new_server->index_current_address = 0; new_server->current_address = NULL; new_server->current_ip = NULL; new_server->current_port = 0; new_server->sock = -1; new_server->hook_connect = NULL; new_server->hook_fd = NULL; new_server->hook_timer_connection = NULL; new_server->hook_timer_sasl = NULL; new_server->is_connected = 0; new_server->ssl_connected = 0; new_server->unterminated_message = NULL; new_server->nicks_count = 0; new_server->nicks_array = NULL; new_server->nick_first_tried = 0; new_server->nick = NULL; new_server->nick_modes = NULL; new_server->isupport = NULL; new_server->prefix_modes = NULL; new_server->prefix_chars = NULL; new_server->reconnect_delay = 0; new_server->reconnect_start = 0; new_server->command_time = 0; new_server->reconnect_join = 0; new_server->disable_autojoin = 0; new_server->is_away = 0; new_server->away_message = NULL; new_server->away_time = 0; new_server->lag = 0; new_server->lag_check_time.tv_sec = 0; new_server->lag_check_time.tv_usec = 0; new_server->lag_next_check = time (NULL) + weechat_config_integer (irc_config_network_lag_check); new_server->lag_last_refresh = 0; new_server->cmd_list_regexp = NULL; new_server->last_user_message = 0; new_server->last_away_check = 0; for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { new_server->outqueue[i] = NULL; new_server->last_outqueue[i] = NULL; } new_server->redirects = NULL; new_server->last_redirect = NULL; new_server->notify_list = NULL; new_server->last_notify = NULL; new_server->buffer = NULL; new_server->buffer_as_string = NULL; new_server->channels = NULL; new_server->last_channel = NULL; /* create options with null value */ for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { length = strlen (new_server->name) + 1 + strlen (irc_server_option_string[i]) + 1; option_name = malloc (length); if (option_name) { snprintf (option_name, length, "%s.%s", new_server->name, irc_server_option_string[i]); new_server->options[i] = irc_config_server_new_option (irc_config_file, irc_config_section_server, i, option_name, NULL, NULL, 1, &irc_config_server_change_cb, irc_server_option_string[i]); irc_config_server_change_cb (irc_server_option_string[i], new_server->options[i]); free (option_name); } } return new_server; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,759
irc_server_alloc_with_url (const char *irc_url) { char *irc_url2, *pos_server, *pos_nick, *pos_password; char *pos_address, *pos_port, *pos_channel, *pos; char *server_address, *server_nicks, *server_autojoin; int ipv6, ssl, length; struct t_irc_server *ptr_server; irc_url2 = strdup (irc_url); if (!irc_url2) return 0; pos_server = NULL; pos_nick = NULL; pos_password = NULL; pos_address = NULL; pos_port = NULL; pos_channel = NULL; ipv6 = 0; ssl = 0; pos_server = strstr (irc_url2, "://"); if (!pos_server) { free (irc_url2); return 0; } pos_server[0] = '\0'; pos_server += 3; pos_channel = strstr (pos_server, "/"); if (pos_channel) { pos_channel[0] = '\0'; pos_channel++; while (pos_channel[0] == '/') { pos_channel++; } } /* check for SSL / IPv6 */ if (weechat_strcasecmp (irc_url2, "irc6") == 0) { ipv6 = 1; } else if (weechat_strcasecmp (irc_url2, "ircs") == 0) { ssl = 1; } else if ((weechat_strcasecmp (irc_url2, "irc6s") == 0) || (weechat_strcasecmp (irc_url2, "ircs6") == 0)) { ipv6 = 1; ssl = 1; } /* search for nick, password, address+port */ pos_address = strchr (pos_server, '@'); if (pos_address) { pos_address[0] = '\0'; pos_address++; pos_nick = pos_server; pos_password = strchr (pos_server, ':'); if (pos_password) { pos_password[0] = '\0'; pos_password++; } } else pos_address = pos_server; /* * search for port in address, and skip optional [ ] around address * (can be used to indicate IPv6 port, after ']') */ if (pos_address[0] == '[') { pos_address++; pos = strchr (pos_address, ']'); if (!pos) { free (irc_url2); return 0; } pos[0] = '\0'; pos++; pos_port = strchr (pos, ':'); if (pos_port) { pos_port[0] = '\0'; pos_port++; } } else { pos_port = strchr (pos_address, ':'); if (pos_port) { pos_port[0] = '\0'; pos_port++; } } ptr_server = irc_server_alloc (pos_address); if (ptr_server) { ptr_server->temp_server = 1; if (pos_address && pos_address[0]) { length = strlen (pos_address) + 1 + ((pos_port) ? strlen (pos_port) : 0) + 1; server_address = malloc (length); if (server_address) { snprintf (server_address, length, "%s%s%s", pos_address, (pos_port && pos_port[0]) ? "/" : "", (pos_port && pos_port[0]) ? pos_port : ""); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES], server_address, 1); free (server_address); } } weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_IPV6], (ipv6) ? "on" : "off", 1); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_SSL], (ssl) ? "on" : "off", 1); if (pos_nick && pos_nick[0]) { length = ((strlen (pos_nick) + 2) * 5) + 1; server_nicks = malloc (length); if (server_nicks) { snprintf (server_nicks, length, "%s,%s1,%s2,%s3,%s4", pos_nick, pos_nick, pos_nick, pos_nick, pos_nick); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_NICKS], server_nicks, 1); free (server_nicks); } } if (pos_password && pos_password[0]) weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_PASSWORD], pos_password, 1); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT], "on", 1); /* autojoin */ if (pos_channel && pos_channel[0]) { if (irc_channel_is_channel (pos_channel)) server_autojoin = strdup (pos_channel); else { server_autojoin = malloc (strlen (pos_channel) + 2); if (server_autojoin) { strcpy (server_autojoin, "#"); strcat (server_autojoin, pos_channel); } } if (server_autojoin) { weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN], server_autojoin, 1); free (server_autojoin); } } } else { weechat_printf (NULL, _("%s%s: error creating new server \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, pos_address); } free (irc_url2); return (ptr_server) ? 1 : 0; }
null
0
irc_server_alloc_with_url (const char *irc_url) { char *irc_url2, *pos_server, *pos_nick, *pos_password; char *pos_address, *pos_port, *pos_channel, *pos; char *server_address, *server_nicks, *server_autojoin; int ipv6, ssl, length; struct t_irc_server *ptr_server; irc_url2 = strdup (irc_url); if (!irc_url2) return 0; pos_server = NULL; pos_nick = NULL; pos_password = NULL; pos_address = NULL; pos_port = NULL; pos_channel = NULL; ipv6 = 0; ssl = 0; pos_server = strstr (irc_url2, "://"); if (!pos_server) { free (irc_url2); return 0; } pos_server[0] = '\0'; pos_server += 3; pos_channel = strstr (pos_server, "/"); if (pos_channel) { pos_channel[0] = '\0'; pos_channel++; while (pos_channel[0] == '/') { pos_channel++; } } /* check for SSL / IPv6 */ if (weechat_strcasecmp (irc_url2, "irc6") == 0) { ipv6 = 1; } else if (weechat_strcasecmp (irc_url2, "ircs") == 0) { ssl = 1; } else if ((weechat_strcasecmp (irc_url2, "irc6s") == 0) || (weechat_strcasecmp (irc_url2, "ircs6") == 0)) { ipv6 = 1; ssl = 1; } /* search for nick, password, address+port */ pos_address = strchr (pos_server, '@'); if (pos_address) { pos_address[0] = '\0'; pos_address++; pos_nick = pos_server; pos_password = strchr (pos_server, ':'); if (pos_password) { pos_password[0] = '\0'; pos_password++; } } else pos_address = pos_server; /* * search for port in address, and skip optional [ ] around address * (can be used to indicate IPv6 port, after ']') */ if (pos_address[0] == '[') { pos_address++; pos = strchr (pos_address, ']'); if (!pos) { free (irc_url2); return 0; } pos[0] = '\0'; pos++; pos_port = strchr (pos, ':'); if (pos_port) { pos_port[0] = '\0'; pos_port++; } } else { pos_port = strchr (pos_address, ':'); if (pos_port) { pos_port[0] = '\0'; pos_port++; } } ptr_server = irc_server_alloc (pos_address); if (ptr_server) { ptr_server->temp_server = 1; if (pos_address && pos_address[0]) { length = strlen (pos_address) + 1 + ((pos_port) ? strlen (pos_port) : 0) + 1; server_address = malloc (length); if (server_address) { snprintf (server_address, length, "%s%s%s", pos_address, (pos_port && pos_port[0]) ? "/" : "", (pos_port && pos_port[0]) ? pos_port : ""); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES], server_address, 1); free (server_address); } } weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_IPV6], (ipv6) ? "on" : "off", 1); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_SSL], (ssl) ? "on" : "off", 1); if (pos_nick && pos_nick[0]) { length = ((strlen (pos_nick) + 2) * 5) + 1; server_nicks = malloc (length); if (server_nicks) { snprintf (server_nicks, length, "%s,%s1,%s2,%s3,%s4", pos_nick, pos_nick, pos_nick, pos_nick, pos_nick); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_NICKS], server_nicks, 1); free (server_nicks); } } if (pos_password && pos_password[0]) weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_PASSWORD], pos_password, 1); weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT], "on", 1); /* autojoin */ if (pos_channel && pos_channel[0]) { if (irc_channel_is_channel (pos_channel)) server_autojoin = strdup (pos_channel); else { server_autojoin = malloc (strlen (pos_channel) + 2); if (server_autojoin) { strcpy (server_autojoin, "#"); strcat (server_autojoin, pos_channel); } } if (server_autojoin) { weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN], server_autojoin, 1); free (server_autojoin); } } } else { weechat_printf (NULL, _("%s%s: error creating new server \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, pos_address); } free (irc_url2); return (ptr_server) ? 1 : 0; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,760
irc_server_apply_command_line_options (struct t_irc_server *server, int argc, char **argv) { int i, index_option; char *pos, *option_name, *ptr_value, *value_boolean[2] = { "off", "on" }; for (i = 0; i < argc; i++) { if (argv[i][0] == '-') { pos = strchr (argv[i], '='); if (pos) { option_name = weechat_strndup (argv[i] + 1, pos - argv[i] - 1); ptr_value = pos + 1; } else { option_name = strdup (argv[i] + 1); ptr_value = value_boolean[1]; } if (option_name) { index_option = irc_server_search_option (option_name); if (index_option < 0) { /* look if option is negative, like "-noxxx" */ if (weechat_strncasecmp (argv[i], "-no", 3) == 0) { free (option_name); option_name = strdup (argv[i] + 3); index_option = irc_server_search_option (option_name); ptr_value = value_boolean[0]; } } if (index_option >= 0) { weechat_config_option_set (server->options[index_option], ptr_value, 1); } free (option_name); } } } }
null
0
irc_server_apply_command_line_options (struct t_irc_server *server, int argc, char **argv) { int i, index_option; char *pos, *option_name, *ptr_value, *value_boolean[2] = { "off", "on" }; for (i = 0; i < argc; i++) { if (argv[i][0] == '-') { pos = strchr (argv[i], '='); if (pos) { option_name = weechat_strndup (argv[i] + 1, pos - argv[i] - 1); ptr_value = pos + 1; } else { option_name = strdup (argv[i] + 1); ptr_value = value_boolean[1]; } if (option_name) { index_option = irc_server_search_option (option_name); if (index_option < 0) { /* look if option is negative, like "-noxxx" */ if (weechat_strncasecmp (argv[i], "-no", 3) == 0) { free (option_name); option_name = strdup (argv[i] + 3); index_option = irc_server_search_option (option_name); ptr_value = value_boolean[0]; } } if (index_option >= 0) { weechat_config_option_set (server->options[index_option], ptr_value, 1); } free (option_name); } } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,761
irc_server_auto_connect () { struct t_irc_server *ptr_server; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) { if (!irc_server_connect (ptr_server)) irc_server_reconnect_schedule (ptr_server); } } }
null
0
irc_server_auto_connect () { struct t_irc_server *ptr_server; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) { if (!irc_server_connect (ptr_server)) irc_server_reconnect_schedule (ptr_server); } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,762
irc_server_check_away (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; if (server->is_connected) { for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_check_away (server, ptr_channel); } server->last_away_check = time (NULL); } }
null
0
irc_server_check_away (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; if (server->is_connected) { for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_check_away (server, ptr_channel); } server->last_away_check = time (NULL); } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,763
irc_server_connect (struct t_irc_server *server) { int set, length; char *option_name; struct t_config_option *proxy_type, *proxy_ipv6, *proxy_address, *proxy_port; const char *proxy, *str_proxy_type, *str_proxy_address; if (!server->buffer) { if (!irc_server_create_buffer (server)) return 0; weechat_buffer_set (server->buffer, "display", "auto"); } weechat_bar_item_update ("buffer_name"); irc_server_set_index_current_address (server, server->index_current_address); if (!server->current_address) { weechat_printf (server->buffer, _("%s%s: unknown address server \"%s\", " "cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name); return 0; } /* free some old values (from a previous connection to server) */ if (server->isupport) { free (server->isupport); server->isupport = NULL; } if (server->prefix_modes) { free (server->prefix_modes); server->prefix_modes = NULL; } if (server->prefix_chars) { free (server->prefix_chars); server->prefix_chars = NULL; } proxy_type = NULL; proxy_ipv6 = NULL; proxy_address = NULL; proxy_port = NULL; str_proxy_type = NULL; str_proxy_address = NULL; proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); if (proxy && proxy[0]) { length = 32 + strlen (proxy) + 1; option_name = malloc (length); if (!option_name) { weechat_printf (server->buffer, _("%s%s: not enough memory"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } snprintf (option_name, length, "weechat.proxy.%s.type", proxy); proxy_type = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.ipv6", proxy); proxy_ipv6 = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.address", proxy); proxy_address = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.port", proxy); proxy_port = weechat_config_get (option_name); free (option_name); if (!proxy_type || !proxy_address) { weechat_printf (server->buffer, _("%s%s: proxy \"%s\" not found for server " "\"%s\", cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, proxy, server->name); return 0; } str_proxy_type = weechat_config_string (proxy_type); str_proxy_address = weechat_config_string (proxy_address); if (!str_proxy_type[0] || !proxy_ipv6 || !str_proxy_address[0] || !proxy_port) { weechat_printf (server->buffer, _("%s%s: missing proxy settings, check options " "for proxy \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, proxy); return 0; } } if (!server->nicks_array) { weechat_printf (server->buffer, _("%s%s: nicks not defined for server \"%s\", " "cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name); return 0; } #ifndef HAVE_GNUTLS if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) { weechat_printf (server->buffer, _("%s%s: cannot connect with SSL because WeeChat " "was not built with GnuTLS support"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } #endif if (proxy_type) { weechat_printf (server->buffer, _("%s: connecting to server %s/%d%s%s via %s " "proxy %s/%d%s..."), IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), (weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : ""); weechat_log_printf (_("Connecting to server %s/%d%s%s via %s proxy " "%s/%d%s..."), server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), (weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : ""); } else { weechat_printf (server->buffer, _("%s: connecting to server %s/%d%s%s..."), IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : ""); weechat_log_printf (_("%s%s: connecting to server %s/%d%s%s..."), "", IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : ""); } /* close connection if opened */ irc_server_close_connection (server); /* create socket and set options */ if (proxy_type) { server->sock = socket ((weechat_config_integer (proxy_ipv6)) ? AF_INET6 : AF_INET, SOCK_STREAM, 0); } else { server->sock = socket ((IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? AF_INET6 : AF_INET, SOCK_STREAM, 0); } if (server->sock == -1) { weechat_printf (server->buffer, _("%s%s: cannot create socket"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } /* set SO_REUSEADDR option for socket */ set = 1; if (setsockopt (server->sock, SOL_SOCKET, SO_REUSEADDR, (void *) &set, sizeof (set)) == -1) { weechat_printf (server->buffer, _("%s%s: cannot set socket option " "\"SO_REUSEADDR\""), weechat_prefix ("error"), IRC_PLUGIN_NAME); } /* set SO_KEEPALIVE option for socket */ set = 1; if (setsockopt (server->sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &set, sizeof (set)) == -1) { weechat_printf (server->buffer, _("%s%s: cannot set socket option " "\"SO_KEEPALIVE\""), weechat_prefix ("error"), IRC_PLUGIN_NAME); } /* init SSL if asked and connect */ server->ssl_connected = 0; #ifdef HAVE_GNUTLS if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) server->ssl_connected = 1; server->hook_connect = weechat_hook_connect (proxy, server->current_address, server->current_port, server->sock, IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6), (server->ssl_connected) ? &server->gnutls_sess : NULL, (server->ssl_connected) ? irc_server_gnutls_callback : NULL, IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE), IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME), &irc_server_connect_cb, server); #else server->hook_connect = weechat_hook_connect (proxy, server->current_address, server->current_port, server->sock, IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6), NULL, NULL, 0, IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME), &irc_server_connect_cb, server); #endif /* send signal "irc_server_connecting" with server name */ weechat_hook_signal_send ("irc_server_connecting", WEECHAT_HOOK_SIGNAL_STRING, server->name); return 1; }
null
0
irc_server_connect (struct t_irc_server *server) { int set, length; char *option_name; struct t_config_option *proxy_type, *proxy_ipv6, *proxy_address, *proxy_port; const char *proxy, *str_proxy_type, *str_proxy_address; if (!server->buffer) { if (!irc_server_create_buffer (server)) return 0; weechat_buffer_set (server->buffer, "display", "auto"); } weechat_bar_item_update ("buffer_name"); irc_server_set_index_current_address (server, server->index_current_address); if (!server->current_address) { weechat_printf (server->buffer, _("%s%s: unknown address server \"%s\", " "cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name); return 0; } /* free some old values (from a previous connection to server) */ if (server->isupport) { free (server->isupport); server->isupport = NULL; } if (server->prefix_modes) { free (server->prefix_modes); server->prefix_modes = NULL; } if (server->prefix_chars) { free (server->prefix_chars); server->prefix_chars = NULL; } proxy_type = NULL; proxy_ipv6 = NULL; proxy_address = NULL; proxy_port = NULL; str_proxy_type = NULL; str_proxy_address = NULL; proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); if (proxy && proxy[0]) { length = 32 + strlen (proxy) + 1; option_name = malloc (length); if (!option_name) { weechat_printf (server->buffer, _("%s%s: not enough memory"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } snprintf (option_name, length, "weechat.proxy.%s.type", proxy); proxy_type = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.ipv6", proxy); proxy_ipv6 = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.address", proxy); proxy_address = weechat_config_get (option_name); snprintf (option_name, length, "weechat.proxy.%s.port", proxy); proxy_port = weechat_config_get (option_name); free (option_name); if (!proxy_type || !proxy_address) { weechat_printf (server->buffer, _("%s%s: proxy \"%s\" not found for server " "\"%s\", cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, proxy, server->name); return 0; } str_proxy_type = weechat_config_string (proxy_type); str_proxy_address = weechat_config_string (proxy_address); if (!str_proxy_type[0] || !proxy_ipv6 || !str_proxy_address[0] || !proxy_port) { weechat_printf (server->buffer, _("%s%s: missing proxy settings, check options " "for proxy \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, proxy); return 0; } } if (!server->nicks_array) { weechat_printf (server->buffer, _("%s%s: nicks not defined for server \"%s\", " "cannot connect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name); return 0; } #ifndef HAVE_GNUTLS if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) { weechat_printf (server->buffer, _("%s%s: cannot connect with SSL because WeeChat " "was not built with GnuTLS support"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } #endif if (proxy_type) { weechat_printf (server->buffer, _("%s: connecting to server %s/%d%s%s via %s " "proxy %s/%d%s..."), IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), (weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : ""); weechat_log_printf (_("Connecting to server %s/%d%s%s via %s proxy " "%s/%d%s..."), server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : "", str_proxy_type, str_proxy_address, weechat_config_integer (proxy_port), (weechat_config_boolean (proxy_ipv6)) ? " (IPv6)" : ""); } else { weechat_printf (server->buffer, _("%s: connecting to server %s/%d%s%s..."), IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : ""); weechat_log_printf (_("%s%s: connecting to server %s/%d%s%s..."), "", IRC_PLUGIN_NAME, server->current_address, server->current_port, (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? " (IPv6)" : "", (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) ? " (SSL)" : ""); } /* close connection if opened */ irc_server_close_connection (server); /* create socket and set options */ if (proxy_type) { server->sock = socket ((weechat_config_integer (proxy_ipv6)) ? AF_INET6 : AF_INET, SOCK_STREAM, 0); } else { server->sock = socket ((IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6)) ? AF_INET6 : AF_INET, SOCK_STREAM, 0); } if (server->sock == -1) { weechat_printf (server->buffer, _("%s%s: cannot create socket"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return 0; } /* set SO_REUSEADDR option for socket */ set = 1; if (setsockopt (server->sock, SOL_SOCKET, SO_REUSEADDR, (void *) &set, sizeof (set)) == -1) { weechat_printf (server->buffer, _("%s%s: cannot set socket option " "\"SO_REUSEADDR\""), weechat_prefix ("error"), IRC_PLUGIN_NAME); } /* set SO_KEEPALIVE option for socket */ set = 1; if (setsockopt (server->sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &set, sizeof (set)) == -1) { weechat_printf (server->buffer, _("%s%s: cannot set socket option " "\"SO_KEEPALIVE\""), weechat_prefix ("error"), IRC_PLUGIN_NAME); } /* init SSL if asked and connect */ server->ssl_connected = 0; #ifdef HAVE_GNUTLS if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SSL)) server->ssl_connected = 1; server->hook_connect = weechat_hook_connect (proxy, server->current_address, server->current_port, server->sock, IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6), (server->ssl_connected) ? &server->gnutls_sess : NULL, (server->ssl_connected) ? irc_server_gnutls_callback : NULL, IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE), IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME), &irc_server_connect_cb, server); #else server->hook_connect = weechat_hook_connect (proxy, server->current_address, server->current_port, server->sock, IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_IPV6), NULL, NULL, 0, IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_LOCAL_HOSTNAME), &irc_server_connect_cb, server); #endif /* send signal "irc_server_connecting" with server name */ weechat_hook_signal_send ("irc_server_connecting", WEECHAT_HOOK_SIGNAL_STRING, server->name); return 1; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,764
irc_server_connect_cb (void *data, int status, int gnutls_rc, const char *error, const char *ip_address) { struct t_irc_server *server; const char *proxy; server = (struct t_irc_server *)data; proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); server->hook_connect = NULL; switch (status) { case WEECHAT_HOOK_CONNECT_OK: /* login to server */ if (server->current_ip) free (server->current_ip); server->current_ip = (ip_address) ? strdup (ip_address) : NULL; weechat_printf (server->buffer, _("%s: connected to %s/%d (%s)"), IRC_PLUGIN_NAME, server->current_address, server->current_port, (server->current_ip) ? server->current_ip : "?"); server->hook_fd = weechat_hook_fd (server->sock, 1, 0, 0, &irc_server_recv_cb, server); irc_server_login (server); break; case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy address \"%s\" not found") : _("%s%s: address \"%s\" not found"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->current_address); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy IP address not found") : _("%s%s: IP address not found"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy connection refused") : _("%s%s: connection refused"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_PROXY_ERROR: weechat_printf (server->buffer, _("%s%s: proxy fails to establish " "connection to server " "(check username/password if used " "and if server address/port is allowed by " "proxy)"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR: weechat_printf (server->buffer, _("%s%s: unable to set local hostname/IP"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; case WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR: weechat_printf (server->buffer, _("%s%s: TLS init error"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; case WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR: weechat_printf (server->buffer, _("%s%s: TLS handshake failed"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } #ifdef HAVE_GNUTLS if (gnutls_rc == GNUTLS_E_DH_PRIME_UNACCEPTABLE) { weechat_printf (server->buffer, _("%s%s: you should play with option " "irc.server.%s.ssl_dhkey_size (current " "value is %d)"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name, IRC_SERVER_OPTION_INTEGER (server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); } #else (void) gnutls_rc; #endif irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_MEMORY_ERROR: weechat_printf (server->buffer, _("%s%s: not enough memory"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; } return WEECHAT_RC_OK; }
null
0
irc_server_connect_cb (void *data, int status, int gnutls_rc, const char *error, const char *ip_address) { struct t_irc_server *server; const char *proxy; server = (struct t_irc_server *)data; proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY); server->hook_connect = NULL; switch (status) { case WEECHAT_HOOK_CONNECT_OK: /* login to server */ if (server->current_ip) free (server->current_ip); server->current_ip = (ip_address) ? strdup (ip_address) : NULL; weechat_printf (server->buffer, _("%s: connected to %s/%d (%s)"), IRC_PLUGIN_NAME, server->current_address, server->current_port, (server->current_ip) ? server->current_ip : "?"); server->hook_fd = weechat_hook_fd (server->sock, 1, 0, 0, &irc_server_recv_cb, server); irc_server_login (server); break; case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy address \"%s\" not found") : _("%s%s: address \"%s\" not found"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->current_address); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy IP address not found") : _("%s%s: IP address not found"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED: weechat_printf (server->buffer, (proxy && proxy[0]) ? _("%s%s: proxy connection refused") : _("%s%s: connection refused"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_PROXY_ERROR: weechat_printf (server->buffer, _("%s%s: proxy fails to establish " "connection to server " "(check username/password if used " "and if server address/port is allowed by " "proxy)"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR: weechat_printf (server->buffer, _("%s%s: unable to set local hostname/IP"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; case WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR: weechat_printf (server->buffer, _("%s%s: TLS init error"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; case WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR: weechat_printf (server->buffer, _("%s%s: TLS handshake failed"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } #ifdef HAVE_GNUTLS if (gnutls_rc == GNUTLS_E_DH_PRIME_UNACCEPTABLE) { weechat_printf (server->buffer, _("%s%s: you should play with option " "irc.server.%s.ssl_dhkey_size (current " "value is %d)"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server->name, IRC_SERVER_OPTION_INTEGER (server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); } #else (void) gnutls_rc; #endif irc_server_close_connection (server); irc_server_switch_address (server, 1); break; case WEECHAT_HOOK_CONNECT_MEMORY_ERROR: weechat_printf (server->buffer, _("%s%s: not enough memory"), weechat_prefix ("error"), IRC_PLUGIN_NAME); if (error && error[0]) { weechat_printf (server->buffer, _("%s%s: error: %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, error); } irc_server_close_connection (server); irc_server_reconnect_schedule (server); break; } return WEECHAT_RC_OK; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,765
irc_server_copy (struct t_irc_server *server, const char *new_name) { struct t_irc_server *new_server; struct t_infolist *infolist; char *mask, *pos; const char *option_name; int length, index_option; /* check if another server exists with this name */ if (irc_server_search (new_name)) return NULL; new_server = irc_server_alloc (new_name); if (new_server) { /* duplicate options */ length = 32 + strlen (server->name) + 1; mask = malloc (length); if (!mask) return 0; snprintf (mask, length, "irc.server.%s.*", server->name); infolist = weechat_infolist_get ("option", NULL, mask); free (mask); while (weechat_infolist_next (infolist)) { if (!weechat_infolist_integer (infolist, "value_is_null")) { option_name = weechat_infolist_string (infolist, "option_name"); pos = strrchr (option_name, '.'); if (pos) { index_option = irc_server_search_option (pos + 1); if (index_option >= 0) { weechat_config_option_set (new_server->options[index_option], weechat_infolist_string (infolist, "value"), 1); } } } } } return new_server; }
null
0
irc_server_copy (struct t_irc_server *server, const char *new_name) { struct t_irc_server *new_server; struct t_infolist *infolist; char *mask, *pos; const char *option_name; int length, index_option; /* check if another server exists with this name */ if (irc_server_search (new_name)) return NULL; new_server = irc_server_alloc (new_name); if (new_server) { /* duplicate options */ length = 32 + strlen (server->name) + 1; mask = malloc (length); if (!mask) return 0; snprintf (mask, length, "irc.server.%s.*", server->name); infolist = weechat_infolist_get ("option", NULL, mask); free (mask); while (weechat_infolist_next (infolist)) { if (!weechat_infolist_integer (infolist, "value_is_null")) { option_name = weechat_infolist_string (infolist, "option_name"); pos = strrchr (option_name, '.'); if (pos) { index_option = irc_server_search_option (pos + 1); if (index_option >= 0) { weechat_config_option_set (new_server->options[index_option], weechat_infolist_string (infolist, "value"), 1); } } } } } return new_server; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,766
irc_server_disconnect (struct t_irc_server *server, int switch_address, int reconnect) { struct t_irc_channel *ptr_channel; if (server->is_connected) { /* * remove all nicks and write disconnection message on each * channel/private buffer */ for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { irc_nick_free_all (server, ptr_channel); weechat_printf (ptr_channel->buffer, _("%s%s: disconnected from server"), "", IRC_PLUGIN_NAME); } } irc_server_close_connection (server); if (server->buffer) { weechat_printf (server->buffer, _("%s: disconnected from server"), IRC_PLUGIN_NAME); } if (switch_address) irc_server_switch_address (server, 0); else irc_server_set_index_current_address(server, 0); if (server->nick_modes) { free (server->nick_modes); server->nick_modes = NULL; weechat_bar_item_update ("input_prompt"); } server->is_away = 0; server->away_time = 0; server->lag = 0; server->lag_check_time.tv_sec = 0; server->lag_check_time.tv_usec = 0; server->lag_next_check = time (NULL) + weechat_config_integer (irc_config_network_lag_check); server->lag_last_refresh = 0; if (reconnect && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) irc_server_reconnect_schedule (server); else { server->reconnect_delay = 0; server->reconnect_start = 0; } /* discard current nick if no reconnection asked */ if (!reconnect && server->nick) irc_server_set_nick (server, NULL); irc_server_set_buffer_title (server); /* send signal "irc_server_disconnected" with server name */ weechat_hook_signal_send ("irc_server_disconnected", WEECHAT_HOOK_SIGNAL_STRING, server->name); }
null
0
irc_server_disconnect (struct t_irc_server *server, int switch_address, int reconnect) { struct t_irc_channel *ptr_channel; if (server->is_connected) { /* * remove all nicks and write disconnection message on each * channel/private buffer */ for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { irc_nick_free_all (server, ptr_channel); weechat_printf (ptr_channel->buffer, _("%s%s: disconnected from server"), "", IRC_PLUGIN_NAME); } } irc_server_close_connection (server); if (server->buffer) { weechat_printf (server->buffer, _("%s: disconnected from server"), IRC_PLUGIN_NAME); } if (switch_address) irc_server_switch_address (server, 0); else irc_server_set_index_current_address(server, 0); if (server->nick_modes) { free (server->nick_modes); server->nick_modes = NULL; weechat_bar_item_update ("input_prompt"); } server->is_away = 0; server->away_time = 0; server->lag = 0; server->lag_check_time.tv_sec = 0; server->lag_check_time.tv_usec = 0; server->lag_next_check = time (NULL) + weechat_config_integer (irc_config_network_lag_check); server->lag_last_refresh = 0; if (reconnect && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) irc_server_reconnect_schedule (server); else { server->reconnect_delay = 0; server->reconnect_start = 0; } /* discard current nick if no reconnection asked */ if (!reconnect && server->nick) irc_server_set_nick (server, NULL); irc_server_set_buffer_title (server); /* send signal "irc_server_disconnected" with server name */ weechat_hook_signal_send ("irc_server_disconnected", WEECHAT_HOOK_SIGNAL_STRING, server->name); }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,767
irc_server_free (struct t_irc_server *server) { struct t_irc_server *new_irc_servers; if (!server) return; /* close all channels/privates */ irc_channel_free_all (server); /* remove server from queue */ if (last_irc_server == server) last_irc_server = server->prev_server; if (server->prev_server) { (server->prev_server)->next_server = server->next_server; new_irc_servers = irc_servers; } else new_irc_servers = server->next_server; if (server->next_server) (server->next_server)->prev_server = server->prev_server; irc_server_free_data (server); free (server); irc_servers = new_irc_servers; }
null
0
irc_server_free (struct t_irc_server *server) { struct t_irc_server *new_irc_servers; if (!server) return; /* close all channels/privates */ irc_channel_free_all (server); /* remove server from queue */ if (last_irc_server == server) last_irc_server = server->prev_server; if (server->prev_server) { (server->prev_server)->next_server = server->next_server; new_irc_servers = irc_servers; } else new_irc_servers = server->next_server; if (server->next_server) (server->next_server)->prev_server = server->prev_server; irc_server_free_data (server); free (server); irc_servers = new_irc_servers; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,768
irc_server_free_all () { /* for each server in memory, remove it */ while (irc_servers) { irc_server_free (irc_servers); } }
null
0
irc_server_free_all () { /* for each server in memory, remove it */ while (irc_servers) { irc_server_free (irc_servers); } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,769
irc_server_free_data (struct t_irc_server *server) { int i; if (!server) return; /* free data */ for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { if (server->options[i]) weechat_config_option_free (server->options[i]); } if (server->name) free (server->name); if (server->addresses_array) weechat_string_free_split (server->addresses_array); if (server->ports_array) free (server->ports_array); if (server->current_address) free (server->current_address); if (server->current_ip) free (server->current_ip); if (server->hook_connect) weechat_unhook (server->hook_connect); if (server->hook_fd) weechat_unhook (server->hook_fd); if (server->hook_timer_connection) weechat_unhook (server->hook_timer_connection); if (server->hook_timer_sasl) weechat_unhook (server->hook_timer_sasl); if (server->unterminated_message) free (server->unterminated_message); if (server->nicks_array) weechat_string_free_split (server->nicks_array); if (server->nick) free (server->nick); if (server->nick_modes) free (server->nick_modes); if (server->isupport) free (server->isupport); if (server->prefix_modes) free (server->prefix_modes); if (server->prefix_chars) free (server->prefix_chars); if (server->away_message) free (server->away_message); if (server->cmd_list_regexp) { regfree (server->cmd_list_regexp); free (server->cmd_list_regexp); } for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { irc_server_outqueue_free_all (server, i); } irc_notify_free_all (server); irc_redirect_free_all (server); if (server->channels) irc_channel_free_all (server); if (server->buffer_as_string) free (server->buffer_as_string); }
null
0
irc_server_free_data (struct t_irc_server *server) { int i; if (!server) return; /* free data */ for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { if (server->options[i]) weechat_config_option_free (server->options[i]); } if (server->name) free (server->name); if (server->addresses_array) weechat_string_free_split (server->addresses_array); if (server->ports_array) free (server->ports_array); if (server->current_address) free (server->current_address); if (server->current_ip) free (server->current_ip); if (server->hook_connect) weechat_unhook (server->hook_connect); if (server->hook_fd) weechat_unhook (server->hook_fd); if (server->hook_timer_connection) weechat_unhook (server->hook_timer_connection); if (server->hook_timer_sasl) weechat_unhook (server->hook_timer_sasl); if (server->unterminated_message) free (server->unterminated_message); if (server->nicks_array) weechat_string_free_split (server->nicks_array); if (server->nick) free (server->nick); if (server->nick_modes) free (server->nick_modes); if (server->isupport) free (server->isupport); if (server->prefix_modes) free (server->prefix_modes); if (server->prefix_chars) free (server->prefix_chars); if (server->away_message) free (server->away_message); if (server->cmd_list_regexp) { regfree (server->cmd_list_regexp); free (server->cmd_list_regexp); } for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { irc_server_outqueue_free_all (server, i); } irc_notify_free_all (server); irc_redirect_free_all (server); if (server->channels) irc_channel_free_all (server); if (server->buffer_as_string) free (server->buffer_as_string); }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,770
irc_server_get_channel_count (struct t_irc_server *server) { int count; struct t_irc_channel *ptr_channel; count = 0; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) count++; } return count; }
null
0
irc_server_get_channel_count (struct t_irc_server *server) { int count; struct t_irc_channel *ptr_channel; count = 0; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) count++; } return count; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,771
irc_server_get_isupport_value (struct t_irc_server *server, const char *feature) { char feature2[64], *pos_feature, *pos_equal, *pos_space; int length; static char value[256]; if (!server || !server->isupport || !feature) return NULL; /* search feature with value */ snprintf (feature2, sizeof (feature2), " %s=", feature); pos_feature = strstr (server->isupport, feature2); if (pos_feature) { /* feature found with value, return value */ pos_feature++; pos_equal = strchr (pos_feature, '='); pos_space = strchr (pos_feature, ' '); if (pos_space) length = pos_space - pos_equal - 1; else length = strlen (pos_equal) + 1; if (length > (int)sizeof (value) - 1) length = (int)sizeof (value) - 1; memcpy (value, pos_equal + 1, length); value[length] = '\0'; return value; } /* search feature without value */ feature2[strlen (feature2) - 1] = ' '; pos_feature = strstr (server->isupport, feature2); if (pos_feature) { value[0] = '\0'; return value; } /* feature not found in isupport */ return NULL; }
null
0
irc_server_get_isupport_value (struct t_irc_server *server, const char *feature) { char feature2[64], *pos_feature, *pos_equal, *pos_space; int length; static char value[256]; if (!server || !server->isupport || !feature) return NULL; /* search feature with value */ snprintf (feature2, sizeof (feature2), " %s=", feature); pos_feature = strstr (server->isupport, feature2); if (pos_feature) { /* feature found with value, return value */ pos_feature++; pos_equal = strchr (pos_feature, '='); pos_space = strchr (pos_feature, ' '); if (pos_space) length = pos_space - pos_equal - 1; else length = strlen (pos_equal) + 1; if (length > (int)sizeof (value) - 1) length = (int)sizeof (value) - 1; memcpy (value, pos_equal + 1, length); value[length] = '\0'; return value; } /* search feature without value */ feature2[strlen (feature2) - 1] = ' '; pos_feature = strstr (server->isupport, feature2); if (pos_feature) { value[0] = '\0'; return value; } /* feature not found in isupport */ return NULL; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,772
irc_server_get_name_without_port (const char *name) { char *pos; if (!name) return NULL; pos = strchr (name, '/'); if (pos && (pos != name)) return weechat_strndup (name, pos - name); return strdup (name); }
null
0
irc_server_get_name_without_port (const char *name) { char *pos; if (!name) return NULL; pos = strchr (name, '/'); if (pos && (pos != name)) return weechat_strndup (name, pos - name); return strdup (name); }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,773
irc_server_get_nick_index (struct t_irc_server *server) { int i; if (!server->nick) return -1; for (i = 0; i < server->nicks_count; i++) { if (strcmp (server->nick, server->nicks_array[i]) == 0) { return i; } } /* nick not found */ return -1; }
null
0
irc_server_get_nick_index (struct t_irc_server *server) { int i; if (!server->nick) return -1; for (i = 0; i < server->nicks_count; i++) { if (strcmp (server->nick, server->nicks_array[i]) == 0) { return i; } } /* nick not found */ return -1; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,774
irc_server_get_number_connected () { struct t_irc_server *ptr_server; int number; number = 0; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->is_connected) number++; } return number; }
null
0
irc_server_get_number_connected () { struct t_irc_server *ptr_server; int number; number = 0; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->is_connected) number++; } return number; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,775
irc_server_get_prefix_char_for_mode (struct t_irc_server *server, char mode) { const char *prefix_chars; int index; if (server) { prefix_chars = irc_server_get_prefix_chars (server); index = irc_server_get_prefix_mode_index (server, mode); if (index >= 0) return prefix_chars[index]; } return ' '; }
null
0
irc_server_get_prefix_char_for_mode (struct t_irc_server *server, char mode) { const char *prefix_chars; int index; if (server) { prefix_chars = irc_server_get_prefix_chars (server); index = irc_server_get_prefix_mode_index (server, mode); if (index >= 0) return prefix_chars[index]; } return ' '; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,776
irc_server_get_prefix_chars (struct t_irc_server *server) { return (server && server->prefix_chars) ? server->prefix_chars : irc_server_prefix_chars_default; }
null
0
irc_server_get_prefix_chars (struct t_irc_server *server) { return (server && server->prefix_chars) ? server->prefix_chars : irc_server_prefix_chars_default; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,777
irc_server_get_prefix_mode_index (struct t_irc_server *server, char mode) { const char *prefix_modes; char *pos; if (server) { prefix_modes = irc_server_get_prefix_modes (server); pos = strchr (prefix_modes, mode); if (pos) return pos - prefix_modes; } return -1; }
null
0
irc_server_get_prefix_mode_index (struct t_irc_server *server, char mode) { const char *prefix_modes; char *pos; if (server) { prefix_modes = irc_server_get_prefix_modes (server); pos = strchr (prefix_modes, mode); if (pos) return pos - prefix_modes; } return -1; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,778
irc_server_get_prefix_modes (struct t_irc_server *server) { return (server && server->prefix_modes) ? server->prefix_modes : irc_server_prefix_modes_default; }
null
0
irc_server_get_prefix_modes (struct t_irc_server *server) { return (server && server->prefix_modes) ? server->prefix_modes : irc_server_prefix_modes_default; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,779
irc_server_get_pv_count (struct t_irc_server *server) { int count; struct t_irc_channel *ptr_channel; count = 0; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) count++; } return count; }
null
0
irc_server_get_pv_count (struct t_irc_server *server) { int count; struct t_irc_channel *ptr_channel; count = 0; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) count++; } return count; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,780
irc_server_get_tags_to_send (const char *tags) { int length; char *buf; if (!tags && !irc_server_send_default_tags) return NULL; if (!tags) return strdup (irc_server_send_default_tags); if (!irc_server_send_default_tags) return strdup (tags); /* concatenate tags and irc_server_send_default_tags */ length = strlen (tags) + 1 + strlen (irc_server_send_default_tags) + 1; buf = malloc (length); if (buf) snprintf (buf, length, "%s,%s", tags, irc_server_send_default_tags); return buf; }
null
0
irc_server_get_tags_to_send (const char *tags) { int length; char *buf; if (!tags && !irc_server_send_default_tags) return NULL; if (!tags) return strdup (irc_server_send_default_tags); if (!irc_server_send_default_tags) return strdup (tags); /* concatenate tags and irc_server_send_default_tags */ length = strlen (tags) + 1 + strlen (irc_server_send_default_tags) + 1; buf = malloc (length); if (buf) snprintf (buf, length, "%s,%s", tags, irc_server_send_default_tags); return buf; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,781
irc_server_login (struct t_irc_server *server) { const char *password, *username, *realname; password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD); username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME); realname = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME); if (password && password[0]) irc_server_sendf (server, 0, NULL, "PASS %s", password); if (!server->nick) { irc_server_set_nick (server, (server->nicks_array) ? server->nicks_array[0] : "weechat"); server->nick_first_tried = 0; } else server->nick_first_tried = irc_server_get_nick_index (server); if (irc_server_sasl_enabled (server)) { irc_server_sendf (server, 0, NULL, "CAP LS"); } irc_server_sendf (server, 0, NULL, "NICK %s\n" "USER %s %s %s :%s", server->nick, (username && username[0]) ? username : "weechat", (username && username[0]) ? username : "weechat", server->current_address, (realname && realname[0]) ? realname : ((username && username[0]) ? username : "weechat")); if (server->hook_timer_connection) weechat_unhook (server->hook_timer_connection); server->hook_timer_connection = weechat_hook_timer ( IRC_SERVER_OPTION_INTEGER (server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT) * 1000, 0, 1, &irc_server_timer_connection_cb, server); }
null
0
irc_server_login (struct t_irc_server *server) { const char *password, *username, *realname; password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD); username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME); realname = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME); if (password && password[0]) irc_server_sendf (server, 0, NULL, "PASS %s", password); if (!server->nick) { irc_server_set_nick (server, (server->nicks_array) ? server->nicks_array[0] : "weechat"); server->nick_first_tried = 0; } else server->nick_first_tried = irc_server_get_nick_index (server); if (irc_server_sasl_enabled (server)) { irc_server_sendf (server, 0, NULL, "CAP LS"); } irc_server_sendf (server, 0, NULL, "NICK %s\n" "USER %s %s %s :%s", server->nick, (username && username[0]) ? username : "weechat", (username && username[0]) ? username : "weechat", server->current_address, (realname && realname[0]) ? realname : ((username && username[0]) ? username : "weechat")); if (server->hook_timer_connection) weechat_unhook (server->hook_timer_connection); server->hook_timer_connection = weechat_hook_timer ( IRC_SERVER_OPTION_INTEGER (server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT) * 1000, 0, 1, &irc_server_timer_connection_cb, server); }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,782
irc_server_msgq_add_buffer (struct t_irc_server *server, const char *buffer) { char *pos_cr, *pos_lf; while (buffer[0]) { pos_cr = strchr (buffer, '\r'); pos_lf = strchr (buffer, '\n'); if (!pos_cr && !pos_lf) { /* no CR/LF found => add to unterminated and return */ irc_server_msgq_add_unterminated (server, buffer); return; } if (pos_cr && ((!pos_lf) || (pos_lf > pos_cr))) { /* found '\r' first => ignore this char */ pos_cr[0] = '\0'; irc_server_msgq_add_unterminated (server, buffer); buffer = pos_cr + 1; } else { /* found: '\n' first => terminate message */ pos_lf[0] = '\0'; irc_server_msgq_add_msg (server, buffer); buffer = pos_lf + 1; } } }
null
0
irc_server_msgq_add_buffer (struct t_irc_server *server, const char *buffer) { char *pos_cr, *pos_lf; while (buffer[0]) { pos_cr = strchr (buffer, '\r'); pos_lf = strchr (buffer, '\n'); if (!pos_cr && !pos_lf) { /* no CR/LF found => add to unterminated and return */ irc_server_msgq_add_unterminated (server, buffer); return; } if (pos_cr && ((!pos_lf) || (pos_lf > pos_cr))) { /* found '\r' first => ignore this char */ pos_cr[0] = '\0'; irc_server_msgq_add_unterminated (server, buffer); buffer = pos_cr + 1; } else { /* found: '\n' first => terminate message */ pos_lf[0] = '\0'; irc_server_msgq_add_msg (server, buffer); buffer = pos_lf + 1; } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,783
irc_server_msgq_add_msg (struct t_irc_server *server, const char *msg) { struct t_irc_message *message; if (!server->unterminated_message && !msg[0]) return; message = malloc (sizeof (*message)); if (!message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } message->server = server; if (server->unterminated_message) { message->data = malloc (strlen (server->unterminated_message) + strlen (msg) + 1); if (!message->data) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } else { strcpy (message->data, server->unterminated_message); strcat (message->data, msg); } free (server->unterminated_message); server->unterminated_message = NULL; } else message->data = strdup (msg); message->next_message = NULL; if (irc_msgq_last_msg) { irc_msgq_last_msg->next_message = message; irc_msgq_last_msg = message; } else { irc_recv_msgq = message; irc_msgq_last_msg = message; } }
null
0
irc_server_msgq_add_msg (struct t_irc_server *server, const char *msg) { struct t_irc_message *message; if (!server->unterminated_message && !msg[0]) return; message = malloc (sizeof (*message)); if (!message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } message->server = server; if (server->unterminated_message) { message->data = malloc (strlen (server->unterminated_message) + strlen (msg) + 1); if (!message->data) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } else { strcpy (message->data, server->unterminated_message); strcat (message->data, msg); } free (server->unterminated_message); server->unterminated_message = NULL; } else message->data = strdup (msg); message->next_message = NULL; if (irc_msgq_last_msg) { irc_msgq_last_msg->next_message = message; irc_msgq_last_msg = message; } else { irc_recv_msgq = message; irc_msgq_last_msg = message; } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,784
irc_server_msgq_add_unterminated (struct t_irc_server *server, const char *string) { if (!string[0]) return; if (server->unterminated_message) { server->unterminated_message = realloc (server->unterminated_message, (strlen (server->unterminated_message) + strlen (string) + 1)); if (!server->unterminated_message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } else strcat (server->unterminated_message, string); } else { server->unterminated_message = strdup (string); if (!server->unterminated_message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } } }
null
0
irc_server_msgq_add_unterminated (struct t_irc_server *server, const char *string) { if (!string[0]) return; if (server->unterminated_message) { server->unterminated_message = realloc (server->unterminated_message, (strlen (server->unterminated_message) + strlen (string) + 1)); if (!server->unterminated_message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } else strcat (server->unterminated_message, string); } else { server->unterminated_message = strdup (string); if (!server->unterminated_message) { weechat_printf (server->buffer, _("%s%s: not enough memory for received message"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,785
irc_server_outqueue_add (struct t_irc_server *server, int priority, const char *command, const char *msg1, const char *msg2, int modified, const char *tags, struct t_irc_redirect *redirect) { struct t_irc_outqueue *new_outqueue; new_outqueue = malloc (sizeof (*new_outqueue)); if (new_outqueue) { new_outqueue->command = (command) ? strdup (command) : strdup ("unknown"); new_outqueue->message_before_mod = (msg1) ? strdup (msg1) : NULL; new_outqueue->message_after_mod = (msg2) ? strdup (msg2) : NULL; new_outqueue->modified = modified; new_outqueue->tags = (tags) ? strdup (tags) : NULL; new_outqueue->redirect = redirect; new_outqueue->prev_outqueue = server->last_outqueue[priority]; new_outqueue->next_outqueue = NULL; if (server->outqueue[priority]) server->last_outqueue[priority]->next_outqueue = new_outqueue; else server->outqueue[priority] = new_outqueue; server->last_outqueue[priority] = new_outqueue; } }
null
0
irc_server_outqueue_add (struct t_irc_server *server, int priority, const char *command, const char *msg1, const char *msg2, int modified, const char *tags, struct t_irc_redirect *redirect) { struct t_irc_outqueue *new_outqueue; new_outqueue = malloc (sizeof (*new_outqueue)); if (new_outqueue) { new_outqueue->command = (command) ? strdup (command) : strdup ("unknown"); new_outqueue->message_before_mod = (msg1) ? strdup (msg1) : NULL; new_outqueue->message_after_mod = (msg2) ? strdup (msg2) : NULL; new_outqueue->modified = modified; new_outqueue->tags = (tags) ? strdup (tags) : NULL; new_outqueue->redirect = redirect; new_outqueue->prev_outqueue = server->last_outqueue[priority]; new_outqueue->next_outqueue = NULL; if (server->outqueue[priority]) server->last_outqueue[priority]->next_outqueue = new_outqueue; else server->outqueue[priority] = new_outqueue; server->last_outqueue[priority] = new_outqueue; } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,786
irc_server_outqueue_free (struct t_irc_server *server, int priority, struct t_irc_outqueue *outqueue) { struct t_irc_outqueue *new_outqueue; /* remove outqueue message */ if (server->last_outqueue[priority] == outqueue) server->last_outqueue[priority] = outqueue->prev_outqueue; if (outqueue->prev_outqueue) { (outqueue->prev_outqueue)->next_outqueue = outqueue->next_outqueue; new_outqueue = server->outqueue[priority]; } else new_outqueue = outqueue->next_outqueue; if (outqueue->next_outqueue) (outqueue->next_outqueue)->prev_outqueue = outqueue->prev_outqueue; /* free data */ if (outqueue->command) free (outqueue->command); if (outqueue->message_before_mod) free (outqueue->message_before_mod); if (outqueue->message_after_mod) free (outqueue->message_after_mod); if (outqueue->tags) free (outqueue->tags); free (outqueue); server->outqueue[priority] = new_outqueue; }
null
0
irc_server_outqueue_free (struct t_irc_server *server, int priority, struct t_irc_outqueue *outqueue) { struct t_irc_outqueue *new_outqueue; /* remove outqueue message */ if (server->last_outqueue[priority] == outqueue) server->last_outqueue[priority] = outqueue->prev_outqueue; if (outqueue->prev_outqueue) { (outqueue->prev_outqueue)->next_outqueue = outqueue->next_outqueue; new_outqueue = server->outqueue[priority]; } else new_outqueue = outqueue->next_outqueue; if (outqueue->next_outqueue) (outqueue->next_outqueue)->prev_outqueue = outqueue->prev_outqueue; /* free data */ if (outqueue->command) free (outqueue->command); if (outqueue->message_before_mod) free (outqueue->message_before_mod); if (outqueue->message_after_mod) free (outqueue->message_after_mod); if (outqueue->tags) free (outqueue->tags); free (outqueue); server->outqueue[priority] = new_outqueue; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,787
irc_server_outqueue_free_all (struct t_irc_server *server, int priority) { while (server->outqueue[priority]) { irc_server_outqueue_free (server, priority, server->outqueue[priority]); } }
null
0
irc_server_outqueue_free_all (struct t_irc_server *server, int priority) { while (server->outqueue[priority]) { irc_server_outqueue_free (server, priority, server->outqueue[priority]); } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,788
irc_server_outqueue_send (struct t_irc_server *server) { time_t time_now; char *pos, *tags_to_send; int priority, anti_flood; time_now = time (NULL); /* detect if system clock has been changed (now lower than before) */ if (server->last_user_message > time_now) server->last_user_message = time_now; for (priority = 0; priority < IRC_SERVER_NUM_OUTQUEUES_PRIO; priority++) { switch (priority) { case 0: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH); break; default: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW); break; } if (server->outqueue[priority] && (time_now >= server->last_user_message + anti_flood)) { if (server->outqueue[priority]->message_before_mod) { pos = strchr (server->outqueue[priority]->message_before_mod, '\r'); if (pos) pos[0] = '\0'; irc_raw_print (server, IRC_RAW_FLAG_SEND, server->outqueue[priority]->message_before_mod); if (pos) pos[0] = '\r'; } if (server->outqueue[priority]->message_after_mod) { pos = strchr (server->outqueue[priority]->message_after_mod, '\r'); if (pos) pos[0] = '\0'; irc_raw_print (server, IRC_RAW_FLAG_SEND | ((server->outqueue[priority]->modified) ? IRC_RAW_FLAG_MODIFIED : 0), server->outqueue[priority]->message_after_mod); if (pos) pos[0] = '\r'; /* send signal with command that will be sent to server */ irc_server_send_signal (server, "irc_out", server->outqueue[priority]->command, server->outqueue[priority]->message_after_mod, NULL); tags_to_send = irc_server_get_tags_to_send (server->outqueue[priority]->tags); irc_server_send_signal (server, "irc_outtags", server->outqueue[priority]->command, server->outqueue[priority]->message_after_mod, (tags_to_send) ? tags_to_send : ""); if (tags_to_send) free (tags_to_send); /* send command */ irc_server_send (server, server->outqueue[priority]->message_after_mod, strlen (server->outqueue[priority]->message_after_mod)); server->last_user_message = time_now; /* start redirection if redirect is set */ if (server->outqueue[priority]->redirect) { irc_redirect_init_command (server->outqueue[priority]->redirect, server->outqueue[priority]->message_after_mod); } } irc_server_outqueue_free (server, priority, server->outqueue[priority]); break; } } }
null
0
irc_server_outqueue_send (struct t_irc_server *server) { time_t time_now; char *pos, *tags_to_send; int priority, anti_flood; time_now = time (NULL); /* detect if system clock has been changed (now lower than before) */ if (server->last_user_message > time_now) server->last_user_message = time_now; for (priority = 0; priority < IRC_SERVER_NUM_OUTQUEUES_PRIO; priority++) { switch (priority) { case 0: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH); break; default: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW); break; } if (server->outqueue[priority] && (time_now >= server->last_user_message + anti_flood)) { if (server->outqueue[priority]->message_before_mod) { pos = strchr (server->outqueue[priority]->message_before_mod, '\r'); if (pos) pos[0] = '\0'; irc_raw_print (server, IRC_RAW_FLAG_SEND, server->outqueue[priority]->message_before_mod); if (pos) pos[0] = '\r'; } if (server->outqueue[priority]->message_after_mod) { pos = strchr (server->outqueue[priority]->message_after_mod, '\r'); if (pos) pos[0] = '\0'; irc_raw_print (server, IRC_RAW_FLAG_SEND | ((server->outqueue[priority]->modified) ? IRC_RAW_FLAG_MODIFIED : 0), server->outqueue[priority]->message_after_mod); if (pos) pos[0] = '\r'; /* send signal with command that will be sent to server */ irc_server_send_signal (server, "irc_out", server->outqueue[priority]->command, server->outqueue[priority]->message_after_mod, NULL); tags_to_send = irc_server_get_tags_to_send (server->outqueue[priority]->tags); irc_server_send_signal (server, "irc_outtags", server->outqueue[priority]->command, server->outqueue[priority]->message_after_mod, (tags_to_send) ? tags_to_send : ""); if (tags_to_send) free (tags_to_send); /* send command */ irc_server_send (server, server->outqueue[priority]->message_after_mod, strlen (server->outqueue[priority]->message_after_mod)); server->last_user_message = time_now; /* start redirection if redirect is set */ if (server->outqueue[priority]->redirect) { irc_redirect_init_command (server->outqueue[priority]->redirect, server->outqueue[priority]->message_after_mod); } } irc_server_outqueue_free (server, priority, server->outqueue[priority]); break; } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,789
irc_server_print_log () { struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; int i; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { weechat_log_printf (""); weechat_log_printf ("[server %s (addr:0x%lx)]", ptr_server->name, ptr_server); /* addresses */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])) weechat_log_printf (" addresses. . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_ADDRESSES)); else weechat_log_printf (" addresses. . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])); /* proxy */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PROXY])) weechat_log_printf (" proxy. . . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_PROXY)); else weechat_log_printf (" proxy. . . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_PROXY])); /* ipv6 */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_IPV6])) weechat_log_printf (" ipv6 . . . . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_IPV6)) ? "on" : "off"); else weechat_log_printf (" ipv6 . . . . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_IPV6]) ? "on" : "off"); /* ssl */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL])) weechat_log_printf (" ssl. . . . . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SSL)) ? "on" : "off"); else weechat_log_printf (" ssl. . . . . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SSL]) ? "on" : "off"); /* ssl_cert */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_CERT])) weechat_log_printf (" ssl_cert . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_SSL_CERT)); else weechat_log_printf (" ssl_cert . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_SSL_CERT])); /* ssl_dhkey_size */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_DHKEY_SIZE])) weechat_log_printf (" ssl_dhkey_size . . . : null ('%d')", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); else weechat_log_printf (" ssl_dhkey_size . . . : '%d'", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_SSL_DHKEY_SIZE])); /* ssl_verify */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_VERIFY])) weechat_log_printf (" ssl_verify . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SSL_VERIFY)) ? "on" : "off"); else weechat_log_printf (" ssl_verify . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SSL_VERIFY]) ? "on" : "off"); /* password */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PASSWORD])) weechat_log_printf (" password . . . . . . : null"); else weechat_log_printf (" password . . . . . . : (hidden)"); /* sasl_mechanism */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_MECHANISM])) weechat_log_printf (" sasl_mechanism . . . : null ('%s')", irc_sasl_mechanism_string[IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_SASL_MECHANISM)]); else weechat_log_printf (" sasl_mechanism . . . : '%s'", irc_sasl_mechanism_string[weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_SASL_MECHANISM])]); /* sasl_username */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_USERNAME])) weechat_log_printf (" sasl_username. . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_SASL_USERNAME)); else weechat_log_printf (" sasl_username. . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERNAME])); /* sasl_password */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_PASSWORD])) weechat_log_printf (" sasl_password. . . . : null"); else weechat_log_printf (" sasl_password. . . . : (hidden)"); /* autoconnect */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT])) weechat_log_printf (" autoconnect. . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) ? "on" : "off"); else weechat_log_printf (" autoconnect. . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT]) ? "on" : "off"); /* autoreconnect */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT])) weechat_log_printf (" autoreconnect. . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT)) ? "on" : "off"); else weechat_log_printf (" autoreconnect. . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT]) ? "on" : "off"); /* autoreconnect_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])) weechat_log_printf (" autoreconnect_delay. : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY)); else weechat_log_printf (" autoreconnect_delay. : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])); /* nicks */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_NICKS])) weechat_log_printf (" nicks. . . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_NICKS)); else weechat_log_printf (" nicks. . . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_NICKS])); /* username */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_USERNAME])) weechat_log_printf (" username . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_USERNAME)); else weechat_log_printf (" username . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERNAME])); /* realname */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_REALNAME])) weechat_log_printf (" realname . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_REALNAME)); else weechat_log_printf (" realname . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_REALNAME])); /* local_hostname */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])) weechat_log_printf (" local_hostname . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_LOCAL_HOSTNAME)); else weechat_log_printf (" local_hostname . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])); /* command */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND])) weechat_log_printf (" command. . . . . . . : null"); else weechat_log_printf (" command. . . . . . . : (hidden)"); /* command_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])) weechat_log_printf (" command_delay. . . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY)); else weechat_log_printf (" command_delay. . . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])); /* autojoin */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])) weechat_log_printf (" autojoin . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_AUTOJOIN)); else weechat_log_printf (" autojoin . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])); /* autorejoin */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN])) weechat_log_printf (" autorejoin . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN)) ? "on" : "off"); else weechat_log_printf (" autorejoin . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ? "on" : "off"); /* autorejoin_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY])) weechat_log_printf (" autorejoin_delay . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY)); else weechat_log_printf (" autorejoin_delay . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY])); /* connection_timeout */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT])) weechat_log_printf (" connection_timeout . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT)); else weechat_log_printf (" connection_timeout . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT])); /* anti_flood_prio_high */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH])) weechat_log_printf (" anti_flood_prio_high : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH)); else weechat_log_printf (" anti_flood_prio_high : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH])); /* anti_flood_prio_low */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW])) weechat_log_printf (" anti_flood_prio_low. : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW)); else weechat_log_printf (" anti_flood_prio_low. : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW])); /* away_check */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK])) weechat_log_printf (" away_check . . . . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AWAY_CHECK)); else weechat_log_printf (" away_check . . . . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK])); /* away_check_max_nicks */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])) weechat_log_printf (" away_check_max_nicks : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS)); else weechat_log_printf (" away_check_max_nicks : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])); /* default_msg_part */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])) weechat_log_printf (" default_msg_part . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_DEFAULT_MSG_PART)); else weechat_log_printf (" default_msg_part . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])); /* default_msg_quit */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_QUIT])) weechat_log_printf (" default_msg_quit . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_DEFAULT_MSG_QUIT)); else weechat_log_printf (" default_msg_quit . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_QUIT])); /* other server variables */ weechat_log_printf (" temp_server. . . . . : %d", ptr_server->temp_server); weechat_log_printf (" reloading_from_config: %d", ptr_server->reloaded_from_config); weechat_log_printf (" reloaded_from_config : %d", ptr_server->reloaded_from_config); weechat_log_printf (" addresses_count. . . : %d", ptr_server->addresses_count); weechat_log_printf (" addresses_array. . . : 0x%lx", ptr_server->addresses_array); weechat_log_printf (" ports_array. . . . . : 0x%lx", ptr_server->ports_array); weechat_log_printf (" index_current_address: %d", ptr_server->index_current_address); weechat_log_printf (" current_address. . . : '%s'", ptr_server->current_address); weechat_log_printf (" current_ip . . . . . : '%s'", ptr_server->current_ip); weechat_log_printf (" current_port . . . . : %d", ptr_server->current_port); weechat_log_printf (" sock . . . . . . . . : %d", ptr_server->sock); weechat_log_printf (" hook_connect . . . . : 0x%lx", ptr_server->hook_connect); weechat_log_printf (" hook_fd. . . . . . . : 0x%lx", ptr_server->hook_fd); weechat_log_printf (" hook_timer_connection: 0x%lx", ptr_server->hook_timer_connection); weechat_log_printf (" hook_timer_sasl. . . : 0x%lx", ptr_server->hook_timer_sasl); weechat_log_printf (" is_connected . . . . : %d", ptr_server->is_connected); weechat_log_printf (" ssl_connected. . . . : %d", ptr_server->ssl_connected); #ifdef HAVE_GNUTLS weechat_log_printf (" gnutls_sess. . . . . : 0x%lx", ptr_server->gnutls_sess); #endif weechat_log_printf (" unterminated_message : '%s'", ptr_server->unterminated_message); weechat_log_printf (" nicks_count. . . . . : %d", ptr_server->nicks_count); weechat_log_printf (" nicks_array. . . . . : 0x%lx", ptr_server->nicks_array); weechat_log_printf (" nick_first_tried . . : %d", ptr_server->nick_first_tried); weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick); weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes); weechat_log_printf (" isupport . . . . . . : '%s'", ptr_server->isupport); weechat_log_printf (" prefix_modes . . . . : '%s'", ptr_server->prefix_modes); weechat_log_printf (" prefix_chars . . . . : '%s'", ptr_server->prefix_chars); weechat_log_printf (" reconnect_delay. . . : %d", ptr_server->reconnect_delay); weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start); weechat_log_printf (" command_time . . . . : %ld", ptr_server->command_time); weechat_log_printf (" reconnect_join . . . : %d", ptr_server->reconnect_join); weechat_log_printf (" disable_autojoin . . : %d", ptr_server->disable_autojoin); weechat_log_printf (" is_away. . . . . . . : %d", ptr_server->is_away); weechat_log_printf (" away_message . . . . : '%s'", ptr_server->away_message); weechat_log_printf (" away_time. . . . . . : %ld", ptr_server->away_time); weechat_log_printf (" lag. . . . . . . . . : %d", ptr_server->lag); weechat_log_printf (" lag_check_time . . . : tv_sec:%d, tv_usec:%d", ptr_server->lag_check_time.tv_sec, ptr_server->lag_check_time.tv_usec); weechat_log_printf (" lag_next_check . . . : %ld", ptr_server->lag_next_check); weechat_log_printf (" lag_last_refresh . . : %ld", ptr_server->lag_last_refresh); weechat_log_printf (" cmd_list_regexp. . . : 0x%lx", ptr_server->cmd_list_regexp); weechat_log_printf (" last_user_message. . : %ld", ptr_server->last_user_message); weechat_log_printf (" last_away_check. . . : %ld", ptr_server->last_away_check); for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { weechat_log_printf (" outqueue[%02d] . . . . : 0x%lx", i, ptr_server->outqueue[i]); weechat_log_printf (" last_outqueue[%02d]. . : 0x%lx", i, ptr_server->last_outqueue[i]); } weechat_log_printf (" redirects. . . . . . : 0x%lx", ptr_server->redirects); weechat_log_printf (" last_redirect. . . . : 0x%lx", ptr_server->last_redirect); weechat_log_printf (" notify_list. . . . . : 0x%lx", ptr_server->notify_list); weechat_log_printf (" last_notify. . . . . : 0x%lx", ptr_server->last_notify); weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer); weechat_log_printf (" buffer_as_string . . : 0x%lx", ptr_server->buffer_as_string); weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels); weechat_log_printf (" last_channel . . . . : 0x%lx", ptr_server->last_channel); weechat_log_printf (" prev_server. . . . . : 0x%lx", ptr_server->prev_server); weechat_log_printf (" next_server. . . . . : 0x%lx", ptr_server->next_server); irc_redirect_print_log (ptr_server); irc_notify_print_log (ptr_server); for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { irc_channel_print_log (ptr_channel); } } }
null
0
irc_server_print_log () { struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; int i; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { weechat_log_printf (""); weechat_log_printf ("[server %s (addr:0x%lx)]", ptr_server->name, ptr_server); /* addresses */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])) weechat_log_printf (" addresses. . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_ADDRESSES)); else weechat_log_printf (" addresses. . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES])); /* proxy */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PROXY])) weechat_log_printf (" proxy. . . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_PROXY)); else weechat_log_printf (" proxy. . . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_PROXY])); /* ipv6 */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_IPV6])) weechat_log_printf (" ipv6 . . . . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_IPV6)) ? "on" : "off"); else weechat_log_printf (" ipv6 . . . . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_IPV6]) ? "on" : "off"); /* ssl */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL])) weechat_log_printf (" ssl. . . . . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SSL)) ? "on" : "off"); else weechat_log_printf (" ssl. . . . . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SSL]) ? "on" : "off"); /* ssl_cert */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_CERT])) weechat_log_printf (" ssl_cert . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_SSL_CERT)); else weechat_log_printf (" ssl_cert . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_SSL_CERT])); /* ssl_dhkey_size */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_DHKEY_SIZE])) weechat_log_printf (" ssl_dhkey_size . . . : null ('%d')", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); else weechat_log_printf (" ssl_dhkey_size . . . : '%d'", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_SSL_DHKEY_SIZE])); /* ssl_verify */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SSL_VERIFY])) weechat_log_printf (" ssl_verify . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SSL_VERIFY)) ? "on" : "off"); else weechat_log_printf (" ssl_verify . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SSL_VERIFY]) ? "on" : "off"); /* password */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_PASSWORD])) weechat_log_printf (" password . . . . . . : null"); else weechat_log_printf (" password . . . . . . : (hidden)"); /* sasl_mechanism */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_MECHANISM])) weechat_log_printf (" sasl_mechanism . . . : null ('%s')", irc_sasl_mechanism_string[IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_SASL_MECHANISM)]); else weechat_log_printf (" sasl_mechanism . . . : '%s'", irc_sasl_mechanism_string[weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_SASL_MECHANISM])]); /* sasl_username */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_USERNAME])) weechat_log_printf (" sasl_username. . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_SASL_USERNAME)); else weechat_log_printf (" sasl_username. . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERNAME])); /* sasl_password */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_PASSWORD])) weechat_log_printf (" sasl_password. . . . : null"); else weechat_log_printf (" sasl_password. . . . : (hidden)"); /* autoconnect */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT])) weechat_log_printf (" autoconnect. . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOCONNECT)) ? "on" : "off"); else weechat_log_printf (" autoconnect. . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT]) ? "on" : "off"); /* autoreconnect */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT])) weechat_log_printf (" autoreconnect. . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT)) ? "on" : "off"); else weechat_log_printf (" autoreconnect. . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT]) ? "on" : "off"); /* autoreconnect_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])) weechat_log_printf (" autoreconnect_delay. : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY)); else weechat_log_printf (" autoreconnect_delay. : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTORECONNECT_DELAY])); /* nicks */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_NICKS])) weechat_log_printf (" nicks. . . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_NICKS)); else weechat_log_printf (" nicks. . . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_NICKS])); /* username */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_USERNAME])) weechat_log_printf (" username . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_USERNAME)); else weechat_log_printf (" username . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERNAME])); /* realname */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_REALNAME])) weechat_log_printf (" realname . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_REALNAME)); else weechat_log_printf (" realname . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_REALNAME])); /* local_hostname */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])) weechat_log_printf (" local_hostname . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_LOCAL_HOSTNAME)); else weechat_log_printf (" local_hostname . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_LOCAL_HOSTNAME])); /* command */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND])) weechat_log_printf (" command. . . . . . . : null"); else weechat_log_printf (" command. . . . . . . : (hidden)"); /* command_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])) weechat_log_printf (" command_delay. . . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY)); else weechat_log_printf (" command_delay. . . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY])); /* autojoin */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])) weechat_log_printf (" autojoin . . . . . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_AUTOJOIN)); else weechat_log_printf (" autojoin . . . . . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN])); /* autorejoin */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN])) weechat_log_printf (" autorejoin . . . . . : null (%s)", (IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN)) ? "on" : "off"); else weechat_log_printf (" autorejoin . . . . . : %s", weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ? "on" : "off"); /* autorejoin_delay */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY])) weechat_log_printf (" autorejoin_delay . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY)); else weechat_log_printf (" autorejoin_delay . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY])); /* connection_timeout */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT])) weechat_log_printf (" connection_timeout . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_CONNECTION_TIMEOUT)); else weechat_log_printf (" connection_timeout . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT])); /* anti_flood_prio_high */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH])) weechat_log_printf (" anti_flood_prio_high : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH)); else weechat_log_printf (" anti_flood_prio_high : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH])); /* anti_flood_prio_low */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW])) weechat_log_printf (" anti_flood_prio_low. : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW)); else weechat_log_printf (" anti_flood_prio_low. : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW])); /* away_check */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK])) weechat_log_printf (" away_check . . . . . : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AWAY_CHECK)); else weechat_log_printf (" away_check . . . . . : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK])); /* away_check_max_nicks */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])) weechat_log_printf (" away_check_max_nicks : null (%d)", IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS)); else weechat_log_printf (" away_check_max_nicks : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])); /* default_msg_part */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])) weechat_log_printf (" default_msg_part . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_DEFAULT_MSG_PART)); else weechat_log_printf (" default_msg_part . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])); /* default_msg_quit */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_QUIT])) weechat_log_printf (" default_msg_quit . . : null ('%s')", IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_DEFAULT_MSG_QUIT)); else weechat_log_printf (" default_msg_quit . . : '%s'", weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_QUIT])); /* other server variables */ weechat_log_printf (" temp_server. . . . . : %d", ptr_server->temp_server); weechat_log_printf (" reloading_from_config: %d", ptr_server->reloaded_from_config); weechat_log_printf (" reloaded_from_config : %d", ptr_server->reloaded_from_config); weechat_log_printf (" addresses_count. . . : %d", ptr_server->addresses_count); weechat_log_printf (" addresses_array. . . : 0x%lx", ptr_server->addresses_array); weechat_log_printf (" ports_array. . . . . : 0x%lx", ptr_server->ports_array); weechat_log_printf (" index_current_address: %d", ptr_server->index_current_address); weechat_log_printf (" current_address. . . : '%s'", ptr_server->current_address); weechat_log_printf (" current_ip . . . . . : '%s'", ptr_server->current_ip); weechat_log_printf (" current_port . . . . : %d", ptr_server->current_port); weechat_log_printf (" sock . . . . . . . . : %d", ptr_server->sock); weechat_log_printf (" hook_connect . . . . : 0x%lx", ptr_server->hook_connect); weechat_log_printf (" hook_fd. . . . . . . : 0x%lx", ptr_server->hook_fd); weechat_log_printf (" hook_timer_connection: 0x%lx", ptr_server->hook_timer_connection); weechat_log_printf (" hook_timer_sasl. . . : 0x%lx", ptr_server->hook_timer_sasl); weechat_log_printf (" is_connected . . . . : %d", ptr_server->is_connected); weechat_log_printf (" ssl_connected. . . . : %d", ptr_server->ssl_connected); #ifdef HAVE_GNUTLS weechat_log_printf (" gnutls_sess. . . . . : 0x%lx", ptr_server->gnutls_sess); #endif weechat_log_printf (" unterminated_message : '%s'", ptr_server->unterminated_message); weechat_log_printf (" nicks_count. . . . . : %d", ptr_server->nicks_count); weechat_log_printf (" nicks_array. . . . . : 0x%lx", ptr_server->nicks_array); weechat_log_printf (" nick_first_tried . . : %d", ptr_server->nick_first_tried); weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick); weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes); weechat_log_printf (" isupport . . . . . . : '%s'", ptr_server->isupport); weechat_log_printf (" prefix_modes . . . . : '%s'", ptr_server->prefix_modes); weechat_log_printf (" prefix_chars . . . . : '%s'", ptr_server->prefix_chars); weechat_log_printf (" reconnect_delay. . . : %d", ptr_server->reconnect_delay); weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start); weechat_log_printf (" command_time . . . . : %ld", ptr_server->command_time); weechat_log_printf (" reconnect_join . . . : %d", ptr_server->reconnect_join); weechat_log_printf (" disable_autojoin . . : %d", ptr_server->disable_autojoin); weechat_log_printf (" is_away. . . . . . . : %d", ptr_server->is_away); weechat_log_printf (" away_message . . . . : '%s'", ptr_server->away_message); weechat_log_printf (" away_time. . . . . . : %ld", ptr_server->away_time); weechat_log_printf (" lag. . . . . . . . . : %d", ptr_server->lag); weechat_log_printf (" lag_check_time . . . : tv_sec:%d, tv_usec:%d", ptr_server->lag_check_time.tv_sec, ptr_server->lag_check_time.tv_usec); weechat_log_printf (" lag_next_check . . . : %ld", ptr_server->lag_next_check); weechat_log_printf (" lag_last_refresh . . : %ld", ptr_server->lag_last_refresh); weechat_log_printf (" cmd_list_regexp. . . : 0x%lx", ptr_server->cmd_list_regexp); weechat_log_printf (" last_user_message. . : %ld", ptr_server->last_user_message); weechat_log_printf (" last_away_check. . . : %ld", ptr_server->last_away_check); for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++) { weechat_log_printf (" outqueue[%02d] . . . . : 0x%lx", i, ptr_server->outqueue[i]); weechat_log_printf (" last_outqueue[%02d]. . : 0x%lx", i, ptr_server->last_outqueue[i]); } weechat_log_printf (" redirects. . . . . . : 0x%lx", ptr_server->redirects); weechat_log_printf (" last_redirect. . . . : 0x%lx", ptr_server->last_redirect); weechat_log_printf (" notify_list. . . . . : 0x%lx", ptr_server->notify_list); weechat_log_printf (" last_notify. . . . . : 0x%lx", ptr_server->last_notify); weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer); weechat_log_printf (" buffer_as_string . . : 0x%lx", ptr_server->buffer_as_string); weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels); weechat_log_printf (" last_channel . . . . : 0x%lx", ptr_server->last_channel); weechat_log_printf (" prev_server. . . . . : 0x%lx", ptr_server->prev_server); weechat_log_printf (" next_server. . . . . : 0x%lx", ptr_server->next_server); irc_redirect_print_log (ptr_server); irc_notify_print_log (ptr_server); for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { irc_channel_print_log (ptr_channel); } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,790
irc_server_reconnect (struct t_irc_server *server) { weechat_printf (server->buffer, _("%s: reconnecting to server..."), IRC_PLUGIN_NAME); server->reconnect_start = 0; if (irc_server_connect (server)) server->reconnect_join = 1; else irc_server_reconnect_schedule (server); }
null
0
irc_server_reconnect (struct t_irc_server *server) { weechat_printf (server->buffer, _("%s: reconnecting to server..."), IRC_PLUGIN_NAME); server->reconnect_start = 0; if (irc_server_connect (server)) server->reconnect_join = 1; else irc_server_reconnect_schedule (server); }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,791
irc_server_reconnect_schedule (struct t_irc_server *server) { int minutes, seconds; if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) { /* growing reconnect delay */ if (server->reconnect_delay == 0) server->reconnect_delay = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); else server->reconnect_delay = server->reconnect_delay * weechat_config_integer (irc_config_network_autoreconnect_delay_growing); if ((weechat_config_integer (irc_config_network_autoreconnect_delay_max) > 0) && (server->reconnect_delay > weechat_config_integer (irc_config_network_autoreconnect_delay_max))) server->reconnect_delay = weechat_config_integer (irc_config_network_autoreconnect_delay_max); server->reconnect_start = time (NULL); minutes = server->reconnect_delay / 60; seconds = server->reconnect_delay % 60; if ((minutes > 0) && (seconds > 0)) { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s, %d %s"), IRC_PLUGIN_NAME, minutes, NG_("minute", "minutes", minutes), seconds, NG_("second", "seconds", seconds)); } else if (minutes > 0) { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s"), IRC_PLUGIN_NAME, minutes, NG_("minute", "minutes", minutes)); } else { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s"), IRC_PLUGIN_NAME, seconds, NG_("second", "seconds", seconds)); } } else { server->reconnect_delay = 0; server->reconnect_start = 0; } }
null
0
irc_server_reconnect_schedule (struct t_irc_server *server) { int minutes, seconds; if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT)) { /* growing reconnect delay */ if (server->reconnect_delay == 0) server->reconnect_delay = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTORECONNECT_DELAY); else server->reconnect_delay = server->reconnect_delay * weechat_config_integer (irc_config_network_autoreconnect_delay_growing); if ((weechat_config_integer (irc_config_network_autoreconnect_delay_max) > 0) && (server->reconnect_delay > weechat_config_integer (irc_config_network_autoreconnect_delay_max))) server->reconnect_delay = weechat_config_integer (irc_config_network_autoreconnect_delay_max); server->reconnect_start = time (NULL); minutes = server->reconnect_delay / 60; seconds = server->reconnect_delay % 60; if ((minutes > 0) && (seconds > 0)) { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s, %d %s"), IRC_PLUGIN_NAME, minutes, NG_("minute", "minutes", minutes), seconds, NG_("second", "seconds", seconds)); } else if (minutes > 0) { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s"), IRC_PLUGIN_NAME, minutes, NG_("minute", "minutes", minutes)); } else { weechat_printf (server->buffer, _("%s: reconnecting to server in %d %s"), IRC_PLUGIN_NAME, seconds, NG_("second", "seconds", seconds)); } } else { server->reconnect_delay = 0; server->reconnect_start = 0; } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,792
irc_server_recv_cb (void *data, int fd) { struct t_irc_server *server; static char buffer[4096 + 2]; int num_read; /* make C compiler happy */ (void) fd; server = (struct t_irc_server *)data; if (!server) return WEECHAT_RC_ERROR; #ifdef HAVE_GNUTLS if (server->ssl_connected) num_read = gnutls_record_recv (server->gnutls_sess, buffer, sizeof (buffer) - 2); else #endif num_read = recv (server->sock, buffer, sizeof (buffer) - 2, 0); if (num_read > 0) { buffer[num_read] = '\0'; irc_server_msgq_add_buffer (server, buffer); irc_server_msgq_flush (); } else { #ifdef HAVE_GNUTLS if (server->ssl_connected) { if ((num_read == 0) || ((num_read != GNUTLS_E_AGAIN) && (num_read != GNUTLS_E_INTERRUPTED))) { weechat_printf (server->buffer, _("%s%s: reading data on socket: error %d %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, num_read, (num_read == 0) ? _("(connection closed by peer)") : gnutls_strerror (num_read)); weechat_printf (server->buffer, _("%s: disconnecting from server..."), IRC_PLUGIN_NAME); irc_server_disconnect (server, !server->is_connected, 1); } } else #endif { if ((num_read == 0) || ((errno != EAGAIN) && (errno != EWOULDBLOCK))) { weechat_printf (server->buffer, _("%s%s: reading data on socket: error %d %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, errno, (num_read == 0) ? _("(connection closed by peer)") : strerror (errno)); weechat_printf (server->buffer, _("%s: disconnecting from server..."), IRC_PLUGIN_NAME); irc_server_disconnect (server, !server->is_connected, 1); } } } return WEECHAT_RC_OK; }
null
0
irc_server_recv_cb (void *data, int fd) { struct t_irc_server *server; static char buffer[4096 + 2]; int num_read; /* make C compiler happy */ (void) fd; server = (struct t_irc_server *)data; if (!server) return WEECHAT_RC_ERROR; #ifdef HAVE_GNUTLS if (server->ssl_connected) num_read = gnutls_record_recv (server->gnutls_sess, buffer, sizeof (buffer) - 2); else #endif num_read = recv (server->sock, buffer, sizeof (buffer) - 2, 0); if (num_read > 0) { buffer[num_read] = '\0'; irc_server_msgq_add_buffer (server, buffer); irc_server_msgq_flush (); } else { #ifdef HAVE_GNUTLS if (server->ssl_connected) { if ((num_read == 0) || ((num_read != GNUTLS_E_AGAIN) && (num_read != GNUTLS_E_INTERRUPTED))) { weechat_printf (server->buffer, _("%s%s: reading data on socket: error %d %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, num_read, (num_read == 0) ? _("(connection closed by peer)") : gnutls_strerror (num_read)); weechat_printf (server->buffer, _("%s: disconnecting from server..."), IRC_PLUGIN_NAME); irc_server_disconnect (server, !server->is_connected, 1); } } else #endif { if ((num_read == 0) || ((errno != EAGAIN) && (errno != EWOULDBLOCK))) { weechat_printf (server->buffer, _("%s%s: reading data on socket: error %d %s"), weechat_prefix ("error"), IRC_PLUGIN_NAME, errno, (num_read == 0) ? _("(connection closed by peer)") : strerror (errno)); weechat_printf (server->buffer, _("%s: disconnecting from server..."), IRC_PLUGIN_NAME); irc_server_disconnect (server, !server->is_connected, 1); } } } return WEECHAT_RC_OK; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,793
irc_server_remove_away (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; if (server->is_connected) { for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_remove_away (server, ptr_channel); } server->last_away_check = 0; } }
null
0
irc_server_remove_away (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; if (server->is_connected) { for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_remove_away (server, ptr_channel); } server->last_away_check = 0; } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,794
irc_server_sasl_enabled (struct t_irc_server *server) { const char *sasl_username, *sasl_password; sasl_username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_USERNAME); sasl_password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_PASSWORD); /* SASL is enabled if username AND password are set */ return (sasl_username && sasl_username[0] && sasl_password && sasl_password[0]) ? 1 : 0; }
null
0
irc_server_sasl_enabled (struct t_irc_server *server) { const char *sasl_username, *sasl_password; sasl_username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_USERNAME); sasl_password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_PASSWORD); /* SASL is enabled if username AND password are set */ return (sasl_username && sasl_username[0] && sasl_password && sasl_password[0]) ? 1 : 0; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,795
irc_server_search (const char *server_name) { struct t_irc_server *ptr_server; if (!server_name) return NULL; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (strcmp (ptr_server->name, server_name) == 0) return ptr_server; } /* server not found */ return NULL; }
null
0
irc_server_search (const char *server_name) { struct t_irc_server *ptr_server; if (!server_name) return NULL; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (strcmp (ptr_server->name, server_name) == 0) return ptr_server; } /* server not found */ return NULL; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,796
irc_server_search_option (const char *option_name) { int i; if (!option_name) return -1; for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { if (weechat_strcasecmp (irc_server_option_string[i], option_name) == 0) return i; } /* server option not found */ return -1; }
null
0
irc_server_search_option (const char *option_name) { int i; if (!option_name) return -1; for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++) { if (weechat_strcasecmp (irc_server_option_string[i], option_name) == 0) return i; } /* server option not found */ return -1; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,797
irc_server_send_one_msg (struct t_irc_server *server, int flags, const char *message, const char *tags) { static char buffer[4096]; const char *ptr_msg; char *new_msg, *pos, *nick, *command, *channel, *tags_to_send; char *ptr_chan_nick, *msg_encoded; char str_modifier[64], modifier_data[256]; int rc, queue_msg, add_to_queue, first_message, anti_flood; time_t time_now; struct t_irc_redirect *ptr_redirect; rc = 1; irc_message_parse (message, &nick, NULL, &command, &channel, NULL); snprintf (str_modifier, sizeof (str_modifier), "irc_out_%s", (command) ? command : "unknown"); new_msg = weechat_hook_modifier_exec (str_modifier, server->name, message); /* no changes in new message */ if (new_msg && (strcmp (message, new_msg) == 0)) { free (new_msg); new_msg = NULL; } /* message not dropped? */ if (!new_msg || new_msg[0]) { first_message = 1; ptr_msg = (new_msg) ? new_msg : message; msg_encoded = NULL; ptr_chan_nick = (channel) ? channel : nick; if (ptr_chan_nick) { snprintf (modifier_data, sizeof (modifier_data), "%s.%s.%s", weechat_plugin->name, server->name, ptr_chan_nick); } else { snprintf (modifier_data, sizeof (modifier_data), "%s.%s", weechat_plugin->name, server->name); } msg_encoded = weechat_hook_modifier_exec ("charset_encode", modifier_data, ptr_msg); if (msg_encoded) ptr_msg = msg_encoded; while (rc && ptr_msg && ptr_msg[0]) { pos = strchr (ptr_msg, '\n'); if (pos) pos[0] = '\0'; snprintf (buffer, sizeof (buffer) - 1, "%s\r\n", ptr_msg); /* anti-flood: look whether we should queue outgoing message or not */ time_now = time (NULL); /* detect if system clock has been changed (now lower than before) */ if (server->last_user_message > time_now) server->last_user_message = time_now; /* get queue from flags */ queue_msg = 0; if (flags & IRC_SERVER_SEND_OUTQ_PRIO_HIGH) queue_msg = 1; else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_LOW) queue_msg = 2; switch (queue_msg - 1) { case 0: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH); break; default: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW); break; } add_to_queue = 0; if ((queue_msg > 0) && (server->outqueue[queue_msg - 1] || ((anti_flood > 0) && (time_now - server->last_user_message < anti_flood)))) { add_to_queue = queue_msg; } tags_to_send = irc_server_get_tags_to_send (tags); ptr_redirect = irc_redirect_search_available (server); if (add_to_queue > 0) { /* queue message (do not send anything now) */ irc_server_outqueue_add (server, add_to_queue - 1, command, (new_msg && first_message) ? message : NULL, buffer, (new_msg) ? 1 : 0, tags_to_send, ptr_redirect); } else { if (first_message) { irc_raw_print (server, IRC_RAW_FLAG_SEND, message); } if (new_msg) { irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED, ptr_msg); } /* send signal with command that will be sent to server */ irc_server_send_signal (server, "irc_out", (command) ? command : "unknown", ptr_msg, NULL); irc_server_send_signal (server, "irc_outtags", (command) ? command : "unknown", ptr_msg, (tags_to_send) ? tags_to_send : ""); if (irc_server_send (server, buffer, strlen (buffer)) <= 0) rc = 0; else { if (queue_msg > 0) server->last_user_message = time_now; } if (ptr_redirect) irc_redirect_init_command (ptr_redirect, buffer); } if (tags_to_send) free (tags_to_send); if (pos) { pos[0] = '\n'; ptr_msg = pos + 1; } else ptr_msg = NULL; first_message = 0; } if (msg_encoded) free (msg_encoded); } else { irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED, _("(message dropped)")); } if (nick) free (nick); if (command) free (command); if (channel) free (channel); if (new_msg) free (new_msg); return rc; }
null
0
irc_server_send_one_msg (struct t_irc_server *server, int flags, const char *message, const char *tags) { static char buffer[4096]; const char *ptr_msg; char *new_msg, *pos, *nick, *command, *channel, *tags_to_send; char *ptr_chan_nick, *msg_encoded; char str_modifier[64], modifier_data[256]; int rc, queue_msg, add_to_queue, first_message, anti_flood; time_t time_now; struct t_irc_redirect *ptr_redirect; rc = 1; irc_message_parse (message, &nick, NULL, &command, &channel, NULL); snprintf (str_modifier, sizeof (str_modifier), "irc_out_%s", (command) ? command : "unknown"); new_msg = weechat_hook_modifier_exec (str_modifier, server->name, message); /* no changes in new message */ if (new_msg && (strcmp (message, new_msg) == 0)) { free (new_msg); new_msg = NULL; } /* message not dropped? */ if (!new_msg || new_msg[0]) { first_message = 1; ptr_msg = (new_msg) ? new_msg : message; msg_encoded = NULL; ptr_chan_nick = (channel) ? channel : nick; if (ptr_chan_nick) { snprintf (modifier_data, sizeof (modifier_data), "%s.%s.%s", weechat_plugin->name, server->name, ptr_chan_nick); } else { snprintf (modifier_data, sizeof (modifier_data), "%s.%s", weechat_plugin->name, server->name); } msg_encoded = weechat_hook_modifier_exec ("charset_encode", modifier_data, ptr_msg); if (msg_encoded) ptr_msg = msg_encoded; while (rc && ptr_msg && ptr_msg[0]) { pos = strchr (ptr_msg, '\n'); if (pos) pos[0] = '\0'; snprintf (buffer, sizeof (buffer) - 1, "%s\r\n", ptr_msg); /* anti-flood: look whether we should queue outgoing message or not */ time_now = time (NULL); /* detect if system clock has been changed (now lower than before) */ if (server->last_user_message > time_now) server->last_user_message = time_now; /* get queue from flags */ queue_msg = 0; if (flags & IRC_SERVER_SEND_OUTQ_PRIO_HIGH) queue_msg = 1; else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_LOW) queue_msg = 2; switch (queue_msg - 1) { case 0: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH); break; default: anti_flood = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW); break; } add_to_queue = 0; if ((queue_msg > 0) && (server->outqueue[queue_msg - 1] || ((anti_flood > 0) && (time_now - server->last_user_message < anti_flood)))) { add_to_queue = queue_msg; } tags_to_send = irc_server_get_tags_to_send (tags); ptr_redirect = irc_redirect_search_available (server); if (add_to_queue > 0) { /* queue message (do not send anything now) */ irc_server_outqueue_add (server, add_to_queue - 1, command, (new_msg && first_message) ? message : NULL, buffer, (new_msg) ? 1 : 0, tags_to_send, ptr_redirect); } else { if (first_message) { irc_raw_print (server, IRC_RAW_FLAG_SEND, message); } if (new_msg) { irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED, ptr_msg); } /* send signal with command that will be sent to server */ irc_server_send_signal (server, "irc_out", (command) ? command : "unknown", ptr_msg, NULL); irc_server_send_signal (server, "irc_outtags", (command) ? command : "unknown", ptr_msg, (tags_to_send) ? tags_to_send : ""); if (irc_server_send (server, buffer, strlen (buffer)) <= 0) rc = 0; else { if (queue_msg > 0) server->last_user_message = time_now; } if (ptr_redirect) irc_redirect_init_command (ptr_redirect, buffer); } if (tags_to_send) free (tags_to_send); if (pos) { pos[0] = '\n'; ptr_msg = pos + 1; } else ptr_msg = NULL; first_message = 0; } if (msg_encoded) free (msg_encoded); } else { irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED, _("(message dropped)")); } if (nick) free (nick); if (command) free (command); if (channel) free (channel); if (new_msg) free (new_msg); return rc; }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,798
irc_server_set_away (struct t_irc_server *server, const char *nick, int is_away) { struct t_irc_channel *ptr_channel; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (server->is_connected) { /* set away flag for nick on channel */ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_set_away (server, ptr_channel, nick, is_away); /* set/del "away" local variable */ if (is_away) { weechat_buffer_set (ptr_channel->buffer, "localvar_set_away", server->away_message); } else { weechat_buffer_set (ptr_channel->buffer, "localvar_del_away", ""); } } } }
null
0
irc_server_set_away (struct t_irc_server *server, const char *nick, int is_away) { struct t_irc_channel *ptr_channel; for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (server->is_connected) { /* set away flag for nick on channel */ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) irc_channel_set_away (server, ptr_channel, nick, is_away); /* set/del "away" local variable */ if (is_away) { weechat_buffer_set (ptr_channel->buffer, "localvar_set_away", server->away_message); } else { weechat_buffer_set (ptr_channel->buffer, "localvar_del_away", ""); } } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null
2,799
irc_server_set_buffer_title (struct t_irc_server *server) { char *title; int length; if (server && server->buffer) { if (server->is_connected) { length = 16 + ((server->current_address) ? strlen (server->current_address) : 16) + 16 + ((server->current_ip) ? strlen (server->current_ip) : 16) + 1; title = malloc (length); if (title) { snprintf (title, length, "IRC: %s/%d (%s)", server->current_address, server->current_port, (server->current_ip) ? server->current_ip : ""); weechat_buffer_set (server->buffer, "title", title); free (title); } } else { weechat_buffer_set (server->buffer, "title", ""); } } }
null
0
irc_server_set_buffer_title (struct t_irc_server *server) { char *title; int length; if (server && server->buffer) { if (server->is_connected) { length = 16 + ((server->current_address) ? strlen (server->current_address) : 16) + 16 + ((server->current_ip) ? strlen (server->current_ip) : 16) + 1; title = malloc (length); if (title) { snprintf (title, length, "IRC: %s/%d (%s)", server->current_address, server->current_port, (server->current_ip) ? server->current_ip : ""); weechat_buffer_set (server->buffer, "title", title); free (title); } } else { weechat_buffer_set (server->buffer, "title", ""); } } }
@@ -2805,7 +2805,8 @@ int irc_server_gnutls_callback (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) { struct t_irc_server *server; gnutls_retr_st tls_struct; @@ -2837,207 +2838,212 @@ irc_server_gnutls_callback (void *data, gnutls_session_t tls_session, hostname = server->current_address; hostname_match = 0; - weechat_printf (server->buffer, - _("gnutls: connected using %d-bit Diffie-Hellman shared " - "secret exchange"), - IRC_SERVER_OPTION_INTEGER (server, - IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); - if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) + if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT) { weechat_printf (server->buffer, - _("%sgnutls: error while checking peer's certificate"), - weechat_prefix ("error")); - rc = -1; - } - else - { - /* some checks */ - if (status & GNUTLS_CERT_INVALID) + _("gnutls: connected using %d-bit Diffie-Hellman shared " + "secret exchange"), + IRC_SERVER_OPTION_INTEGER (server, + IRC_SERVER_OPTION_SSL_DHKEY_SIZE)); + if (gnutls_certificate_verify_peers2 (tls_session, &status) < 0) { weechat_printf (server->buffer, - _("%sgnutls: peer's certificate is NOT trusted"), + _("%sgnutls: error while checking peer's certificate"), weechat_prefix ("error")); rc = -1; } else { - weechat_printf (server->buffer, - _("gnutls: peer's certificate is trusted")); - } - if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) - { - weechat_printf (server->buffer, - _("%sgnutls: peer's certificate issuer is unknown"), - weechat_prefix ("error")); - rc = -1; - } - if (status & GNUTLS_CERT_REVOKED) - { - weechat_printf (server->buffer, - _("%sgnutls: the certificate has been revoked"), - weechat_prefix ("error")); - rc = -1; - } - - /* check certificates */ - if (gnutls_x509_crt_init (&cert_temp) >= 0) - { - cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); - if (cert_list) + /* some checks */ + if (status & GNUTLS_CERT_INVALID) + { + weechat_printf (server->buffer, + _("%sgnutls: peer's certificate is NOT trusted"), + weechat_prefix ("error")); + rc = -1; + } + else + { + weechat_printf (server->buffer, + _("gnutls: peer's certificate is trusted")); + } + if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) { weechat_printf (server->buffer, - NG_("gnutls: receiving %d certificate", - "gnutls: receiving %d certificates", - cert_list_len), - cert_list_len); - for (i = 0, j = (int) cert_list_len; i < j; i++) + _("%sgnutls: peer's certificate issuer is unknown"), + weechat_prefix ("error")); + rc = -1; + } + if (status & GNUTLS_CERT_REVOKED) + { + weechat_printf (server->buffer, + _("%sgnutls: the certificate has been revoked"), + weechat_prefix ("error")); + rc = -1; + } + + /* check certificates */ + if (gnutls_x509_crt_init (&cert_temp) >= 0) + { + cert_list = gnutls_certificate_get_peers (tls_session, &cert_list_len); + if (cert_list) { - if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) + weechat_printf (server->buffer, + NG_("gnutls: receiving %d certificate", + "gnutls: receiving %d certificates", + cert_list_len), + cert_list_len); + for (i = 0, j = (int) cert_list_len; i < j; i++) { - /* checking if hostname matches in the first certificate */ - if (i == 0 && gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0) + if (gnutls_x509_crt_import (cert_temp, &cert_list[i], GNUTLS_X509_FMT_DER) >= 0) { - hostname_match = 1; - } + /* checking if hostname matches in the first certificate */ + if ((i == 0) && (gnutls_x509_crt_check_hostname (cert_temp, hostname) != 0)) + { + hostname_match = 1; + } #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* displaying infos about certificate */ + /* displaying infos about certificate */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_X509_CRT_ONELINE, &cinfo); #else - rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); + rinfo = gnutls_x509_crt_print (cert_temp, GNUTLS_CRT_PRINT_ONELINE, &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - certificate[%d] info:"), i + 1); - weechat_printf (server->buffer, - " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - certificate[%d] info:"), i + 1); + weechat_printf (server->buffer, + " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - /* check expiration date */ - cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); - if (cert_time < time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate has expired"), - weechat_prefix ("error")); - rc = -1; - } - /* check expiration date */ - cert_time = gnutls_x509_crt_get_activation_time (cert_temp); - if (cert_time > time(NULL)) - { - weechat_printf (server->buffer, - _("%sgnutls: certificate is not yet activated"), - weechat_prefix ("error")); - rc = -1; + /* check expiration date */ + cert_time = gnutls_x509_crt_get_expiration_time (cert_temp); + if (cert_time < time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate has expired"), + weechat_prefix ("error")); + rc = -1; + } + /* check activation date */ + cert_time = gnutls_x509_crt_get_activation_time (cert_temp); + if (cert_time > time (NULL)) + { + weechat_printf (server->buffer, + _("%sgnutls: certificate is not yet activated"), + weechat_prefix ("error")); + rc = -1; + } } } - } - if (hostname_match == 0) - { - weechat_printf (server->buffer, - _("%sgnutls: the hostname in the " - "certificate does NOT match \"%s\""), - weechat_prefix ("error"), hostname); - rc = -1; + if (hostname_match == 0) + { + weechat_printf (server->buffer, + _("%sgnutls: the hostname in the " + "certificate does NOT match \"%s\""), + weechat_prefix ("error"), hostname); + rc = -1; + } } } } } - - /* using client certificate if it exists */ - cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, - IRC_SERVER_OPTION_SSL_CERT); - if (cert_path0 && cert_path0[0]) + else if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_SET_CERT) { - weechat_dir = weechat_info_get ("weechat_dir", ""); - cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); - cert_path2 = (cert_path1) ? - weechat_string_expand_home (cert_path1) : NULL; - - if (cert_path2) + /* using client certificate if it exists */ + cert_path0 = (char *) IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_SSL_CERT); + if (cert_path0 && cert_path0[0]) { - cert_str = weechat_file_get_content (cert_path2); - if (cert_str) + weechat_dir = weechat_info_get ("weechat_dir", ""); + cert_path1 = weechat_string_replace (cert_path0, "%h", weechat_dir); + cert_path2 = (cert_path1) ? + weechat_string_expand_home (cert_path1) : NULL; + + if (cert_path2) { - weechat_printf (server->buffer, - _("gnutls: sending one certificate")); - - filedatum.data = (unsigned char *) cert_str; - filedatum.size = strlen (cert_str); - - /* certificate */ - gnutls_x509_crt_init (&server->tls_cert); - gnutls_x509_crt_import (server->tls_cert, &filedatum, - GNUTLS_X509_FMT_PEM); - - /* key */ - gnutls_x509_privkey_init (&server->tls_cert_key); - ret = gnutls_x509_privkey_import (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM); - if (ret < 0) - { - ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, - &filedatum, - GNUTLS_X509_FMT_PEM, - NULL, - GNUTLS_PKCS_PLAIN); - } - if (ret < 0) + cert_str = weechat_file_get_content (cert_path2); + if (cert_str) { weechat_printf (server->buffer, - _("%sgnutls: invalid certificate \"%s\", " - "error: %s"), - weechat_prefix ("error"), cert_path2, - gnutls_strerror (ret)); - rc = -1; - } - else - { - tls_struct.type = GNUTLS_CRT_X509; - tls_struct.ncerts = 1; - tls_struct.deinit_all = 0; - tls_struct.cert.x509 = &server->tls_cert; - tls_struct.key.x509 = server->tls_cert_key; + _("gnutls: sending one certificate")); + + filedatum.data = (unsigned char *) cert_str; + filedatum.size = strlen (cert_str); + + /* certificate */ + gnutls_x509_crt_init (&server->tls_cert); + gnutls_x509_crt_import (server->tls_cert, &filedatum, + GNUTLS_X509_FMT_PEM); + + /* key */ + gnutls_x509_privkey_init (&server->tls_cert_key); + ret = gnutls_x509_privkey_import (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM); + if (ret < 0) + { + ret = gnutls_x509_privkey_import_pkcs8 (server->tls_cert_key, + &filedatum, + GNUTLS_X509_FMT_PEM, + NULL, + GNUTLS_PKCS_PLAIN); + } + if (ret < 0) + { + weechat_printf (server->buffer, + _("%sgnutls: invalid certificate \"%s\", " + "error: %s"), + weechat_prefix ("error"), cert_path2, + gnutls_strerror (ret)); + rc = -1; + } + else + { + tls_struct.type = GNUTLS_CRT_X509; + tls_struct.ncerts = 1; + tls_struct.deinit_all = 0; + tls_struct.cert.x509 = &server->tls_cert; + tls_struct.key.x509 = server->tls_cert_key; #if LIBGNUTLS_VERSION_NUMBER >= 0x010706 - /* client certificate info */ + /* client certificate info */ #if LIBGNUTLS_VERSION_NUMBER < 0x020400 - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_X509_CRT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_X509_CRT_ONELINE, + &cinfo); #else - rinfo = gnutls_x509_crt_print (server->tls_cert, - GNUTLS_CRT_PRINT_ONELINE, - &cinfo); + rinfo = gnutls_x509_crt_print (server->tls_cert, + GNUTLS_CRT_PRINT_ONELINE, + &cinfo); #endif - if (rinfo == 0) - { - weechat_printf (server->buffer, - _(" - client certificate info (%s):"), - cert_path2); - weechat_printf (server->buffer, " - %s", cinfo.data); - gnutls_free (cinfo.data); - } + if (rinfo == 0) + { + weechat_printf (server->buffer, + _(" - client certificate info (%s):"), + cert_path2); + weechat_printf (server->buffer, " - %s", cinfo.data); + gnutls_free (cinfo.data); + } #endif - memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); - free (cert_str); + memcpy (answer, &tls_struct, sizeof (gnutls_retr_st)); + free (cert_str); + } + } + else + { + weechat_printf (server->buffer, + _("%sgnutls: unable to read certifcate \"%s\""), + weechat_prefix ("error"), cert_path2); } } - else - { - weechat_printf (server->buffer, - _("%sgnutls: unable to read certifcate \"%s\""), - weechat_prefix ("error"), cert_path2); - } + + if (cert_path1) + free (cert_path1); + if (cert_path2) + free (cert_path2); } - - if (cert_path1) - free (cert_path1); - if (cert_path2) - free (cert_path2); } /* an error should stop the handshake unless the user doesn't care */
CWE-20
null
null