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-12 13:28:57 +01:00
|
|
|
#include "compiler.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;
|
2004-08-12 13:28:57 +01:00
|
|
|
Protocol INTRUDER; // Pointers, to be set by the Init
|
|
|
|
Role I_GOAL; // Same here.
|
2004-08-12 12:55:03 +01:00
|
|
|
Role I_TEE;
|
|
|
|
Role I_SPLIT;
|
|
|
|
Role I_TUPLE;
|
|
|
|
Role I_ENCRYPT;
|
|
|
|
Role I_DECRYPT;
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2004-08-13 12:11:59 +01:00
|
|
|
static int indentDepth;
|
|
|
|
|
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
|
2004-08-12 13:28:57 +01:00
|
|
|
static int e_run;
|
|
|
|
static Term e_term1;
|
|
|
|
static Term e_term2;
|
|
|
|
static Term e_term3;
|
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-12 12:55:03 +01:00
|
|
|
Roledef rd = NULL;
|
|
|
|
|
|
|
|
void add_event (int event, Term message)
|
2004-08-12 13:28:57 +01:00
|
|
|
{
|
|
|
|
rd = roledefAdd (rd, event, NULL, NULL, NULL, message, NULL);
|
|
|
|
}
|
|
|
|
Role add_role (const char *rolenamestring)
|
|
|
|
{
|
|
|
|
Role r;
|
|
|
|
Term rolename;
|
|
|
|
|
|
|
|
rolename = makeGlobalConstant (rolenamestring);
|
|
|
|
r = roleCreate (rolename);
|
|
|
|
r->roledef = rd;
|
|
|
|
rd = NULL;
|
|
|
|
r->next = INTRUDER->roles;
|
|
|
|
INTRUDER->roles = r;
|
2004-08-12 14:22:49 +01:00
|
|
|
// compute_role_variables (sys, INTRUDER, r);
|
2004-08-12 13:28:57 +01:00
|
|
|
return r;
|
|
|
|
}
|
2004-08-12 12:55:03 +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
|
|
|
|
*/
|
2004-08-12 12:55:03 +01:00
|
|
|
|
|
|
|
INTRUDER = protocolCreate (makeGlobalConstant (" INTRUDER "));
|
|
|
|
|
|
|
|
add_event (READ, NULL);
|
|
|
|
I_GOAL = add_role (" I_GOAL ");
|
|
|
|
|
2004-08-11 12:22:20 +01:00
|
|
|
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-12 12:35:13 +01:00
|
|
|
//! Indent print
|
|
|
|
void
|
|
|
|
indentPrint ()
|
|
|
|
{
|
2004-08-13 11:50:56 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-12 12:35:13 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < indentDepth; i++)
|
|
|
|
eprintf ("| ");
|
2004-08-13 11:50:56 +01:00
|
|
|
#else
|
|
|
|
eprintf (">> ");
|
2004-08-12 12:35:13 +01:00
|
|
|
#endif
|
2004-08-13 11:50:56 +01:00
|
|
|
}
|
2004-08-12 12:35:13 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2004-08-12 13:37:30 +01:00
|
|
|
if (!func (p, r, rd, index))
|
2004-08-11 15:09:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-13 11:25:23 +01:00
|
|
|
//! Generate a new intruder goal
|
2004-08-11 22:04:52 +01:00
|
|
|
int
|
2004-08-13 11:25:23 +01:00
|
|
|
create_intruder_goal (Term t)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
|
|
|
int run;
|
2004-08-11 22:04:52 +01:00
|
|
|
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;
|
|
|
|
rd = sys->runs[run].start;
|
2004-08-13 09:29:11 +01:00
|
|
|
sys->runs[run].length = 1;
|
2004-08-13 11:25:23 +01:00
|
|
|
rd->message = termDuplicate (t);
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-13 11:25:23 +01:00
|
|
|
explanation = "Adding intruder goal for message ";
|
|
|
|
e_term1 = t;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-13 11:25:23 +01:00
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Generates a new intruder goal, iterates
|
|
|
|
/**
|
|
|
|
* Sloppy, does not unify term but hardcodes it into the stuff.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
add_intruder_goal_iterate (Goal goal)
|
|
|
|
{
|
2004-08-13 21:56:51 +01:00
|
|
|
// [x][todo][cc] remove debug you know the drill
|
|
|
|
//!@debug Remove this
|
|
|
|
return 1;
|
|
|
|
|
2004-08-13 11:25:23 +01:00
|
|
|
int flag;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
run = create_intruder_goal (goal.rd->message);
|
|
|
|
goal.rd->bind_run = run;
|
|
|
|
goal.rd->bind_index = 0;
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
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;
|
|
|
|
|
2004-08-13 21:56:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Trying to bind ");
|
|
|
|
termPrint (goal.rd->message);
|
|
|
|
eprintf (" to an existing instance of ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf ("\n");
|
|
|
|
#endif
|
2004-08-11 15:09:12 +01:00
|
|
|
flag = 1;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
if (sys->runs[run].protocol == p && sys->runs[run].role == r)
|
|
|
|
{
|
|
|
|
int old_length;
|
|
|
|
Roledef rd;
|
|
|
|
|
2004-08-13 09:29:11 +01:00
|
|
|
// Roledef entry
|
|
|
|
rd = roledef_shift (sys->runs[run].start, index);
|
2004-08-11 15:09:12 +01:00
|
|
|
|
|
|
|
// 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-12 13:28:57 +01:00
|
|
|
e_run = run;
|
|
|
|
e_term1 = goal.rd->message;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-13 11:52:20 +01:00
|
|
|
flag = (flag
|
|
|
|
&& termMguInTerm (goal.rd->message, rd->message,
|
|
|
|
mgu_iterate));
|
2004-08-11 15:09:12 +01:00
|
|
|
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;
|
2004-08-13 14:25:25 +01:00
|
|
|
int old_run;
|
|
|
|
int old_index;
|
2004-08-11 16:05:13 +01:00
|
|
|
|
|
|
|
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-13 14:25:25 +01:00
|
|
|
old_run = goal.rd->bind_run;
|
|
|
|
old_index = goal.rd->bind_index;
|
2004-08-11 16:05:13 +01:00
|
|
|
goal.rd->bind_run = run;
|
|
|
|
goal.rd->bind_index = index;
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
explanation = "Bind new run";
|
2004-08-13 09:29:11 +01:00
|
|
|
e_run = run;
|
|
|
|
e_term1 = r->nameterm;
|
|
|
|
rd = roledef_shift (sys->runs[run].start, index);
|
|
|
|
e_term2 = rd->message;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-11 16:05:13 +01:00
|
|
|
|
2004-08-13 15:35:22 +01:00
|
|
|
flag = iterate ();
|
2004-08-11 16:05:13 +01:00
|
|
|
|
2004-08-13 14:25:25 +01:00
|
|
|
goal.rd->bind_run = old_run;
|
|
|
|
goal.rd->bind_index = old_index;
|
2004-08-13 15:35:22 +01:00
|
|
|
|
2004-08-11 16:05:13 +01:00
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
return flag;
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
|
2004-08-13 09:29:11 +01:00
|
|
|
//! Print the current semistate
|
|
|
|
void
|
|
|
|
printSemiState ()
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("[ Run %i, ", run);
|
|
|
|
termPrint (sys->runs[run].role->nameterm);
|
|
|
|
eprintf (" ]\n");
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
while (index < sys->runs[run].length)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("\\ %i ", index);
|
|
|
|
roledefPrint (rd);
|
|
|
|
eprintf ("\n");
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-13 21:56:51 +01:00
|
|
|
int flag;
|
2004-08-11 15:09:12 +01:00
|
|
|
/*
|
|
|
|
* This is a local function so we have access to goal
|
|
|
|
*/
|
2004-08-13 21:56:51 +01:00
|
|
|
int bind_this_role_send (Protocol p, Role r, Roledef rd, int index)
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
2004-08-13 21:56:51 +01:00
|
|
|
int bind_this_unification (Termlist substlist)
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
2004-08-13 21:56:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Term ");
|
|
|
|
termPrint (goal.rd->message);
|
|
|
|
eprintf (" can possibly be bound by role ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (", index %i.\n", index);
|
|
|
|
#endif
|
2004-08-11 22:04:52 +01:00
|
|
|
/**
|
|
|
|
* Two options; as this, it is from an existing run,
|
|
|
|
* or from a new one.
|
|
|
|
*/
|
2004-08-13 21:09:12 +01:00
|
|
|
return (bind_existing_run (goal, p, r, index)
|
|
|
|
&& bind_new_run (goal, p, r, index));
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
|
2004-08-13 21:56:51 +01:00
|
|
|
if (p == INTRUDER)
|
|
|
|
{
|
|
|
|
/* only bind to regular runs */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Test for interm unification
|
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Checking send candidate with message ");
|
|
|
|
termPrint (rd->message);
|
|
|
|
eprintf (" from ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (", index%i\n");
|
|
|
|
#endif
|
|
|
|
return termMguInTerm (goal.rd->message, rd->message,
|
|
|
|
bind_this_unification);
|
|
|
|
}
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
|
2004-08-13 11:25:23 +01:00
|
|
|
// Bind to all possible sends or intruder node;
|
2004-08-13 21:56:51 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Try regular role send.\n");
|
|
|
|
#endif
|
|
|
|
flag = iterate_role_sends (bind_this_role_send);
|
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Try intruder send.\n");
|
|
|
|
#endif
|
|
|
|
return (flag && add_intruder_goal_iterate (goal));
|
2004-08-13 11:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Bind an intruder goal to a regular run
|
|
|
|
int
|
2004-08-13 21:09:12 +01:00
|
|
|
bind_intruder_to_regular (Goal goal)
|
2004-08-13 11:25:23 +01:00
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
int bind_this_roleevent (Protocol p, Role r, Roledef rd, int index)
|
2004-08-13 11:25:23 +01:00
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
int bind_this_unification (Termlist substlist, Termlist keylist)
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
2004-08-13 11:25:23 +01:00
|
|
|
int flag;
|
2004-08-13 21:09:12 +01:00
|
|
|
int keygoals;
|
|
|
|
Termlist tl;
|
2004-08-13 11:25:23 +01:00
|
|
|
|
|
|
|
/**
|
2004-08-13 21:09:12 +01:00
|
|
|
* the list of keys is added as a new goal.
|
2004-08-13 11:25:23 +01:00
|
|
|
*/
|
2004-08-13 21:09:12 +01:00
|
|
|
keygoals = 0;
|
|
|
|
tl = keylist;
|
|
|
|
while (tl != NULL)
|
2004-08-13 11:25:23 +01:00
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
keygoals++;
|
|
|
|
create_intruder_goal (tl->term);
|
|
|
|
//!@todo This needs a mapping Pi relation as well.
|
2004-08-13 11:25:23 +01:00
|
|
|
|
2004-08-13 21:09:12 +01:00
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Two options; as this, it is from an existing run,
|
|
|
|
* or from a new one.
|
|
|
|
*/
|
2004-08-13 11:25:23 +01:00
|
|
|
|
2004-08-13 21:09:12 +01:00
|
|
|
flag = (bind_existing_run (goal, p, r, index)
|
|
|
|
&& bind_new_run (goal, p, r, index));
|
2004-08-13 11:50:56 +01:00
|
|
|
|
2004-08-13 21:09:12 +01:00
|
|
|
/**
|
|
|
|
* deconstruct key list goals
|
|
|
|
*/
|
|
|
|
while (keygoals > 0)
|
|
|
|
{
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
keygoals--;
|
2004-08-13 11:25:23 +01:00
|
|
|
}
|
2004-08-13 21:09:12 +01:00
|
|
|
|
|
|
|
return flag;
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
2004-08-13 11:25:23 +01:00
|
|
|
|
2004-08-13 21:09:12 +01:00
|
|
|
/**
|
|
|
|
* Note that we only bind to regular runs here
|
|
|
|
*/
|
|
|
|
if (p == INTRUDER)
|
|
|
|
{
|
|
|
|
return 1; // don't abort scans
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Test for subterm unification
|
|
|
|
return termMguSubTerm (goal.rd->message, rd->message,
|
|
|
|
bind_this_unification, sys->know->inverses,
|
|
|
|
NULL);
|
|
|
|
}
|
2004-08-13 11:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bind to all possible sends?
|
2004-08-13 21:09:12 +01:00
|
|
|
return iterate_role_sends (bind_this_roleevent);
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
|
2004-08-13 11:25:23 +01:00
|
|
|
//! Bind an intruder goal by intruder construction
|
2004-08-13 21:56:51 +01:00
|
|
|
/**
|
|
|
|
* Handles the case where the intruder constructs a composed term himself.
|
|
|
|
*/
|
2004-08-13 11:25:23 +01:00
|
|
|
int
|
|
|
|
bind_intruder_to_construct (const Goal goal)
|
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
Term term;
|
|
|
|
|
|
|
|
term = goal.rd->message;
|
|
|
|
if (!realTermLeaf (term))
|
|
|
|
{
|
|
|
|
Term t1, t2;
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
if (realTermTuple (term))
|
|
|
|
{
|
|
|
|
// tuple construction
|
|
|
|
t1 = term->left.op1;
|
|
|
|
t2 = term->right.op2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// must be encryption
|
|
|
|
t1 = term->left.op;
|
|
|
|
t2 = term->right.key;
|
|
|
|
}
|
|
|
|
create_intruder_goal (t1);
|
|
|
|
create_intruder_goal (t2);
|
|
|
|
|
|
|
|
flag = iterate ();
|
|
|
|
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2004-08-13 11:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//! Bind an intruder goal
|
2004-08-13 11:25:23 +01:00
|
|
|
/**
|
|
|
|
* Computes F2 as in Athena explanations.
|
|
|
|
*/
|
2004-08-11 13:08:10 +01:00
|
|
|
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-13 11:25:23 +01:00
|
|
|
return (bind_intruder_to_regular (goal) &&
|
|
|
|
bind_intruder_to_construct (goal));
|
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
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
if (indentDepth > 10)
|
2004-08-13 14:25:25 +01:00
|
|
|
{
|
|
|
|
// Hardcoded limit on iterations
|
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Pruned because too many iteration levels.\n");
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
2004-08-12 12:35:13 +01:00
|
|
|
if (sys->maxruns > 5)
|
|
|
|
{
|
|
|
|
// Hardcoded limit on runs
|
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Pruned because too many runs.\n");
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
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;
|
2004-08-12 10:14:31 +01:00
|
|
|
indentDepth++;
|
2004-08-12 12:35:13 +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)
|
|
|
|
{
|
2004-08-12 12:35:13 +01:00
|
|
|
indentPrint ();
|
2004-08-12 13:28:57 +01:00
|
|
|
eprintf ("%s ", explanation);
|
|
|
|
|
|
|
|
if (e_run != INVALID)
|
|
|
|
eprintf ("#%i ", e_run);
|
|
|
|
if (e_term1 != NULL)
|
|
|
|
{
|
|
|
|
termPrint (e_term1);
|
|
|
|
eprintf (" ");
|
|
|
|
}
|
|
|
|
if (e_term2 != NULL)
|
|
|
|
{
|
|
|
|
termPrint (e_term2);
|
|
|
|
eprintf (" ");
|
|
|
|
}
|
|
|
|
if (e_term3 != NULL)
|
|
|
|
{
|
|
|
|
termPrint (e_term3);
|
|
|
|
eprintf (" ");
|
|
|
|
}
|
|
|
|
eprintf ("\n");
|
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
|
|
|
|
*/
|
2004-08-13 09:29:11 +01:00
|
|
|
sys->claims = statesIncrease (sys->claims);
|
|
|
|
printSemiState ();
|
2004-08-11 22:04:52 +01:00
|
|
|
//!@todo Property check in Arachne.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-12 12:35:13 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Trying to bind goal ");
|
|
|
|
termPrint (goal.rd->message);
|
|
|
|
eprintf (" from run %i, index %i.\n", goal.run, goal.index);
|
|
|
|
#endif
|
2004-08-11 22:04:52 +01:00
|
|
|
/*
|
|
|
|
* bind this goal in all possible ways and iterate
|
|
|
|
*/
|
|
|
|
flag = bind_goal (goal);
|
|
|
|
}
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
2004-08-13 21:09:12 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
explanation = NULL;
|
|
|
|
e_run = INVALID;
|
|
|
|
e_term1 = NULL;
|
|
|
|
e_term2 = NULL;
|
|
|
|
e_term3 = NULL;
|
|
|
|
#endif
|
2004-08-12 10:14:31 +01:00
|
|
|
indentDepth--;
|
2004-08-11 22:04:52 +01:00
|
|
|
return flag;
|
2004-08-11 12:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Main code for Arachne
|
|
|
|
/**
|
|
|
|
* For this test, we manually set up some stuff.
|
2004-08-12 12:35:13 +01:00
|
|
|
*
|
|
|
|
* But later, this will just iterate over all claims.
|
2004-08-11 12:22:20 +01:00
|
|
|
*/
|
|
|
|
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-12 12:35:13 +01:00
|
|
|
|
|
|
|
if (sys->maxruns > 0)
|
|
|
|
{
|
|
|
|
sys->runs[0].length = roledef_length (sys->runs[0].start);
|
|
|
|
}
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-13 21:56:51 +01:00
|
|
|
int print_send (Protocol p, Role r, Roledef rd, int index)
|
|
|
|
{
|
|
|
|
eprintf ("IRS: ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (", %i, ", index);
|
|
|
|
roledefPrint (rd);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
iterate_role_sends (print_send);
|
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
explanation = NULL;
|
2004-08-12 13:28:57 +01:00
|
|
|
e_run = INVALID;
|
|
|
|
e_term1 = NULL;
|
|
|
|
e_term2 = NULL;
|
|
|
|
e_term3 = NULL;
|
2004-08-11 22:04:52 +01:00
|
|
|
#endif
|
2004-08-13 12:11:59 +01:00
|
|
|
indentDepth = 0;
|
2004-08-13 09:29:11 +01:00
|
|
|
printSemiState ();
|
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
|
|
|
}
|