]> git.sesse.net Git - vlc/blobdiff - src/misc/tls.c
- Add httpd_ServerIP() to obtain HTTP server's IP used with a given client
[vlc] / src / misc / tls.c
index 689c8b8991de155302ad59e060e40899f5698bb8..4fec8319eba535dcea05131b3c4fe2f4649bd430 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * tls.c
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
- * $Id: httpd.c 8263 2004-07-24 09:06:58Z courmisch $
+ * Copyright (C) 2004-2005 the VideoLAN team
+ * $Id$
  *
- * Authors: Remi Denis-Courmont <courmisch@via.ecp.fr>
+ * Authors: Remi Denis-Courmont <rem # videolan.org>
  *
  * 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
 #include "vlc_tls.h"
 
 
-/*
- * TODO:
- * - client side stuff,
- * - server-side client cert validation,
- * - client-side server cert validation (?).
- */
-
 /*****************************************************************************
  * tls_ServerCreate:
  *****************************************************************************
@@ -56,18 +49,18 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
         if( psz_key == NULL )
             psz_key = psz_cert;
 
-        p_server = __tls_ServerCreate( p_tls, psz_cert, psz_key );
+        p_server = p_tls->pf_server_create( p_tls, psz_cert, psz_key );
         if( p_server != NULL )
         {
-            msg_Dbg( p_this, "TLS/SSL provider initialized" );
+            msg_Dbg( p_tls, "TLS/SSL provider initialized" );
             return p_server;
         }
         else
-            msg_Err( p_this, "TLS/SSL provider error" );
+            msg_Err( p_tls, "TLS/SSL provider error" );
         module_Unneed( p_tls, p_tls->p_module );
     }
     else
-        msg_Err( p_this, "TLS/SSL provider not found" );
+        msg_Err( p_tls, "TLS/SSL provider not found" );
 
     vlc_object_detach( p_tls );
     vlc_object_destroy( p_tls );
@@ -83,9 +76,9 @@ tls_ServerCreate( vlc_object_t *p_this, const char *psz_cert,
 void
 tls_ServerDelete( tls_server_t *p_server )
 {
-    tls_t *p_tls = p_server->p_tls;
+    tls_t *p_tls = (tls_t *)p_server->p_parent;
 
-    __tls_ServerDelete( p_server );
+    p_server->pf_delete( p_server );
 
     module_Unneed( p_tls, p_tls->p_module );
     vlc_object_detach( p_tls );
@@ -97,10 +90,10 @@ tls_ServerDelete( tls_server_t *p_server )
  * tls_ClientCreate:
  *****************************************************************************
  * Allocates a client's TLS credentials and shakes hands through the network.
- * Returns NULL on error.
+ * Returns NULL on error. This is a blocking network operation.
  *****************************************************************************/
 tls_session_t *
-tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
+tls_ClientCreate( vlc_object_t *p_this, int fd, const char *psz_hostname )
 {
     tls_t *p_tls;
     tls_session_t *p_session;
@@ -111,16 +104,22 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
     p_tls->p_module = module_Need( p_tls, "tls", 0, 0 );
     if( p_tls->p_module != NULL )
     {
-        p_session = __tls_ClientCreate( p_tls, psz_ca );
+        p_session = p_tls->pf_client_create( p_tls );
         if( p_session != NULL )
         {
-            if( tls_SessionHandshake( p_session, fd ) )
+            int i_val;
+
+            for( i_val = tls_ClientSessionHandshake( p_session, fd,
+                                                     psz_hostname );
+                 i_val > 0;
+                 i_val = tls_SessionContinueHandshake( p_session ) );
+            
+            if( i_val == 0 )
             {
                 msg_Dbg( p_this, "TLS/SSL provider initialized" );
                 return p_session;
             }
-            else
-                msg_Err( p_this, "TLS/SSL session handshake error" );
+            msg_Err( p_this, "TLS/SSL session handshake error" );
         }
         else
             msg_Err( p_this, "TLS/SSL provider error" );
@@ -143,9 +142,9 @@ tls_ClientCreate( vlc_object_t *p_this, const char *psz_ca, int fd )
 void
 tls_ClientDelete( tls_session_t *p_session )
 {
-    tls_t *p_tls = p_session->p_tls;
+    tls_t *p_tls = (tls_t *)p_session->p_parent;
 
-    tls_SessionClose( p_session );
+    p_session->pf_close( p_session );
 
     module_Unneed( p_tls, p_tls->p_module );
     vlc_object_detach( p_tls );