]> git.sesse.net Git - vlc/blob - src/misc/tls.c
Oups, forgot this file
[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     const char *psz_pem;
50
51     p_tls = vlc_object_create( p_this, VLC_OBJECT_TLS );
52     vlc_object_attach( p_tls, p_this );
53
54     p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
55     if( p_tls->p_module != NULL )
56     {
57         if( psz_key == NULL )
58             psz_key = psz_cert;
59
60         p_server = __tls_ServerCreate( p_tls, psz_cert, psz_key );
61         if( p_server != NULL )
62         {
63             msg_Dbg( p_this, "TLS/SSL provider initialized" );
64             return p_server;
65         }
66         else
67             msg_Err( p_this, "TLS/SSL provider error" );
68         module_Unneed( p_tls, p_tls->p_module );
69     }
70     else
71         msg_Err( p_this, "TLS/SSL provider not found" );
72
73     vlc_object_detach( p_tls );
74     vlc_object_destroy( p_tls );
75     return NULL;
76 }
77
78
79 /*****************************************************************************
80  * tls_ServerDelete:
81  *****************************************************************************
82  * Releases data allocated with tls_ServerCreate
83  *****************************************************************************/
84 void
85 tls_ServerDelete( tls_server_t *p_server )
86 {
87     tls_t *p_tls = p_server->p_tls;
88
89     __tls_ServerDelete( p_server );
90
91     module_Unneed( p_tls, p_tls->p_module );
92     vlc_object_detach( p_tls );
93     vlc_object_destroy( p_tls );
94 }
95