2004-08-11 10:51:17 +01:00
|
|
|
/**
|
|
|
|
*@file arachne.c
|
|
|
|
*
|
|
|
|
* Introduces a method for proofs akin to the Athena modelchecker
|
|
|
|
* http://www.ece.cmu.edu/~dawnsong/athena/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
#include "term.h"
|
2004-08-11 15:09:12 +01:00
|
|
|
#include "termlist.h"
|
2004-08-11 13:08:10 +01:00
|
|
|
#include "role.h"
|
2004-08-11 10:51:17 +01:00
|
|
|
#include "system.h"
|
2004-08-11 15:09:12 +01:00
|
|
|
#include "states.h"
|
|
|
|
#include "mgu.h"
|
2004-08-11 10:51:17 +01:00
|
|
|
#include "arachne.h"
|
|
|
|
|
2004-08-11 15:09:12 +01:00
|
|
|
static System sys;
|
|
|
|
static Protocol INTRUDER; // Pointers, to be set by the Init
|
|
|
|
static Role I_GOAL; // Same here.
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-12 10:14:31 +01:00
|
|
|
static char *explanation; // Pointer to a string that describes what we just tried to do
|
|
|
|
static int indentDepth;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
struct goalstruct
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
int index;
|
2004-08-11 15:09:12 +01:00
|
|
|
Roledef rd;
|
2004-08-11 13:08:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct goalstruct Goal;
|
|
|
|
|
2004-08-11 15:09:12 +01:00
|
|
|
/**
|
|
|
|
* Forward declarations
|
|
|
|
*/
|
|
|
|
|
|
|
|
int iterate ();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Program code
|
|
|
|
*/
|
|
|
|
|
2004-08-11 12:22:20 +01:00
|
|
|
//! Init Arachne engine
|
|
|
|
void
|
2004-08-11 15:09:12 +01:00
|
|
|
arachneInit (const System mysys)
|
2004-08-11 12:22:20 +01:00
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
sys = mysys; // make sys available for this module as a global
|
2004-08-11 12:22:20 +01:00
|
|
|
/*
|
|
|
|
* Add intruder protocol roles
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Close Arachne engine
|
|
|
|
void
|
2004-08-11 15:09:12 +01:00
|
|
|
arachneDone ()
|
2004-08-11 12:22:20 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Detail
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* runs[rid].step is now the number of 'valid' events within the run, but we
|
|
|
|
* call it 'length' here.
|
|
|
|
*/
|
|
|
|
#define INVALID -1
|
2004-08-11 15:09:12 +01:00
|
|
|
#define isGoal(rd) (rd->type == READ && !rd->internal)
|
2004-08-11 13:08:10 +01:00
|
|
|
#define isBound(rd) (rd->bind_run != INVALID)
|
|
|
|
#define length step
|
|
|
|
|
2004-08-11 15:09:12 +01:00
|
|
|
//! Iterate but discard the info of the termlist
|
|
|
|
int
|
|
|
|
mgu_iterate (const Termlist tl)
|
|
|
|
{
|
|
|
|
return iterate ();
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Sub
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2004-08-11 15:09:12 +01:00
|
|
|
//! Iterate over all send types in the roles (including the intruder ones)
|
|
|
|
/**
|
|
|
|
* Function is called with (protocol pointer, role pointer, roledef pointer, index)
|
|
|
|
* and returns an integer. If it is false, iteration aborts.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iterate_role_sends (int (*func) ())
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
p = sys->protocols;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
Role r;
|
|
|
|
|
|
|
|
r = p->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
rd = r->roledef;
|
|
|
|
index = 0;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
if (rd->type == SEND)
|
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
flag = func (p, r, rd, index);
|
|
|
|
if (!flag)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
//! Generates a new intruder goal, iterates
|
2004-08-11 13:08:10 +01:00
|
|
|
/**
|
2004-08-11 22:04:52 +01:00
|
|
|
* Sloppy, does not unify term but hardcodes it into the stuff.
|
2004-08-11 13:08:10 +01:00
|
|
|
*/
|
2004-08-11 22:04:52 +01:00
|
|
|
int
|
|
|
|
add_intruder_goal (Goal goal)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
|
|
|
int run;
|
2004-08-11 22:04:52 +01:00
|
|
|
int flag;
|
|
|
|
Roledef rd;
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
roleInstance (sys, INTRUDER, I_GOAL, NULL);
|
|
|
|
run = sys->maxruns - 1;
|
|
|
|
goal.rd->bind_run = run;
|
|
|
|
goal.rd->bind_index = 0;
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
termDelete (rd->message);
|
|
|
|
rd->message = goal.rd->message;
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
explanation = "Adding intruder goal";
|
|
|
|
#endif
|
|
|
|
flag = iterate ();
|
|
|
|
|
|
|
|
roleInstanceDestroy (sys); // destroy the created run
|
|
|
|
goal.rd->bind_run = INVALID;
|
|
|
|
return flag;
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
|
2004-08-11 15:09:12 +01:00
|
|
|
//! Bind a goal to an existing regular run, if possible
|
|
|
|
int
|
|
|
|
bind_existing_run (const Goal goal, const Protocol p, const Role r,
|
|
|
|
const int index)
|
|
|
|
{
|
|
|
|
int run, flag;
|
|
|
|
|
|
|
|
flag = 1;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
if (sys->runs[run].protocol == p && sys->runs[run].role == r)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int old_length;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
// find roledef entry
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
for (i = 0; i < index; i++)
|
|
|
|
rd = rd->next;
|
|
|
|
|
|
|
|
// mgu and iterate
|
|
|
|
old_length = sys->runs[run].length;
|
|
|
|
if (index >= old_length)
|
|
|
|
sys->runs[run].length = index + 1;
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-12 10:14:31 +01:00
|
|
|
explanation = "Bind existing run";
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-11 15:09:12 +01:00
|
|
|
flag =
|
|
|
|
flag & termMguInTerm (goal.rd->message, rd->message, mgu_iterate);
|
|
|
|
sys->runs[run].length = old_length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Bind a goal to a new run
|
|
|
|
int
|
|
|
|
bind_new_run (const Goal goal, const Protocol p, const Role r,
|
|
|
|
const int index)
|
|
|
|
{
|
2004-08-11 16:05:13 +01:00
|
|
|
int run;
|
|
|
|
int flag;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
roleInstance (sys, p, r, NULL);
|
2004-08-12 10:14:31 +01:00
|
|
|
run = sys->maxruns - 1;
|
|
|
|
sys->runs[run].length = index + 1;
|
2004-08-11 16:05:13 +01:00
|
|
|
goal.rd->bind_run = run;
|
|
|
|
goal.rd->bind_index = index;
|
|
|
|
rd = roledef_shift (sys->runs[run].start, index);
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
explanation = "Bind new run";
|
|
|
|
#endif
|
2004-08-11 16:05:13 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
iterate ();
|
2004-08-11 16:05:13 +01:00
|
|
|
|
|
|
|
goal.rd->bind_run = INVALID;
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
return flag;
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Larger logical componentents
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//! Goal selection
|
|
|
|
/**
|
|
|
|
* Should be ordered to prefer most constrained; for now, it is simply the first one encountered.
|
|
|
|
*/
|
|
|
|
Goal
|
|
|
|
select_goal ()
|
|
|
|
{
|
|
|
|
Goal goal;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
goal.run = INVALID;
|
|
|
|
goal.rd = NULL;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
while (rd != NULL && index < sys->runs[run].length)
|
|
|
|
{
|
|
|
|
if (isGoal (rd) && !isBound (rd))
|
|
|
|
{
|
|
|
|
// Return this goal
|
|
|
|
goal.run = run;
|
|
|
|
goal.index = index;
|
|
|
|
goal.rd = rd;
|
|
|
|
return goal;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return goal;
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//! Bind a regular goal
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
bind_goal_regular (const Goal goal)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
int flag;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a local function so we have access to goal
|
|
|
|
*/
|
|
|
|
int bind_this (Protocol p, Role r, Roledef rd, int index)
|
|
|
|
{
|
|
|
|
int element_f1 (Termlist substlist)
|
|
|
|
{
|
2004-08-11 22:04:52 +01:00
|
|
|
/**
|
|
|
|
* Two options; as this, it is from an existing run,
|
|
|
|
* or from a new one.
|
|
|
|
*
|
|
|
|
* Note that we only bind to regular runs here
|
|
|
|
*/
|
2004-08-11 15:09:12 +01:00
|
|
|
int flag;
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
if (p == INTRUDER)
|
|
|
|
{
|
2004-08-12 10:14:31 +01:00
|
|
|
return 1; // don't abort scans
|
2004-08-11 22:04:52 +01:00
|
|
|
}
|
2004-08-11 15:09:12 +01:00
|
|
|
flag = bind_existing_run (goal, p, r, index);
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
flag = bind_new_run (goal, p, r, index);
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for interm unification
|
|
|
|
return termMguInTerm (goal.rd->message, rd->message, element_f1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind to all possible sends?
|
|
|
|
flag = iterate_role_sends (bind_this);
|
|
|
|
// Bind to an intruder node?
|
|
|
|
if (flag)
|
|
|
|
{
|
2004-08-11 22:04:52 +01:00
|
|
|
add_intruder_goal (goal); // creates a new run
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
return flag;
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Bind an intruder goal
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
bind_goal_intruder (const Goal goal)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
//!@todo Fix intruder goal stuff
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Bind a goal in all possible ways
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
bind_goal (const Goal goal)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
if (sys->runs[goal.run].protocol == INTRUDER)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
return bind_goal_intruder (goal);
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-11 15:09:12 +01:00
|
|
|
return bind_goal_regular (goal);
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 12:22:20 +01:00
|
|
|
//! Prune determination
|
|
|
|
/**
|
|
|
|
*@returns true iff this state is invalid for some reason
|
|
|
|
*/
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
prune ()
|
2004-08-11 12:22:20 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Main logic core
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2004-08-11 10:51:17 +01:00
|
|
|
//! Main recursive procedure for Arachne
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
iterate ()
|
2004-08-11 12:22:20 +01:00
|
|
|
{
|
2004-08-11 22:04:52 +01:00
|
|
|
int flag;
|
2004-08-11 13:08:10 +01:00
|
|
|
Goal goal;
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
flag = 1;
|
|
|
|
#ifdef DEBUG
|
2004-08-12 10:14:31 +01:00
|
|
|
indentDepth++;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-11 15:09:12 +01:00
|
|
|
if (prune ())
|
2004-08-11 22:04:52 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Not pruned: count
|
|
|
|
*/
|
2004-08-11 15:09:12 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
sys->states = statesIncrease (sys->states);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (explanation != NULL)
|
|
|
|
{
|
|
|
|
int i;
|
2004-08-11 15:09:12 +01:00
|
|
|
|
2004-08-12 10:14:31 +01:00
|
|
|
for (i = 0; i < indentDepth; i++)
|
|
|
|
eprintf (" ");
|
2004-08-11 22:04:52 +01:00
|
|
|
eprintf ("%s\n", explanation);
|
2004-08-12 10:14:31 +01:00
|
|
|
explanation = NULL;
|
2004-08-11 22:04:52 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
/**
|
|
|
|
* Check whether its a final state (i.e. all goals bound)
|
2004-08-11 13:08:10 +01:00
|
|
|
*/
|
2004-08-11 22:04:52 +01:00
|
|
|
|
|
|
|
goal = select_goal ();
|
|
|
|
if (goal.run == INVALID)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* all goals bound, check for property
|
|
|
|
*/
|
|
|
|
//!@todo Property check in Arachne.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* bind this goal in all possible ways and iterate
|
|
|
|
*/
|
|
|
|
flag = bind_goal (goal);
|
|
|
|
}
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-12 10:14:31 +01:00
|
|
|
indentDepth--;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
|
|
|
return flag;
|
2004-08-11 12:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Main code for Arachne
|
|
|
|
/**
|
|
|
|
* For this test, we manually set up some stuff.
|
|
|
|
*/
|
|
|
|
int
|
2004-08-11 15:09:12 +01:00
|
|
|
arachne ()
|
2004-08-11 10:51:17 +01:00
|
|
|
{
|
2004-08-11 12:22:20 +01:00
|
|
|
/*
|
|
|
|
* set up claim role(s)
|
|
|
|
*/
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
explanation = NULL;
|
2004-08-12 10:14:31 +01:00
|
|
|
indentDepth = -1;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-11 12:22:20 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* iterate
|
|
|
|
*/
|
2004-08-11 15:09:12 +01:00
|
|
|
iterate ();
|
2004-08-11 10:51:17 +01:00
|
|
|
}
|