vlc_tls.h 4.01 KB
Newer Older
1
/*****************************************************************************
2
 * tls.c: Transport Layer Security API
3
 *****************************************************************************
4
 * Copyright (C) 2004-2007 the VideoLAN team
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
5
 * $Id$
6
 *
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
7
 * Authors: Rémi Denis-Courmont <rem # videolan.org>
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

Clément Stenac's avatar
Clément Stenac committed
24 25 26 27
#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
28 29 30
#ifndef _VLC_TLS_H
# define _VLC_TLS_H

Clément Stenac's avatar
Clément Stenac committed
31
# include <vlc_network.h>
32

33
typedef struct tls_server_sys_t tls_server_sys_t;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
34 35 36

struct tls_server_t
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
37 38
    VLC_COMMON_MEMBERS

39 40
    module_t  *p_module;
    tls_server_sys_t *p_sys;
41

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
42 43
    int (*pf_add_CA) ( tls_server_t *, const char * );
    int (*pf_add_CRL) ( tls_server_t *, const char * );
44

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
45 46 47
    tls_session_t * (*pf_session_prepare) ( tls_server_t * );
};

48 49
typedef struct tls_session_sys_t tls_session_sys_t;

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
50 51
struct tls_session_t
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
52
    VLC_COMMON_MEMBERS
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
53

54 55
    module_t  *p_module;
    tls_session_sys_t *p_sys;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
56

57
    struct virtual_socket_t sock;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
58
    int (*pf_handshake) ( tls_session_t *, int, const char * );
59
    int (*pf_handshake2) ( tls_session_t * );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
60 61 62
    void (*pf_close) ( tls_session_t * );
};

63 64 65 66 67 68 69

/*****************************************************************************
 * tls_ServerCreate:
 *****************************************************************************
 * Allocates a whole server's TLS credentials.
 * Returns NULL on error.
 *****************************************************************************/
70
VLC_EXPORT( tls_server_t *, tls_ServerCreate, ( vlc_object_t *, const char *, const char * ) );
71 72 73 74 75 76 77

/*****************************************************************************
 * tls_ServerAddCA:
 *****************************************************************************
 * Adds one or more certificate authorities.
 * Returns -1 on error, 0 on success.
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
78
# define tls_ServerAddCA( a, b ) (((tls_server_t *)a)->pf_add_CA (a, b))
79 80 81 82 83 84 85 86


/*****************************************************************************
 * tls_ServerAddCRL:
 *****************************************************************************
 * Adds a certificates revocation list to be sent to TLS clients.
 * Returns -1 on error, 0 on success.
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
87 88
# define tls_ServerAddCRL( a, b ) (((tls_server_t *)a)->pf_add_CRL (a, b))

89

90
VLC_EXPORT( void, tls_ServerDelete, ( tls_server_t * ) );
91 92


Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
93
# define tls_ServerSessionPrepare( a ) (((tls_server_t *)a)->pf_session_prepare (a))
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
94 95
# define tls_ServerSessionHandshake( a, b ) (((tls_session_t *)a)->pf_handshake (a, b, NULL))
# define tls_ServerSessionClose( a ) (((tls_session_t *)a)->pf_close (a))
96

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
97
VLC_EXPORT( tls_session_t *, tls_ClientCreate, ( vlc_object_t *, int, const char * ) );
98 99
VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
100 101
# define tls_ClientSessionHandshake( a, b, c ) (((tls_session_t *)a)->pf_handshake (a, b, c))

102
# define tls_SessionContinueHandshake( a ) (((tls_session_t *)a)->pf_handshake2 (a))
103 104


105 106
/* NOTE: It is assumed that a->sock.p_sys = a */
# define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
107

108
# define tls_Recv( a, b, c ) (((tls_session_t *)a)->sock.pf_recv (a, b, c ))
109

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
110
#endif