Mon, 27 Apr 2020 05:47:20 -0400
Remove unused sslconn code.
| ChangeLog.API | file | annotate | diff | comparison | revisions | |
| doc/reference/libpurple/libpurple-docs.xml | file | annotate | diff | comparison | revisions | |
| libpurple/connection.h | file | annotate | diff | comparison | revisions | |
| libpurple/core.c | file | annotate | diff | comparison | revisions | |
| libpurple/meson.build | file | annotate | diff | comparison | revisions | |
| libpurple/protocols/facebook/facebook.c | file | annotate | diff | comparison | revisions | |
| libpurple/protocols/jabber/auth.c | file | annotate | diff | comparison | revisions | |
| libpurple/protocols/jabber/jabber.h | file | annotate | diff | comparison | revisions | |
| libpurple/sslconn.c | file | annotate | diff | comparison | revisions | |
| libpurple/sslconn.h | file | annotate | diff | comparison | revisions |
--- a/ChangeLog.API Mon Apr 27 05:20:40 2020 -0400 +++ b/ChangeLog.API Mon Apr 27 05:47:20 2020 -0400 @@ -327,6 +327,7 @@ * _PurplePrefType * _PurplePrivacyType * _PurpleSoundEventID + * _PurpleSslConnection * _XMLNodeType * account-authorization-requested-with-message signal * file-recv-accept, file-recv-cancel, file-recv-complete, @@ -451,8 +452,23 @@ * purple_srv_cancel * purple_srv_resolve_account * purple_srv_txt_query_destroy + * PURPLE_SSL_DEFAULT_PORT + * PurpleSslConnection + * PurpleSslErrorFunction + * PurpleSslInputFunction + * purple_ssl_close + * purple_ssl_connect * purple_ssl_connect_fd + * purple_ssl_connect_with_host_fd + * purple_ssl_connect_with_ssl_cn + * purple_ssl_get_peer_certificates + * purple_ssl_init + * purple_ssl_input_add + * purple_ssl_input_remove + * purple_ssl_read * purple_ssl_strerror + * purple_ssl_uninit + * purple_ssl_write * purple_status_set_attr_boolean * purple_status_set_attr_int * purple_status_set_attr_string
--- a/doc/reference/libpurple/libpurple-docs.xml Mon Apr 27 05:20:40 2020 -0400 +++ b/doc/reference/libpurple/libpurple-docs.xml Mon Apr 27 05:47:20 2020 -0400 @@ -76,7 +76,6 @@ <xi:include href="xml/savedstatuses.xml" /> <xi:include href="xml/server.xml" /> <xi:include href="xml/sound.xml" /> - <xi:include href="xml/sslconn.xml" /> <xi:include href="xml/core.xml" /> <xi:include href="xml/status.xml" /> <xi:include href="xml/stun.xml" />
--- a/libpurple/connection.h Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/connection.h Mon Apr 27 05:47:20 2020 -0400 @@ -215,7 +215,6 @@ #include "account.h" #include "protocol.h" #include "status.h" -#include "sslconn.h" /** * PurpleConnectionUiOps:
--- a/libpurple/core.c Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/core.c Mon Apr 27 05:47:20 2020 -0400 @@ -42,7 +42,6 @@ #include "smiley-theme.h" #include "sound.h" #include "sound-theme-loader.h" -#include "sslconn.h" #include "status.h" #include "stun.h" #include "theme-manager.h"
--- a/libpurple/meson.build Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/meson.build Mon Apr 27 05:47:20 2020 -0400 @@ -67,7 +67,6 @@ 'sound.c', 'sound-theme.c', 'sound-theme-loader.c', - 'sslconn.c', 'theme.c', 'theme-loader.c', 'theme-manager.c', @@ -145,7 +144,6 @@ 'sound.h', 'sound-theme.h', 'sound-theme-loader.h', - 'sslconn.h', 'tests.h', 'theme.h', 'theme-loader.h',
--- a/libpurple/protocols/facebook/facebook.c Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/protocols/facebook/facebook.c Mon Apr 27 05:47:20 2020 -0400 @@ -45,7 +45,6 @@ #include "roomlist.h" #include "server.h" #include "signals.h" -#include "sslconn.h" #include "status.h" #include "util.h" #include "version.h"
--- a/libpurple/protocols/jabber/auth.c Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/protocols/jabber/auth.c Mon Apr 27 05:47:20 2020 -0400 @@ -27,7 +27,6 @@ #include "core.h" #include "conversation.h" #include "request.h" -#include "sslconn.h" #include "util.h" #include "xmlnode.h"
--- a/libpurple/protocols/jabber/jabber.h Mon Apr 27 05:20:40 2020 -0400 +++ b/libpurple/protocols/jabber/jabber.h Mon Apr 27 05:47:20 2020 -0400 @@ -69,7 +69,6 @@ #include "protocol.h" #include "queuedoutputstream.h" #include "roomlist.h" -#include "sslconn.h" #include "namespaces.h"
--- a/libpurple/sslconn.c Mon Apr 27 05:20:40 2020 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,401 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#include "internal.h" - -#include "debug.h" -#include "plugins.h" -#include "request.h" -#include "sslconn.h" - -#define CONNECTION_CLOSE_TIMEOUT 15 - -static void -emit_error(PurpleSslConnection *gsc, int error_code) -{ - if (gsc->error_cb != NULL) - gsc->error_cb(gsc, error_code, gsc->connect_cb_data); -} - -static void -tls_handshake_cb(GObject *source, GAsyncResult *res, gpointer user_data) -{ - PurpleSslConnection *gsc = user_data; - GError *error = NULL; - - if (!g_tls_connection_handshake_finish(G_TLS_CONNECTION(source), res, - &error)) { - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - /* Connection already closed/freed. Escape. */ - return; - } else if (g_error_matches(error, G_TLS_ERROR, - G_TLS_ERROR_HANDSHAKE)) { - /* In Gio, a handshake error is because of the cert */ - emit_error(gsc, PURPLE_SSL_CERTIFICATE_INVALID); - } else { - /* Report any other errors as handshake failing */ - emit_error(gsc, PURPLE_SSL_HANDSHAKE_FAILED); - } - - purple_ssl_close(gsc); - return; - } - - gsc->connect_cb(gsc->connect_cb_data, gsc, PURPLE_INPUT_READ); -} - -static gboolean -tls_connect(PurpleSslConnection *gsc) -{ - GSocket *socket; - GSocketConnection *conn; - GSocketConnectable *identity; - GIOStream *tls_conn; - GError *error = NULL; - - g_return_val_if_fail(gsc->conn == NULL, FALSE); - - socket = g_socket_new_from_fd(gsc->fd, &error); - if (socket == NULL) { - purple_debug_warning("sslconn", - "Error creating socket from fd (%u): %s", - gsc->fd, error->message); - g_clear_error(&error); - return FALSE; - } - - conn = g_socket_connection_factory_create_connection(socket); - g_object_unref(socket); - - identity = g_network_address_new(gsc->host, gsc->port); - tls_conn = g_tls_client_connection_new(G_IO_STREAM(conn), identity, - &error); - g_object_unref(identity); - g_object_unref(conn); - - if (tls_conn == NULL) { - purple_debug_warning("sslconn", - "Error creating TLS client connection: %s", - error->message); - g_clear_error(&error); - return FALSE; - } - - gsc->conn = G_TLS_CONNECTION(tls_conn); - gsc->cancellable = g_cancellable_new(); - - g_tls_connection_handshake_async(gsc->conn, G_PRIORITY_DEFAULT, - gsc->cancellable, tls_handshake_cb, gsc); - - return TRUE; -} - -static void -purple_ssl_connect_cb(gpointer data, gint source, const gchar *error_message) -{ - PurpleSslConnection *gsc; - - gsc = data; - gsc->connect_data = NULL; - - if (source < 0) - { - emit_error(gsc, PURPLE_SSL_CONNECT_FAILED); - purple_ssl_close(gsc); - return; - } - - gsc->fd = source; - - if (!tls_connect(gsc)) { - emit_error(gsc, PURPLE_SSL_CONNECT_FAILED); - purple_ssl_close(gsc); - } -} - -PurpleSslConnection * -purple_ssl_connect(PurpleAccount *account, const char *host, int port, - PurpleSslInputFunction func, PurpleSslErrorFunction error_func, - void *data) -{ - return purple_ssl_connect_with_ssl_cn(account, host, port, func, error_func, - NULL, data); -} - -PurpleSslConnection * -purple_ssl_connect_with_ssl_cn(PurpleAccount *account, const char *host, int port, - PurpleSslInputFunction func, PurpleSslErrorFunction error_func, - const char *ssl_cn, void *data) -{ - PurpleSslConnection *gsc; - - g_return_val_if_fail(host != NULL, NULL); - g_return_val_if_fail(port != 0 && port != -1, NULL); - g_return_val_if_fail(func != NULL, NULL); - - gsc = g_new0(PurpleSslConnection, 1); - - gsc->fd = -1; - gsc->host = ssl_cn ? g_strdup(ssl_cn) : g_strdup(host); - gsc->port = port; - gsc->connect_cb_data = data; - gsc->connect_cb = func; - gsc->error_cb = error_func; - - gsc->connect_data = purple_proxy_connect(NULL, account, host, port, purple_ssl_connect_cb, gsc); - - if (gsc->connect_data == NULL) - { - g_free(gsc->host); - g_free(gsc); - - return NULL; - } - - return (PurpleSslConnection *)gsc; -} - -static gboolean -recv_cb(GObject *source, gpointer data) -{ - PurpleSslConnection *gsc = data; - - gsc->recv_cb(gsc->recv_cb_data, gsc, PURPLE_INPUT_READ); - - return TRUE; -} - -void -purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func, - void *data) -{ - GInputStream *input; - GSource *source; - - g_return_if_fail(func != NULL); - g_return_if_fail(gsc->conn != NULL); - - purple_ssl_input_remove(gsc); - - gsc->recv_cb_data = data; - gsc->recv_cb = func; - - input = g_io_stream_get_input_stream(G_IO_STREAM(gsc->conn)); - /* Pass NULL for cancellable as we don't want it notified on cancel */ - source = g_pollable_input_stream_create_source( - G_POLLABLE_INPUT_STREAM(input), NULL); - g_source_set_callback(source, (GSourceFunc)recv_cb, gsc, NULL); - gsc->inpa = g_source_attach(source, NULL); - g_source_unref(source); -} - -void -purple_ssl_input_remove(PurpleSslConnection *gsc) -{ - if (gsc->inpa > 0) { - g_source_remove(gsc->inpa); - gsc->inpa = 0; - } -} - -const gchar * -purple_ssl_strerror(PurpleSslErrorType error) -{ - switch(error) { - case PURPLE_SSL_CONNECT_FAILED: - return _("SSL Connection Failed"); - case PURPLE_SSL_HANDSHAKE_FAILED: - return _("SSL Handshake Failed"); - case PURPLE_SSL_CERTIFICATE_INVALID: - return _("SSL peer presented an invalid certificate"); - default: - purple_debug_warning("sslconn", "Unknown SSL error code %d\n", error); - return _("Unknown SSL error"); - } -} - -PurpleSslConnection * -purple_ssl_connect_with_host_fd(PurpleAccount *account, int fd, - PurpleSslInputFunction func, - PurpleSslErrorFunction error_func, - const char *host, - void *data) -{ - PurpleSslConnection *gsc; - - g_return_val_if_fail(fd != -1, NULL); - g_return_val_if_fail(func != NULL, NULL); - - gsc = g_new0(PurpleSslConnection, 1); - - gsc->connect_cb_data = data; - gsc->connect_cb = func; - gsc->error_cb = error_func; - gsc->fd = fd; - gsc->host = g_strdup(host); - gsc->cancellable = g_cancellable_new(); - - if (!tls_connect(gsc)) { - emit_error(gsc, PURPLE_SSL_CONNECT_FAILED); - g_clear_pointer(&gsc, purple_ssl_close); - } - - return (PurpleSslConnection *)gsc; -} - -static void -connection_closed_cb(GObject *stream, GAsyncResult *result, - gpointer timeout_id) -{ - GError *error = NULL; - - g_source_remove(GPOINTER_TO_UINT(timeout_id)); - - g_io_stream_close_finish(G_IO_STREAM(stream), result, &error); - - if (error) { - purple_debug_info("sslconn", "Connection close error: %s", - error->message); - g_clear_error(&error); - } else { - purple_debug_info("sslconn", "Connection closed."); - } -} - -static void -cleanup_cancellable_cb(gpointer data, GObject *where_the_object_was) -{ - g_object_unref(G_CANCELLABLE(data)); -} - -void -purple_ssl_close(PurpleSslConnection *gsc) -{ - g_return_if_fail(gsc != NULL); - - purple_request_close_with_handle(gsc); - purple_notify_close_with_handle(gsc); - - if (gsc->connect_data != NULL) - purple_proxy_connect_cancel(gsc->connect_data); - - if (gsc->inpa > 0) - purple_input_remove(gsc->inpa); - - /* Stop any pending operations */ - if (G_IS_CANCELLABLE(gsc->cancellable)) { - g_cancellable_cancel(gsc->cancellable); - g_clear_object(&gsc->cancellable); - } - - if (gsc->conn != NULL) { - GCancellable *cancellable; - guint timer_id; - - cancellable = g_cancellable_new(); - g_object_weak_ref(G_OBJECT(gsc->conn), cleanup_cancellable_cb, - cancellable); - - timer_id = g_timeout_add_seconds(CONNECTION_CLOSE_TIMEOUT, - (GSourceFunc)g_cancellable_cancel, cancellable); - - g_io_stream_close_async(G_IO_STREAM(gsc->conn), - G_PRIORITY_DEFAULT, cancellable, - connection_closed_cb, - GUINT_TO_POINTER(timer_id)); - g_clear_object(&gsc->conn); - } - - g_free(gsc->host); - g_free(gsc); -} - -size_t -purple_ssl_read(PurpleSslConnection *gsc, void *data, size_t len) -{ - GInputStream *input; - gssize outlen; - GError *error = NULL; - - g_return_val_if_fail(gsc != NULL, 0); - g_return_val_if_fail(data != NULL, 0); - g_return_val_if_fail(len > 0, 0); - g_return_val_if_fail(gsc->conn != NULL, 0); - - input = g_io_stream_get_input_stream(G_IO_STREAM(gsc->conn)); - outlen = g_pollable_input_stream_read_nonblocking( - G_POLLABLE_INPUT_STREAM(input), data, len, - gsc->cancellable, &error); - - if (outlen < 0) { - if (g_error_matches(error, G_IO_ERROR, - G_IO_ERROR_WOULD_BLOCK)) { - errno = EAGAIN; - } - - g_clear_error(&error); - } - - return outlen; -} - -size_t -purple_ssl_write(PurpleSslConnection *gsc, const void *data, size_t len) -{ - GOutputStream *output; - gssize outlen; - GError *error = NULL; - - g_return_val_if_fail(gsc != NULL, 0); - g_return_val_if_fail(data != NULL, 0); - g_return_val_if_fail(len > 0, 0); - g_return_val_if_fail(gsc->conn != NULL, 0); - - output = g_io_stream_get_output_stream(G_IO_STREAM(gsc->conn)); - outlen = g_pollable_output_stream_write_nonblocking( - G_POLLABLE_OUTPUT_STREAM(output), data, len, - gsc->cancellable, &error); - - if (outlen < 0) { - if (g_error_matches(error, G_IO_ERROR, - G_IO_ERROR_WOULD_BLOCK)) { - errno = EAGAIN; - } - - g_clear_error(&error); - } - - return outlen; -} - -GList * -purple_ssl_get_peer_certificates(PurpleSslConnection *gsc) -{ - GTlsCertificate *certificate; - - g_return_val_if_fail(gsc != NULL, NULL); - g_return_val_if_fail(gsc->conn != NULL, NULL); - - certificate = g_tls_connection_get_peer_certificate(gsc->conn); - - return certificate != NULL ? g_list_append(NULL, certificate) : NULL; -} -
--- a/libpurple/sslconn.h Mon Apr 27 05:20:40 2020 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - */ - -#ifndef PURPLE_SSLCONN_H -#define PURPLE_SSLCONN_H -/** - * SECTION:sslconn - * @section_id: libpurple-sslconn - * @short_description: <filename>sslconn.h</filename> - * @title: SSL API - */ - -#include <gio/gio.h> -#include "proxy.h" - -#define PURPLE_SSL_DEFAULT_PORT 443 - -typedef struct _PurpleSslConnection PurpleSslConnection; - -typedef void (*PurpleSslInputFunction)(gpointer data, PurpleSslConnection *connection, - PurpleInputCondition cond); -typedef void (*PurpleSslErrorFunction)(PurpleSslConnection *connection, PurpleSslErrorType err, - gpointer data); - -/** - * PurpleSslConnection: - * @host: Hostname to which the SSL connection will be made - * @port: Port to connect to - * @connect_cb_data: Data to pass to @connect_cb - * @connect_cb: Callback triggered once the SSL handshake is complete - * @error_cb: Callback triggered if there is an error during connection - * @recv_cb_data: Data passed to @recv_cb - * @recv_cb: User-defined callback executed when the SSL connection - * receives data - * @fd: File descriptor used to refer to the socket - * @inpa: Glib event source ID; used to refer to the received data - * callback in the glib eventloop - * @connect_data: Data related to the underlying TCP connection - * @conn: The underlying #GTlsConnection - * @cancellable: A cancellable to call when cancelled - * @private_data: Internal connection data managed by the SSL backend - * (GnuTLS/LibNSS/whatever) - */ -struct _PurpleSslConnection -{ - char *host; - int port; - void *connect_cb_data; - PurpleSslInputFunction connect_cb; - PurpleSslErrorFunction error_cb; - void *recv_cb_data; - PurpleSslInputFunction recv_cb; - - int fd; - guint inpa; - PurpleProxyConnectData *connect_data; - - GTlsConnection *conn; - GCancellable *cancellable; - - void *private_data; -}; - -G_BEGIN_DECLS - -/**************************************************************************/ -/* SSL API */ -/**************************************************************************/ - -/** - * purple_ssl_connect: (skip) - * @account: The account making the connection. - * @host: The destination host. - * @port: The destination port. - * @func: The SSL input handler function. - * @error_func: The SSL error handler function. This function - * should <emphasis>NOT</emphasis> call purple_ssl_close(). In - * the event of an error the #PurpleSslConnection will be - * destroyed for you. - * @data: User-defined data. - * - * Makes a SSL connection to the specified host and port. The caller - * should keep track of the returned value and use it to cancel the - * connection, if needed. - * - * Returns: The SSL connection handle. - */ -PurpleSslConnection *purple_ssl_connect(PurpleAccount *account, const char *host, - int port, PurpleSslInputFunction func, - PurpleSslErrorFunction error_func, - void *data); - -/** - * purple_ssl_connect_with_ssl_cn: (skip) - * @account: The account making the connection. - * @host: The destination host. - * @port: The destination port. - * @func: The SSL input handler function. - * @error_func: The SSL error handler function. This function - * should <emphasis>NOT</emphasis> call purple_ssl_close(). In - * the event of an error the #PurpleSslConnection will be - * destroyed for you. - * @ssl_host: The hostname of the other peer (to verify the CN) - * @data: User-defined data. - * - * Makes a SSL connection to the specified host and port, using the separate - * name to verify with the certificate. The caller should keep track of the - * returned value and use it to cancel the connection, if needed. - * - * Returns: The SSL connection handle. - */ -PurpleSslConnection *purple_ssl_connect_with_ssl_cn(PurpleAccount *account, const char *host, - int port, PurpleSslInputFunction func, - PurpleSslErrorFunction error_func, - const char *ssl_host, - void *data); - -/** - * purple_ssl_connect_with_host_fd: (skip) - * @account: The account making the connection. - * @fd: The file descriptor. - * @func: The SSL input handler function. - * @error_func: The SSL error handler function. - * @host: The hostname of the other peer (to verify the CN) - * @data: User-defined data. - * - * Makes a SSL connection using an already open file descriptor. - * - * Returns: The SSL connection handle. - */ -PurpleSslConnection *purple_ssl_connect_with_host_fd(PurpleAccount *account, int fd, - PurpleSslInputFunction func, - PurpleSslErrorFunction error_func, - const char *host, - void *data); - -/** - * purple_ssl_input_add: (skip) - * @gsc: The SSL connection handle. - * @func: The callback function. - * @data: User-defined data. - * - * Adds an input watcher for the specified SSL connection. - * Once the SSL handshake is complete, use this to watch for actual data across it. - */ -void purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func, - void *data); - -/** - * purple_ssl_input_remove: (skip) - * @gsc: The SSL connection handle. - * - * Removes an input watcher, added with purple_ssl_input_add(). - * - * If there is no input watcher set, does nothing. - */ -void -purple_ssl_input_remove(PurpleSslConnection *gsc); - -/** - * purple_ssl_close: (skip) - * @gsc: The SSL connection to close. - * - * Closes a SSL connection. - */ -void purple_ssl_close(PurpleSslConnection *gsc); - -/** - * purple_ssl_read: (skip) - * @gsc: The SSL connection handle. - * @buffer: The destination buffer. - * @len: The maximum number of bytes to read. - * - * Reads data from an SSL connection. - * - * Returns: The number of bytes read. - */ -size_t purple_ssl_read(PurpleSslConnection *gsc, void *buffer, size_t len); - -/** - * purple_ssl_write: (skip) - * @gsc: The SSL connection handle. - * @buffer: The buffer to write. - * @len: The length of the data to write. - * - * Writes data to an SSL connection. - * - * Returns: The number of bytes written. - */ -size_t purple_ssl_write(PurpleSslConnection *gsc, const void *buffer, size_t len); - -/** - * purple_ssl_get_peer_certificates: (skip) - * @gsc: The SSL connection handle - * - * Obtains the peer's presented certificates - * - * Returns: (element-type GTlsCertificate): The peer certificate chain, in the - * order of certificate, issuer, issuer's issuer, etc. %NULL if no - * certificates have been provided. - */ -GList * purple_ssl_get_peer_certificates(PurpleSslConnection *gsc); - -/**************************************************************************/ -/* Subsystem API */ -/**************************************************************************/ - -/** - * purple_ssl_init: - * - * Initializes the SSL subsystem. - */ -void purple_ssl_init(void); - -/** - * purple_ssl_uninit: - * - * Uninitializes the SSL subsystem. - */ -void purple_ssl_uninit(void); - -G_END_DECLS - -#endif /* PURPLE_SSLCONN_H */