1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2005 the VideoLAN team
7 * Authors: Remi 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
30 /*****************************************************************************
32 *****************************************************************************
33 * Allocates a whole server's TLS credentials.
34 * Returns NULL on error.
35 *****************************************************************************/
37 tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
41 tls_server_t *p_server;
43 p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
44 vlc_object_attach( p_tls, p_this );
46 p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
47 if( p_tls->p_module != NULL )
52 p_server = p_tls->pf_server_create( p_tls, psz_cert, psz_key );
53 if( p_server != NULL )
55 msg_Dbg( p_tls, "TLS/SSL provider initialized" );
59 msg_Err( p_tls, "TLS/SSL provider error" );
60 module_Unneed( p_tls, p_tls->p_module );
63 msg_Err( p_tls, "TLS/SSL provider not found" );
65 vlc_object_detach( p_tls );
66 vlc_object_destroy( p_tls );
71 /*****************************************************************************
73 *****************************************************************************
74 * Releases data allocated with tls_ServerCreate.
75 *****************************************************************************/
77 tls_ServerDelete( tls_server_t *p_server )
79 tls_t *p_tls = (tls_t *)p_server->p_parent;
81 p_server->pf_delete( p_server );
83 module_Unneed( p_tls, p_tls->p_module );
84 vlc_object_detach( p_tls );
85 vlc_object_destroy( p_tls );
89 /*****************************************************************************
91 *****************************************************************************
92 * Allocates a client's TLS credentials and shakes hands through the network.
93 * Returns NULL on error. This is a blocking network operation.
94 *****************************************************************************/
96 tls_ClientCreate( vlc_object_t *p_this, int fd, const char *psz_hostname )
99 tls_session_t *p_session;
101 p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
102 vlc_object_attach( p_tls, p_this );
104 p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
105 if( p_tls->p_module != NULL )
107 p_session = p_tls->pf_client_create( p_tls );
108 if( p_session != NULL )
112 for( i_val = tls_ClientSessionHandshake( p_session, fd,
115 i_val = tls_SessionContinueHandshake( p_session ) );
119 msg_Dbg( p_this, "TLS/SSL provider initialized" );
122 msg_Err( p_this, "TLS/SSL session handshake error" );
125 msg_Err( p_this, "TLS/SSL provider error" );
126 module_Unneed( p_tls, p_tls->p_module );
129 msg_Err( p_this, "TLS/SSL provider not found" );
131 vlc_object_detach( p_tls );
132 vlc_object_destroy( p_tls );
137 /*****************************************************************************
139 *****************************************************************************
140 * Releases data allocated with tls_ClientCreate.
141 *****************************************************************************/
143 tls_ClientDelete( tls_session_t *p_session )
145 tls_t *p_tls = (tls_t *)p_session->p_parent;
147 p_session->pf_close( p_session );
149 module_Unneed( p_tls, p_tls->p_module );
150 vlc_object_detach( p_tls );
151 vlc_object_destroy( p_tls );