Introduced workitems to Attestation IMV
This commit is contained in:
@@ -262,6 +262,12 @@ INSERT INTO files ( /* 5 */
|
||||
'openssl', 8
|
||||
);
|
||||
|
||||
INSERT INTO files ( /* 6 */
|
||||
name, dir
|
||||
) VALUES (
|
||||
'tnc_config', 2
|
||||
);
|
||||
|
||||
/* Algorithms */
|
||||
|
||||
INSERT INTO algorithms (
|
||||
@@ -639,15 +645,40 @@ INSERT INTO policies ( /* 7 */
|
||||
INSERT INTO policies ( /* 8 */
|
||||
type, name, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
9, 'No Open TCP Ports', 1, 1
|
||||
11, 'No Open TCP Ports', 1, 1
|
||||
);
|
||||
|
||||
INSERT INTO policies ( /* 9 */
|
||||
type, name, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
10, 'No Open UDP Ports', 1, 1
|
||||
12, 'No Open UDP Ports', 1, 1
|
||||
);
|
||||
|
||||
INSERT INTO policies ( /* 10 */
|
||||
type, name, file, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
7, 'Metadata of /etc/tnc_config', 6, 0, 0
|
||||
);
|
||||
|
||||
INSERT INTO policies ( /* 11 */
|
||||
type, name, dir, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
8, 'Measure as reference /bin', 1, 0, 0
|
||||
);
|
||||
|
||||
INSERT INTO policies ( /* 12 */
|
||||
type, name, file, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
6, 'Measure /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', 2, 2, 2
|
||||
);
|
||||
|
||||
INSERT INTO policies ( /* 13 */
|
||||
type, name, file, rec_fail, rec_noresult
|
||||
) VALUES (
|
||||
6, 'Measure /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0', 4, 2, 2
|
||||
);
|
||||
|
||||
|
||||
/* Enforcements */
|
||||
|
||||
INSERT INTO enforcements (
|
||||
@@ -713,13 +744,13 @@ INSERT INTO enforcements (
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
5, 2, 86400
|
||||
5, 4, 86400
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
6, 2, 86400
|
||||
6, 4, 86400
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
@@ -788,3 +819,27 @@ INSERT INTO enforcements (
|
||||
9, 5, 60
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
10, 2, 60
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
11, 2, 86400
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
12, 2, 86400
|
||||
);
|
||||
|
||||
INSERT INTO enforcements (
|
||||
policy, group_id, max_age
|
||||
) VALUES (
|
||||
13, 2, 86400
|
||||
);
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ static bool delete_connection(private_imv_agent_t *this, TNC_ConnectionID id)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
imv_state_t *state;
|
||||
imv_session_t *session;
|
||||
bool found = FALSE;
|
||||
|
||||
this->connection_lock->write_lock(this->connection_lock);
|
||||
@@ -294,6 +295,11 @@ static bool delete_connection(private_imv_agent_t *this, TNC_ConnectionID id)
|
||||
if (id == state->get_connection_id(state))
|
||||
{
|
||||
found = TRUE;
|
||||
session = state->get_session(state);
|
||||
if (session)
|
||||
{
|
||||
imcv_db->remove_session(imcv_db, session);
|
||||
}
|
||||
state->destroy(state);
|
||||
this->connections->remove_at(this->connections, enumerator);
|
||||
break;
|
||||
@@ -480,7 +486,7 @@ METHOD(imv_agent_t, create_state, TNC_Result,
|
||||
|
||||
if (imcv_db)
|
||||
{
|
||||
session = imcv_db->get_session(imcv_db, conn_id, ar_id_type, ar_id_value);
|
||||
session = imcv_db->add_session(imcv_db, conn_id, ar_id_type, ar_id_value);
|
||||
if (session)
|
||||
{
|
||||
DBG2(DBG_IMV, " assigned session ID %d",
|
||||
|
||||
@@ -59,7 +59,7 @@ struct private_imv_database_t {
|
||||
|
||||
};
|
||||
|
||||
METHOD(imv_database_t, get_session, imv_session_t*,
|
||||
METHOD(imv_database_t, add_session, imv_session_t*,
|
||||
private_imv_database_t *this, TNC_ConnectionID conn_id,
|
||||
u_int32_t ar_id_type, chunk_t ar_id_value)
|
||||
{
|
||||
@@ -123,6 +123,26 @@ METHOD(imv_database_t, get_session, imv_session_t*,
|
||||
return session;
|
||||
}
|
||||
|
||||
METHOD(imv_database_t, remove_session, void,
|
||||
private_imv_database_t *this, imv_session_t *session)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
imv_session_t *current;
|
||||
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->sessions->create_enumerator(this->sessions);
|
||||
while (enumerator->enumerate(enumerator, ¤t))
|
||||
{
|
||||
if (current == session)
|
||||
{
|
||||
this->sessions->remove_at(this->sessions, enumerator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
this->mutex->unlock(this->mutex);
|
||||
}
|
||||
|
||||
METHOD(imv_database_t, add_product, int,
|
||||
private_imv_database_t *this, imv_session_t *session, char *product)
|
||||
{
|
||||
@@ -204,10 +224,9 @@ METHOD(imv_database_t, policy_script, bool,
|
||||
{
|
||||
imv_workitem_t *workitem;
|
||||
imv_workitem_type_t type;
|
||||
imv_session_t *current;
|
||||
int id, session_id, rec_fail, rec_noresult;
|
||||
enumerator_t *enumerator, *e;
|
||||
char command[512], resp[128], *last, *argument;
|
||||
int id, session_id, arg_int, rec_fail, rec_noresult;
|
||||
enumerator_t *e;
|
||||
char command[512], resp[128], *last, *arg_str;
|
||||
FILE *shell;
|
||||
|
||||
session_id = session->get_session_id(session);
|
||||
@@ -250,17 +269,18 @@ METHOD(imv_database_t, policy_script, bool,
|
||||
{
|
||||
/* get workitem list generated by policy manager */
|
||||
e = this->db->query(this->db,
|
||||
"SELECT id, type, argument, rec_fail, rec_noresult "
|
||||
"FROM workitems WHERE session = ?",
|
||||
DB_INT, session_id, DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT);
|
||||
"SELECT id, type, arg_str, arg_int, rec_fail, rec_noresult "
|
||||
"FROM workitems WHERE session = ?", DB_INT, session_id,
|
||||
DB_INT, DB_INT, DB_TEXT, DB_INT,DB_INT, DB_INT);
|
||||
if (!e)
|
||||
{
|
||||
DBG1(DBG_IMV, "no workitem enumerator returned");
|
||||
return FALSE;
|
||||
}
|
||||
while (e->enumerate(e, &id, &type, &argument, &rec_fail, &rec_noresult))
|
||||
while (e->enumerate(e, &id, &type, &arg_str, &arg_int, &rec_fail,
|
||||
&rec_noresult))
|
||||
{
|
||||
workitem = imv_workitem_create(id, type, argument, rec_fail,
|
||||
workitem = imv_workitem_create(id, type, arg_str, arg_int, rec_fail,
|
||||
rec_noresult);
|
||||
session->insert_workitem(session, workitem);
|
||||
}
|
||||
@@ -270,20 +290,6 @@ METHOD(imv_database_t, policy_script, bool,
|
||||
}
|
||||
else if (!start && session->get_policy_started(session))
|
||||
{
|
||||
/* remove session */
|
||||
this->mutex->lock(this->mutex);
|
||||
enumerator = this->sessions->create_enumerator(this->sessions);
|
||||
while (enumerator->enumerate(enumerator, ¤t))
|
||||
{
|
||||
if (current == session)
|
||||
{
|
||||
this->sessions->remove_at(this->sessions, enumerator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
this->mutex->unlock(this->mutex);
|
||||
|
||||
session->set_policy_started(session, FALSE);
|
||||
}
|
||||
|
||||
@@ -329,7 +335,8 @@ imv_database_t *imv_database_create(char *uri, char *script)
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.get_session = _get_session,
|
||||
.add_session = _add_session,
|
||||
.remove_session = _remove_session,
|
||||
.add_product = _add_product,
|
||||
.add_device = _add_device,
|
||||
.add_recommendation = _add_recommendation,
|
||||
|
||||
@@ -44,10 +44,17 @@ struct imv_database_t {
|
||||
* @param ar_id_value Access Requestor identity value
|
||||
* @return Session associated with TNCCS Connection
|
||||
*/
|
||||
imv_session_t* (*get_session)(imv_database_t *this,
|
||||
imv_session_t* (*add_session)(imv_database_t *this,
|
||||
TNC_ConnectionID conn_id,
|
||||
u_int32_t ar_id_type, chunk_t ar_id_value);
|
||||
|
||||
/**
|
||||
* Remove and delete a session
|
||||
*
|
||||
* @param session Session
|
||||
*/
|
||||
void (*remove_session)(imv_database_t *this, imv_session_t *session);
|
||||
|
||||
/**
|
||||
* Add product information string to a session database entry
|
||||
*
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/**
|
||||
* global debug output variables
|
||||
*/
|
||||
static int debug_level = 2;
|
||||
static int debug_level = 1;
|
||||
static bool stderr_quiet = FALSE;
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ bool policy_start(database_t *db, int session_id)
|
||||
{
|
||||
enumerator_t *e;
|
||||
int id, gid, device_id, product_id, group_id = 0;
|
||||
int type, rec_fail, rec_noresult;
|
||||
int type, file, dir, arg_int, rec_fail, rec_noresult;
|
||||
char *argument;
|
||||
|
||||
/* get session data */
|
||||
@@ -107,22 +107,41 @@ bool policy_start(database_t *db, int session_id)
|
||||
|
||||
/* get enforcements for given group */
|
||||
e = db->query(db,
|
||||
"SELECT e.id, p.type, p.argument, p.rec_fail, p.rec_noresult "
|
||||
"SELECT e.id, "
|
||||
"p.type, p.argument, p.file, p.dir, p.rec_fail, p.rec_noresult "
|
||||
"FROM enforcements AS e JOIN policies as p ON e.policy = p.id "
|
||||
"WHERE e.group_id = ?",
|
||||
DB_INT, group_id, DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT);
|
||||
"WHERE e.group_id = ?", DB_INT, group_id,
|
||||
DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT, DB_INT);
|
||||
if (!e)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
while (e->enumerate(e, &id, &type, &argument, &rec_fail, &rec_noresult))
|
||||
while (e->enumerate(e, &id, &type, &argument, &file, &dir, &rec_fail,
|
||||
&rec_noresult))
|
||||
{
|
||||
/* determine arg_int */
|
||||
switch ((imv_workitem_type_t)type)
|
||||
{
|
||||
case IMV_WORKITEM_FILE_REF_MEAS:
|
||||
case IMV_WORKITEM_FILE_MEAS:
|
||||
case IMV_WORKITEM_FILE_META:
|
||||
arg_int = file;
|
||||
break;
|
||||
case IMV_WORKITEM_DIR_REF_MEAS:
|
||||
case IMV_WORKITEM_DIR_MEAS:
|
||||
case IMV_WORKITEM_DIR_META:
|
||||
arg_int = dir;
|
||||
break;
|
||||
default:
|
||||
arg_int = 0;
|
||||
}
|
||||
|
||||
/* insert a workitem */
|
||||
if (db->execute(db, NULL,
|
||||
"INSERT INTO workitems (session, enforcement, type, argument, "
|
||||
"rec_fail, rec_noresult) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
"INSERT INTO workitems (session, enforcement, type, arg_str, "
|
||||
"arg_int, rec_fail, rec_noresult) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
DB_INT, session_id, DB_INT, id, DB_INT, type, DB_TEXT, argument,
|
||||
DB_INT, rec_fail, DB_INT, rec_noresult) != 1)
|
||||
DB_INT, arg_int, DB_INT, rec_fail, DB_INT, rec_noresult) != 1)
|
||||
{
|
||||
e->destroy(e);
|
||||
fprintf(stderr, "could not insert workitem\n");
|
||||
@@ -139,7 +158,6 @@ bool policy_stop(database_t *db, int session_id)
|
||||
enumerator_t *e;
|
||||
int rec, policy;
|
||||
char *result;
|
||||
bool no_worklists = TRUE;
|
||||
|
||||
e = db->query(db,
|
||||
"SELECT w.rec_final, w.result, e.policy FROM workitems AS w "
|
||||
@@ -150,24 +168,16 @@ bool policy_stop(database_t *db, int session_id)
|
||||
{
|
||||
while (e->enumerate(e, &rec, &result, &policy))
|
||||
{
|
||||
no_worklists = FALSE;
|
||||
|
||||
/* insert result */
|
||||
db->execute(db, NULL,
|
||||
"INSERT INTO results (session, policy, rec, result) "
|
||||
"VALUES (?, ?, ?, ?)", DB_INT, session_id, DB_INT, policy,
|
||||
DB_INT, rec, DB_TEXT, result);
|
||||
}
|
||||
e->destroy(e);
|
||||
|
||||
if (no_worklists)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return db->execute(db, NULL,
|
||||
"DELETE FROM workitems WHERE session = ?",
|
||||
DB_UINT, session_id) > 0;
|
||||
DB_UINT, session_id) >= 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -224,6 +234,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* attach IMV database */
|
||||
uri = lib->settings->get_str(lib->settings, "libimcv.database", NULL);
|
||||
if (!uri)
|
||||
{
|
||||
fprintf(stderr, "database uri not defined.\n");
|
||||
exit(SS_RC_INITIALIZATION_FAILED);
|
||||
}
|
||||
|
||||
db = lib->db->create(lib->db, uri);
|
||||
if (!db)
|
||||
{
|
||||
|
||||
@@ -79,6 +79,20 @@ struct imv_state_t {
|
||||
*/
|
||||
u_int32_t (*get_max_msg_len)(imv_state_t *this);
|
||||
|
||||
/**
|
||||
* Set flags for completed actions
|
||||
*
|
||||
* @param flags Flags to be set
|
||||
*/
|
||||
void (*set_action_flags)(imv_state_t *this, u_int32_t flags);
|
||||
|
||||
/**
|
||||
* Get flags set for completed actions
|
||||
*
|
||||
* @return Flags set for completed actions
|
||||
*/
|
||||
u_int32_t (*get_action_flags)(imv_state_t *this);
|
||||
|
||||
/**
|
||||
* Set Access Requestor ID
|
||||
*
|
||||
|
||||
@@ -27,8 +27,10 @@ ENUM(imv_workitem_type_names, IMV_WORKITEM_PACKAGES, IMV_WORKITEM_UDP_SCAN,
|
||||
"PWDEN",
|
||||
"FREFM",
|
||||
"FMEAS",
|
||||
"FMETA",
|
||||
"DREFM",
|
||||
"DMEAS",
|
||||
"DMETA",
|
||||
"TCPSC",
|
||||
"UDPSC"
|
||||
);
|
||||
@@ -62,7 +64,12 @@ struct private_imv_workitem_t {
|
||||
/**
|
||||
* Argument string
|
||||
*/
|
||||
char *argument;
|
||||
char *arg_str;
|
||||
|
||||
/**
|
||||
* Argument integer
|
||||
*/
|
||||
int arg_int;
|
||||
|
||||
/**
|
||||
* Result string
|
||||
@@ -110,10 +117,16 @@ METHOD(imv_workitem_t, get_type, imv_workitem_type_t,
|
||||
return this->type;
|
||||
}
|
||||
|
||||
METHOD(imv_workitem_t, get_argument, char*,
|
||||
METHOD(imv_workitem_t, get_arg_str, char*,
|
||||
private_imv_workitem_t *this)
|
||||
{
|
||||
return this->argument;
|
||||
return this->arg_str;
|
||||
}
|
||||
|
||||
METHOD(imv_workitem_t, get_arg_int, int,
|
||||
private_imv_workitem_t *this)
|
||||
{
|
||||
return this->arg_int;
|
||||
}
|
||||
|
||||
METHOD(imv_workitem_t, set_result, TNC_IMV_Action_Recommendation,
|
||||
@@ -135,9 +148,10 @@ METHOD(imv_workitem_t, set_result, TNC_IMV_Action_Recommendation,
|
||||
this->rec_final = this->rec_noresult;
|
||||
break;
|
||||
}
|
||||
DBG2(DBG_IMV, "workitem %N: %N%s%s", imv_workitem_type_names, this->type,
|
||||
TNC_IMV_Action_Recommendation_names, this->rec_final,
|
||||
strlen(result) ? " - " : "", result);
|
||||
DBG2(DBG_IMV, "IMV %d handled %N workitem %d: %N%s%s", this->imv_id,
|
||||
imv_workitem_type_names, this->type, this->id,
|
||||
TNC_IMV_Action_Recommendation_names, this->rec_final,
|
||||
strlen(result) ? " - " : "", result);
|
||||
|
||||
return this->rec_final;
|
||||
}
|
||||
@@ -155,7 +169,7 @@ METHOD(imv_workitem_t, get_result, TNC_IMV_Action_Recommendation,
|
||||
METHOD(imv_workitem_t, destroy, void,
|
||||
private_imv_workitem_t *this)
|
||||
{
|
||||
free(this->argument);
|
||||
free(this->arg_str);
|
||||
free(this->result);
|
||||
free(this);
|
||||
}
|
||||
@@ -164,7 +178,7 @@ METHOD(imv_workitem_t, destroy, void,
|
||||
* See header
|
||||
*/
|
||||
imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
|
||||
char *argument,
|
||||
char *arg_str, int arg_int,
|
||||
TNC_IMV_Action_Recommendation rec_fail,
|
||||
TNC_IMV_Action_Recommendation rec_noresult)
|
||||
{
|
||||
@@ -176,7 +190,8 @@ imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
|
||||
.set_imv_id = _set_imv_id,
|
||||
.get_imv_id = _get_imv_id,
|
||||
.get_type = _get_type,
|
||||
.get_argument = _get_argument,
|
||||
.get_arg_str = _get_arg_str,
|
||||
.get_arg_int = _get_arg_int,
|
||||
.set_result = _set_result,
|
||||
.get_result = _get_result,
|
||||
.destroy = _destroy,
|
||||
@@ -184,7 +199,8 @@ imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
|
||||
.id = id,
|
||||
.imv_id = TNC_IMVID_ANY,
|
||||
.type = type,
|
||||
.argument = strdup(argument),
|
||||
.arg_str = arg_str ? strdup(arg_str) : NULL,
|
||||
.arg_int = arg_int,
|
||||
.rec_fail = rec_fail,
|
||||
.rec_noresult = rec_noresult,
|
||||
.rec_final = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
|
||||
|
||||
@@ -36,10 +36,12 @@ enum imv_workitem_type_t {
|
||||
IMV_WORKITEM_DEFAULT_PWD = 4,
|
||||
IMV_WORKITEM_FILE_REF_MEAS = 5,
|
||||
IMV_WORKITEM_FILE_MEAS = 6,
|
||||
IMV_WORKITEM_DIR_REF_MEAS = 7,
|
||||
IMV_WORKITEM_DIR_MEAS = 8,
|
||||
IMV_WORKITEM_TCP_SCAN = 9,
|
||||
IMV_WORKITEM_UDP_SCAN = 10
|
||||
IMV_WORKITEM_FILE_META = 7,
|
||||
IMV_WORKITEM_DIR_REF_MEAS = 8,
|
||||
IMV_WORKITEM_DIR_MEAS = 9,
|
||||
IMV_WORKITEM_DIR_META = 10,
|
||||
IMV_WORKITEM_TCP_SCAN = 11,
|
||||
IMV_WORKITEM_UDP_SCAN = 12
|
||||
};
|
||||
|
||||
extern enum_name_t *imv_workitem_type_names;
|
||||
@@ -78,11 +80,18 @@ struct imv_workitem_t {
|
||||
TNC_IMVID (*get_imv_id)(imv_workitem_t *this);
|
||||
|
||||
/**
|
||||
* Get argument string
|
||||
* Get string argument
|
||||
*
|
||||
* @return Argument string
|
||||
*/
|
||||
char* (*get_argument)(imv_workitem_t *this);
|
||||
char* (*get_arg_str)(imv_workitem_t *this);
|
||||
|
||||
/**
|
||||
* Get integer argument
|
||||
*
|
||||
* @return Argument integer
|
||||
*/
|
||||
int (*get_arg_int)(imv_workitem_t *this);
|
||||
|
||||
/**
|
||||
* Set result string
|
||||
@@ -114,12 +123,13 @@ struct imv_workitem_t {
|
||||
*
|
||||
* @param id Primary workitem key
|
||||
* @param type Workitem type
|
||||
* @param argument Argument string
|
||||
* @param arg_str String argument
|
||||
* @param arg_int Integer argument
|
||||
* @param rec_fail Recommendation with minor/major non-compliance case
|
||||
* @param rec_noresult Recommendation in don't know/error case
|
||||
*/
|
||||
imv_workitem_t *imv_workitem_create(int id, imv_workitem_type_t type,
|
||||
char *argument,
|
||||
char *arg_str, int arg_int,
|
||||
TNC_IMV_Action_Recommendation rec_fail,
|
||||
TNC_IMV_Action_Recommendation rec_noresult);
|
||||
|
||||
|
||||
@@ -107,7 +107,8 @@ CREATE TABLE workitems (
|
||||
session integer NOT NULL REFERENCES sessions(id),
|
||||
enforcement integer NOT NULL REFERENCES enforcements(id),
|
||||
type integer NOT NULL,
|
||||
argument text NOT NULL,
|
||||
arg_str text,
|
||||
arg_int INTEGER DEFAULT 0,
|
||||
rec_fail integer NOT NULL,
|
||||
rec_noresult integer NOT NULL,
|
||||
rec_final integer,
|
||||
|
||||
Reference in New Issue
Block a user