]> git.sesse.net Git - vlc/blob - src/misc/tls.c
823f01b3768197d3d4cb7e643cccf43576b87229
[vlc] / src / misc / tls.c
1 /*****************************************************************************
2  * tls.c
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: httpd.c 8263 2004-07-24 09:06:58Z courmisch $
6  *
7  * Authors: Remi Denis-Courmont <courmisch@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include <stdlib.h>
25 #include <vlc/vlc.h>
26
27 #include "vlc_tls.h"
28
29
30 /*
31  * TODO:
32  * - client side stuff,
33  * - server-side client cert validation,
34  * - client-side server cert validation (?).
35  */
36
37 /*****************************************************************************
38  * tls_ServerCreate:
39  *****************************************************************************
40  * Allocates a whole server's TLS credentials.
41  * Returns NULL on error.
42  *****************************************************************************/
43 tls_server_t *
44 tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
45                   const char *psz_key )
46 {
47     tls_t *p_tls;
48     tls_server_t *p_server;
49
50     p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
51     vlc_object_attach( p_tls, p_this );
52
53     p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
54     if( p_tls->p_module != NULL )
55     {
56         if( psz_key == NULL )
57             psz_key = psz_cert;
58
59         p_server = __tls_ServerCreate( p_tls, psz_cert, psz_key );
60         if( p_server != NULL )
61         {
62             msg_Dbg( p_this, "TLS/SSL provider initialized" );
63             return p_server;
64         }
65         else
66             msg_Err( p_this, "TLS/SSL provider error" );
67         module_Unneed( p_tls, p_tls->p_module );
68     }
69     else
70         msg_Err( p_this, "TLS/SSL provider not found" );
71
72     vlc_object_detach( p_tls );
73     vlc_object_destroy( p_tls );
74     return NULL;
75 }
76
77
78 /*****************************************************************************
79  * tls_ServerDelete:
80  *****************************************************************************
81  * Releases data allocated with tls_ServerCreate
82  *****************************************************************************/
83 void
84 tls_ServerDelete( tls_server_t *p_server )
85 {
86     tls_t *p_tls = p_server->p_tls;
87
88     __tls_ServerDelete( p_server );
89
90     module_Unneed( p_tls, p_tls->p_module );
91     vlc_object_detach( p_tls );
92     vlc_object_destroy( p_tls );
93 }
94