Process PB-TNC batches received via PT-TLS asynchronously

This commit is contained in:
Andreas Steffen
2013-08-19 09:52:12 +02:00
parent 9dc3b2053d
commit 1e92d5f114
2 changed files with 61 additions and 68 deletions
+1 -4
View File
@@ -587,8 +587,7 @@ static bool pt_tls_receive_more(pt_tls_server_t *this, int fd,
switch (this->handle(this)) switch (this->handle(this))
{ {
case NEED_MORE: case NEED_MORE:
DBG1(DBG_TNC, "PT-TLS connection needs more"); return TRUE;
break;
case FAILED: case FAILED:
case SUCCESS: case SUCCESS:
default: default:
@@ -597,8 +596,6 @@ static bool pt_tls_receive_more(pt_tls_server_t *this, int fd,
close(fd); close(fd);
return FALSE; return FALSE;
} }
return TRUE;
} }
/** /**
+26 -30
View File
@@ -400,9 +400,7 @@ static bool authenticate(private_pt_tls_server_t *this)
/** /**
* Perform assessment * Perform assessment
*/ */
static bool assess(private_pt_tls_server_t *this, tls_t *tnccs) static status_t assess(private_pt_tls_server_t *this, tls_t *tnccs)
{
while (TRUE)
{ {
size_t msglen; size_t msglen;
size_t buflen = PT_TLS_MAX_MESSAGE_LEN; size_t buflen = PT_TLS_MAX_MESSAGE_LEN;
@@ -410,30 +408,12 @@ static bool assess(private_pt_tls_server_t *this, tls_t *tnccs)
bio_reader_t *reader; bio_reader_t *reader;
u_int32_t vendor, type, identifier; u_int32_t vendor, type, identifier;
chunk_t data; chunk_t data;
status_t status;
switch (tnccs->build(tnccs, buf, &buflen, &msglen))
{
case SUCCESS:
return tnccs->is_complete(tnccs);
case ALREADY_DONE:
data = chunk_create(buf, buflen);
if (!pt_tls_write(this->tls, PT_TLS_PB_TNC_BATCH,
this->identifier++, data))
{
return FALSE;
}
break;
case INVALID_STATE:
break;
case FAILED:
default:
return FALSE;
}
reader = pt_tls_read(this->tls, &vendor, &type, &identifier); reader = pt_tls_read(this->tls, &vendor, &type, &identifier);
if (!reader) if (!reader)
{ {
return FALSE; return FAILED;
} }
if (vendor == 0) if (vendor == 0)
{ {
@@ -441,20 +421,20 @@ static bool assess(private_pt_tls_server_t *this, tls_t *tnccs)
{ {
DBG1(DBG_TNC, "received PT-TLS error"); DBG1(DBG_TNC, "received PT-TLS error");
reader->destroy(reader); reader->destroy(reader);
return FALSE; return FAILED;
} }
if (type != PT_TLS_PB_TNC_BATCH) if (type != PT_TLS_PB_TNC_BATCH)
{ {
DBG1(DBG_TNC, "unexpected PT-TLS message: %d", type); DBG1(DBG_TNC, "unexpected PT-TLS message: %d", type);
reader->destroy(reader); reader->destroy(reader);
return FALSE; return FAILED;
} }
data = reader->peek(reader); data = reader->peek(reader);
switch (tnccs->process(tnccs, data.ptr, data.len)) switch (tnccs->process(tnccs, data.ptr, data.len))
{ {
case SUCCESS: case SUCCESS:
reader->destroy(reader); reader->destroy(reader);
return tnccs->is_complete(tnccs); return tnccs->is_complete(tnccs) ? SUCCESS : FAILED;
case FAILED: case FAILED:
default: default:
reader->destroy(reader); reader->destroy(reader);
@@ -468,8 +448,19 @@ static bool assess(private_pt_tls_server_t *this, tls_t *tnccs)
DBG1(DBG_TNC, "ignoring vendor specific PT-TLS message"); DBG1(DBG_TNC, "ignoring vendor specific PT-TLS message");
} }
reader->destroy(reader); reader->destroy(reader);
status = tnccs->build(tnccs, buf, &buflen, &msglen);
if (status == ALREADY_DONE)
{
data = chunk_create(buf, buflen);
if (!pt_tls_write(this->tls, PT_TLS_PB_TNC_BATCH,
this->identifier++, data))
{
return FAILED;
} }
} }
return status;
}
METHOD(pt_tls_server_t, handle, status_t, METHOD(pt_tls_server_t, handle, status_t,
private_pt_tls_server_t *this) private_pt_tls_server_t *this)
@@ -492,15 +483,20 @@ METHOD(pt_tls_server_t, handle, status_t,
return FAILED; return FAILED;
} }
this->state = PT_TLS_SERVER_TNCCS; this->state = PT_TLS_SERVER_TNCCS;
DBG1(DBG_TNC, "entering PT-TLS data transport phase");
break; break;
case PT_TLS_SERVER_TNCCS: case PT_TLS_SERVER_TNCCS:
DBG1(DBG_TNC, "entering PT-TLS data transport phase"); switch (assess(this, (tls_t*)this->tnccs))
if (!assess(this, (tls_t*)this->tnccs))
{ {
return FAILED; case SUCCESS:
}
this->state = PT_TLS_SERVER_END; this->state = PT_TLS_SERVER_END;
return SUCCESS; return SUCCESS;
case FAILED:
return FAILED;
default:
break;
}
break;
default: default:
return FAILED; return FAILED;
} }