configure: Fix typo when enabling CPAN modules as dependency
[strongswan.git] / src / libpttls / pt_tls_dispatcher.c
index adcf5b4..5c30637 100644 (file)
@@ -42,9 +42,24 @@ struct private_pt_tls_dispatcher_t {
        int fd;
 
        /**
+        * Client authentication requirements
+        */
+       pt_tls_auth_t auth;
+
+       /**
         * Server identity
         */
        identification_t *server;
+
+       /**
+        * Peer identity
+        */
+       identification_t *peer;
+
+       /**
+        * TNCCS protocol handler constructor
+        */
+       pt_tls_tnccs_constructor_t *create;
 };
 
 /**
@@ -106,11 +121,13 @@ static void cleanup(pt_tls_server_t *connection)
 }
 
 METHOD(pt_tls_dispatcher_t, dispatch, void,
-       private_pt_tls_dispatcher_t *this)
+       private_pt_tls_dispatcher_t *this,
+       pt_tls_tnccs_constructor_t *create)
 {
        while (TRUE)
        {
                pt_tls_server_t *connection;
+               tnccs_t *tnccs;
                bool old;
                int fd;
 
@@ -123,7 +140,13 @@ METHOD(pt_tls_dispatcher_t, dispatch, void,
                        continue;
                }
 
-               connection = pt_tls_server_create(this->server, fd);
+               tnccs = create(this->server, this->peer);
+               if (!tnccs)
+               {
+                       close(fd);
+                       continue;
+               }
+               connection = pt_tls_server_create(this->server, fd, this->auth, tnccs);
                if (!connection)
                {
                        close(fd);
@@ -145,6 +168,7 @@ METHOD(pt_tls_dispatcher_t, destroy, void,
                close(this->fd);
        }
        this->server->destroy(this->server);
+       this->peer->destroy(this->peer);
        free(this);
 }
 
@@ -152,7 +176,7 @@ METHOD(pt_tls_dispatcher_t, destroy, void,
  * See header
  */
 pt_tls_dispatcher_t *pt_tls_dispatcher_create(host_t *address,
-                                                                                         identification_t *id)
+                                                                       identification_t *id, pt_tls_auth_t auth)
 {
        private_pt_tls_dispatcher_t *this;
 
@@ -161,17 +185,18 @@ pt_tls_dispatcher_t *pt_tls_dispatcher_create(host_t *address,
                        .dispatch = _dispatch,
                        .destroy = _destroy,
                },
-               .server = id,
+               .server = id->clone(id),
+               /* we currently don't authenticate the peer, use %any identity */
+               .peer = identification_create_from_encoding(ID_ANY, chunk_empty),
                .fd = -1,
+               .auth = auth,
        );
 
        if (!open_socket(this, address))
        {
-               address->destroy(address);
                destroy(this);
                return NULL;
        }
-       address->destroy(address);
 
        return &this->public;
 }