* 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 * 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_id: libpurple-sslconn * @short_description: <filename>sslconn.h</filename> PURPLE_SSL_HANDSHAKE_FAILED = 1, PURPLE_SSL_CONNECT_FAILED = 2, PURPLE_SSL_CERTIFICATE_INVALID = 3 #define PURPLE_SSL_DEFAULT_PORT 443 typedef struct _PurpleSslConnection PurpleSslConnection; typedef struct _PurpleSslOps PurpleSslOps; typedef void (*PurpleSslInputFunction)(gpointer, PurpleSslConnection *, typedef void (*PurpleSslErrorFunction)(PurpleSslConnection *, PurpleSslErrorType, * @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 * @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 * @private_data: Internal connection data managed by the SSL backend * (GnuTLS/LibNSS/whatever) * @verifier: Verifier to use in authenticating the peer struct _PurpleSslConnection PurpleSslInputFunction connect_cb; PurpleSslErrorFunction error_cb; PurpleSslInputFunction recv_cb; PurpleProxyConnectData *connect_data; PurpleCertificateVerifier *verifier; * @init: Initializes the SSL system provided. See purple_ssl_init(). * <sbr/>Returns: %TRUE if initialization succeeded * @uninit: Unloads the SSL system. Inverse of PurpleSslOps::init. * See purple_ssl_uninit(). * @connectfunc: Sets up the SSL connection for a #PurpleSslConnection once the * TCP connection has been established. See purple_ssl_connect(). * @close: Destroys the internal data of the SSL connection provided. Freeing * @gsc itself is left to purple_ssl_close(). * @read: Reads data from a connection (like POSIX read()). * <sbr/>@gsc: Connection context * <sbr/>@data: Pointer to buffer to drop data into * <sbr/>@len: Maximum number of bytes to read * <sbr/>Returns: Number of bytes actually written into @data * (which may be less than @len), or <0 on error * @write: Writes data to a connection (like POSIX send()). * See purple_ssl_write(). * <sbr/>@gsc: Connection context * <sbr/>@data: Data buffer to send data from * <sbr/>@len: Number of bytes to send from buffer * <sbr/>Returns: The number of bytes written to @data (may be less than * @get_peer_certificates: Obtains the certificate chain provided by the peer. * See #PurpleCertificate. * <sbr/>@gsc: Connection context * <sbr/>Returns: A newly allocated list containing the * certificates the peer provided. * SSL implementation operations structure. * Every SSL implementation must provide all of these and register it via * These should not be called directly! Instead, use the purple_ssl_* functions. void (*connectfunc)(PurpleSslConnection *gsc); void (*close)(PurpleSslConnection *gsc); size_t (*read)(PurpleSslConnection *gsc, void *data, size_t len); size_t (*write)(PurpleSslConnection *gsc, const void *data, size_t len); /* TODO Decide whether the ordering of certificates in this list can be GList * (* get_peer_certificates)(PurpleSslConnection * gsc); void (*_purple_reserved1)(void); void (*_purple_reserved2)(void); void (*_purple_reserved3)(void); void (*_purple_reserved4)(void); /**************************************************************************/ /**************************************************************************/ * Returns a human-readable string for an SSL error. * Returns: Human-readable error explanation const gchar * purple_ssl_strerror(PurpleSslErrorType error); * @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 * @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 * Returns: The SSL connection handle. PurpleSslConnection *purple_ssl_connect(PurpleAccount *account, const char *host, int port, PurpleSslInputFunction func, PurpleSslErrorFunction error_func, * purple_ssl_connect_with_ssl_cn: * @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 * @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, * purple_ssl_connect_with_host_fd: * @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, * @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, * purple_ssl_input_remove: * @gsc: The SSL connection handle. * Removes an input watcher, added with purple_ssl_input_add(). * If there is no input watcher set, does nothing. purple_ssl_input_remove(PurpleSslConnection *gsc); * @gsc: The SSL connection to close. * Closes a SSL connection. void purple_ssl_close(PurpleSslConnection *gsc); * @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); * @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: * @gsc: The SSL connection handle * Obtains the peer's presented certificates * Returns: 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); /**************************************************************************/ /**************************************************************************/ * @ops: The SSL operations structure to assign. * Sets the current SSL operations structure. void purple_ssl_set_ops(PurpleSslOps *ops); * Returns the current SSL operations structure. * Returns: The SSL operations structure. PurpleSslOps *purple_ssl_get_ops(void); * Initializes the SSL subsystem. void purple_ssl_init(void); * Uninitializes the SSL subsystem. void purple_ssl_uninit(void); #endif /* _PURPLE_SSLCONN_H_ */