Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Steve Lhomme
VLC
Commits
52eb2b94
Commit
52eb2b94
authored
Sep 29, 2012
by
Rémi Denis-Courmont
Browse files
tls: simplify server code
parent
79a5d687
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/vlc_tls.h
View file @
52eb2b94
...
...
@@ -48,9 +48,8 @@ struct vlc_tls
VLC_API
vlc_tls_t
*
vlc_tls_ClientSessionCreate
(
vlc_tls_creds_t
*
,
int
fd
,
const
char
*
host
);
vlc_tls_t
*
vlc_tls_ServerSessionCreate
(
vlc_tls_creds_t
*
,
int
fd
);
int
vlc_tls_
Server
SessionHandshake
(
vlc_tls_t
*
);
int
vlc_tls_SessionHandshake
(
vlc_tls_t
*
);
VLC_API
void
vlc_tls_SessionDelete
(
vlc_tls_t
*
);
#define vlc_tls_ServerSessionDelete vlc_tls_SessionDelete
/* NOTE: It is assumed that a->sock.p_sys = a */
# define tls_Send( a, b, c ) (((vlc_tls_t *)a)->sock.pf_send (a, b, c))
...
...
@@ -77,7 +76,6 @@ VLC_API vlc_tls_creds_t *vlc_tls_ClientCreate (vlc_object_t *);
vlc_tls_creds_t
*
vlc_tls_ServerCreate
(
vlc_object_t
*
,
const
char
*
cert
,
const
char
*
key
);
VLC_API
void
vlc_tls_Delete
(
vlc_tls_creds_t
*
);
#define vlc_tls_ServerDelete vlc_tls_Delete
int
vlc_tls_ServerAddCA
(
vlc_tls_creds_t
*
srv
,
const
char
*
path
);
int
vlc_tls_ServerAddCRL
(
vlc_tls_creds_t
*
srv
,
const
char
*
path
);
...
...
src/network/httpd.c
View file @
52eb2b94
...
...
@@ -928,7 +928,7 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
return
httpd_HostCreate
(
obj
,
"http-host"
,
"https-port"
,
tls
);
error:
vlc_tls_
Server
Delete
(
tls
);
vlc_tls_Delete
(
tls
);
return
NULL
;
}
...
...
@@ -987,8 +987,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
vlc_mutex_unlock
(
&
httpd
.
mutex
);
vlc_UrlClean
(
&
url
);
if
(
p_tls
!=
NULL
)
vlc_tls_ServerDelete
(
p_tls
);
vlc_tls_Delete
(
p_tls
);
return
host
;
}
...
...
@@ -1051,10 +1050,7 @@ error:
}
vlc_UrlClean
(
&
url
);
if
(
p_tls
!=
NULL
)
vlc_tls_ServerDelete
(
p_tls
);
vlc_tls_Delete
(
p_tls
);
return
NULL
;
}
...
...
@@ -1100,9 +1096,7 @@ void httpd_HostDelete( httpd_host_t *host )
/* TODO */
}
if
(
host
->
p_tls
!=
NULL
)
vlc_tls_ServerDelete
(
host
->
p_tls
);
vlc_tls_Delete
(
host
->
p_tls
);
net_ListenClose
(
host
->
fds
);
vlc_cond_destroy
(
&
host
->
wait
);
vlc_mutex_destroy
(
&
host
->
lock
);
...
...
@@ -1300,7 +1294,7 @@ static void httpd_ClientClean( httpd_client_t *cl )
if
(
cl
->
fd
>=
0
)
{
if
(
cl
->
p_tls
!=
NULL
)
vlc_tls_
Server
SessionDelete
(
cl
->
p_tls
);
vlc_tls_SessionDelete
(
cl
->
p_tls
);
net_Close
(
cl
->
fd
);
cl
->
fd
=
-
1
;
}
...
...
@@ -1324,6 +1318,8 @@ static httpd_client_t *httpd_ClientNew( int fd, vlc_tls_t *p_tls, mtime_t now )
cl
->
p_tls
=
p_tls
;
httpd_ClientInit
(
cl
,
now
);
if
(
p_tls
!=
NULL
)
cl
->
i_state
=
HTTPD_CLIENT_TLS_HS_OUT
;
return
cl
;
}
...
...
@@ -1882,9 +1878,9 @@ static void httpd_ClientSend( httpd_client_t *cl )
}
}
static
void
httpd_ClientTlsH
sIn
(
httpd_client_t
*
cl
)
static
void
httpd_ClientTlsH
andshake
(
httpd_client_t
*
cl
)
{
switch
(
vlc_tls_
Server
SessionHandshake
(
cl
->
p_tls
)
)
switch
(
vlc_tls_SessionHandshake
(
cl
->
p_tls
)
)
{
case
0
:
cl
->
i_state
=
HTTPD_CLIENT_RECEIVING
;
...
...
@@ -1892,30 +1888,15 @@ static void httpd_ClientTlsHsIn( httpd_client_t *cl )
case
-
1
:
cl
->
i_state
=
HTTPD_CLIENT_DEAD
;
cl
->
p_tls
=
NULL
;
break
;
case
2
:
cl
->
i_state
=
HTTPD_CLIENT_TLS_HS_OUT
;
}
}
static
void
httpd_ClientTlsHsOut
(
httpd_client_t
*
cl
)
{
switch
(
vlc_tls_ServerSessionHandshake
(
cl
->
p_tls
)
)
{
case
0
:
cl
->
i_state
=
HTTPD_CLIENT_RECEIVING
;
break
;
case
-
1
:
cl
->
i_state
=
HTTPD_CLIENT_DEAD
;
cl
->
p_tls
=
NULL
;
break
;
case
1
:
cl
->
i_state
=
HTTPD_CLIENT_TLS_HS_IN
;
break
;
case
2
:
cl
->
i_state
=
HTTPD_CLIENT_TLS_HS_OUT
;
break
;
}
}
...
...
@@ -2303,13 +2284,10 @@ static void* httpd_HostThread( void *data )
{
httpd_ClientSend
(
cl
);
}
else
if
(
cl
->
i_state
==
HTTPD_CLIENT_TLS_HS_IN
)
else
if
(
cl
->
i_state
==
HTTPD_CLIENT_TLS_HS_IN
||
cl
->
i_state
==
HTTPD_CLIENT_TLS_HS_OUT
)
{
httpd_ClientTlsHsIn
(
cl
);
}
else
if
(
cl
->
i_state
==
HTTPD_CLIENT_TLS_HS_OUT
)
{
httpd_ClientTlsHsOut
(
cl
);
httpd_ClientTlsHandshake
(
cl
);
}
}
...
...
@@ -2317,7 +2295,6 @@ static void* httpd_HostThread( void *data )
for
(
nfd
=
0
;
nfd
<
host
->
nfd
;
nfd
++
)
{
httpd_client_t
*
cl
;
int
i_state
=
-
1
;
int
fd
=
ufd
[
nfd
].
fd
;
assert
(
fd
==
host
->
fds
[
nfd
]);
...
...
@@ -2335,34 +2312,13 @@ static void* httpd_HostThread( void *data )
vlc_tls_t
*
p_tls
;
if
(
host
->
p_tls
!=
NULL
)
{
p_tls
=
vlc_tls_ServerSessionCreate
(
host
->
p_tls
,
fd
);
switch
(
vlc_tls_ServerSessionHandshake
(
p_tls
)
)
{
case
-
1
:
msg_Err
(
host
,
"Rejecting TLS connection"
);
/* p_tls is destroyed implicitly */
net_Close
(
fd
);
fd
=
-
1
;
p_tls
=
NULL
;
continue
;
case
1
:
/* missing input - most likely */
i_state
=
HTTPD_CLIENT_TLS_HS_IN
;
break
;
case
2
:
/* missing output */
i_state
=
HTTPD_CLIENT_TLS_HS_OUT
;
break
;
}
}
else
p_tls
=
NULL
;
cl
=
httpd_ClientNew
(
fd
,
p_tls
,
now
);
TAB_APPEND
(
host
->
i_client
,
host
->
client
,
cl
);
if
(
i_state
!=
-
1
)
cl
->
i_state
=
i_state
;
// override state for TLS
}
}
vlc_mutex_unlock
(
&
host
->
lock
);
...
...
src/network/tls.c
View file @
52eb2b94
...
...
@@ -185,12 +185,9 @@ vlc_tls_t *vlc_tls_ServerSessionCreate (vlc_tls_creds_t *crd, int fd)
return
vlc_tls_SessionCreate
(
crd
,
fd
,
NULL
);
}
int
vlc_tls_
Server
SessionHandshake
(
vlc_tls_t
*
ses
)
int
vlc_tls_SessionHandshake
(
vlc_tls_t
*
ses
sion
)
{
int
val
=
ses
->
handshake
(
ses
);
if
(
val
<
0
)
vlc_tls_ServerSessionDelete
(
ses
);
return
val
;
return
session
->
handshake
(
session
);
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment