2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
2013-10-05 23:56:12 +01:00
|
|
|
* Copyright (C) 2007-2013 Cas Cremers
|
2007-06-11 13:01:04 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2004-08-11 10:51:17 +01:00
|
|
|
/**
|
2004-08-18 16:46:33 +01:00
|
|
|
*
|
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/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-05-17 19:45:01 +01:00
|
|
|
#include <stdlib.h>
|
2004-08-27 19:09:09 +01:00
|
|
|
#include <limits.h>
|
2004-12-29 14:17:49 +00:00
|
|
|
#include <float.h>
|
2006-03-08 13:58:46 +00:00
|
|
|
#include <string.h>
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
#include "mymalloc.h"
|
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-15 17:44:54 +01:00
|
|
|
#include "knowledge.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-14 16:59:14 +01:00
|
|
|
#include "error.h"
|
|
|
|
#include "claim.h"
|
2004-08-14 17:12:32 +01:00
|
|
|
#include "debug.h"
|
2004-08-15 13:24:27 +01:00
|
|
|
#include "binding.h"
|
2004-08-28 14:47:37 +01:00
|
|
|
#include "warshall.h"
|
2005-01-05 15:29:27 +00:00
|
|
|
#include "timer.h"
|
2005-06-02 13:14:28 +01:00
|
|
|
#include "type.h"
|
2005-06-07 16:02:27 +01:00
|
|
|
#include "switches.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "specialterm.h"
|
2005-12-27 11:19:45 +00:00
|
|
|
#include "cost.h"
|
2005-12-27 11:50:46 +00:00
|
|
|
#include "dotout.h"
|
2006-01-02 18:43:25 +00:00
|
|
|
#include "prune_bounds.h"
|
|
|
|
#include "prune_theorems.h"
|
2006-01-02 20:18:47 +00:00
|
|
|
#include "arachne.h"
|
2006-02-22 08:24:29 +00:00
|
|
|
#include "hidelevel.h"
|
2006-02-26 15:00:58 +00:00
|
|
|
#include "depend.h"
|
2007-01-06 14:45:29 +00:00
|
|
|
#include "xmlout.h"
|
|
|
|
#include "heuristic.h"
|
2014-03-18 13:53:51 +00:00
|
|
|
#include "tempfile.h"
|
2004-08-14 20:19:23 +01:00
|
|
|
|
2004-08-28 14:47:37 +01:00
|
|
|
extern int *graph;
|
|
|
|
extern int nodes;
|
2004-12-08 16:25:27 +00:00
|
|
|
extern int graph_uordblks;
|
2004-08-28 14:47:37 +01:00
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
static System sys; //!< local buffer for the system pointer
|
2006-01-02 18:43:25 +00:00
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
int attack_length; //!< length of the attack
|
|
|
|
int attack_leastcost; //!< cost of the best attack sofar \sa cost.c
|
2004-08-18 21:22:33 +01:00
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
Protocol INTRUDER; //!< intruder protocol
|
|
|
|
Role I_M; //!< Initial knowledge role of the intruder
|
|
|
|
Role I_RRS; //!< Encrypt role of the intruder
|
|
|
|
Role I_RRSD; //!< Decrypt role of the intruder
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
int proofDepth; //!< Current depth of the proof
|
|
|
|
int max_encryption_level; //!< Maximum encryption level of any term
|
2006-01-02 18:43:25 +00:00
|
|
|
|
2004-08-13 12:11:59 +01:00
|
|
|
static int indentDepth;
|
2005-05-19 15:43:32 +01:00
|
|
|
static int prevIndentDepth;
|
|
|
|
static int indentDepthChanges;
|
2005-12-27 10:49:22 +00:00
|
|
|
static FILE *attack_stream;
|
2004-08-13 12:11:59 +01:00
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
/*
|
2004-08-11 15:09:12 +01:00
|
|
|
* Forward declarations
|
|
|
|
*/
|
|
|
|
|
|
|
|
int iterate ();
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
/*
|
2004-08-11 15:09:12 +01:00
|
|
|
* 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-12-08 19:30:26 +00:00
|
|
|
Roledef rd;
|
2004-08-12 12:55:03 +01:00
|
|
|
|
|
|
|
void add_event (int event, Term message)
|
2004-08-12 13:28:57 +01:00
|
|
|
{
|
|
|
|
rd = roledefAdd (rd, event, NULL, NULL, NULL, message, NULL);
|
|
|
|
}
|
2006-03-05 15:18:39 +00:00
|
|
|
|
2004-08-12 13:28:57 +01:00
|
|
|
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-14 15:23:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Very important: turn role terms that are local to a run, into variables.
|
|
|
|
*/
|
|
|
|
term_rolelocals_are_variables ();
|
|
|
|
|
2004-08-11 12:22:20 +01:00
|
|
|
/*
|
|
|
|
* Add intruder protocol roles
|
|
|
|
*/
|
2004-08-12 12:55:03 +01:00
|
|
|
|
|
|
|
INTRUDER = protocolCreate (makeGlobalConstant (" INTRUDER "));
|
|
|
|
|
2004-12-08 19:30:26 +00:00
|
|
|
// Initially empty roledef
|
|
|
|
rd = NULL;
|
|
|
|
|
2004-12-08 16:25:27 +00:00
|
|
|
add_event (SEND, NULL);
|
2004-08-17 12:30:03 +01:00
|
|
|
I_M = add_role ("I_M: Atomic message");
|
2004-08-12 12:55:03 +01:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
add_event (RECV, NULL);
|
|
|
|
add_event (RECV, NULL);
|
2004-08-16 15:49:41 +01:00
|
|
|
add_event (SEND, NULL);
|
2004-08-19 15:49:03 +01:00
|
|
|
I_RRS = add_role ("I_E: Encrypt");
|
2004-08-16 15:49:41 +01:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
add_event (RECV, NULL);
|
|
|
|
add_event (RECV, NULL);
|
2005-05-17 19:45:01 +01:00
|
|
|
add_event (SEND, NULL);
|
|
|
|
I_RRSD = add_role ("I_D: Decrypt");
|
|
|
|
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_regular_runs = 0;
|
|
|
|
sys->num_intruder_runs = 0;
|
2005-05-17 19:45:01 +01:00
|
|
|
max_encryption_level = 0;
|
|
|
|
|
2005-05-19 15:43:32 +01:00
|
|
|
indentDepth = 0;
|
|
|
|
prevIndentDepth = 0;
|
|
|
|
indentDepthChanges = 0;
|
|
|
|
|
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
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
//! Just a defined integer for invalid
|
2004-08-11 13:08:10 +01:00
|
|
|
#define INVALID -1
|
2012-04-25 08:53:07 +01:00
|
|
|
//! can this roledef constitute a recv Goal?
|
|
|
|
#define isGoal(rd) (rd->type == RECV && !rd->internal)
|
2006-01-02 21:06:08 +00:00
|
|
|
//! is this roledef already bound?
|
2004-08-15 13:24:27 +01:00
|
|
|
#define isBound(rd) (rd->bound)
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2005-05-19 15:43:32 +01:00
|
|
|
//! Indent prefix print
|
2004-08-12 12:35:13 +01:00
|
|
|
void
|
2005-05-19 15:43:32 +01:00
|
|
|
indentPrefixPrint (const int annotate, const int jumps)
|
2004-08-12 12:35:13 +01:00
|
|
|
{
|
2006-02-27 22:27:09 +00:00
|
|
|
void counterPrint ()
|
|
|
|
{
|
2006-03-08 13:58:46 +00:00
|
|
|
statesFormat (sys->current_claim->states);
|
|
|
|
eprintf ("\t");
|
2006-02-27 22:27:09 +00:00
|
|
|
eprintf ("%i", annotate);
|
|
|
|
eprintf ("\t");
|
|
|
|
}
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == ATTACK && globalError == 0)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
2004-10-18 14:04:34 +01:00
|
|
|
// Arachne, attack, not an error
|
|
|
|
// We assume that means DOT output
|
2006-02-27 22:27:09 +00:00
|
|
|
eprintf ("// ");
|
|
|
|
counterPrint ();
|
2004-10-18 14:04:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If it is not to stdout, or it is not an attack...
|
|
|
|
int i;
|
|
|
|
|
2006-02-27 22:27:09 +00:00
|
|
|
counterPrint ();
|
2005-05-19 15:43:32 +01:00
|
|
|
for (i = 0; i < jumps; i++)
|
2004-10-18 14:04:34 +01:00
|
|
|
{
|
|
|
|
if (i % 3 == 0)
|
|
|
|
eprintf ("|");
|
|
|
|
else
|
|
|
|
eprintf (" ");
|
|
|
|
eprintf (" ");
|
|
|
|
}
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
2004-08-13 11:50:56 +01:00
|
|
|
}
|
2004-08-12 12:35:13 +01:00
|
|
|
|
2005-05-19 15:43:32 +01:00
|
|
|
//! Indent print
|
|
|
|
/**
|
|
|
|
* More subtle than before. Indentlevel changes now cause a counter to be increased, which is printed. Nice to find stuff in attacks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
indentPrint ()
|
|
|
|
{
|
|
|
|
if (indentDepth != prevIndentDepth)
|
|
|
|
{
|
|
|
|
indentDepthChanges++;
|
|
|
|
while (indentDepth != prevIndentDepth)
|
|
|
|
{
|
|
|
|
if (prevIndentDepth < indentDepth)
|
|
|
|
{
|
|
|
|
indentPrefixPrint (indentDepthChanges, prevIndentDepth);
|
|
|
|
eprintf ("{\n");
|
|
|
|
prevIndentDepth++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prevIndentDepth--;
|
|
|
|
indentPrefixPrint (indentDepthChanges, prevIndentDepth);
|
|
|
|
eprintf ("}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
indentPrefixPrint (indentDepthChanges, indentDepth);
|
|
|
|
}
|
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
//! Print indented binding
|
|
|
|
void
|
2004-08-20 12:47:00 +01:00
|
|
|
binding_indent_print (const Binding b, const int flag)
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
if (flag)
|
|
|
|
eprintf ("!! ");
|
|
|
|
binding_print (b);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
//! Keylevel tester: can this term ever be sent at this keylevel?
|
|
|
|
int
|
|
|
|
isKeylevelRight (Term t, const int kl)
|
|
|
|
{
|
|
|
|
t = deVar (t);
|
|
|
|
if (realTermLeaf (t))
|
|
|
|
{
|
|
|
|
// Leaf
|
|
|
|
if (isTermVariable (t))
|
|
|
|
{
|
|
|
|
// Variables are okay
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Constant, does it have a keylevel?
|
|
|
|
int mykl;
|
|
|
|
|
|
|
|
mykl = TermSymb (t)->keylevel;
|
|
|
|
if (mykl < INT_MAX)
|
|
|
|
{
|
|
|
|
// Sensible keylevel, so it must be possible
|
|
|
|
return (mykl <= kl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Never sent?
|
|
|
|
// So we can not expect it to come from that
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Node
|
|
|
|
if (realTermTuple (t))
|
|
|
|
{
|
|
|
|
// Tuple
|
|
|
|
return isKeylevelRight (TermOp1 (t), kl)
|
|
|
|
&& isKeylevelRight (TermOp2 (t), kl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Crypt
|
|
|
|
return isKeylevelRight (TermOp1 (t), kl)
|
|
|
|
&& isKeylevelRight (TermOp2 (t), kl + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Keylevel tester: can this term ever be sent at this keylevel?
|
|
|
|
/**
|
2006-02-22 09:53:50 +00:00
|
|
|
* Depends on the keylevel lemma (so this will not be called when those lemmas
|
|
|
|
* are disabled) and the keylevel constructors in symbol.c The idea is that
|
|
|
|
* certain terms will never be sent.
|
2005-03-08 13:02:16 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
isPossiblySent (Term t)
|
|
|
|
{
|
|
|
|
return isKeylevelRight (t, 0);
|
|
|
|
}
|
|
|
|
|
2004-08-19 13:47:53 +01:00
|
|
|
//! Wrapper for roleInstance
|
|
|
|
/**
|
|
|
|
*@return Returns the run number
|
|
|
|
*/
|
2004-08-19 14:09:35 +01:00
|
|
|
int
|
|
|
|
semiRunCreate (const Protocol p, const Role r)
|
2004-08-19 13:47:53 +01:00
|
|
|
{
|
|
|
|
int run;
|
|
|
|
|
|
|
|
if (p == INTRUDER)
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_intruder_runs++;
|
2004-08-19 13:47:53 +01:00
|
|
|
else
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_regular_runs++;
|
2006-02-26 17:18:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
globalError++;
|
|
|
|
eprintf ("Adding a run %i with semiRunCreate, ", sys->maxruns);
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf ("\n");
|
|
|
|
globalError--;
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-19 13:47:53 +01:00
|
|
|
roleInstance (sys, p, r, NULL, NULL);
|
2004-08-19 15:55:21 +01:00
|
|
|
run = sys->maxruns - 1;
|
2006-01-02 21:06:08 +00:00
|
|
|
sys->runs[run].height = 0;
|
2004-08-19 13:47:53 +01:00
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Wrapper for roleDestroy
|
2004-08-19 14:09:35 +01:00
|
|
|
void
|
|
|
|
semiRunDestroy ()
|
2004-08-19 13:47:53 +01:00
|
|
|
{
|
2004-08-19 15:49:03 +01:00
|
|
|
if (sys->maxruns > 0)
|
|
|
|
{
|
|
|
|
Protocol p;
|
2004-08-19 13:47:53 +01:00
|
|
|
|
2004-08-19 15:49:03 +01:00
|
|
|
p = sys->runs[sys->maxruns - 1].protocol;
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
if (p == INTRUDER)
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_intruder_runs--;
|
2004-08-19 15:49:03 +01:00
|
|
|
else
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_regular_runs--;
|
2004-08-19 15:49:03 +01:00
|
|
|
}
|
2004-08-19 13:47:53 +01:00
|
|
|
}
|
2004-08-18 15:06:14 +01:00
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
//! Fix the keylevels of any agents
|
|
|
|
/**
|
|
|
|
* We simply extract the agent names from m0 (ugly hack)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fixAgentKeylevels (void)
|
|
|
|
{
|
|
|
|
Termlist tl, m0tl;
|
|
|
|
|
|
|
|
m0tl = knowledgeSet (sys->know);
|
|
|
|
tl = m0tl;
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = deVar (tl->term);
|
|
|
|
if (realTermLeaf (t))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// a real agent type thing
|
|
|
|
if (TermSymb (t)->keylevel == INT_MAX)
|
|
|
|
{
|
|
|
|
// Fix the keylevel
|
|
|
|
TermSymb (t)->keylevel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
termlistDelete (m0tl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-17 16:52:52 +01:00
|
|
|
//! After a role instance, or an extension of a run, we might need to add some goals
|
|
|
|
/**
|
2006-01-02 21:06:08 +00:00
|
|
|
* From old to new. Sets the new height to new.
|
2004-08-17 16:52:52 +01:00
|
|
|
*@returns The number of goals added (for destructions)
|
|
|
|
*/
|
|
|
|
int
|
2012-04-25 08:53:07 +01:00
|
|
|
add_recv_goals (const int run, const int old, const int new)
|
2004-08-17 16:52:52 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
if (new <= sys->runs[run].height)
|
2004-08-17 16:52:52 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
sys->runs[run].height = new;
|
|
|
|
i = old;
|
2006-03-15 08:51:08 +00:00
|
|
|
rd = eventRoledef (sys, run, i);
|
2006-02-27 16:08:17 +00:00
|
|
|
count = 0;
|
|
|
|
while (i < new && rd != NULL)
|
2004-08-17 16:52:52 +01:00
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
if (rd->type == RECV)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Thus, we must also produce ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eprintf (", ");
|
|
|
|
}
|
|
|
|
termPrint (rd->message);
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
count = count + goal_add (rd->message, run, i, 0);
|
2004-08-19 12:37:41 +01:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
rd = rd->next;
|
|
|
|
i++;
|
2004-08-17 16:52:52 +01:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
if ((count > 0) && switches.output == PROOF)
|
|
|
|
{
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
return count;
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
2004-08-17 16:52:52 +01:00
|
|
|
}
|
|
|
|
|
2004-08-27 19:09:09 +01:00
|
|
|
//! Determine trace length
|
|
|
|
int
|
2005-05-01 14:32:50 +01:00
|
|
|
get_semitrace_length ()
|
2004-08-27 19:09:09 +01:00
|
|
|
{
|
|
|
|
int run;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
run = 0;
|
|
|
|
length = 0;
|
|
|
|
while (run < sys->maxruns)
|
|
|
|
{
|
|
|
|
if (sys->runs[run].protocol != INTRUDER)
|
|
|
|
{
|
|
|
|
// Non-intruder run: count length
|
2004-08-27 20:15:24 +01:00
|
|
|
// Subtract 'firstReal' to ignore chooses.
|
2006-01-02 21:06:08 +00:00
|
|
|
length = length + sys->runs[run].height - sys->runs[run].firstReal;
|
2004-08-27 19:09:09 +01:00
|
|
|
}
|
|
|
|
run++;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2005-08-21 22:38:32 +01:00
|
|
|
//! Count intruder events
|
|
|
|
int
|
|
|
|
countIntruderActions ()
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
run = 0;
|
|
|
|
while (run < sys->maxruns)
|
|
|
|
{
|
|
|
|
if (sys->runs[run].protocol == INTRUDER)
|
|
|
|
{
|
|
|
|
// Only intruder roles
|
|
|
|
if (sys->runs[run].role != I_M)
|
|
|
|
{
|
|
|
|
// The M_0 (initial knowledge) events don't count.
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2004-08-19 11:46:27 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Proof reporting
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//! Protocol/role name of a run
|
|
|
|
void
|
|
|
|
role_name_print (const int run)
|
|
|
|
{
|
|
|
|
eprintf ("protocol ");
|
|
|
|
termPrint (sys->runs[run].protocol->nameterm);
|
|
|
|
eprintf (", role ");
|
|
|
|
termPrint (sys->runs[run].role->nameterm);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Adding a run/extending a run
|
|
|
|
void
|
|
|
|
proof_suppose_run (const int run, const int oldlength, const int newlength)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
|
|
|
int reallength;
|
|
|
|
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Suppose ");
|
|
|
|
if (oldlength == 0)
|
|
|
|
eprintf ("there is a ");
|
|
|
|
else
|
|
|
|
eprintf ("we extend ");
|
|
|
|
reallength = roledef_length (sys->runs[run].start);
|
|
|
|
if (reallength > newlength)
|
|
|
|
eprintf ("semi-");
|
|
|
|
eprintf ("run #%i of ", run);
|
|
|
|
role_name_print (run);
|
|
|
|
if (reallength > newlength)
|
|
|
|
{
|
|
|
|
if (oldlength == 0)
|
|
|
|
eprintf (" of");
|
|
|
|
else
|
|
|
|
eprintf (" to");
|
2004-08-19 15:52:17 +01:00
|
|
|
eprintf (" length %i", newlength);
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Select a goal
|
|
|
|
void
|
|
|
|
proof_select_goal (Binding b)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = roledef_shift (sys->runs[b->run_to].start, b->ev_to);
|
|
|
|
indentPrint ();
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf ("Selected goal: Where does term ");
|
2004-08-19 11:46:27 +01:00
|
|
|
termPrint (b->term);
|
2004-08-19 15:55:21 +01:00
|
|
|
eprintf (" occur first as an interm?\n");
|
2004-08-19 12:37:41 +01:00
|
|
|
indentPrint ();
|
|
|
|
eprintf ("* It is required for ");
|
2004-08-19 11:46:27 +01:00
|
|
|
roledefPrint (rd);
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf (" at index %i in run %i\n", b->ev_to, b->run_to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Cannot bind because of cycle
|
|
|
|
void
|
|
|
|
proof_cannot_bind (const Binding b, const int run, const int index)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 12:37:41 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf
|
|
|
|
("Cannot bind this to run %i, index %i because that introduces a cycle.\n",
|
|
|
|
run, index);
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Test a binding
|
|
|
|
void
|
|
|
|
proof_suppose_binding (Binding b)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 11:46:27 +01:00
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
indentPrint ();
|
|
|
|
rd = roledef_shift (sys->runs[b->run_from].start, b->ev_from);
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf ("Suppose it originates in run %i, at index %i\n", b->run_from,
|
|
|
|
b->ev_from);
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("* I.e. event ");
|
2004-08-19 11:46:27 +01:00
|
|
|
roledefPrint (rd);
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf ("\n");
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("* from ");
|
2004-08-19 11:46:27 +01:00
|
|
|
role_name_print (b->run_from);
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf ("\n");
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Sub
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2005-04-18 06:51:25 +01:00
|
|
|
//! Iterate over all events in the roles (including the intruder ones)
|
2004-08-11 15:09:12 +01:00
|
|
|
/**
|
|
|
|
* Function is called with (protocol pointer, role pointer, roledef pointer, index)
|
|
|
|
* and returns an integer. If it is false, iteration aborts.
|
|
|
|
*/
|
|
|
|
int
|
2005-04-18 06:51:25 +01:00
|
|
|
iterate_role_events (int (*func) ())
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2005-04-18 06:51:25 +01:00
|
|
|
if (!func (p, r, rd, index))
|
|
|
|
return 0;
|
2004-08-11 15:09:12 +01:00
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-18 06:51:25 +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) ())
|
|
|
|
{
|
2018-10-14 16:43:13 +01:00
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
p = sys->protocols;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
Role r;
|
2005-04-18 06:51:25 +01:00
|
|
|
|
2018-10-14 16:43:13 +01:00
|
|
|
r = p->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
rd = r->roledef;
|
|
|
|
index = 0;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2018-10-15 14:40:07 +01:00
|
|
|
if (rd->type == SEND)
|
2018-10-14 16:43:13 +01:00
|
|
|
{
|
|
|
|
if (!func (p, r, rd, index))
|
2018-10-15 14:40:07 +01:00
|
|
|
return 0;
|
2018-10-14 16:43:13 +01:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 1;
|
2005-04-18 06:51:25 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 16:43:13 +01:00
|
|
|
|
2005-05-17 19:45:01 +01:00
|
|
|
//! Create decryption role instance
|
|
|
|
/**
|
2012-04-25 08:53:07 +01:00
|
|
|
* Note that this does not add any bindings for the receives.
|
2005-05-17 19:45:01 +01:00
|
|
|
*
|
|
|
|
*@param term The term to be decrypted (implies decryption key)
|
2006-01-02 21:06:08 +00:00
|
|
|
*@param key The key that is needed to decrypt the term
|
2005-05-17 19:45:01 +01:00
|
|
|
*
|
|
|
|
*@returns The run id of the decryptor instance
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
create_decryptor (const Term term, const Term key)
|
|
|
|
{
|
|
|
|
if (term != NULL && isTermEncrypt (term))
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int run;
|
|
|
|
|
2006-02-26 17:18:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
globalError++;
|
|
|
|
eprintf ("Creating decryptor for term ");
|
|
|
|
termPrint (term);
|
|
|
|
eprintf (" and key ");
|
|
|
|
termPrint (key);
|
|
|
|
eprintf ("\n");
|
|
|
|
globalError--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-17 19:45:01 +01:00
|
|
|
run = semiRunCreate (INTRUDER, I_RRSD);
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
rd->message = termDuplicateUV (term);
|
|
|
|
rd->next->message = termDuplicateUV (key);
|
|
|
|
rd->next->next->message = termDuplicateUV (TermOp (term));
|
2006-01-02 21:06:08 +00:00
|
|
|
sys->runs[run].height = 3;
|
2005-05-17 19:45:01 +01:00
|
|
|
proof_suppose_run (run, 0, 3);
|
|
|
|
|
|
|
|
return run;
|
|
|
|
}
|
2007-01-06 14:45:29 +00:00
|
|
|
|
|
|
|
globalError++;
|
|
|
|
eprintf ("Term for which a decryptor instance is requested: ");
|
|
|
|
termPrint (term);
|
|
|
|
eprintf ("\n");
|
|
|
|
error ("Trying to build a decryptor instance for a non-encrypted term.");
|
|
|
|
return -1;
|
2005-05-17 19:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Get the priority level of a key that is needed for a term (typical pk/sk distinction)
|
|
|
|
int
|
|
|
|
getPriorityOfNeededKey (const System sys, const Term keyneeded)
|
|
|
|
{
|
|
|
|
int prioritylevel;
|
|
|
|
|
|
|
|
/* Normally, a key gets higher priority, but unfortunately this is not propagated at the moment. Maybe later.
|
|
|
|
*/
|
|
|
|
prioritylevel = 1;
|
|
|
|
if (realTermEncrypt (keyneeded))
|
|
|
|
{
|
|
|
|
/* the key is a construction itself */
|
|
|
|
if (inKnowledge (sys->know, TermKey (keyneeded)))
|
|
|
|
{
|
|
|
|
/* the key is constructed by a public thing */
|
|
|
|
/* typically, this is a public key, so we postpone it */
|
|
|
|
prioritylevel = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prioritylevel;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:27:09 +00:00
|
|
|
//! Report failed binding
|
|
|
|
void
|
|
|
|
report_failed_binding (Binding b, int run, int index)
|
|
|
|
{
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Failed to bind the binding at r%ii%i with term ", b->run_to,
|
|
|
|
b->ev_to);
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" to the source r%ii%i because of orderings.\n", run, index);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
dependPrint ();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
|
|
|
|
//! Make a decryption chain from a binding to some run,index using the key list, and callback if this works.
|
2006-02-26 17:18:59 +00:00
|
|
|
/**
|
2006-03-15 08:56:23 +00:00
|
|
|
* The key goals are bound to the goal, and then we iterate on that.
|
|
|
|
*
|
|
|
|
*@param b binding to fix (bind), destination filled in
|
|
|
|
*@param run run of binding start
|
|
|
|
*@param index index in run of binding start
|
2006-02-27 16:08:17 +00:00
|
|
|
* Callback return value is int, but is effectively ignored.
|
2006-02-26 17:18:59 +00:00
|
|
|
*/
|
2006-02-26 20:01:22 +00:00
|
|
|
void
|
2006-02-27 16:08:17 +00:00
|
|
|
createDecryptionChain (const Binding b, const int run, const int index,
|
|
|
|
Termlist keylist, int (*callback) (void))
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
if (keylist == NULL)
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
// Immediate binding, no key needed.
|
|
|
|
if (goal_bind (b, run, index))
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
callback ();
|
2006-02-26 20:01:22 +00:00
|
|
|
goal_unbind (b);
|
2006-02-27 16:08:17 +00:00
|
|
|
return;
|
2006-02-26 17:18:59 +00:00
|
|
|
}
|
2006-02-27 22:27:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
report_failed_binding (b, run, index);
|
|
|
|
}
|
2006-02-26 17:18:59 +00:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Term tdecr, tkey;
|
|
|
|
int smallrun;
|
2006-02-26 17:18:59 +00:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
// Some decryptor is needed for the term in the list
|
2006-02-26 17:18:59 +00:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
indentDepth++;
|
2006-02-26 17:18:59 +00:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
tdecr = keylist->term;
|
2013-04-26 10:36:41 +01:00
|
|
|
tkey = inverseKey (sys->know, TermKey (tdecr));
|
2006-02-27 16:08:17 +00:00
|
|
|
smallrun = create_decryptor (tdecr, tkey);
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
|
|
|
Roledef rddecrypt;
|
|
|
|
Binding bnew;
|
2006-02-27 16:08:17 +00:00
|
|
|
int newgoals;
|
|
|
|
int prioritylevel;
|
2006-02-26 20:01:22 +00:00
|
|
|
|
2006-02-26 17:18:59 +00:00
|
|
|
/*
|
|
|
|
* 2. Add goal bindings
|
|
|
|
*/
|
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
rddecrypt = sys->runs[smallrun].start;
|
|
|
|
// Add goal for tdecr copy
|
2006-02-26 17:18:59 +00:00
|
|
|
newgoals = goal_add (rddecrypt->message, smallrun, 0, 0);
|
2006-02-27 16:08:17 +00:00
|
|
|
if (newgoals != 1)
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
error
|
|
|
|
("Added %i goals (instead of one) for decryptor goal 1, weird.",
|
|
|
|
newgoals);
|
2006-02-26 17:18:59 +00:00
|
|
|
}
|
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
// This is the unique new goal
|
|
|
|
bnew = (Binding) sys->bindings->data;
|
|
|
|
|
|
|
|
// Add goal for needed key copy
|
|
|
|
prioritylevel = getPriorityOfNeededKey (sys, tkey);
|
2006-02-26 17:18:59 +00:00
|
|
|
newgoals += goal_add (rddecrypt->next->message, smallrun, 1,
|
|
|
|
prioritylevel);
|
2006-02-27 16:08:17 +00:00
|
|
|
|
2006-02-26 20:01:22 +00:00
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
indentPrint ();
|
|
|
|
eprintf
|
|
|
|
("This introduces the obligation to decrypt the following subterm: ");
|
|
|
|
termPrint (tdecr);
|
|
|
|
eprintf (" to be decrypted using ");
|
|
|
|
termPrint (tkey);
|
|
|
|
eprintf ("\n");
|
|
|
|
|
2006-02-26 20:01:22 +00:00
|
|
|
indentPrint ();
|
|
|
|
eprintf
|
|
|
|
("To this end, we added two new goals and one new send: ");
|
|
|
|
termPrint (rddecrypt->message);
|
|
|
|
eprintf (",");
|
|
|
|
termPrint (rddecrypt->next->message);
|
|
|
|
eprintf (",");
|
|
|
|
termPrint (rddecrypt->next->next->message);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
|
2006-02-26 17:18:59 +00:00
|
|
|
/*
|
2006-02-26 20:01:22 +00:00
|
|
|
* 3. Bind open goal to decryptor?
|
2006-02-26 17:18:59 +00:00
|
|
|
*/
|
2006-02-27 16:08:17 +00:00
|
|
|
if (goal_bind (b, smallrun, 2))
|
2006-02-26 17:18:59 +00:00
|
|
|
{
|
2006-02-26 20:01:22 +00:00
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
2006-03-05 15:18:39 +00:00
|
|
|
eprintf ("Bound ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" to r%ii%i: trying new createDecryptionChain.\n",
|
|
|
|
smallrun, 2);
|
2006-02-26 20:01:22 +00:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
|
|
|
|
// Iterate with the new goal
|
|
|
|
createDecryptionChain (bnew, run, index, keylist->next, callback);
|
|
|
|
goal_unbind (b);
|
2006-02-26 17:18:59 +00:00
|
|
|
}
|
2006-02-27 22:27:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
report_failed_binding (b, smallrun, 2);
|
|
|
|
}
|
2006-02-26 17:18:59 +00:00
|
|
|
/*
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
goal_remove_last (newgoals);
|
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
semiRunDestroy ();
|
|
|
|
termDelete (tkey);
|
2006-02-26 17:18:59 +00:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
indentDepth--;
|
2006-02-26 17:18:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
|
2004-08-16 10:50:37 +01:00
|
|
|
//! Try to bind a specific existing run to a goal.
|
2004-08-15 20:58:26 +01:00
|
|
|
/**
|
2006-02-27 16:08:17 +00:00
|
|
|
* The idea is that we try to bind it this specific run and index. If this
|
|
|
|
* requires keys, then we should add such goals as well with the required
|
|
|
|
* decryptor things.
|
2005-05-17 19:45:01 +01:00
|
|
|
*
|
2006-07-09 16:08:42 +01:00
|
|
|
* The 'newdecr' boolean signals the addition of decryptors. If it is false, we should not add any.
|
|
|
|
*
|
2006-02-27 16:08:17 +00:00
|
|
|
* The key goals are bound to the goal. Iterates on success.
|
2004-08-15 20:58:26 +01:00
|
|
|
*/
|
2006-02-27 16:08:17 +00:00
|
|
|
void
|
2006-07-09 16:08:42 +01:00
|
|
|
bind_existing_to_goal (const Binding b, const int run, const int index,
|
|
|
|
int newdecr)
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
Term bigterm;
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
int unifiesWithKeys (Termlist substlist, Termlist keylist)
|
2004-08-16 10:50:37 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
int old_length;
|
2005-05-17 19:45:01 +01:00
|
|
|
int newgoals;
|
|
|
|
|
2006-07-09 16:08:42 +01:00
|
|
|
// TODO this is a hack: in this case we really should not use subterm
|
|
|
|
// unification but interm instead. However, this effectively does the same
|
|
|
|
// by avoiding branches that get immediately pruned anyway.
|
|
|
|
if (!newdecr && keylist != NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
// We need some adapting because the height would increase; we therefore
|
2012-04-25 08:53:07 +01:00
|
|
|
// have to add recv goals before we know whether it unifies.
|
2006-02-27 16:08:17 +00:00
|
|
|
old_length = sys->runs[run].height;
|
2012-04-25 08:53:07 +01:00
|
|
|
newgoals = add_recv_goals (run, old_length, index + 1);
|
2005-05-17 19:45:01 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
{
|
|
|
|
// wrap substitution lists
|
2004-08-16 14:18:04 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
void wrapSubst (Termlist sl)
|
2005-05-17 19:45:01 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
if (sl == NULL)
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
2006-03-05 15:18:39 +00:00
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Suppose ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" originates first at run %i, event %i, as part of ",
|
|
|
|
run, index);
|
|
|
|
rd = roledef_shift (sys->runs[run].start, index);
|
|
|
|
termPrint (rd->message);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
// new create key goals, bind etc.
|
|
|
|
createDecryptionChain (b, run, index, keylist, iterate);
|
2004-08-18 15:06:14 +01:00
|
|
|
}
|
2005-05-17 19:45:01 +01:00
|
|
|
else
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
int neworders;
|
|
|
|
int allgood;
|
2006-02-27 22:27:09 +00:00
|
|
|
Term tvar;
|
2005-05-17 19:45:01 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
// the idea is, that a substitution in run x with
|
|
|
|
// something containing should be wrapped; this
|
|
|
|
// occurs for all subterms of other runs.
|
2006-02-27 22:27:09 +00:00
|
|
|
int makeDepend (Term tsmall)
|
2006-02-27 16:08:17 +00:00
|
|
|
{
|
2006-02-27 22:27:09 +00:00
|
|
|
Term tsubst;
|
2004-08-18 15:06:14 +01:00
|
|
|
|
2006-02-27 22:27:09 +00:00
|
|
|
tsubst = deVar (tsmall);
|
|
|
|
if (!realTermVariable (tsubst))
|
2006-02-27 16:08:17 +00:00
|
|
|
{
|
2006-02-27 22:27:09 +00:00
|
|
|
// Only for non-variables (i.e. local constants)
|
2006-03-05 15:18:39 +00:00
|
|
|
int r1, e1;
|
2006-02-27 22:27:09 +00:00
|
|
|
|
|
|
|
r1 = TermRunid (tsubst);
|
|
|
|
e1 = firstOccurrence (sys, r1, tsubst, SEND);
|
|
|
|
if (e1 >= 0)
|
|
|
|
{
|
2006-03-05 15:18:39 +00:00
|
|
|
int r2, e2;
|
|
|
|
|
2006-02-27 22:27:09 +00:00
|
|
|
r2 = TermRunid (tvar);
|
2012-04-25 08:53:07 +01:00
|
|
|
e2 = firstOccurrence (sys, r2, tsubst, RECV);
|
2006-02-27 22:27:09 +00:00
|
|
|
if (e2 >= 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (dependPushEvent (r1, e1, r2, e2))
|
|
|
|
{
|
|
|
|
neworders++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
allgood = false;
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Substitution for ");
|
|
|
|
termSubstPrint (sl->term);
|
|
|
|
eprintf (" (subterm ");
|
|
|
|
termPrint (tsmall);
|
|
|
|
eprintf (") could not be safely bound.\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
}
|
2006-02-27 22:27:09 +00:00
|
|
|
return true;
|
2006-02-27 16:08:17 +00:00
|
|
|
}
|
2005-05-17 19:45:01 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
neworders = 0;
|
|
|
|
allgood = true;
|
2006-02-27 22:27:09 +00:00
|
|
|
tvar = sl->term;
|
|
|
|
iterateTermOther (run, tvar, makeDepend);
|
2006-02-27 16:08:17 +00:00
|
|
|
if (allgood)
|
2005-05-17 19:45:01 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
wrapSubst (sl->next);
|
|
|
|
}
|
|
|
|
while (neworders > 0)
|
|
|
|
{
|
|
|
|
neworders--;
|
|
|
|
dependPopEvent ();
|
2005-05-17 19:45:01 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-16 10:50:37 +01:00
|
|
|
}
|
2005-05-17 19:45:01 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
wrapSubst (substlist);
|
|
|
|
}
|
2005-05-19 15:43:32 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
// undo
|
|
|
|
goal_remove_last (newgoals);
|
|
|
|
sys->runs[run].height = old_length;
|
|
|
|
return true;
|
2004-08-16 10:50:37 +01:00
|
|
|
}
|
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
bigterm = roledef_shift (sys->runs[run].start, index)->message;
|
|
|
|
subtermUnify (bigterm, b->term, NULL, NULL, unifiesWithKeys);
|
|
|
|
}
|
|
|
|
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2004-08-16 14:18:04 +01:00
|
|
|
|
2004-08-16 10:50:37 +01:00
|
|
|
|
2006-07-09 16:08:42 +01:00
|
|
|
//! Bind a goal to an existing regular run, if possible, by adding decr events
|
2004-08-16 10:50:37 +01:00
|
|
|
int
|
2004-08-18 10:57:01 +01:00
|
|
|
bind_existing_run (const Binding b, const Protocol p, const Role r,
|
2004-08-18 20:43:58 +01:00
|
|
|
const int index)
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
|
|
|
int run, flag;
|
2004-08-19 12:37:41 +01:00
|
|
|
int found;
|
2004-08-11 15:09:12 +01:00
|
|
|
|
|
|
|
flag = 1;
|
2004-08-19 12:37:41 +01:00
|
|
|
found = 0;
|
2004-08-11 15:09:12 +01:00
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
2004-08-16 14:18:04 +01:00
|
|
|
if (sys->runs[run].protocol == p && sys->runs[run].role == r)
|
|
|
|
{
|
2004-08-19 12:37:41 +01:00
|
|
|
found++;
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 12:37:41 +01:00
|
|
|
{
|
|
|
|
if (found == 1)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Can we bind it to an existing regular run of ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf ("?\n");
|
|
|
|
}
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("%i. Can we bind it to run %i?\n", found, run);
|
|
|
|
}
|
|
|
|
indentDepth++;
|
2006-07-09 16:08:42 +01:00
|
|
|
bind_existing_to_goal (b, run, index, true);
|
2004-08-19 12:37:41 +01:00
|
|
|
indentDepth--;
|
2004-08-16 14:18:04 +01:00
|
|
|
}
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF && found == 0)
|
2004-08-19 12:37:41 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("There is no existing run for ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
2004-08-11 15:09:12 +01:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2006-07-09 16:08:42 +01:00
|
|
|
//! Bind a goal to a new run, possibly adding decr events
|
2004-08-11 15:09:12 +01:00
|
|
|
int
|
2004-08-18 10:57:01 +01:00
|
|
|
bind_new_run (const Binding b, const Protocol p, const Role r,
|
2004-08-18 20:43:58 +01:00
|
|
|
const int index)
|
2004-08-11 15:09:12 +01:00
|
|
|
{
|
2004-08-11 16:05:13 +01:00
|
|
|
int run;
|
|
|
|
|
2004-08-19 13:47:53 +01:00
|
|
|
run = semiRunCreate (p, r);
|
2004-08-19 12:37:41 +01:00
|
|
|
proof_suppose_run (run, 0, index + 1);
|
2005-03-07 15:38:01 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
int newgoals;
|
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
newgoals = add_recv_goals (run, 0, index + 1);
|
2005-03-07 15:38:01 +00:00
|
|
|
indentDepth++;
|
2006-07-09 16:08:42 +01:00
|
|
|
bind_existing_to_goal (b, run, index, true);
|
2005-03-07 15:38:01 +00:00
|
|
|
indentDepth--;
|
|
|
|
goal_remove_last (newgoals);
|
|
|
|
}
|
2004-08-19 13:47:53 +01:00
|
|
|
semiRunDestroy ();
|
2006-02-26 20:01:22 +00:00
|
|
|
return true;
|
2004-08-11 15:09:12 +01:00
|
|
|
}
|
|
|
|
|
2012-10-02 12:43:30 +01:00
|
|
|
//! Proof markers
|
|
|
|
void
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_down (const Term label, const Term t)
|
2012-10-02 12:43:30 +01:00
|
|
|
{
|
|
|
|
Termlist l;
|
|
|
|
int depth;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (switches.output != PROOF)
|
2013-06-19 20:51:52 +01:00
|
|
|
return;
|
2012-10-02 12:43:30 +01:00
|
|
|
// Prepend the terms (the list is in reverse)
|
2013-06-19 20:51:52 +01:00
|
|
|
TERMLISTPREPEND (sys->proofstate, label);
|
|
|
|
TERMLISTPREPEND (sys->proofstate, t);
|
|
|
|
len = termlistLength (sys->proofstate) / 2;
|
2012-10-02 12:43:30 +01:00
|
|
|
// Display state
|
2013-06-19 20:51:52 +01:00
|
|
|
eprintf ("Proof state: branch at level %i\n", len);
|
|
|
|
l = termlistForward (sys->proofstate);
|
2012-10-02 12:43:30 +01:00
|
|
|
depth = 0;
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
int i;
|
2013-06-19 20:51:52 +01:00
|
|
|
eprintf ("Proof state: ");
|
2012-10-02 12:43:30 +01:00
|
|
|
|
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
{
|
2013-06-19 20:51:52 +01:00
|
|
|
eprintf (" ");
|
2012-10-02 12:43:30 +01:00
|
|
|
}
|
2013-06-19 20:51:52 +01:00
|
|
|
termPrint (l->prev->term);
|
|
|
|
eprintf ("(");
|
|
|
|
termPrint (l->term);
|
|
|
|
eprintf ("); ");
|
2012-10-02 12:43:30 +01:00
|
|
|
l = l->prev->prev;
|
2013-06-19 20:51:52 +01:00
|
|
|
eprintf ("\n");
|
2012-10-02 12:43:30 +01:00
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up (void)
|
2012-10-02 12:43:30 +01:00
|
|
|
{
|
|
|
|
if (switches.output != PROOF)
|
2013-06-19 20:51:52 +01:00
|
|
|
return;
|
|
|
|
sys->proofstate = termlistDelTerm (sys->proofstate);
|
|
|
|
sys->proofstate = termlistDelTerm (sys->proofstate);
|
2012-10-02 12:43:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-13 09:29:11 +01:00
|
|
|
//! Print the current semistate
|
|
|
|
void
|
|
|
|
printSemiState ()
|
|
|
|
{
|
|
|
|
int run;
|
2004-08-14 15:38:30 +01:00
|
|
|
int open;
|
2004-08-15 18:50:41 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
int binding_state_print (void *dt)
|
2004-08-15 20:58:26 +01:00
|
|
|
{
|
2004-08-18 15:06:14 +01:00
|
|
|
binding_indent_print ((Binding) dt, 1);
|
2004-08-15 20:58:26 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2004-08-13 09:29:11 +01:00
|
|
|
|
2004-08-14 15:38:30 +01:00
|
|
|
indentPrint ();
|
|
|
|
eprintf ("!! --=[ Semistate ]=--\n");
|
2004-08-27 19:18:16 +01:00
|
|
|
indentPrint ();
|
|
|
|
eprintf ("!!\n");
|
|
|
|
indentPrint ();
|
2005-05-01 14:32:50 +01:00
|
|
|
eprintf ("!! Trace length: %i\n", get_semitrace_length ());
|
2004-08-14 15:38:30 +01:00
|
|
|
open = 0;
|
2004-08-13 09:29:11 +01:00
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
int index;
|
2004-08-15 18:16:13 +01:00
|
|
|
Role r;
|
2004-08-13 09:29:11 +01:00
|
|
|
Roledef rd;
|
2004-08-15 18:16:13 +01:00
|
|
|
Term oldagent;
|
2004-08-13 09:29:11 +01:00
|
|
|
|
2004-08-15 18:16:13 +01:00
|
|
|
indentPrint ();
|
|
|
|
eprintf ("!!\n");
|
2004-08-13 09:29:11 +01:00
|
|
|
indentPrint ();
|
2004-08-14 15:38:30 +01:00
|
|
|
eprintf ("!! [ Run %i, ", run);
|
2004-08-15 18:16:13 +01:00
|
|
|
termPrint (sys->runs[run].protocol->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
r = sys->runs[run].role;
|
|
|
|
oldagent = r->nameterm->subst;
|
|
|
|
r->nameterm->subst = NULL;
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
r->nameterm->subst = oldagent;
|
|
|
|
if (oldagent != NULL)
|
|
|
|
{
|
|
|
|
eprintf (": ");
|
|
|
|
termPrint (oldagent);
|
|
|
|
}
|
2004-08-13 09:29:11 +01:00
|
|
|
eprintf (" ]\n");
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
rd = sys->runs[run].start;
|
2006-01-02 21:06:08 +00:00
|
|
|
while (index < sys->runs[run].height)
|
2004-08-13 09:29:11 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
2004-08-14 15:38:30 +01:00
|
|
|
eprintf ("!! %i ", index);
|
2004-08-13 09:29:11 +01:00
|
|
|
roledefPrint (rd);
|
|
|
|
eprintf ("\n");
|
2004-08-14 15:38:30 +01:00
|
|
|
if (isGoal (rd) && !isBound (rd))
|
2004-08-14 17:12:32 +01:00
|
|
|
open++;
|
2004-08-13 09:29:11 +01:00
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
2004-08-15 18:50:41 +01:00
|
|
|
if (sys->bindings != NULL)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("!!\n");
|
2004-08-18 15:06:14 +01:00
|
|
|
list_iterate (sys->bindings, binding_state_print);
|
2004-08-15 18:50:41 +01:00
|
|
|
}
|
2004-08-14 15:38:30 +01:00
|
|
|
indentPrint ();
|
2004-08-15 18:16:13 +01:00
|
|
|
eprintf ("!!\n");
|
|
|
|
indentPrint ();
|
2004-08-14 15:38:30 +01:00
|
|
|
eprintf ("!! - open: %i -\n", open);
|
2004-08-13 09:29:11 +01:00
|
|
|
}
|
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
//! Check if a binding duplicates an old one: if so, simply connect
|
2006-02-27 16:08:17 +00:00
|
|
|
/**
|
|
|
|
* If it returns true, it has bound the b_new binding, which we must unbind later.
|
|
|
|
*/
|
2005-03-08 13:02:16 +00:00
|
|
|
int
|
|
|
|
bind_old_goal (const Binding b_new)
|
|
|
|
{
|
|
|
|
if (!b_new->done)
|
|
|
|
{
|
|
|
|
List bl;
|
|
|
|
|
|
|
|
bl = sys->bindings;
|
|
|
|
while (bl != NULL)
|
|
|
|
{
|
|
|
|
Binding b_old;
|
|
|
|
|
|
|
|
b_old = (Binding) bl->data;
|
|
|
|
if (b_old->done && isTermEqual (b_new->term, b_old->term))
|
|
|
|
{
|
|
|
|
// Old is done and has the same term!
|
2006-02-26 15:00:58 +00:00
|
|
|
// So we try to copy this binding, and fix it.
|
|
|
|
if (goal_bind (b_new, b_old->run_from, b_old->ev_from))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
bl = bl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// No old binding to connect to
|
2006-02-26 15:00:58 +00:00
|
|
|
return false;
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 19:22:59 +01:00
|
|
|
//! Bind an intruder goal by intruder composition 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
|
2004-08-18 19:22:59 +01:00
|
|
|
bind_goal_new_encrypt (const Binding b)
|
2004-08-13 11:25:23 +01:00
|
|
|
{
|
2004-08-13 21:09:12 +01:00
|
|
|
Term term;
|
2004-08-16 15:49:41 +01:00
|
|
|
int flag;
|
2004-08-19 15:49:03 +01:00
|
|
|
int can_be_encrypted;
|
2004-08-13 21:09:12 +01:00
|
|
|
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2004-08-16 15:49:41 +01:00
|
|
|
flag = 1;
|
2004-08-19 15:55:21 +01:00
|
|
|
term = deVar (b->term);
|
2004-08-19 15:49:03 +01:00
|
|
|
can_be_encrypted = 0;
|
2004-08-18 19:22:59 +01:00
|
|
|
|
2004-08-13 21:09:12 +01:00
|
|
|
if (!realTermLeaf (term))
|
|
|
|
{
|
|
|
|
Term t1, t2;
|
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
if (switches.intruder && (!realTermEncrypt (term)))
|
2004-08-13 21:09:12 +01:00
|
|
|
{
|
|
|
|
// tuple construction
|
2004-08-18 16:46:33 +01:00
|
|
|
error ("Goal that is a tuple should not occur!");
|
2004-08-13 21:09:12 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 16:46:33 +01:00
|
|
|
// must be encryption
|
2004-11-16 12:07:55 +00:00
|
|
|
t1 = TermOp (term);
|
|
|
|
t2 = TermKey (term);
|
2004-08-18 16:46:33 +01:00
|
|
|
|
2004-08-19 15:49:03 +01:00
|
|
|
if (t2 != TERM_Hidden)
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
int run;
|
|
|
|
|
2004-08-19 15:49:03 +01:00
|
|
|
can_be_encrypted = 1;
|
|
|
|
run = semiRunCreate (INTRUDER, I_RRS);
|
2006-02-27 16:08:17 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = sys->runs[run].start;
|
|
|
|
rd->message = termDuplicateUV (t1);
|
|
|
|
rd->next->message = termDuplicateUV (t2);
|
|
|
|
rd->next->next->message = termDuplicateUV (term);
|
|
|
|
index = 2;
|
|
|
|
proof_suppose_run (run, 0, index + 1);
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("* Encrypting ");
|
|
|
|
termPrint (term);
|
|
|
|
eprintf (" using term ");
|
|
|
|
termPrint (t1);
|
|
|
|
eprintf (" and key ");
|
|
|
|
termPrint (t2);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
2004-08-19 15:55:21 +01:00
|
|
|
|
2004-12-09 13:34:36 +00:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
int newgoals;
|
2012-04-25 08:53:07 +01:00
|
|
|
newgoals = add_recv_goals (run, 0, index + 1);
|
2006-02-27 16:08:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
indentDepth++;
|
|
|
|
if (goal_bind (b, run, index))
|
|
|
|
{
|
|
|
|
proof_suppose_binding (b);
|
|
|
|
flag = flag && iterate ();
|
|
|
|
goal_unbind (b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
proof_cannot_bind (b, run, index);
|
|
|
|
}
|
|
|
|
indentDepth--;
|
|
|
|
}
|
|
|
|
goal_remove_last (newgoals);
|
2004-12-09 13:34:36 +00:00
|
|
|
}
|
2006-02-27 16:08:17 +00:00
|
|
|
}
|
2004-08-19 15:49:03 +01:00
|
|
|
semiRunDestroy ();
|
2004-08-19 12:37:41 +01:00
|
|
|
}
|
2004-08-13 21:09:12 +01:00
|
|
|
}
|
2004-08-19 15:49:03 +01:00
|
|
|
|
|
|
|
if (!can_be_encrypted)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Term ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" cannot be constructed by encryption.\n");
|
|
|
|
}
|
|
|
|
}
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2004-08-16 15:49:41 +01:00
|
|
|
return flag;
|
2004-08-13 11:25:23 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 19:22:59 +01:00
|
|
|
//! Bind an intruder goal by intruder construction
|
|
|
|
/**
|
2005-03-08 13:02:16 +00:00
|
|
|
* Handles the case where the intruder constructs a composed term himself, or retrieves it from m0.
|
|
|
|
* However, it must not already have been created in an intruder run; then it gets bound to that.
|
2004-08-18 19:22:59 +01:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
bind_goal_new_intruder_run (const Binding b)
|
|
|
|
{
|
2004-08-19 13:35:51 +01:00
|
|
|
int flag;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Can we bind ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" from a new intruder run?\n");
|
|
|
|
}
|
|
|
|
indentDepth++;
|
2006-07-09 16:08:42 +01:00
|
|
|
//flag = flag && bind_goal_new_encrypt (b);
|
|
|
|
flag = bind_goal_new_encrypt (b);
|
2004-08-19 13:35:51 +01:00
|
|
|
indentDepth--;
|
|
|
|
return flag;
|
2004-08-18 19:22:59 +01:00
|
|
|
}
|
2004-08-13 11:25:23 +01:00
|
|
|
|
2018-10-20 01:17:50 +01:00
|
|
|
//! Dummy helper function for iterator; abort if sub-unification found
|
|
|
|
int
|
|
|
|
test_sub_unification (Termlist substlist, Termlist keylist)
|
|
|
|
{
|
|
|
|
// A unification exists; return the signal
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
//! Bind a regular goal
|
2004-08-30 23:08:44 +01:00
|
|
|
/**
|
|
|
|
* Problem child. Valgrind does not like it.
|
|
|
|
*/
|
2004-08-11 13:08:10 +01:00
|
|
|
int
|
2004-08-18 16:46:33 +01:00
|
|
|
bind_goal_regular_run (const Binding b)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-15 18:07:38 +01:00
|
|
|
int flag;
|
2004-08-19 12:37:41 +01:00
|
|
|
int found;
|
2004-08-15 18:07:38 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
/*
|
|
|
|
* This is a local function so we have access to goal
|
|
|
|
*/
|
|
|
|
int bind_this_role_send (Protocol p, Role r, Roledef rd, int index)
|
|
|
|
{
|
2004-08-18 16:46:33 +01:00
|
|
|
if (p == INTRUDER)
|
|
|
|
{
|
|
|
|
// No intruder roles here
|
2006-03-19 12:59:26 +00:00
|
|
|
return true;
|
2004-08-18 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
// Test for interm unification
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Checking send candidate with message ");
|
|
|
|
termPrint (rd->message);
|
|
|
|
eprintf (" from ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (", index %i\n", index);
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-19 12:59:26 +00:00
|
|
|
if (!subtermUnify
|
|
|
|
(rd->message, b->term, NULL, NULL, test_sub_unification))
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
2004-08-30 23:08:44 +01:00
|
|
|
int sflag;
|
2004-08-18 15:06:14 +01:00
|
|
|
|
|
|
|
// A good candidate
|
2004-08-19 12:37:41 +01:00
|
|
|
found++;
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF && found == 1)
|
2004-08-18 15:06:14 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
2004-08-19 13:35:51 +01:00
|
|
|
eprintf ("The term ", found);
|
2004-08-18 15:06:14 +01:00
|
|
|
termPrint (b->term);
|
2004-08-19 14:09:35 +01:00
|
|
|
eprintf
|
|
|
|
(" matches patterns from the role definitions. Investigate.\n");
|
2004-08-19 13:35:51 +01:00
|
|
|
}
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("%i. It matches the pattern ", found);
|
2004-08-19 12:37:41 +01:00
|
|
|
termPrint (rd->message);
|
|
|
|
eprintf (" from ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
2004-08-18 15:06:14 +01:00
|
|
|
termPrint (r->nameterm);
|
2004-08-19 12:37:41 +01:00
|
|
|
eprintf (", at %i\n", index);
|
2004-08-18 15:06:14 +01:00
|
|
|
}
|
2004-08-19 13:35:51 +01:00
|
|
|
indentDepth++;
|
2005-05-19 15:43:32 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
// Bind to existing run
|
2006-02-26 17:18:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug (5, "Trying to bind to existing run.");
|
|
|
|
#endif
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_down (TERM_DeEx, b->term);
|
2004-08-30 23:08:44 +01:00
|
|
|
sflag = bind_existing_run (b, p, r, index);
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up ();
|
2004-08-18 16:46:33 +01:00
|
|
|
// bind to new run
|
2006-02-26 17:18:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug (5, "Trying to bind to new run.");
|
|
|
|
#endif
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_down (TERM_DeNew, b->term);
|
2005-05-19 15:43:32 +01:00
|
|
|
sflag = sflag && bind_new_run (b, p, r, index);
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up ();
|
2005-05-19 15:43:32 +01:00
|
|
|
|
2004-08-19 13:35:51 +01:00
|
|
|
indentDepth--;
|
2004-08-30 23:08:44 +01:00
|
|
|
return sflag;
|
2004-08-18 15:06:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-19 12:59:26 +00:00
|
|
|
return true;
|
2004-08-18 15:06:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-27 18:35:23 +01:00
|
|
|
|
2004-08-18 16:46:33 +01:00
|
|
|
// Bind to all possible sends of regular runs
|
2004-08-19 12:37:41 +01:00
|
|
|
found = 0;
|
|
|
|
flag = iterate_role_sends (bind_this_role_send);
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF && found == 0)
|
2004-08-19 12:37:41 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("The term ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" does not match any pattern from the role definitions.\n");
|
|
|
|
}
|
|
|
|
return flag;
|
2004-08-18 16:46:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
//! Bind to all possible sends of intruder runs
|
2004-08-18 20:43:58 +01:00
|
|
|
int
|
|
|
|
bind_goal_old_intruder_run (Binding b)
|
2004-08-18 16:46:33 +01:00
|
|
|
{
|
|
|
|
int run;
|
|
|
|
int flag;
|
2004-08-19 13:35:51 +01:00
|
|
|
int found;
|
2004-08-18 16:46:33 +01:00
|
|
|
|
2004-08-19 13:35:51 +01:00
|
|
|
found = 0;
|
2004-08-18 16:46:33 +01:00
|
|
|
flag = 1;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
if (sys->runs[run].protocol == INTRUDER)
|
|
|
|
{
|
|
|
|
int ev;
|
|
|
|
Roledef rd;
|
2004-08-18 15:06:14 +01:00
|
|
|
|
2004-08-18 20:43:58 +01:00
|
|
|
rd = sys->runs[run].start;
|
2004-08-18 16:46:33 +01:00
|
|
|
ev = 0;
|
2006-01-02 21:06:08 +00:00
|
|
|
while (ev < sys->runs[run].height)
|
2004-08-18 16:46:33 +01:00
|
|
|
{
|
|
|
|
if (rd->type == SEND)
|
|
|
|
{
|
2004-08-19 13:35:51 +01:00
|
|
|
found++;
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF && found == 1)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
2004-08-19 14:09:35 +01:00
|
|
|
eprintf
|
|
|
|
("Suppose it is from an existing intruder run.\n");
|
2004-08-19 13:35:51 +01:00
|
|
|
}
|
2004-08-19 14:09:35 +01:00
|
|
|
indentDepth++;
|
2006-07-09 16:08:42 +01:00
|
|
|
bind_existing_to_goal (b, run, ev,
|
|
|
|
(sys->runs[run].role != I_RRS));
|
2004-08-19 14:09:35 +01:00
|
|
|
indentDepth--;
|
2004-08-18 16:46:33 +01:00
|
|
|
}
|
|
|
|
rd = rd->next;
|
|
|
|
ev++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF && found == 0)
|
2004-08-19 13:35:51 +01:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("No existing intruder runs to match to.\n");
|
|
|
|
}
|
2004-08-18 15:06:14 +01:00
|
|
|
return flag;
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Bind a goal in all possible ways
|
|
|
|
int
|
2006-02-27 16:08:17 +00:00
|
|
|
bind_goal_all_options (const Binding b)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2005-01-14 18:18:40 +00:00
|
|
|
if (b->blocked)
|
|
|
|
{
|
|
|
|
error ("Trying to bind a blocked goal!");
|
|
|
|
}
|
2004-08-18 10:57:01 +01:00
|
|
|
if (!b->done)
|
2004-08-11 13:08:10 +01:00
|
|
|
{
|
2004-08-18 16:46:33 +01:00
|
|
|
int flag;
|
|
|
|
|
2004-12-08 16:25:27 +00:00
|
|
|
flag = 1;
|
2004-08-19 11:46:27 +01:00
|
|
|
proof_select_goal (b);
|
|
|
|
indentDepth++;
|
2004-08-20 12:47:00 +01:00
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
// Consider a duplicate goal that we already bound before (C-minimality)
|
|
|
|
// if (1 == 0)
|
|
|
|
if (bind_old_goal (b))
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.output == PROOF)
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Goal for term ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf (" was bound once before, linking up to #%i, %i.\n",
|
|
|
|
b->run_from, b->ev_from);
|
|
|
|
}
|
2004-08-27 18:35:23 +01:00
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
flag = flag && iterate ();
|
|
|
|
|
|
|
|
// Unbind again
|
2006-02-26 15:00:58 +00:00
|
|
|
goal_unbind (b);
|
2005-03-08 13:02:16 +00:00
|
|
|
indentDepth--;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
else
|
2004-08-20 12:47:00 +01:00
|
|
|
{
|
2006-01-17 16:18:26 +00:00
|
|
|
int know_only;
|
2005-03-08 13:02:16 +00:00
|
|
|
|
2006-02-28 15:01:58 +00:00
|
|
|
know_only = false;
|
2006-01-17 16:18:26 +00:00
|
|
|
|
|
|
|
if (1 == 0) // blocked for now
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-01-17 16:18:26 +00:00
|
|
|
// Prune: if it is an SK type construct, ready
|
|
|
|
// No regular run will apply SK for you.
|
|
|
|
//!@todo This still needs a lemma, and a more generic (correct) algorithm!! It is currently
|
|
|
|
// actually false, e.g. for signing protocols, and password-like functions.
|
|
|
|
//
|
|
|
|
Term function;
|
|
|
|
|
|
|
|
function = getTermFunction (b->term);
|
|
|
|
if (function != NULL)
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-01-17 16:18:26 +00:00
|
|
|
if (!inKnowledge (sys->know, function))
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-01-17 16:18:26 +00:00
|
|
|
// Prune because we didn't know it before, and it is never subterm-sent
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("* Because ");
|
|
|
|
termPrint (b->term);
|
|
|
|
eprintf
|
|
|
|
(" is never sent from a regular run, so we only intruder construct it.\n");
|
|
|
|
}
|
2006-02-28 15:01:58 +00:00
|
|
|
know_only = true;
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-28 15:01:58 +00:00
|
|
|
if (switches.experimental & 16)
|
2004-08-20 12:47:00 +01:00
|
|
|
{
|
2006-02-22 09:53:50 +00:00
|
|
|
// Keylevel lemmas: improves on the previous one
|
|
|
|
if (!isPossiblySent (b->term))
|
2004-08-20 12:47:00 +01:00
|
|
|
{
|
2006-02-22 09:53:50 +00:00
|
|
|
if (switches.output == PROOF)
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-02-22 09:53:50 +00:00
|
|
|
eprintf
|
|
|
|
("Rejecting a term as a regular bind because key levels are off: ");
|
|
|
|
termPrint (b->term);
|
|
|
|
if (know_only)
|
|
|
|
{
|
|
|
|
eprintf (" [in accordance with function lemma]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eprintf (" [stronger than function lemma]");
|
|
|
|
}
|
|
|
|
eprintf ("\n");
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
2006-02-28 15:01:58 +00:00
|
|
|
know_only = true;
|
2004-08-20 12:47:00 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-28 15:01:58 +00:00
|
|
|
|
|
|
|
if (!(switches.experimental & 32))
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-02-28 15:01:58 +00:00
|
|
|
/**
|
|
|
|
* Note: this is slightly weaker than the previous & 16,
|
|
|
|
* but it actually differs in such minimal cases that it
|
|
|
|
* might be better to simply have the (much cleaner)
|
|
|
|
* keylevel lemma.
|
|
|
|
*
|
|
|
|
* That's why this is default and the other isn't.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Hidelevel variant
|
|
|
|
int hlf;
|
|
|
|
|
|
|
|
hlf = hidelevelFlag (sys, b->term);
|
|
|
|
if (hlf == HLFLAG_NONE || hlf == HLFLAG_KNOW)
|
2005-03-08 13:02:16 +00:00
|
|
|
{
|
2006-02-28 15:01:58 +00:00
|
|
|
know_only = true;
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-28 15:01:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Allright, proceed
|
2004-08-27 18:35:23 +01:00
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
proofDepth++;
|
|
|
|
if (know_only)
|
|
|
|
{
|
|
|
|
// Special case: only from intruder
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_down (TERM_CoOld, b->term);
|
2005-03-08 13:02:16 +00:00
|
|
|
flag = flag && bind_goal_old_intruder_run (b);
|
2006-07-09 16:08:42 +01:00
|
|
|
//flag = flag && bind_goal_new_intruder_run (b);
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up ();
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal case
|
2013-06-19 20:51:52 +01:00
|
|
|
flag = bind_goal_regular_run (b);
|
|
|
|
proof_go_down (TERM_CoOld, b->term);
|
2005-03-08 13:02:16 +00:00
|
|
|
flag = flag && bind_goal_old_intruder_run (b);
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up ();
|
|
|
|
proof_go_down (TERM_CoNew, b->term);
|
2005-03-08 13:02:16 +00:00
|
|
|
flag = flag && bind_goal_new_intruder_run (b);
|
2013-06-19 20:51:52 +01:00
|
|
|
proof_go_up ();
|
2005-03-08 13:02:16 +00:00
|
|
|
}
|
|
|
|
proofDepth--;
|
2004-08-20 12:47:00 +01:00
|
|
|
|
2005-03-08 13:02:16 +00:00
|
|
|
indentDepth--;
|
|
|
|
return flag;
|
|
|
|
}
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-15 13:24:27 +01:00
|
|
|
return 1;
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-12 21:13:00 +00:00
|
|
|
//! Create a generic new term of the same type, with a new run identifier.
|
|
|
|
/**
|
|
|
|
* Output: the first element of the returned list.
|
|
|
|
*/
|
|
|
|
Termlist
|
|
|
|
createNewTermGeneric (Termlist tl, Term t)
|
|
|
|
{
|
|
|
|
int freenumber;
|
|
|
|
Termlist tlscan;
|
|
|
|
Term newterm;
|
|
|
|
|
|
|
|
/* Determine first free number */
|
2006-04-02 12:56:22 +01:00
|
|
|
freenumber = sys->maxruns;
|
2005-11-12 21:13:00 +00:00
|
|
|
tlscan = tl;
|
|
|
|
while (tlscan != NULL)
|
|
|
|
{
|
|
|
|
Term ts;
|
|
|
|
|
|
|
|
ts = tlscan->term;
|
|
|
|
if (isLeafNameEqual (t, ts))
|
|
|
|
{
|
|
|
|
if (TermRunid (ts) >= freenumber)
|
|
|
|
{
|
|
|
|
freenumber = TermRunid (ts) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tlscan = tlscan->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a new term with the free number */
|
2006-03-08 13:58:46 +00:00
|
|
|
newterm = (Term) malloc (sizeof (struct term));
|
2005-11-12 21:13:00 +00:00
|
|
|
memcpy (newterm, t, sizeof (struct term));
|
|
|
|
TermRunid (newterm) = freenumber;
|
|
|
|
|
2006-12-05 10:10:17 +00:00
|
|
|
/* The type of the new term should be that of the parent! */
|
|
|
|
newterm->stype = termlistAppend (NULL, t);
|
|
|
|
|
2005-11-12 21:13:00 +00:00
|
|
|
/* return */
|
|
|
|
return termlistPrepend (tl, newterm);
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:24:32 +01:00
|
|
|
//! Construct a list of already used constants
|
|
|
|
Termlist
|
|
|
|
findUsedConstants (const System sys)
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
Termlist tl;
|
|
|
|
Termlist tlconst;
|
|
|
|
|
|
|
|
tl = NULL;
|
|
|
|
tlconst = NULL;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
tl = termlistAddBasics (tl, sys->runs[run].rho);
|
|
|
|
tl = termlistAddBasics (tl, sys->runs[run].sigma);
|
|
|
|
}
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = tl->term;
|
|
|
|
if (!realTermVariable (t))
|
|
|
|
{
|
|
|
|
tlconst = termlistAddNew (tlconst, t);
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
termlistDelete (tl);
|
|
|
|
return tlconst;
|
|
|
|
}
|
|
|
|
|
2014-06-30 17:03:24 +01:00
|
|
|
//! Retrieve a list of agent name candidates
|
|
|
|
Termlist
|
|
|
|
getAgentCandidates (Termlist seen)
|
|
|
|
{
|
|
|
|
Termlist knowlist;
|
|
|
|
Termlist candidatelist;
|
|
|
|
Termlist li; // list loop pointer
|
|
|
|
|
|
|
|
knowlist = knowledgeSet (sys->know);
|
|
|
|
candidatelist = NULL;
|
|
|
|
for (li = knowlist; li != NULL; li = li->next)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = li->term;
|
|
|
|
if (isAgentType (t->stype))
|
|
|
|
{
|
|
|
|
/* agent */
|
|
|
|
/* We don'typeterm want to instantiate untrusted agents. */
|
|
|
|
if (!inTermlist (sys->untrusted, t))
|
|
|
|
{
|
|
|
|
/* trusted agent */
|
|
|
|
if (!inTermlist (seen, t))
|
|
|
|
{
|
|
|
|
/* This agent name is not in the list yet, so could be chosen */
|
|
|
|
candidatelist = termlistPrepend (candidatelist, t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
termlistDelete (knowlist);
|
|
|
|
return candidatelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get to string of term
|
|
|
|
const char *
|
|
|
|
getTermString (Term t)
|
|
|
|
{
|
|
|
|
if (t != NULL)
|
|
|
|
{
|
|
|
|
if (TermSymb (t) != NULL)
|
|
|
|
{
|
|
|
|
return (TermSymb (t)->text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check the first character of two terms
|
|
|
|
int
|
|
|
|
isFirstCharEqual (Term t1, Term t2)
|
|
|
|
{
|
|
|
|
const char *c1, *c2;
|
|
|
|
|
|
|
|
c1 = getTermString (t1);
|
|
|
|
c2 = getTermString (t2);
|
|
|
|
if ((c1 == NULL) || (c2 == NULL))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (c1[0] == c2[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Choose the best term from the (non-null) candidate list for the variable var
|
|
|
|
Term
|
|
|
|
chooseBestCandidate (Termlist candidatelist, Term var)
|
|
|
|
{
|
|
|
|
Term last;
|
|
|
|
Termlist li; // list loop pointer
|
|
|
|
|
|
|
|
// See if we have a candidate that starts with the same first character
|
|
|
|
for (li = candidatelist; li != NULL; li = li->next)
|
|
|
|
{
|
|
|
|
last = li->term;
|
|
|
|
if (isFirstCharEqual (last, var))
|
|
|
|
{
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If not, we may still want to invoke heuristics (Alice initiates, Bob responds)
|
|
|
|
if (li == NULL)
|
|
|
|
{
|
|
|
|
// li==null happens if we did not break out of the loop, i.e., found nothing
|
|
|
|
const char *c;
|
|
|
|
|
|
|
|
c = getTermString (var);
|
|
|
|
if (c != NULL)
|
|
|
|
{
|
|
|
|
// Check if name starts with common prefix, resort to common name if still a candidate
|
|
|
|
if (strchr ("Ii", *c) && inTermlist (candidatelist, AGENT_Alice))
|
|
|
|
{
|
|
|
|
return AGENT_Alice;
|
|
|
|
}
|
|
|
|
if (strchr ("Rr", *c) && inTermlist (candidatelist, AGENT_Bob))
|
|
|
|
{
|
|
|
|
return AGENT_Bob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2005-11-12 21:13:00 +00:00
|
|
|
//! Create a new term with incremented run rumber, starting at sys->maxruns.
|
|
|
|
/**
|
2006-01-02 20:18:47 +00:00
|
|
|
* This is a rather intricate function that tries to generate new terms of a
|
|
|
|
* certain type. It first looks up things in the initial knowledge, checking
|
|
|
|
* whether they are used already. After that, new ones are generated.
|
|
|
|
*
|
2014-06-30 17:03:24 +01:00
|
|
|
* Input:
|
|
|
|
* - seen is a termlist that contains newly generated terms (usage: seen = createNewTerm(seen,.. )
|
|
|
|
* - typeterm is the type name term (e.g., "Agent" term, "Data" in case not clear.)
|
|
|
|
* - isagent is a boolean that is true iff we are looking for an agent name from the initial knowledge for a role
|
2014-06-30 23:11:39 +01:00
|
|
|
* - var is the variable term of which we use the name
|
2014-06-30 17:03:24 +01:00
|
|
|
*
|
|
|
|
* Output: the first element of the returned list, which is otherwise equal to seen.
|
2005-11-12 21:13:00 +00:00
|
|
|
*/
|
|
|
|
Termlist
|
2014-06-30 23:11:39 +01:00
|
|
|
createNewTerm (Termlist seen, Term typeterm, int isagent, Term nameterm)
|
2005-11-12 21:13:00 +00:00
|
|
|
{
|
|
|
|
/* Does if have an explicit type?
|
|
|
|
* If so, we try to find a fresh name from the intruder knowledge first.
|
|
|
|
*/
|
|
|
|
if (isagent)
|
|
|
|
{
|
2014-06-30 17:03:24 +01:00
|
|
|
Termlist candidatelist;
|
2005-11-12 21:13:00 +00:00
|
|
|
|
2014-06-30 17:03:24 +01:00
|
|
|
candidatelist = getAgentCandidates (seen);
|
|
|
|
if (candidatelist != NULL)
|
2005-11-12 21:13:00 +00:00
|
|
|
{
|
2014-06-30 17:03:24 +01:00
|
|
|
Term t;
|
2005-11-12 21:13:00 +00:00
|
|
|
|
2014-06-30 23:11:39 +01:00
|
|
|
t = chooseBestCandidate (candidatelist, nameterm);
|
2014-06-30 17:03:24 +01:00
|
|
|
termlistDelete (candidatelist);
|
|
|
|
return termlistPrepend (seen, t);
|
2005-11-12 21:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not an agent or no free one found */
|
2014-06-30 17:03:24 +01:00
|
|
|
return createNewTermGeneric (seen, typeterm);
|
2005-11-12 21:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Delete a term made in the previous constructions
|
2006-01-02 20:18:47 +00:00
|
|
|
/**
|
|
|
|
* \sa createNewTerm
|
|
|
|
*/
|
2005-11-12 21:13:00 +00:00
|
|
|
void
|
|
|
|
deleteNewTerm (Term t)
|
|
|
|
{
|
|
|
|
if (TermRunid (t) >= 0)
|
|
|
|
{
|
|
|
|
/* if it has a positive runid, it did not come from the intruder
|
|
|
|
* knowledge, so it must have been constructed.
|
|
|
|
*/
|
2006-03-08 13:58:46 +00:00
|
|
|
free (t);
|
2005-11-12 21:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Make a trace concrete
|
2006-01-02 20:18:47 +00:00
|
|
|
/**
|
|
|
|
* People find reading variables in attack outputs difficult.
|
2014-06-30 17:03:24 +01:00
|
|
|
* Thus, we instantiate open variables in a sensible way to make things more readable.
|
2006-01-02 20:18:47 +00:00
|
|
|
*
|
2006-04-02 12:56:22 +01:00
|
|
|
* This happens after sys->maxruns is fixed. Intruder constants thus are numbered from sys->maxruns onwards.
|
|
|
|
*
|
2006-01-02 20:18:47 +00:00
|
|
|
* \sa makeTraceClass
|
|
|
|
*/
|
2005-11-12 21:13:00 +00:00
|
|
|
Termlist
|
|
|
|
makeTraceConcrete (const System sys)
|
|
|
|
{
|
|
|
|
Termlist changedvars;
|
|
|
|
Termlist tlnew;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
changedvars = NULL;
|
2006-03-31 13:24:32 +01:00
|
|
|
tlnew = findUsedConstants (sys);
|
2005-11-12 21:13:00 +00:00
|
|
|
|
2014-06-30 23:11:39 +01:00
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
2005-11-12 21:13:00 +00:00
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
2014-06-30 23:11:39 +01:00
|
|
|
for (tl = termlistForward (sys->runs[run].locals); tl != NULL;
|
|
|
|
tl = tl->prev)
|
2005-11-12 21:13:00 +00:00
|
|
|
{
|
2014-06-30 23:11:39 +01:00
|
|
|
Term basevar;
|
|
|
|
|
|
|
|
basevar = tl->term;
|
|
|
|
|
2005-11-12 21:13:00 +00:00
|
|
|
/* variable, and of some run? */
|
2014-06-30 23:11:39 +01:00
|
|
|
if (isTermVariable (basevar) && TermRunid (basevar) >= 0)
|
2005-11-12 21:13:00 +00:00
|
|
|
{
|
|
|
|
Term var;
|
|
|
|
Term name;
|
|
|
|
Termlist vartype;
|
|
|
|
|
2014-06-30 23:11:39 +01:00
|
|
|
var = deVar (basevar);
|
|
|
|
vartype = basevar->stype;
|
2005-11-12 21:13:00 +00:00
|
|
|
// Determine class name
|
|
|
|
if (vartype != NULL)
|
|
|
|
{
|
|
|
|
// Take first type name
|
|
|
|
name = vartype->term;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just a generic name
|
|
|
|
name = TERM_Data;
|
|
|
|
}
|
|
|
|
// We should turn this into an actual term
|
2014-06-30 17:03:24 +01:00
|
|
|
tlnew =
|
2014-06-30 23:11:39 +01:00
|
|
|
createNewTerm (tlnew, name, isAgentType (var->stype),
|
|
|
|
basevar);
|
2005-11-12 21:13:00 +00:00
|
|
|
var->subst = tlnew->term;
|
|
|
|
|
|
|
|
// Store for undo later
|
2014-06-30 23:11:39 +01:00
|
|
|
TERMLISTADD (changedvars, var);
|
2005-11-12 21:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
termlistDelete (tlnew);
|
|
|
|
return changedvars;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Make a trace a class again
|
2006-01-02 20:18:47 +00:00
|
|
|
/**
|
|
|
|
* \sa makeTraceConcrete
|
|
|
|
*/
|
2005-11-12 21:13:00 +00:00
|
|
|
void
|
|
|
|
makeTraceClass (const System sys, Termlist varlist)
|
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
|
|
|
tl = varlist;
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
Term var;
|
|
|
|
|
|
|
|
var = tl->term;
|
2006-03-15 08:51:08 +00:00
|
|
|
if (realTermVariable (var))
|
|
|
|
{
|
|
|
|
deleteNewTerm (var->subst);
|
|
|
|
var->subst = NULL;
|
|
|
|
}
|
2005-11-12 21:13:00 +00:00
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
termlistDelete (varlist);
|
|
|
|
}
|
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
//! Determine whether to filter to a single attack
|
|
|
|
int
|
|
|
|
useAttackBuffer (void)
|
|
|
|
{
|
|
|
|
if (switches.useAttackBuffer)
|
|
|
|
{
|
|
|
|
// it is possible
|
|
|
|
if (switches.prune != 0)
|
|
|
|
{
|
|
|
|
// it is also desired
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-12-27 10:49:22 +00:00
|
|
|
//! Start attack output
|
|
|
|
void
|
|
|
|
attackOutputStart (void)
|
|
|
|
{
|
2007-05-18 13:06:29 +01:00
|
|
|
if (useAttackBuffer ())
|
2005-12-27 10:49:22 +00:00
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
|
|
|
|
// Close old file (if any)
|
|
|
|
if (attack_stream != NULL)
|
|
|
|
{
|
|
|
|
fclose (attack_stream); // this automatically discards the old temporary file
|
|
|
|
}
|
|
|
|
// Create new file
|
2007-09-17 15:53:37 +01:00
|
|
|
fd = (FILE *) scyther_tempfile ();
|
2005-12-27 10:49:22 +00:00
|
|
|
attack_stream = fd;
|
|
|
|
globalStream = (char *) attack_stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Stop attack output
|
|
|
|
void
|
|
|
|
attackOutputStop (void)
|
|
|
|
{
|
|
|
|
// Nothing to do, just leave the opened tmpfile
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Copy one (finite) stream from beginning to end to another
|
|
|
|
/**
|
|
|
|
* Ugly first implementation, something to improve later (although it is not
|
|
|
|
* crucial code in any way)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fcopy (FILE * fromstream, FILE * tostream)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
// 'Just to be sure'
|
|
|
|
fflush (fromstream);
|
|
|
|
fseek (fromstream, 0, SEEK_SET);
|
|
|
|
|
|
|
|
// Urgh, using the assignment in the loop condition, brrr. Fugly.
|
|
|
|
// Discourage.
|
|
|
|
while ((c = fgetc (fromstream)) != EOF)
|
|
|
|
{
|
|
|
|
fputc (c, tostream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-12 21:13:00 +00:00
|
|
|
//! Output an attack in the desired way
|
|
|
|
void
|
|
|
|
arachneOutputAttack ()
|
|
|
|
{
|
|
|
|
Termlist varlist;
|
|
|
|
|
2005-12-27 10:49:22 +00:00
|
|
|
// Make concrete
|
2005-11-12 21:13:00 +00:00
|
|
|
if (switches.concrete)
|
|
|
|
{
|
|
|
|
varlist = makeTraceConcrete (sys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
varlist = NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-27 10:49:22 +00:00
|
|
|
// Wrapper for the real output
|
|
|
|
attackOutputStart ();
|
|
|
|
|
|
|
|
// Generate the output, already!
|
2005-11-12 21:13:00 +00:00
|
|
|
if (switches.xml)
|
|
|
|
{
|
|
|
|
xmlOutSemitrace (sys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-02 19:19:23 +00:00
|
|
|
dotSemiState (sys);
|
2005-11-12 21:13:00 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 10:49:22 +00:00
|
|
|
// End wrapper
|
|
|
|
attackOutputStop ();
|
|
|
|
|
|
|
|
// Undo concretization
|
2005-11-12 21:13:00 +00:00
|
|
|
makeTraceClass (sys, varlist);
|
|
|
|
}
|
|
|
|
|
2004-08-11 13:08:10 +01:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Main logic core
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2006-01-02 19:19:23 +00:00
|
|
|
|
|
|
|
//! Selector to select the first tuple goal.
|
|
|
|
/**
|
|
|
|
* Basically to get rid of -m2 tuple goals.
|
|
|
|
* Nice iteration, I'd suppose
|
|
|
|
*/
|
|
|
|
Binding
|
|
|
|
select_tuple_goal ()
|
|
|
|
{
|
|
|
|
List bl;
|
|
|
|
Binding tuplegoal;
|
|
|
|
|
|
|
|
bl = sys->bindings;
|
|
|
|
tuplegoal = NULL;
|
|
|
|
while (bl != NULL && tuplegoal == NULL)
|
|
|
|
{
|
|
|
|
Binding b;
|
|
|
|
|
|
|
|
b = (Binding) bl->data;
|
|
|
|
// Ignore done stuff
|
|
|
|
if (!b->blocked && !b->done)
|
|
|
|
{
|
|
|
|
if (isTermTuple (b->term))
|
|
|
|
{
|
|
|
|
tuplegoal = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bl = bl->next;
|
|
|
|
}
|
|
|
|
return tuplegoal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
//! Iterate a binding
|
|
|
|
/**
|
|
|
|
* For DY model, we unfold any tuples first, otherwise we skip that.
|
|
|
|
*/
|
2004-08-11 10:51:17 +01:00
|
|
|
int
|
2006-03-19 12:59:26 +00:00
|
|
|
iterateOneBinding (void)
|
2004-08-11 12:22:20 +01:00
|
|
|
{
|
2006-03-19 12:59:26 +00:00
|
|
|
Binding btup;
|
2004-08-11 22:04:52 +01:00
|
|
|
int flag;
|
2004-08-11 13:08:10 +01:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
// marker
|
|
|
|
flag = true;
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
// Are there any tuple goals?
|
|
|
|
if (switches.intruder)
|
2004-08-11 22:04:52 +01:00
|
|
|
{
|
2006-03-19 12:59:26 +00:00
|
|
|
// Maybe... (well, test)
|
|
|
|
btup = select_tuple_goal ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No, there are non that need to be expanded (no intruder)
|
|
|
|
btup = NULL;
|
|
|
|
}
|
|
|
|
if (btup != NULL)
|
|
|
|
{
|
|
|
|
/* Substitution or something resulted in a tuple goal: we immediately split them into compounds.
|
|
|
|
*/
|
|
|
|
Term tuple;
|
|
|
|
|
|
|
|
tuple = deVar (btup->term);
|
|
|
|
if (realTermTuple (tuple))
|
2004-08-19 14:09:35 +01:00
|
|
|
{
|
2006-03-19 12:59:26 +00:00
|
|
|
int count;
|
|
|
|
Term tupletermbuffer;
|
|
|
|
|
|
|
|
tupletermbuffer = btup->term;
|
|
|
|
/*
|
|
|
|
* We solve this by replacing the tuple goal by the left term, and adding a goal for the right term.
|
|
|
|
*/
|
|
|
|
btup->term = TermOp1 (tuple);
|
|
|
|
count =
|
|
|
|
goal_add (TermOp2 (tuple), btup->run_to,
|
|
|
|
btup->ev_to, btup->level);
|
|
|
|
|
|
|
|
// Show this in output
|
|
|
|
if (switches.output == PROOF)
|
2004-08-27 16:02:33 +01:00
|
|
|
{
|
2006-03-19 12:59:26 +00:00
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Expanding tuple goal ");
|
|
|
|
termPrint (tupletermbuffer);
|
|
|
|
eprintf (" into %i subgoals.\n", count);
|
|
|
|
}
|
2005-01-14 14:08:01 +00:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
// iterate
|
|
|
|
flag = iterate ();
|
2005-01-14 14:08:01 +00:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
// undo
|
|
|
|
goal_remove_last (count);
|
|
|
|
btup->term = tupletermbuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No tuple goals; good
|
|
|
|
Binding b;
|
2005-01-14 14:08:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Not pruned: count
|
|
|
|
*/
|
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
sys->states = statesIncrease (sys->states);
|
|
|
|
sys->current_claim->states =
|
|
|
|
statesIncrease (sys->current_claim->states);
|
2005-01-14 14:08:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether its a final state (i.e. all goals bound)
|
2004-08-27 16:02:33 +01:00
|
|
|
*/
|
2005-01-14 14:08:01 +00:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
b = (Binding) select_goal (sys);
|
|
|
|
if (b == NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* all goals bound, check for property
|
|
|
|
*/
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("All goals are now bound.\n");
|
|
|
|
}
|
|
|
|
sys->claims = statesIncrease (sys->claims);
|
|
|
|
sys->current_claim->count =
|
|
|
|
statesIncrease (sys->current_claim->count);
|
|
|
|
flag = property_check (sys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* bind this goal in all possible ways and iterate
|
|
|
|
*/
|
|
|
|
flag = bind_goal_all_options (b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
//! Unfold this particular name in this way
|
|
|
|
void
|
|
|
|
iterateAgentUnfoldThis (const Term rolevar, const Term agent)
|
|
|
|
{
|
|
|
|
Term buffer;
|
|
|
|
|
|
|
|
buffer = rolevar->subst;
|
|
|
|
rolevar->subst = agent;
|
|
|
|
iterate ();
|
|
|
|
rolevar->subst = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Unfold this particular name
|
|
|
|
void
|
|
|
|
iterateAgentUnfolding (const System sys, const Term rolevar)
|
|
|
|
{
|
|
|
|
Termlist kl;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
iterateAgentUnfoldThis (rolevar, AGENT_Eve);
|
|
|
|
kl = knowledgeSet (sys->know);
|
|
|
|
count = 0;
|
|
|
|
while (kl != NULL && count < switches.agentUnfold)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = deVar (kl->term);
|
|
|
|
if (realTermLeaf (t) && inTermlist (t->stype, TERM_Agent))
|
|
|
|
{
|
|
|
|
if (!inTermlist (sys->untrusted, t))
|
|
|
|
{
|
|
|
|
iterateAgentUnfoldThis (rolevar, t);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kl = kl->next;
|
|
|
|
}
|
|
|
|
termlistDelete (kl);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Unfold names
|
|
|
|
/**
|
|
|
|
* Returns true if nothing was unfolded and the iteration must be done.
|
|
|
|
* Returns false when the iteration should not be done.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
doAgentUnfolding (const System sys)
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
|
|
|
tl = sys->runs[run].rho;
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = deVar (tl->term);
|
|
|
|
if (realTermVariable (t))
|
|
|
|
{
|
|
|
|
// Hey, this role name is still a variable.
|
|
|
|
// We don't want that and so we unfold it as expected.
|
|
|
|
iterateAgentUnfolding (sys, t);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
//! Main recursive procedure for Arachne
|
|
|
|
int
|
|
|
|
iterate ()
|
|
|
|
{
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
flag = 1;
|
2007-05-18 13:06:29 +01:00
|
|
|
|
|
|
|
// check unfolding agent names
|
|
|
|
if (switches.agentUnfold > 0)
|
|
|
|
{
|
|
|
|
if (!doAgentUnfolding (sys))
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
if (!prune_theorems (sys))
|
|
|
|
{
|
|
|
|
if (!prune_claim_specifics (sys))
|
|
|
|
{
|
|
|
|
if (!prune_bounds (sys))
|
|
|
|
{
|
2007-05-18 13:06:29 +01:00
|
|
|
|
2006-03-19 12:59:26 +00:00
|
|
|
// Go and pick a binding for iteration
|
|
|
|
flag = iterateOneBinding ();
|
2004-08-19 14:09:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-27 16:02:33 +01:00
|
|
|
// Pruned because of bound!
|
2005-05-02 14:38:45 +01:00
|
|
|
sys->current_claim->complete = 0;
|
2004-08-19 11:46:27 +01:00
|
|
|
}
|
2004-08-11 22:04:52 +01:00
|
|
|
}
|
2004-08-11 13:08:10 +01:00
|
|
|
}
|
2004-08-18 19:22:59 +01:00
|
|
|
|
2004-08-18 19:41:49 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5) && !flag)
|
2004-08-18 19:22:59 +01:00
|
|
|
{
|
|
|
|
warning ("Flag has turned 0!");
|
|
|
|
}
|
2004-08-18 19:41:49 +01:00
|
|
|
#endif
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2004-08-11 22:04:52 +01:00
|
|
|
return flag;
|
2004-08-11 12:22:20 +01:00
|
|
|
}
|
|
|
|
|
2005-12-27 10:49:22 +00:00
|
|
|
//! Just before starting output of an attack.
|
|
|
|
//
|
|
|
|
//! A wrapper for the case in which we need to buffer attacks.
|
|
|
|
int
|
|
|
|
iterate_buffer_attacks (void)
|
|
|
|
{
|
2007-05-18 13:06:29 +01:00
|
|
|
if (useAttackBuffer ())
|
2005-12-27 10:49:22 +00:00
|
|
|
{
|
|
|
|
// We are pruning attacks, so they should go into a temporary file.
|
|
|
|
/*
|
|
|
|
* Set up the temporary file pointer
|
|
|
|
*/
|
|
|
|
char *buffer;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
// Push the old situation onto the stack
|
|
|
|
buffer = globalStream;
|
|
|
|
|
|
|
|
// Start stuff
|
|
|
|
attack_stream = NULL;
|
|
|
|
attackOutputStart ();
|
|
|
|
|
|
|
|
// Finally, proceed with iteration procedure
|
|
|
|
result = iterate ();
|
|
|
|
|
|
|
|
/* Now, if it has been set, we need to copy the output to the normal streams.
|
|
|
|
*/
|
|
|
|
fcopy (attack_stream, (FILE *) buffer);
|
|
|
|
|
|
|
|
// Close
|
|
|
|
fclose (attack_stream);
|
|
|
|
attack_stream = NULL;
|
|
|
|
|
|
|
|
// Restore
|
|
|
|
globalStream = buffer;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2007-05-18 13:06:29 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// No attack buffering, just output all of them
|
|
|
|
return iterate ();
|
|
|
|
}
|
2005-12-27 10:49:22 +00:00
|
|
|
}
|
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
//! Arachne single claim test
|
2007-01-06 14:45:29 +00:00
|
|
|
void
|
2006-08-08 15:50:28 +01:00
|
|
|
arachneClaimTest (Claimlist cl)
|
2006-08-01 07:04:01 +01:00
|
|
|
{
|
2006-08-08 15:50:28 +01:00
|
|
|
// others we simply test...
|
|
|
|
int run;
|
|
|
|
int newruns;
|
|
|
|
Protocol p;
|
|
|
|
Role r;
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
newruns = 0;
|
|
|
|
sys->current_claim = cl;
|
|
|
|
attack_length = INT_MAX;
|
|
|
|
attack_leastcost = INT_MAX;
|
|
|
|
cl->complete = 1;
|
|
|
|
p = (Protocol) cl->protocol;
|
|
|
|
r = (Role) cl->role;
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Testing Claim ");
|
|
|
|
termPrint (cl->type);
|
|
|
|
eprintf (" from ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (" at index %i.\n", cl->ev);
|
|
|
|
}
|
|
|
|
indentDepth++;
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
run = semiRunCreate (p, r);
|
|
|
|
newruns++;
|
|
|
|
{
|
|
|
|
int newgoals;
|
|
|
|
|
|
|
|
int realStart (void)
|
|
|
|
{
|
2006-08-01 07:04:01 +01:00
|
|
|
#ifdef DEBUG
|
2006-08-08 15:50:28 +01:00
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
printSemiState ();
|
|
|
|
}
|
2006-08-08 13:30:29 +01:00
|
|
|
#endif
|
2006-08-08 15:50:28 +01:00
|
|
|
return iterate_buffer_attacks ();
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
proof_suppose_run (run, 0, cl->ev + 1);
|
2012-04-25 08:53:07 +01:00
|
|
|
newgoals = add_recv_goals (run, 0, cl->ev + 1);
|
2006-08-01 07:04:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add initial knowledge node
|
|
|
|
*/
|
2006-08-08 15:50:28 +01:00
|
|
|
{
|
|
|
|
Termlist m0tl;
|
|
|
|
Term m0t;
|
|
|
|
int m0run;
|
|
|
|
|
|
|
|
m0tl = knowledgeSet (sys->know);
|
2007-05-18 13:06:29 +01:00
|
|
|
if (m0tl != NULL)
|
|
|
|
{
|
|
|
|
m0t = termlist_to_tuple (m0tl);
|
|
|
|
// eprintf("Initial intruder knowledge node for ");
|
|
|
|
// termPrint(m0t);
|
|
|
|
// eprintf("\n");
|
|
|
|
I_M->roledef->message = m0t;
|
|
|
|
m0run = semiRunCreate (INTRUDER, I_M);
|
|
|
|
newruns++;
|
|
|
|
proof_suppose_run (m0run, 0, 1);
|
|
|
|
sys->runs[m0run].height = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m0run = -1;
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
{
|
2006-08-01 07:04:01 +01:00
|
|
|
/**
|
|
|
|
* Add specific goal info and iterate algorithm
|
|
|
|
*/
|
2006-08-08 15:50:28 +01:00
|
|
|
add_claim_specifics (sys, cl,
|
2010-11-10 23:08:09 +00:00
|
|
|
roledef_shift (sys->runs[run].start, cl->ev),
|
|
|
|
realStart);
|
2006-08-08 15:50:28 +01:00
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
|
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
if (m0run != -1)
|
|
|
|
{
|
|
|
|
// remove initial knowledge node
|
|
|
|
termDelete (m0t);
|
|
|
|
termlistDelete (m0tl);
|
|
|
|
semiRunDestroy ();
|
|
|
|
newruns--;
|
|
|
|
}
|
2006-08-08 15:50:28 +01:00
|
|
|
}
|
|
|
|
// remove claiming run goals
|
|
|
|
goal_remove_last (newgoals);
|
|
|
|
semiRunDestroy ();
|
|
|
|
newruns--;
|
|
|
|
}
|
|
|
|
//! Destroy
|
|
|
|
while (sys->maxruns > 0 && newruns > 0)
|
|
|
|
{
|
|
|
|
semiRunDestroy ();
|
|
|
|
newruns--;
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
#ifdef DEBUG
|
2006-08-08 15:50:28 +01:00
|
|
|
if (sys->bindings != NULL)
|
|
|
|
{
|
|
|
|
error ("sys->bindings NOT empty after claim test.");
|
|
|
|
}
|
|
|
|
if (sys->maxruns != 0)
|
|
|
|
{
|
|
|
|
error ("%i undestroyed runs left after claim test.", sys->maxruns);
|
|
|
|
}
|
|
|
|
if (newruns != 0)
|
|
|
|
{
|
|
|
|
error ("Lost %i runs after claim test.", newruns);
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
#endif
|
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
//! Indent back
|
|
|
|
indentDepth--;
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2006-08-08 15:50:28 +01:00
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Proof complete for this claim.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Arachne single claim inspection
|
|
|
|
int
|
2011-01-04 14:17:52 +00:00
|
|
|
arachneClaim ()
|
2006-08-08 15:50:28 +01:00
|
|
|
{
|
2011-01-04 14:17:52 +00:00
|
|
|
Claimlist cl;
|
|
|
|
|
|
|
|
// Skip the dummy claims or SID markers
|
|
|
|
cl = sys->current_claim;
|
|
|
|
if (!isClaimSignal (cl))
|
2006-08-08 15:50:28 +01:00
|
|
|
{
|
|
|
|
// Some claims are always true!
|
|
|
|
if (!cl->alwaystrue)
|
|
|
|
{
|
|
|
|
// others we simply test...
|
|
|
|
arachneClaimTest (cl);
|
2006-08-01 07:04:01 +01:00
|
|
|
}
|
2006-08-01 07:10:12 +01:00
|
|
|
claimStatusReport (sys, cl);
|
2006-08-01 08:31:40 +01:00
|
|
|
if (switches.xml)
|
|
|
|
{
|
|
|
|
xmlOutClaim (sys, cl);
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
2007-01-06 14:45:29 +00:00
|
|
|
return false;
|
2006-08-01 07:04:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2007-01-06 14:45:29 +00:00
|
|
|
*
|
|
|
|
* @TODO what does it return? And is that -1 valid, if nothing is tested?
|
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-14 16:59:14 +01:00
|
|
|
Claimlist cl;
|
2006-08-01 07:04:01 +01:00
|
|
|
int count;
|
2004-08-12 12:35:13 +01:00
|
|
|
|
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");
|
2004-08-18 15:06:14 +01:00
|
|
|
return 1;
|
2004-08-13 21:56:51 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
int determine_encrypt_max (Protocol p, Role r, Roledef rd, int index)
|
|
|
|
{
|
|
|
|
int tlevel;
|
2005-05-01 14:32:50 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
tlevel = term_encryption_level (rd->message);
|
2005-04-18 06:51:25 +01:00
|
|
|
#ifdef DEBUG
|
2005-05-01 14:32:50 +01:00
|
|
|
if (DEBUGL (3))
|
2005-04-18 06:51:25 +01:00
|
|
|
{
|
|
|
|
eprintf ("Encryption level %i found for term ", tlevel);
|
|
|
|
termPrint (rd->message);
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-18 15:06:14 +01:00
|
|
|
if (tlevel > max_encryption_level)
|
|
|
|
max_encryption_level = tlevel;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-19 13:47:53 +01:00
|
|
|
/*
|
|
|
|
* set up claim role(s)
|
|
|
|
*/
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.runs == 0)
|
2004-08-27 19:26:19 +01:00
|
|
|
{
|
|
|
|
// No real checking.
|
2007-01-06 14:45:29 +00:00
|
|
|
return -1;
|
2004-08-27 19:26:19 +01:00
|
|
|
}
|
|
|
|
|
2004-08-19 13:47:53 +01:00
|
|
|
if (sys->maxruns > 0)
|
|
|
|
{
|
|
|
|
error ("Something is wrong, number of runs >0.");
|
|
|
|
}
|
|
|
|
|
2006-04-02 13:29:02 +01:00
|
|
|
sys->num_regular_runs = 0;
|
|
|
|
sys->num_intruder_runs = 0;
|
2004-08-19 13:47:53 +01:00
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
max_encryption_level = 0;
|
2005-04-18 06:51:25 +01:00
|
|
|
iterate_role_events (determine_encrypt_max);
|
2004-08-14 17:12:32 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (1))
|
|
|
|
{
|
2004-08-18 15:06:14 +01:00
|
|
|
eprintf ("Maximum encryption level: %i\n", max_encryption_level);
|
2004-08-14 17:12:32 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-08-13 21:56:51 +01:00
|
|
|
|
2005-04-18 06:51:25 +01:00
|
|
|
fixAgentKeylevels ();
|
|
|
|
|
2004-08-13 12:11:59 +01:00
|
|
|
indentDepth = 0;
|
2004-10-14 16:25:28 +01:00
|
|
|
proofDepth = 0;
|
2004-08-14 16:59:14 +01:00
|
|
|
cl = sys->claimlist;
|
2006-08-01 07:04:01 +01:00
|
|
|
count = 0;
|
2004-08-14 16:59:14 +01:00
|
|
|
while (cl != NULL)
|
|
|
|
{
|
2004-08-15 17:44:54 +01:00
|
|
|
/**
|
|
|
|
* Check each claim
|
|
|
|
*/
|
2011-01-04 14:17:52 +00:00
|
|
|
sys->current_claim = cl;
|
|
|
|
if (isClaimRelevant (cl)) // check for any filtered claims (switch)
|
2004-08-14 17:12:32 +01:00
|
|
|
{
|
2011-01-04 14:17:52 +00:00
|
|
|
if (arachneClaim ())
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
2004-08-14 20:19:23 +01:00
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
|
2004-08-14 16:59:14 +01:00
|
|
|
// next
|
|
|
|
cl = cl->next;
|
|
|
|
}
|
2006-08-01 07:04:01 +01:00
|
|
|
return count;
|
2004-08-11 10:51:17 +01:00
|
|
|
}
|
2005-08-12 13:13:50 +01:00
|
|
|
|
|
|
|
//! Construct knowledge set at some event, based on a semitrace.
|
|
|
|
/**
|
|
|
|
* This is a very 'stupid' algorithm; it is just there because GijsH
|
|
|
|
* requested it. It does in no way guarantee that this is the actual
|
|
|
|
* knowledge set at the given point. It simply gives an underapproximation,
|
|
|
|
* that will be correct in most cases. The main reason for this is that it
|
|
|
|
* completely ignores any information on unbound variables, and regards them
|
|
|
|
* as bound constants.
|
|
|
|
*
|
2012-04-25 08:53:07 +01:00
|
|
|
* Because everything is supposed to be bound, we conclude that even 'recv'
|
2005-08-12 13:13:50 +01:00
|
|
|
* events imply a certain knowledge.
|
|
|
|
*
|
|
|
|
* If aftercomplete is 0 or false, we actually check the ordering; otherwise we
|
|
|
|
* just assume the trace has finished.
|
|
|
|
*
|
|
|
|
* Use knowledgeDelete later to clean up.
|
|
|
|
*/
|
|
|
|
Knowledge
|
|
|
|
knowledgeAtArachne (const System sys, const int myrun, const int myindex,
|
|
|
|
const int aftercomplete)
|
|
|
|
{
|
|
|
|
Knowledge know;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
know = knowledgeDuplicate (sys->know); // duplicate initial knowledge
|
|
|
|
run = 0;
|
|
|
|
while (run < sys->maxruns)
|
|
|
|
{
|
|
|
|
int index;
|
2006-01-02 21:06:08 +00:00
|
|
|
int maxheight;
|
2005-08-12 13:13:50 +01:00
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
rd = sys->runs[run].start;
|
2006-01-02 21:06:08 +00:00
|
|
|
maxheight = sys->runs[run].height;
|
|
|
|
if (run == myrun && myindex > maxheight)
|
2005-08-12 13:13:50 +01:00
|
|
|
{
|
|
|
|
// local run index can override real step
|
2006-01-02 21:06:08 +00:00
|
|
|
maxheight = myindex;
|
2005-08-12 13:13:50 +01:00
|
|
|
}
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
while (rd != NULL && index < maxheight)
|
2005-08-12 13:13:50 +01:00
|
|
|
{
|
|
|
|
// Check whether this event precedes myevent
|
2006-02-26 15:00:58 +00:00
|
|
|
if (aftercomplete || isDependEvent (run, index, myrun, myindex))
|
2005-08-12 13:13:50 +01:00
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
// If it is a send (trivial) or a recv (remarkable, but true
|
2005-08-12 13:13:50 +01:00
|
|
|
// because of bindings) we can add the message and the agents to
|
|
|
|
// the knowledge.
|
2012-04-25 08:53:07 +01:00
|
|
|
if (rd->type == SEND || rd->type == RECV)
|
2005-08-12 13:13:50 +01:00
|
|
|
{
|
|
|
|
knowledgeAddTerm (know, rd->message);
|
|
|
|
if (rd->from != NULL)
|
|
|
|
knowledgeAddTerm (know, rd->from);
|
|
|
|
if (rd->to != NULL)
|
|
|
|
knowledgeAddTerm (know, rd->to);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not ordered before anymore, so we skip to the next run.
|
|
|
|
rd = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run++;
|
|
|
|
}
|
|
|
|
return know;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Determine whether a term is trivially known at some event in a partially ordered structure.
|
|
|
|
/**
|
|
|
|
* Important: read disclaimer at knowledgeAtArachne()
|
|
|
|
*
|
|
|
|
* Returns true iff the term is certainly known at that point in the
|
|
|
|
* semitrace.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isTriviallyKnownAtArachne (const System sys, const Term t, const int run,
|
|
|
|
const int index)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
Knowledge knowset;
|
|
|
|
|
|
|
|
knowset = knowledgeAtArachne (sys, run, index, false);
|
|
|
|
result = inKnowledge (knowset, t);
|
|
|
|
knowledgeDelete (knowset);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Determine whether a term is trivially known after execution of some partially ordered structure.
|
|
|
|
/**
|
|
|
|
* Important: read disclaimer at knowledgeAtArachne()
|
|
|
|
*
|
|
|
|
* Returns true iff the term is certainly known after all events in the
|
|
|
|
* semitrace.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isTriviallyKnownAfterArachne (const System sys, const Term t, const int run,
|
|
|
|
const int index)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
Knowledge knowset;
|
|
|
|
|
|
|
|
knowset = knowledgeAtArachne (sys, run, index, true);
|
|
|
|
result = inKnowledge (knowset, t);
|
|
|
|
knowledgeDelete (knowset);
|
|
|
|
return result;
|
|
|
|
}
|
2007-09-17 15:53:37 +01:00
|
|
|
|
|
|
|
//! Mark that we have no full proof
|
|
|
|
/**
|
|
|
|
* Provides an interface for marking incomplete proofs.
|
|
|
|
* Currently used in mgusubterm in mgu.c
|
|
|
|
*/
|
|
|
|
void
|
2007-09-18 14:36:11 +01:00
|
|
|
markNoFullProof (const Term tbig, const Term tsmall)
|
2007-09-17 15:53:37 +01:00
|
|
|
{
|
2007-09-18 14:36:11 +01:00
|
|
|
// Comment in proof
|
|
|
|
if (switches.output == PROOF)
|
|
|
|
{
|
|
|
|
indentPrint ();
|
|
|
|
eprintf ("Note: the pattern set will be incomplete, because ");
|
|
|
|
termPrint (tbig);
|
|
|
|
eprintf (" allows for infinitely many ways to subtermUnify ");
|
|
|
|
termPrint (tsmall);
|
|
|
|
eprintf (".\n");
|
|
|
|
}
|
2007-09-17 15:53:37 +01:00
|
|
|
sys->current_claim->complete = false;
|
|
|
|
}
|