1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2005 VideoLAN
5 * $Id: httpd.c 8263 2004-07-24 09:06:58Z courmisch $
7 * Authors: Remi Denis-Courmont <courmisch@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
32 * - server-side client cert validation,
33 * - client-side server cert validation (?).
36 /*****************************************************************************
38 *****************************************************************************
39 * Allocates a whole server's TLS credentials.
40 * Returns NULL on error.
41 *****************************************************************************/
43 tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
47 tls_server_t *p_server;
49 p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
50 vlc_object_attach( p_tls, p_this );
52 p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
53 if( p_tls->p_module != NULL )
58 p_server = p_tls->pf_server_create( p_tls, psz_cert, psz_key );
59 if( p_server != NULL )
61 msg_Dbg( p_tls, "TLS/SSL provider initialized" );
65 msg_Err( p_tls, "TLS/SSL provider error" );
66 module_Unneed( p_tls, p_tls->p_module );
69 msg_Err( p_tls, "TLS/SSL provider not found" );
71 vlc_object_detach( p_tls );
72 vlc_object_destroy( p_tls );
77 /*****************************************************************************
79 *****************************************************************************
80 * Releases data allocated with tls_ServerCreate.
81 *****************************************************************************/
83 tls_ServerDelete( tls_server_t *p_server )
85 tls_t *p_tls = (tls_t *)p_server->p_parent;
87 p_server->pf_delete( p_server );
89 module_Unneed( p_tls, p_tls->p_module );
90 vlc_object_detach( p_tls );
91 vlc_object_destroy( p_tls );
95 /*****************************************************************************
97 *****************************************************************************
98 * Allocates a client's TLS credentials and shakes hands through the network.
99 * Returns NULL on error. This is a blocking network operation.
100 *****************************************************************************/
102 tls_ClientCreate( vlc_object_t *p_this, int fd, const char *psz_hostname )
105 tls_session_t *p_session;
107 p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
108 vlc_object_attach( p_tls, p_this );
110 p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
111 if( p_tls->p_module != NULL )
113 p_session = p_tls->pf_client_create( p_tls );
114 if( p_session != NULL )
118 for( i_val = tls_ClientSessionHandshake( p_session, fd,
121 i_val = tls_SessionContinueHandshake( p_session ) );
125 msg_Dbg( p_this, "TLS/SSL provider initialized" );
128 msg_Err( p_this, "TLS/SSL session handshake error" );
131 msg_Err( p_this, "TLS/SSL provider error" );
132 module_Unneed( p_tls, p_tls->p_module );
135 msg_Err( p_this, "TLS/SSL provider not found" );
137 vlc_object_detach( p_tls );
138 vlc_object_destroy( p_tls );
143 /*****************************************************************************
145 *****************************************************************************
146 * Releases data allocated with tls_ClientCreate.
147 *****************************************************************************/
149 tls_ClientDelete( tls_session_t *p_session )
151 tls_t *p_tls = (tls_t *)p_session->p_parent;
153 p_session->pf_close( p_session );
155 module_Unneed( p_tls, p_tls->p_module );
156 vlc_object_detach( p_tls );
157 vlc_object_destroy( p_tls );