Commit dc1b41f1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

tls: make session independent of credentials

parent 4b2909ca
...@@ -73,8 +73,6 @@ VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *, int fd, ...@@ -73,8 +73,6 @@ VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *, int fd,
vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *, int fd, const char *host, vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *, int fd, const char *host,
const char *const *alpn); const char *const *alpn);
int vlc_tls_SessionHandshake (vlc_tls_t *, const char *host, const char *serv,
char ** /*restrict*/ alp);
VLC_API void vlc_tls_SessionDelete (vlc_tls_t *); VLC_API void vlc_tls_SessionDelete (vlc_tls_t *);
VLC_API int vlc_tls_Read(vlc_tls_t *, void *buf, size_t len, bool waitall); VLC_API int vlc_tls_Read(vlc_tls_t *, void *buf, size_t len, bool waitall);
...@@ -119,6 +117,12 @@ VLC_API vlc_tls_creds_t *vlc_tls_ClientCreate (vlc_object_t *); ...@@ -119,6 +117,12 @@ VLC_API vlc_tls_creds_t *vlc_tls_ClientCreate (vlc_object_t *);
vlc_tls_creds_t *vlc_tls_ServerCreate (vlc_object_t *, vlc_tls_creds_t *vlc_tls_ServerCreate (vlc_object_t *,
const char *cert, const char *key); const char *cert, const char *key);
static inline int vlc_tls_SessionHandshake (vlc_tls_creds_t *crd,
vlc_tls_t *tls)
{
return crd->handshake (tls, NULL, NULL, NULL);
}
/** /**
* Releases TLS credentials. * Releases TLS credentials.
* *
......
...@@ -1665,9 +1665,9 @@ static void httpd_ClientSend(httpd_client_t *cl) ...@@ -1665,9 +1665,9 @@ static void httpd_ClientSend(httpd_client_t *cl)
} }
} }
static void httpd_ClientTlsHandshake(httpd_client_t *cl) static void httpd_ClientTlsHandshake(httpd_host_t *host, httpd_client_t *cl)
{ {
switch (vlc_tls_SessionHandshake(cl->p_tls, NULL, NULL, NULL)) switch (vlc_tls_SessionHandshake(host->p_tls, cl->p_tls))
{ {
case -1: cl->i_state = HTTPD_CLIENT_DEAD; break; case -1: cl->i_state = HTTPD_CLIENT_DEAD; break;
case 0: cl->i_state = HTTPD_CLIENT_RECEIVING; break; case 0: cl->i_state = HTTPD_CLIENT_RECEIVING; break;
...@@ -2021,7 +2021,9 @@ static void httpdLoop(httpd_host_t *host) ...@@ -2021,7 +2021,9 @@ static void httpdLoop(httpd_host_t *host)
case HTTPD_CLIENT_RECEIVING: httpd_ClientRecv(cl); break; case HTTPD_CLIENT_RECEIVING: httpd_ClientRecv(cl); break;
case HTTPD_CLIENT_SENDING: httpd_ClientSend(cl); break; case HTTPD_CLIENT_SENDING: httpd_ClientSend(cl); break;
case HTTPD_CLIENT_TLS_HS_IN: case HTTPD_CLIENT_TLS_HS_IN:
case HTTPD_CLIENT_TLS_HS_OUT: httpd_ClientTlsHandshake(cl); break; case HTTPD_CLIENT_TLS_HS_OUT:
httpd_ClientTlsHandshake(host, cl);
break;
} }
} }
......
...@@ -131,7 +131,7 @@ void vlc_tls_Delete (vlc_tls_creds_t *crd) ...@@ -131,7 +131,7 @@ void vlc_tls_Delete (vlc_tls_creds_t *crd)
vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd, vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd,
const char *host, const char *const *alpn) const char *host, const char *const *alpn)
{ {
vlc_tls_t *session = vlc_custom_create (crd, sizeof (*session), vlc_tls_t *session = vlc_custom_create (crd->p_parent, sizeof (*session),
"tls session"); "tls session");
int val = crd->open (crd, session, fd, host, alpn); int val = crd->open (crd, session, fd, host, alpn);
if (val != VLC_SUCCESS) if (val != VLC_SUCCESS)
...@@ -143,14 +143,6 @@ vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd, ...@@ -143,14 +143,6 @@ vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd,
return session; return session;
} }
int vlc_tls_SessionHandshake (vlc_tls_t *session, const char *host,
const char *service, char **restrict alp)
{
vlc_tls_creds_t *crd = (vlc_tls_creds_t *)(session->p_parent);
return crd->handshake (session, host, service, alp);
}
void vlc_tls_SessionDelete (vlc_tls_t *session) void vlc_tls_SessionDelete (vlc_tls_t *session)
{ {
session->close (session); session->close (session);
...@@ -186,7 +178,7 @@ vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *crd, int fd, ...@@ -186,7 +178,7 @@ vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *crd, int fd,
ufd[0].fd = fd; ufd[0].fd = fd;
vlc_cleanup_push (cleanup_tls, session); vlc_cleanup_push (cleanup_tls, session);
while ((val = vlc_tls_SessionHandshake (session, host, service, alp)) != 0) while ((val = crd->handshake (session, host, service, alp)) != 0)
{ {
if (val < 0) if (val < 0)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment