Create pt_tls_client with separate server address and identity
This commit is contained in:
@@ -41,14 +41,14 @@ struct private_pt_tls_client_t {
|
|||||||
tls_socket_t *tls;
|
tls_socket_t *tls;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server address
|
* Server address/port
|
||||||
*/
|
*/
|
||||||
char *server;
|
host_t *address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server port
|
* Server identity
|
||||||
*/
|
*/
|
||||||
u_int16_t port;
|
identification_t *id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current PT-TLS message identifier
|
* Current PT-TLS message identifier
|
||||||
@@ -61,36 +61,23 @@ struct private_pt_tls_client_t {
|
|||||||
*/
|
*/
|
||||||
static bool make_connection(private_pt_tls_client_t *this)
|
static bool make_connection(private_pt_tls_client_t *this)
|
||||||
{
|
{
|
||||||
identification_t *id;
|
|
||||||
host_t *server;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
server = host_create_from_dns(this->server, AF_UNSPEC, this->port);
|
fd = socket(this->address->get_family(this->address), SOCK_STREAM, 0);
|
||||||
if (!server)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = socket(server->get_family(server), SOCK_STREAM, 0);
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "opening PT-TLS socket failed: %s", strerror(errno));
|
DBG1(DBG_TNC, "opening PT-TLS socket failed: %s", strerror(errno));
|
||||||
server->destroy(server);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (connect(fd, server->get_sockaddr(server),
|
if (connect(fd, this->address->get_sockaddr(this->address),
|
||||||
*server->get_sockaddr_len(server)) == -1)
|
*this->address->get_sockaddr_len(this->address)) == -1)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "connecting to PT-TLS server failed: %s", strerror(errno));
|
DBG1(DBG_TNC, "connecting to PT-TLS server failed: %s", strerror(errno));
|
||||||
server->destroy(server);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
server->destroy(server);
|
|
||||||
|
|
||||||
id = identification_create_from_string(this->server);
|
this->tls = tls_socket_create(FALSE, this->id, NULL, fd, NULL);
|
||||||
this->tls = tls_socket_create(FALSE, id, NULL, fd, NULL);
|
|
||||||
id->destroy(id);
|
|
||||||
if (!this->tls)
|
if (!this->tls)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -292,14 +279,15 @@ METHOD(pt_tls_client_t, destroy, void,
|
|||||||
close(this->tls->get_fd(this->tls));
|
close(this->tls->get_fd(this->tls));
|
||||||
this->tls->destroy(this->tls);
|
this->tls->destroy(this->tls);
|
||||||
}
|
}
|
||||||
free(this->server);
|
this->address->destroy(this->address);
|
||||||
|
this->id->destroy(this->id);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
pt_tls_client_t *pt_tls_client_create(char *server, u_int16_t port)
|
pt_tls_client_t *pt_tls_client_create(host_t *address, identification_t *id)
|
||||||
{
|
{
|
||||||
private_pt_tls_client_t *this;
|
private_pt_tls_client_t *this;
|
||||||
|
|
||||||
@@ -308,8 +296,8 @@ pt_tls_client_t *pt_tls_client_create(char *server, u_int16_t port)
|
|||||||
.run_assessment = _run_assessment,
|
.run_assessment = _run_assessment,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.server = strdup(server),
|
.address = address,
|
||||||
.port = port,
|
.id = id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
#ifndef PT_TLS_CLIENT_H_
|
#ifndef PT_TLS_CLIENT_H_
|
||||||
#define PT_TLS_CLIENT_H_
|
#define PT_TLS_CLIENT_H_
|
||||||
|
|
||||||
|
#include <networking/host.h>
|
||||||
|
#include <utils/identification.h>
|
||||||
|
|
||||||
#include <tnc/tnccs/tnccs.h>
|
#include <tnc/tnccs/tnccs.h>
|
||||||
|
|
||||||
typedef struct pt_tls_client_t pt_tls_client_t;
|
typedef struct pt_tls_client_t pt_tls_client_t;
|
||||||
@@ -47,10 +50,10 @@ struct pt_tls_client_t {
|
|||||||
/**
|
/**
|
||||||
* Create a pt_tls_client instance.
|
* Create a pt_tls_client instance.
|
||||||
*
|
*
|
||||||
* @param server server address to run assessments against
|
* @param address address/port to run assessments against, gets owned
|
||||||
* @param port server TCP port to connect to
|
* @param id server identity to use for authentication, gets owned
|
||||||
* @return PT-TLS context
|
* @return PT-TLS context
|
||||||
*/
|
*/
|
||||||
pt_tls_client_t *pt_tls_client_create(char *server, u_int16_t port);
|
pt_tls_client_t *pt_tls_client_create(host_t *address, identification_t *id);
|
||||||
|
|
||||||
#endif /** PT_TLS_CLIENT_H_ @}*/
|
#endif /** PT_TLS_CLIENT_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user