1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2004-2007 Rémi Denis-Courmont
7 * Authors: Rémi Denis-Courmont <rem # videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 * libvlc interface to the Transport Layer Security (TLS) plugins.
35 * Allocates a whole server's TLS credentials.
37 * @param cert_path required (Unicode) path to an x509 certificate,
38 * if NULL, anonymous key exchange will be used.
39 * @param key_path (UTF-8) path to the PKCS private key for the certificate,
40 * if NULL; cert_path will be used.
42 * @return NULL on error.
45 tls_ServerCreate (vlc_object_t *obj, const char *cert_path,
50 srv = (tls_server_t *)vlc_custom_create (obj, sizeof (*srv),
56 var_Create (srv, "tls-x509-cert", VLC_VAR_STRING);
57 var_Create (srv, "tls-x509-key", VLC_VAR_STRING);
59 if (cert_path != NULL)
61 var_SetString (srv, "tls-x509-cert", cert_path);
65 var_SetString (srv, "tls-x509-key", key_path);
68 srv->p_module = module_Need (srv, "tls server", 0, 0);
69 if (srv->p_module == NULL)
71 msg_Err (srv, "TLS server plugin not available");
72 vlc_object_destroy (srv);
76 vlc_object_attach (srv, obj);
77 msg_Dbg (srv, "TLS server plugin initialized");
83 * Releases data allocated with tls_ServerCreate.
84 * @param srv TLS server object to be destroyed, or NULL
86 void tls_ServerDelete (tls_server_t *srv)
91 module_Unneed (srv, srv->p_module);
92 vlc_object_detach (srv);
93 vlc_object_destroy (srv);
98 * Allocates a client's TLS credentials and shakes hands through the network.
99 * This is a blocking network operation.
101 * @param fd stream socket through which to establish the secure communication
103 * @param psz_hostname Server Name Indication to pass to the server, or NULL.
105 * @return NULL on error.
108 tls_ClientCreate (vlc_object_t *obj, int fd, const char *psz_hostname)
112 cl = (tls_session_t *)vlc_custom_create (obj, sizeof (*cl),
118 var_Create (cl, "tls-server-name", VLC_VAR_STRING);
119 if (psz_hostname != NULL)
121 msg_Dbg (cl, "requested server name: %s", psz_hostname);
122 var_SetString (cl, "tls-server-name", psz_hostname);
125 msg_Dbg (cl, "requested anonymous server");
127 cl->p_module = module_Need (cl, "tls client", 0, 0);
128 if (cl->p_module == NULL)
130 msg_Err (cl, "TLS client plugin not available");
131 vlc_object_destroy (cl);
135 int val = tls_ClientSessionHandshake (cl, fd);
137 val = tls_SessionContinueHandshake (cl);
141 msg_Dbg (cl, "TLS client session initialized");
142 vlc_object_attach (cl, obj);
145 msg_Err (cl, "TLS client session handshake error");
147 module_Unneed (cl, cl->p_module);
148 vlc_object_destroy (cl);
154 * Releases data allocated with tls_ClientCreate.
155 * It is your job to close the underlying socket.
157 void tls_ClientDelete (tls_session_t *cl)
162 module_Unneed (cl, cl->p_module);
163 vlc_object_detach (cl);
164 vlc_object_destroy (cl);