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-04-23 11:58:43 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2006-02-21 20:29:05 +00:00
|
|
|
#include <limits.h>
|
2006-08-08 13:30:29 +01:00
|
|
|
#include <string.h>
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "tac.h"
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "termlist.h"
|
2004-08-27 13:36:23 +01:00
|
|
|
#include "label.h"
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "knowledge.h"
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "symbol.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "compiler.h"
|
2005-06-07 16:02:27 +01:00
|
|
|
#include "switches.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "specialterm.h"
|
2006-02-26 15:00:58 +00:00
|
|
|
#include "warshall.h"
|
2006-02-21 20:29:05 +00:00
|
|
|
#include "hidelevel.h"
|
2006-03-15 08:33:09 +00:00
|
|
|
#include "debug.h"
|
2006-07-27 12:55:24 +01:00
|
|
|
#include "intruderknowledge.h"
|
2007-01-06 14:45:29 +00:00
|
|
|
#include "error.h"
|
2007-01-29 13:15:35 +00:00
|
|
|
#include "mgu.h"
|
2014-03-18 13:53:51 +00:00
|
|
|
#include "type.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Simple sys pointer as a global. Yields cleaner code although it's against programming standards.
|
|
|
|
It is declared as static to hide it from the outside world, and to indicate its status.
|
|
|
|
Other modules will just see a nicely implemented sys parameter of compile, so we can always change
|
|
|
|
it later if somebody complains. Which they won't.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static System sys;
|
2004-08-09 10:42:58 +01:00
|
|
|
static Tac tac_root;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-27 11:08:03 +01:00
|
|
|
/*
|
|
|
|
* Declaration from system.c
|
|
|
|
*/
|
|
|
|
extern int protocolCount;
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/*
|
|
|
|
Forward declarations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void tacProcess (Tac tc);
|
|
|
|
void levelInit (void);
|
|
|
|
void levelDone (void);
|
|
|
|
Term levelFind (Symbol s, int i);
|
|
|
|
Term symbolFind (Symbol s);
|
|
|
|
Term tacTerm (Tac tc);
|
|
|
|
Termlist tacTermlist (Tac tc);
|
2004-08-12 12:55:03 +01:00
|
|
|
Term levelDeclare (Symbol s, int isVar, int level);
|
2004-08-12 10:14:31 +01:00
|
|
|
void compute_role_variables (const System sys, Protocol p, Role r);
|
2006-07-27 11:44:12 +01:00
|
|
|
void roleKnows (Tac tc);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Global stuff
|
|
|
|
*/
|
|
|
|
|
2004-06-14 10:15:42 +01:00
|
|
|
//! Levels of scope: global, protocol, role
|
2004-04-23 11:58:43 +01:00
|
|
|
#define MAXLEVELS 3
|
|
|
|
static Termlist leveltl[MAXLEVELS];
|
|
|
|
static int level;
|
|
|
|
static int maxruns;
|
|
|
|
static Protocol thisProtocol;
|
|
|
|
static Role thisRole;
|
|
|
|
|
2004-08-09 10:42:58 +01:00
|
|
|
//! Init terms and such
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-08-09 10:42:58 +01:00
|
|
|
compilerInit (const System mysys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* transfer to global static variable */
|
|
|
|
sys = mysys;
|
|
|
|
/* init levels */
|
|
|
|
for (i = 0; i < MAXLEVELS; i++)
|
|
|
|
leveltl[i] = NULL;
|
|
|
|
level = -1;
|
|
|
|
levelInit ();
|
|
|
|
|
2005-06-16 15:10:07 +01:00
|
|
|
/* create special terms */
|
|
|
|
specialTermInit (sys);
|
2004-08-09 10:42:58 +01:00
|
|
|
}
|
|
|
|
|
2004-08-12 12:55:03 +01:00
|
|
|
//! Make a global constant
|
2004-08-15 15:07:34 +01:00
|
|
|
Term
|
|
|
|
makeGlobalConstant (const char *s)
|
2004-08-12 12:55:03 +01:00
|
|
|
{
|
2004-08-15 15:07:34 +01:00
|
|
|
return levelDeclare (symbolSysConst (s), 0, 0);
|
2004-08-12 12:55:03 +01:00
|
|
|
}
|
|
|
|
|
2004-08-18 15:06:14 +01:00
|
|
|
//! Make a global variable
|
|
|
|
Term
|
|
|
|
makeGlobalVariable (const char *s)
|
|
|
|
{
|
|
|
|
return levelDeclare (symbolSysConst (s), 1, 0);
|
|
|
|
}
|
|
|
|
|
2004-08-09 10:42:58 +01:00
|
|
|
//! Clean up afterwards
|
|
|
|
void
|
|
|
|
compilerDone (void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
//! Compute recv variables for a role
|
2005-12-27 13:44:12 +00:00
|
|
|
Termlist
|
2012-04-25 08:53:07 +01:00
|
|
|
compute_recv_variables (const Role r)
|
2005-12-27 13:44:12 +00:00
|
|
|
{
|
2018-10-14 16:39:29 +01:00
|
|
|
Termlist tl = NULL;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = r->roledef;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
if (rd->type == RECV)
|
2018-10-15 14:40:07 +01:00
|
|
|
{
|
2018-10-14 16:39:29 +01:00
|
|
|
tl = termlistAddVariables (tl, rd->from);
|
|
|
|
tl = termlistAddVariables (tl, rd->to);
|
|
|
|
tl = termlistAddVariables (tl, rd->message);
|
2018-10-15 14:40:07 +01:00
|
|
|
}
|
2018-10-14 16:39:29 +01:00
|
|
|
rd = rd->next;
|
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
return tl;
|
|
|
|
}
|
|
|
|
|
2004-08-09 10:42:58 +01:00
|
|
|
/* ------------------------------------------------------------------- */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 10:42:58 +01:00
|
|
|
//! Compile the tac into the system
|
|
|
|
/**
|
|
|
|
*@todo Currently, the semantics assume all labels are globally unique, but this is not enforced yet. There should be some automatic renaming when compositing protocols.
|
|
|
|
*\sa oki_nisynch
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
compile (Tac tc, int maxrunsset)
|
|
|
|
{
|
|
|
|
/* Init globals */
|
|
|
|
maxruns = maxrunsset;
|
|
|
|
tac_root = tc;
|
2004-08-12 10:14:31 +01:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* process the tac */
|
2004-08-09 10:42:58 +01:00
|
|
|
tacProcess (tac_root);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
/* Preprocess the result */
|
|
|
|
preprocess (sys);
|
2004-08-20 20:16:56 +01:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* cleanup */
|
|
|
|
levelDone ();
|
|
|
|
}
|
|
|
|
|
2004-06-14 10:15:42 +01:00
|
|
|
//! Print error line number.
|
|
|
|
/**
|
|
|
|
*@todo This is obsolete, and should all go to stderr
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
errorTac (int lineno)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
|
|
|
eprintf (" on line %i.\n", lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2004-06-14 10:15:42 +01:00
|
|
|
//! Enter nested scope.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
levelInit (void)
|
|
|
|
{
|
|
|
|
level++;
|
|
|
|
if (level >= MAXLEVELS)
|
|
|
|
{
|
2004-06-13 22:42:29 +01:00
|
|
|
error ("level is increased too much.");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
leveltl[level] = NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-14 10:15:42 +01:00
|
|
|
//! Leave nested scope.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
levelDone (void)
|
|
|
|
{
|
|
|
|
if (level < 0)
|
|
|
|
{
|
2004-06-13 22:42:29 +01:00
|
|
|
error ("level is decreased too much.");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
leveltl[level] = NULL;
|
|
|
|
level--;
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
levelDeclare (Symbol s, int isVar, int level)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = levelFind (s, level);
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
/* new! */
|
|
|
|
if (isVar)
|
|
|
|
{
|
|
|
|
t = makeTermType (VARIABLE, s, -(level + 1));
|
|
|
|
sys->variables = termlistAdd (sys->variables, t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = makeTermType (GLOBAL, s, -(level + 1));
|
|
|
|
}
|
|
|
|
leveltl[level] = termlistAdd (leveltl[level], t);
|
|
|
|
|
|
|
|
/* add to relevant list */
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
sys->locals = termlistAdd (sys->locals, t);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
thisProtocol->locals = termlistAdd (thisProtocol->locals, t);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
thisRole->locals = termlistAdd (thisRole->locals, t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2005-12-27 13:44:12 +00:00
|
|
|
//! Generate a term from a symbol
|
2004-04-23 11:58:43 +01:00
|
|
|
Term
|
|
|
|
symbolDeclare (Symbol s, int isVar)
|
|
|
|
{
|
|
|
|
return levelDeclare (s, isVar, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
levelFind (Symbol s, int level)
|
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
|
|
|
tl = leveltl[level];
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
if (isTermLeaf (tl->term))
|
|
|
|
{
|
2004-11-16 12:07:55 +00:00
|
|
|
if (TermSymb (tl->term) == s)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
return tl->term;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
symbolFind (Symbol s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
i = level;
|
|
|
|
while (i >= 0)
|
|
|
|
{
|
|
|
|
t = levelFind (s, i);
|
|
|
|
if (t != NULL)
|
|
|
|
return t;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-09 10:42:58 +01:00
|
|
|
//! Yield a basic global constant term (we suppose it exists) or NULL, given a string
|
2004-08-09 11:05:58 +01:00
|
|
|
Term
|
|
|
|
findGlobalConstant (const char *s)
|
2004-08-09 10:42:58 +01:00
|
|
|
{
|
|
|
|
return levelFind (lookup (s), 0);
|
|
|
|
}
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
defineUsertype (Tac tcdu)
|
|
|
|
{
|
|
|
|
Tac tc;
|
|
|
|
Term t;
|
|
|
|
Term tfind;
|
|
|
|
|
2004-05-26 09:26:40 +01:00
|
|
|
tc = tcdu->t1.tac;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
if (tc == NULL)
|
|
|
|
{
|
2004-06-13 22:42:29 +01:00
|
|
|
error ("Empty usertype declaration on line %i.", tcdu->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
while (tc != NULL && tc->op == TAC_STRING)
|
|
|
|
{
|
|
|
|
/* check whether this term is already declared in the same way
|
|
|
|
* (i.e. as a type) */
|
|
|
|
|
2004-05-26 09:26:40 +01:00
|
|
|
tfind = levelFind (tc->t1.sym, 0);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (tfind == NULL)
|
|
|
|
{
|
|
|
|
/* this is what we expected: this type is not declared yet */
|
2004-05-26 09:26:40 +01:00
|
|
|
t = levelDeclare (tc->t1.sym, 0, 0);
|
2004-04-23 11:58:43 +01:00
|
|
|
t->stype = termlistAdd (NULL, TERM_Type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* oi!, there's already one. Let's hope is is a type too. */
|
|
|
|
if (inTermlist (tfind->stype, TERM_Type))
|
|
|
|
{
|
2006-08-08 13:35:43 +01:00
|
|
|
if (switches.check)
|
|
|
|
{
|
|
|
|
/* phew. warn anyway */
|
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: double declaration of usertype ");
|
|
|
|
termPrint (tfind);
|
|
|
|
eprintf ("\n");
|
|
|
|
globalError--;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* that's not right! */
|
2004-08-09 11:05:58 +01:00
|
|
|
error
|
|
|
|
("Conflicting definitions in usertype definition on line %i.",
|
|
|
|
tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tc = tc->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-27 13:44:12 +00:00
|
|
|
//! Declare a variable at the current level
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
levelTacDeclaration (Tac tc, int isVar)
|
|
|
|
{
|
|
|
|
Tac tscan;
|
|
|
|
Termlist typetl = NULL;
|
|
|
|
Term t;
|
2006-07-27 12:55:24 +01:00
|
|
|
int isAgent;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2005-12-27 13:44:12 +00:00
|
|
|
// tscan contains the type list (as is const x,z: Term or var y: Term,Ding)
|
2004-05-26 09:26:40 +01:00
|
|
|
tscan = tc->t2.tac;
|
2004-04-23 11:58:43 +01:00
|
|
|
if (!isVar && tscan->next != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
error ("Multiple type definition for constant on line %i.",
|
|
|
|
tscan->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
// scan the whole type info list
|
2004-04-23 11:58:43 +01:00
|
|
|
while (tscan != NULL && tscan->op == TAC_STRING)
|
|
|
|
{
|
|
|
|
/* apparently there is type info, termlist? */
|
2004-05-26 09:26:40 +01:00
|
|
|
t = levelFind (tscan->t1.sym, 0);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
/* not declared, that is unacceptable. */
|
2004-08-09 11:05:58 +01:00
|
|
|
error ("Undeclared type on line %i.", tscan->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!inTermlist (t->stype, TERM_Type))
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
error ("Non-type constant in type declaration on line %i.",
|
|
|
|
tscan->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
typetl = termlistAdd (typetl, t);
|
|
|
|
tscan = tscan->next;
|
|
|
|
}
|
2006-07-27 12:55:24 +01:00
|
|
|
/* check whether the type list contains the agent type */
|
|
|
|
isAgent = inTermlist (typetl, TERM_Agent);
|
|
|
|
|
2005-12-27 13:44:12 +00:00
|
|
|
/* parse all constants and vars, because a single declaration can contain multiple ones */
|
2004-05-26 09:26:40 +01:00
|
|
|
tscan = tc->t1.tac;
|
2004-04-23 11:58:43 +01:00
|
|
|
while (tscan != NULL)
|
|
|
|
{
|
2005-12-27 13:44:12 +00:00
|
|
|
/* declare this variable/constant with the previously derived type list */
|
2004-05-26 09:26:40 +01:00
|
|
|
t = symbolDeclare (tscan->t1.sym, isVar);
|
2004-04-23 11:58:43 +01:00
|
|
|
t->stype = typetl;
|
2005-12-28 11:50:17 +00:00
|
|
|
/* local to the role? */
|
|
|
|
if (level == 2)
|
2005-12-27 13:44:12 +00:00
|
|
|
{
|
2005-12-28 11:50:17 +00:00
|
|
|
if (isVar)
|
|
|
|
{
|
|
|
|
/* it is a role variable, so add it to the nicely declared variables */
|
|
|
|
thisRole->declaredvars =
|
|
|
|
termlistAdd (thisRole->declaredvars, t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* it is a role constant, so add it to the nicely declared constants */
|
|
|
|
thisRole->declaredconsts =
|
|
|
|
termlistAdd (thisRole->declaredconsts, t);
|
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
}
|
2006-02-21 20:29:05 +00:00
|
|
|
else if (level == 0)
|
|
|
|
{
|
|
|
|
sys->globalconstants = termlistAdd (sys->globalconstants, t);
|
2006-07-27 12:55:24 +01:00
|
|
|
if (isAgent)
|
|
|
|
{
|
|
|
|
sys->agentnames = termlistAdd (sys->agentnames, t);
|
|
|
|
}
|
2006-02-21 20:29:05 +00:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
tscan = tscan->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-29 17:20:45 +00:00
|
|
|
//! Get last role def
|
|
|
|
Roledef
|
|
|
|
getLastRoledef (Roledef rd)
|
|
|
|
{
|
|
|
|
if (rd != NULL)
|
|
|
|
{
|
|
|
|
while (rd->next != NULL)
|
|
|
|
{
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Mark last roledef lineno
|
|
|
|
void
|
|
|
|
markLastRoledef (Roledef rd, const int lineno)
|
|
|
|
{
|
|
|
|
rd = getLastRoledef (rd);
|
|
|
|
rd->lineno = lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
//! Check whether a claim label already occurs
|
|
|
|
int
|
|
|
|
isClaimlabelUsed (const System sys, const Term label)
|
|
|
|
{
|
|
|
|
Claimlist cl;
|
|
|
|
|
|
|
|
if (label == NULL)
|
|
|
|
{
|
|
|
|
/* we assign this 'occurs' because it is an invalid label */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
cl = sys->claimlist;
|
|
|
|
while (cl != NULL)
|
|
|
|
{
|
|
|
|
if (isTermEqual (cl->label, label))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
cl = cl->next;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Generate a fresh claim label
|
|
|
|
Term
|
2006-08-08 14:00:16 +01:00
|
|
|
generateFreshClaimlabel (const System sys, const Protocol protocol,
|
2011-01-27 13:12:51 +00:00
|
|
|
const Role role, const Term claim, const int n)
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
2006-08-08 14:00:16 +01:00
|
|
|
Term label;
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
/* Simply use the role as a prefix */
|
2006-08-08 14:00:16 +01:00
|
|
|
label = freshTermPrefix (role->nameterm);
|
|
|
|
label = makeTermTuple (protocol->nameterm, label);
|
|
|
|
return label;
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
|
2008-08-20 16:20:32 +01:00
|
|
|
//! Boolean sanity wrapper around C low level madness
|
|
|
|
int
|
|
|
|
isStringEqual (const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
return (strcmp (s1, s2) == 0);
|
|
|
|
}
|
|
|
|
|
2012-05-01 15:37:18 +01:00
|
|
|
//! Check sanity of the parameters occurring in a claim
|
|
|
|
/**
|
|
|
|
* Check if all variables have been received before.
|
|
|
|
* If not, aborts with error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
checkParameterGround (Claimlist cl)
|
|
|
|
{
|
|
|
|
Termlist claimvars;
|
|
|
|
Termlist recvvars;
|
|
|
|
Termlist cli;
|
|
|
|
|
|
|
|
/* Compute received variables and those occurring in the claim parameter */
|
|
|
|
claimvars = termlistAddVariables (NULL, cl->parameter);
|
|
|
|
recvvars = compute_recv_variables (thisRole);
|
|
|
|
|
|
|
|
cli = claimvars;
|
|
|
|
while (cli != NULL)
|
|
|
|
{
|
|
|
|
if (!inTermlist (thisProtocol->rolenames, cli->term))
|
|
|
|
{
|
|
|
|
/* only if it is not a role */
|
|
|
|
if (!inTermlist (recvvars, cli->term))
|
|
|
|
{
|
|
|
|
/* this claimvar does not occur in the recvs? */
|
|
|
|
/* abort with error */
|
|
|
|
error_pre ();
|
|
|
|
globalError++;
|
|
|
|
eprintf ("Claim of role ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf (" contains a variable ");
|
|
|
|
termPrint (cli->term);
|
|
|
|
eprintf
|
|
|
|
(" which is not initialized before (i.e., not received), on line %i.",
|
|
|
|
cl->lineno);
|
|
|
|
globalError--;
|
|
|
|
error_post ("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cli = cli->next;
|
|
|
|
}
|
|
|
|
termlistDelete (claimvars);
|
|
|
|
termlistDelete (recvvars);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check if claim is of certain type, then check if meets parameter range, if not abort with error
|
|
|
|
void
|
|
|
|
checkParameterRange (const Claimlist cl, const Term claimtype, int minargs,
|
|
|
|
int maxargs)
|
|
|
|
{
|
|
|
|
Termlist params;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
if (cl->type != claimtype)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
params = tuple_to_termlist (cl->parameter);
|
|
|
|
num = termlistLength (params);
|
|
|
|
|
|
|
|
if (minargs == -1)
|
|
|
|
{
|
|
|
|
minargs = num - 1;
|
|
|
|
}
|
|
|
|
if (maxargs == -1)
|
|
|
|
{
|
|
|
|
maxargs = num + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((num < minargs) || (num > maxargs))
|
|
|
|
{
|
|
|
|
error_pre ();
|
|
|
|
globalError++;
|
|
|
|
termPrint (cl->type);
|
|
|
|
eprintf (" claim of role ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf (" on line %i", cl->lineno);
|
|
|
|
if (maxargs == 0)
|
|
|
|
{
|
|
|
|
error_post (" does not require any arguments.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (num < minargs)
|
|
|
|
{
|
|
|
|
eprintf (" requires at least");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eprintf (" requires at most");
|
|
|
|
}
|
|
|
|
error_post (" %i arguments.", maxargs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
termlistDelete (params);
|
|
|
|
}
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
//! Create a claim and add it to the claims list, and add the role event.
|
|
|
|
Claimlist
|
|
|
|
claimCreate (const System sys, const Protocol protocol, const Role role,
|
2007-01-29 17:20:45 +00:00
|
|
|
const Term claim, Term label, const Term msg, const int lineno)
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
|
|
|
Claimlist cl;
|
2011-01-27 13:12:51 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = roledef_length (role->roledef);
|
2005-12-28 11:50:17 +00:00
|
|
|
|
2006-08-08 14:00:16 +01:00
|
|
|
/* generate full unique label */
|
|
|
|
/* is the label empty or used? */
|
|
|
|
if (label == NULL || isClaimlabelUsed (sys, label))
|
|
|
|
{
|
|
|
|
/* simply generate a fresh one */
|
2011-01-27 13:12:51 +00:00
|
|
|
label = generateFreshClaimlabel (sys, protocol, role, claim, len);
|
2006-08-08 14:00:16 +01:00
|
|
|
}
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
// Assert: label is unique, add claimlist info
|
2006-03-08 13:58:46 +00:00
|
|
|
cl = malloc (sizeof (struct claimlist));
|
2005-12-28 11:50:17 +00:00
|
|
|
cl->type = claim;
|
|
|
|
cl->label = label;
|
|
|
|
cl->parameter = msg;
|
|
|
|
cl->protocol = thisProtocol;
|
|
|
|
cl->rolename = role->nameterm;
|
|
|
|
cl->role = role;
|
|
|
|
cl->roledef = NULL;
|
|
|
|
cl->count = 0;
|
|
|
|
cl->complete = 0;
|
|
|
|
cl->timebound = 0;
|
|
|
|
cl->failed = 0;
|
2006-02-22 08:24:29 +00:00
|
|
|
cl->states = 0;
|
2005-12-28 11:50:17 +00:00
|
|
|
cl->prec = NULL;
|
|
|
|
cl->roles = NULL;
|
|
|
|
cl->alwaystrue = false;
|
|
|
|
cl->warnings = false;
|
2007-01-29 17:20:45 +00:00
|
|
|
cl->lineno = lineno;
|
2006-08-07 10:56:55 +01:00
|
|
|
|
|
|
|
/* add the claim to the end of the current list */
|
|
|
|
cl->next = NULL;
|
|
|
|
if (sys->claimlist == NULL)
|
|
|
|
{
|
|
|
|
sys->claimlist = cl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Claimlist cl2;
|
|
|
|
|
|
|
|
cl2 = sys->claimlist;
|
|
|
|
while (cl2->next != NULL)
|
|
|
|
{
|
|
|
|
cl2 = cl2->next;
|
|
|
|
}
|
|
|
|
cl2->next = cl;
|
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
|
|
|
|
/* add the role event */
|
|
|
|
role->roledef = roledefAdd (role->roledef, CLAIM, label,
|
|
|
|
role->nameterm, claim, msg, cl);
|
2007-01-29 17:20:45 +00:00
|
|
|
markLastRoledef (role->roledef, lineno);
|
2005-12-28 11:50:17 +00:00
|
|
|
|
|
|
|
/* possible special handlers for each claim */
|
|
|
|
|
2012-05-01 15:37:18 +01:00
|
|
|
if ((claim == CLAIM_Secret) || (claim == CLAIM_SKR))
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
|
|
|
Termlist claimvars;
|
2012-04-25 08:53:07 +01:00
|
|
|
Termlist recvvars;
|
2012-05-01 15:37:18 +01:00
|
|
|
Termlist cli;
|
2005-12-28 11:50:17 +00:00
|
|
|
|
|
|
|
/* now check whether the claim contains variables that can actually be influenced by the intruder */
|
|
|
|
|
2012-05-01 15:37:18 +01:00
|
|
|
claimvars = termlistAddVariables (NULL, cl->parameter);
|
2012-04-25 08:53:07 +01:00
|
|
|
recvvars = compute_recv_variables (thisRole);
|
2012-05-01 15:37:18 +01:00
|
|
|
cli = claimvars;
|
|
|
|
while (cli != NULL)
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
2012-05-01 15:37:18 +01:00
|
|
|
if (!inTermlist (thisProtocol->rolenames, cli->term))
|
2005-12-28 11:50:17 +00:00
|
|
|
{
|
2007-05-18 13:06:29 +01:00
|
|
|
/* only if it is not a role */
|
2012-05-01 15:37:18 +01:00
|
|
|
if (!inTermlist (recvvars, cli->term))
|
2007-05-18 13:06:29 +01:00
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
/* this claimvar does not occur in the recvs? */
|
2007-05-18 13:06:29 +01:00
|
|
|
/* then we should ignore it later */
|
|
|
|
cl->alwaystrue = true;
|
|
|
|
cl->warnings = true;
|
2005-12-28 14:25:06 +00:00
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
/* show a warning for this */
|
|
|
|
globalError++;
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
|
|
|
eprintf ("Secrecy claim of role ");
|
2007-05-18 13:06:29 +01:00
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf (" contains a variable ");
|
2012-05-01 15:37:18 +01:00
|
|
|
termPrint (cli->term);
|
2007-05-18 13:06:29 +01:00
|
|
|
eprintf
|
2012-05-01 15:37:18 +01:00
|
|
|
(" which is never received; therefore the claim will be true.\n");
|
2007-05-18 13:06:29 +01:00
|
|
|
globalError--;
|
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
2012-05-01 15:37:18 +01:00
|
|
|
cli = cli->next;
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
2007-05-18 13:06:29 +01:00
|
|
|
termlistDelete (claimvars);
|
2012-04-25 08:53:07 +01:00
|
|
|
termlistDelete (recvvars);
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
2012-05-01 15:37:18 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If it is NOT a SECRET claim, then check parameters are ground */
|
|
|
|
checkParameterGround (cl);
|
|
|
|
}
|
2012-04-25 14:30:15 +01:00
|
|
|
|
|
|
|
if ((claim == CLAIM_Commit) || (claim == CLAIM_Running))
|
|
|
|
{
|
|
|
|
/* Check that Claim syntax is role,commit,role,data
|
|
|
|
*/
|
|
|
|
Termlist params;
|
|
|
|
|
|
|
|
params = tuple_to_termlist (cl->parameter);
|
|
|
|
|
|
|
|
if (termlistLength (params) < 2)
|
|
|
|
{
|
|
|
|
/* yield error */
|
|
|
|
globalError++;
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
termPrint (claim);
|
|
|
|
eprintf (" claim of role ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf
|
|
|
|
(" requires four arguments. Please specify both the target role and the data to agree on, as in:\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf (" claim(R, Commit, R', data )\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf ("and\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf (" claim(R', Running, R, data ).\n");
|
|
|
|
globalError--;
|
|
|
|
error
|
|
|
|
("Incorrect number of arguments in Commit/Running claim at line %i.",
|
|
|
|
lineno);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The length is at least two, so we can obtain the first element
|
|
|
|
Term targetrole;
|
|
|
|
|
|
|
|
targetrole = params->term;
|
|
|
|
if (!inTermlist (protocol->rolenames, targetrole))
|
|
|
|
{
|
|
|
|
/* yield error */
|
|
|
|
globalError++;
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
termPrint (claim);
|
|
|
|
eprintf (" claim of role ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf (" specifies the target role to be '");
|
|
|
|
termPrint (targetrole);
|
|
|
|
eprintf ("', which is not a role name.\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf ("Please use:\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf (" claim(R, Commit, R', data )\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf ("and\n");
|
2012-05-01 15:37:18 +01:00
|
|
|
warning_pre ();
|
2012-04-25 14:30:15 +01:00
|
|
|
eprintf (" claim(R', Running, R, data ).\n");
|
|
|
|
globalError--;
|
|
|
|
error
|
|
|
|
("Incorrect target role in Commit/Running claim at line %i.",
|
|
|
|
lineno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-01 15:37:18 +01:00
|
|
|
checkParameterRange (cl, CLAIM_Secret, 1, -1);
|
|
|
|
checkParameterRange (cl, CLAIM_SKR, 1, -1);
|
2013-05-23 15:38:44 +01:00
|
|
|
checkParameterRange (cl, CLAIM_Alive, 0, 1);
|
|
|
|
checkParameterRange (cl, CLAIM_Weakagree, 0, 1);
|
2012-05-01 15:37:18 +01:00
|
|
|
checkParameterRange (cl, CLAIM_Nisynch, 0, 0);
|
|
|
|
checkParameterRange (cl, CLAIM_Niagree, 0, 0);
|
|
|
|
checkParameterRange (cl, CLAIM_Reachable, 0, 0);
|
|
|
|
checkParameterRange (cl, CLAIM_SID, 1, -1);
|
2012-04-25 14:30:15 +01:00
|
|
|
|
2007-01-06 14:45:29 +00:00
|
|
|
return cl;
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 10:28:40 +00:00
|
|
|
//! Parse a match event, and add role definitions for it
|
|
|
|
/**
|
|
|
|
* Implemented as pure syntactic sugar:
|
|
|
|
*
|
|
|
|
* match(pattern,term)
|
|
|
|
*
|
|
|
|
* is essentially replaced by:
|
|
|
|
*
|
|
|
|
* fresh XX;
|
|
|
|
* send( {term}XX );
|
|
|
|
* recv( {pattern}XX );
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
matchEvent (Tac tc)
|
|
|
|
{
|
|
|
|
Term myrole;
|
|
|
|
Term msg1, msg2;
|
|
|
|
Term tvar;
|
|
|
|
Term mmsg;
|
|
|
|
Term mpat;
|
|
|
|
Symbol nsymb;
|
|
|
|
Term label1;
|
|
|
|
Labelinfo linfo;
|
|
|
|
|
|
|
|
/* Create fresh Nonce variable */
|
2013-06-19 20:51:52 +01:00
|
|
|
nsymb = symbolNextFree (TermSymb (TERM_Hidden));
|
|
|
|
tvar = symbolDeclare (nsymb, false);
|
2012-11-21 10:28:40 +00:00
|
|
|
//tvar->stype = termlistAdd(NULL,TERM_Nonce);
|
|
|
|
|
|
|
|
/* Make the concrete messages */
|
|
|
|
mpat = tacTerm (tc->t1.tac);
|
|
|
|
mmsg = tacTerm (tc->t2.tac);
|
2013-06-19 20:51:52 +01:00
|
|
|
msg1 = makeTermEncrypt (mmsg, tvar);
|
|
|
|
msg2 = makeTermEncrypt (mpat, tvar);
|
2012-11-21 10:28:40 +00:00
|
|
|
|
|
|
|
/* Declare the const */
|
2013-06-19 20:51:52 +01:00
|
|
|
thisRole->declaredconsts = termlistAdd (thisRole->declaredconsts, tvar);
|
2012-11-21 10:28:40 +00:00
|
|
|
|
|
|
|
/* And send & recv combo (implementing the syntactic sugar) */
|
2013-06-19 20:51:52 +01:00
|
|
|
label1 = freshTermPrefix (LABEL_Match);
|
2012-11-21 10:28:40 +00:00
|
|
|
linfo = label_create (label1, thisProtocol);
|
|
|
|
sys->labellist = list_append (sys->labellist, linfo);
|
|
|
|
myrole = thisRole->nameterm;
|
|
|
|
|
|
|
|
/* add send event */
|
2013-06-19 20:51:52 +01:00
|
|
|
thisRole->roledef =
|
|
|
|
roledefAdd (thisRole->roledef, SEND, label1, myrole, myrole, msg1, NULL);
|
2012-11-21 10:28:40 +00:00
|
|
|
markLastRoledef (thisRole->roledef, tc->lineno);
|
|
|
|
/* add recv event */
|
2013-06-19 20:51:52 +01:00
|
|
|
thisRole->roledef =
|
|
|
|
roledefAdd (thisRole->roledef, RECV, label1, myrole, myrole, msg2, NULL);
|
2012-11-21 10:28:40 +00:00
|
|
|
markLastRoledef (thisRole->roledef, tc->lineno);
|
|
|
|
}
|
|
|
|
|
2012-11-21 12:40:15 +00:00
|
|
|
//! Parse a non-match event, and add role definitions for it
|
|
|
|
/**
|
|
|
|
* Currently implemented by introducing a special claim.
|
|
|
|
*
|
|
|
|
* Claim(R,NotEqual,(pat,term) );
|
|
|
|
*
|
|
|
|
* This special claim, notequal, is later used for pruning.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nonMatchEvent (Tac tc)
|
|
|
|
{
|
|
|
|
Term msg;
|
|
|
|
Term mpat;
|
|
|
|
Term mmsg;
|
|
|
|
|
|
|
|
mpat = tacTerm (tc->t1.tac);
|
|
|
|
mmsg = tacTerm (tc->t2.tac);
|
2013-06-19 20:51:52 +01:00
|
|
|
msg = makeTermTuple (mpat, mmsg);
|
|
|
|
claimCreate (sys, thisProtocol, thisRole, CLAIM_Notequal, NULL, msg,
|
|
|
|
tc->lineno);
|
2012-11-21 12:40:15 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
//! Parse a communication event tc of type event, and add a role definition event for it.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
commEvent (int event, Tac tc)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
/* Add an event to the roledef, send or recv */
|
2004-06-14 23:08:47 +01:00
|
|
|
Claimlist cl;
|
2004-04-23 11:58:43 +01:00
|
|
|
Term fromrole = NULL;
|
|
|
|
Term torole = NULL;
|
|
|
|
Term msg = NULL;
|
|
|
|
Term label = NULL;
|
|
|
|
Term claim = NULL;
|
|
|
|
Term claimbig = NULL;
|
|
|
|
int n = 0;
|
|
|
|
Tac trip;
|
2004-08-27 13:36:23 +01:00
|
|
|
Labelinfo linfo;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* Construct label, if any */
|
2004-05-26 09:26:40 +01:00
|
|
|
if (tc->t1.sym == NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-12-28 11:50:17 +00:00
|
|
|
/* right, now this should not be NULL anyway, if so we construct a fresh one.
|
2012-04-25 08:53:07 +01:00
|
|
|
* This can be a weird choice if it is a recv or send, because in that case
|
|
|
|
* we cannot chain them anymore and the send-recv correspondence is lost.
|
2005-12-28 11:50:17 +00:00
|
|
|
*/
|
2011-01-27 13:12:51 +00:00
|
|
|
int n;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
n = 1;
|
|
|
|
for (rd = thisRole->roledef; rd != NULL; rd = rd->next)
|
|
|
|
{
|
|
|
|
if (rd->type == CLAIM)
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
label = intTermPrefix (n, thisRole->nameterm);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-26 09:26:40 +01:00
|
|
|
label = levelFind (tc->t1.sym, level - 1);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (label == NULL)
|
|
|
|
{
|
|
|
|
/* effectively, labels are bound to the protocol */
|
|
|
|
level--;
|
2004-08-27 11:08:03 +01:00
|
|
|
/* leaves a garbage tuple. dunnoh what to do with it */
|
2006-08-08 13:30:29 +01:00
|
|
|
label = levelConst (tc->t1.sym);
|
2004-04-23 11:58:43 +01:00
|
|
|
level++;
|
|
|
|
}
|
2004-08-27 11:24:19 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* leaves a garbage tuple. dunnoh what to do with it */
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2006-08-08 13:30:29 +01:00
|
|
|
label = makeTermTuple (thisProtocol->nameterm, label);
|
2004-08-27 13:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the specific event type
|
|
|
|
*/
|
2004-05-26 09:26:40 +01:00
|
|
|
trip = tc->t2.tac;
|
2004-04-23 11:58:43 +01:00
|
|
|
switch (event)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
case RECV:
|
2004-04-23 11:58:43 +01:00
|
|
|
case SEND:
|
2005-12-28 11:50:17 +00:00
|
|
|
/**
|
|
|
|
* We know the label. Find the corresponding labelinfo bit or make a new one
|
|
|
|
*/
|
|
|
|
linfo = label_find (sys->labellist, label);
|
|
|
|
if (linfo == NULL)
|
|
|
|
{
|
|
|
|
/* Not found, make a new one */
|
|
|
|
linfo = label_create (label, thisProtocol);
|
|
|
|
sys->labellist = list_append (sys->labellist, linfo);
|
|
|
|
}
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* now parse triplet info */
|
|
|
|
if (trip == NULL || trip->next == NULL || trip->next->next == NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
error ("Problem with %i event on line %i.", event, tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
fromrole = tacTerm (trip);
|
|
|
|
torole = tacTerm (trip->next);
|
|
|
|
msg = tacTerm (tacTuple ((trip->next->next)));
|
2004-06-16 16:28:20 +01:00
|
|
|
cl = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-20 20:16:56 +01:00
|
|
|
if (event == SEND)
|
|
|
|
{
|
2004-08-27 13:36:23 +01:00
|
|
|
/* set sendrole */
|
2004-08-27 14:40:46 +01:00
|
|
|
if (!isTermEqual (fromrole, thisRole->nameterm))
|
2004-11-16 12:07:55 +00:00
|
|
|
error
|
|
|
|
("Send role does not correspond to execution role at line %i.",
|
|
|
|
tc->lineno);
|
2004-08-27 13:36:23 +01:00
|
|
|
if (linfo->sendrole != NULL)
|
2004-11-16 12:07:55 +00:00
|
|
|
error ("Label defined twice for sendrole!");
|
2004-08-27 13:36:23 +01:00
|
|
|
linfo->sendrole = fromrole;
|
|
|
|
|
2004-08-20 20:16:56 +01:00
|
|
|
/* set keylevels based on send events */
|
|
|
|
term_set_keylevels (fromrole);
|
|
|
|
term_set_keylevels (torole);
|
|
|
|
term_set_keylevels (msg);
|
|
|
|
}
|
2004-08-27 13:36:23 +01:00
|
|
|
else
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
// RECV
|
|
|
|
/* set recvrole */
|
2004-08-27 14:40:46 +01:00
|
|
|
if (!isTermEqual (torole, thisRole->nameterm))
|
2004-11-16 12:07:55 +00:00
|
|
|
error
|
2012-04-25 08:53:07 +01:00
|
|
|
("Recv role does not correspond to execution role at line %i.",
|
2004-11-16 12:07:55 +00:00
|
|
|
tc->lineno);
|
2012-04-25 08:53:07 +01:00
|
|
|
if (linfo->recvrole != NULL)
|
|
|
|
error ("Label defined twice for recvrole!");
|
|
|
|
linfo->recvrole = torole;
|
2004-08-27 13:36:23 +01:00
|
|
|
}
|
2004-08-20 20:16:56 +01:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
/* and make that recv/send event */
|
2005-12-28 11:50:17 +00:00
|
|
|
thisRole->roledef = roledefAdd (thisRole->roledef, event, label,
|
|
|
|
fromrole, torole, msg, cl);
|
2007-01-29 17:20:45 +00:00
|
|
|
/* mark last one with line number */
|
|
|
|
markLastRoledef (thisRole->roledef, tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
2005-12-28 11:50:17 +00:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
case CLAIM:
|
2005-12-28 11:50:17 +00:00
|
|
|
/* switch can be used to remove all *parsed* claims */
|
2005-12-27 13:53:49 +00:00
|
|
|
if (!switches.removeclaims)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
/* now parse tuple info */
|
|
|
|
if (trip == NULL || trip->next == NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
error ("Problem with claim %i event on line %i.", event,
|
|
|
|
tc->lineno);
|
|
|
|
}
|
|
|
|
fromrole = tacTerm (trip);
|
|
|
|
claimbig = tacTerm (tacTuple ((trip->next)));
|
|
|
|
/* check for several types */
|
|
|
|
claim = tupleProject (claimbig, 0);
|
|
|
|
torole = claim;
|
|
|
|
|
|
|
|
/* check for obvious flaws */
|
|
|
|
if (claim == NULL)
|
2004-06-14 23:08:47 +01:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
error ("Invalid claim specification on line %i.", tc->lineno);
|
2004-06-14 23:08:47 +01:00
|
|
|
}
|
2005-12-27 13:53:49 +00:00
|
|
|
if (!inTermlist (claim->stype, TERM_Claim))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] claim term is not of claim type ",
|
|
|
|
trip->next->lineno);
|
2005-12-27 13:53:49 +00:00
|
|
|
termPrint (claim);
|
|
|
|
errorTac (trip->next->lineno);
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError--;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2005-12-27 13:53:49 +00:00
|
|
|
/* unfold parameters to msg */
|
|
|
|
msg = NULL;
|
|
|
|
n = tupleCount (claimbig) - 1;
|
|
|
|
if (n < 1)
|
2005-02-19 14:31:15 +00:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
/* no parameters */
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* n parameters */
|
|
|
|
msg = TermOp2 (deVar (claimbig));
|
|
|
|
if (tupleCount (msg) != n)
|
|
|
|
{
|
|
|
|
error ("Problem with claim tuple unfolding at line %i.",
|
|
|
|
trip->next->lineno);
|
|
|
|
}
|
2005-02-19 14:31:15 +00:00
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
// check whether label is unique
|
2005-12-27 13:53:49 +00:00
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
if (isClaimlabelUsed (sys, label))
|
2005-12-27 13:53:49 +00:00
|
|
|
{
|
2006-08-08 13:40:04 +01:00
|
|
|
if (switches.check)
|
|
|
|
{
|
|
|
|
warning
|
|
|
|
("Claim label is not unique at line %i, generating fresh label.",
|
|
|
|
tc->lineno);
|
|
|
|
}
|
2006-08-08 14:00:16 +01:00
|
|
|
// the reported new label will be generated later in claimCreate()
|
2005-12-27 13:53:49 +00:00
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
|
2005-12-27 13:53:49 +00:00
|
|
|
if (!isTermEqual (fromrole, thisRole->nameterm))
|
|
|
|
error
|
|
|
|
("Claim role does not correspond to execution role at line %i.",
|
|
|
|
tc->lineno);
|
2005-12-28 11:50:17 +00:00
|
|
|
|
|
|
|
/* handles claim types with different syntactic claims */
|
2005-12-27 13:53:49 +00:00
|
|
|
|
2012-05-01 15:37:18 +01:00
|
|
|
if ((claim == CLAIM_Secret) || (claim == CLAIM_SKR))
|
2005-12-27 13:53:49 +00:00
|
|
|
{
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("Secrecy claim requires a list of terms to be secret on line %i.",
|
|
|
|
trip->next->lineno);
|
|
|
|
}
|
|
|
|
if (n > 1)
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("Secrecy claim on line %i should not contain tuples (for Arachne) until it is officially supported.",
|
|
|
|
trip->next->lineno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (claim == CLAIM_Nisynch)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
if (n != 0)
|
|
|
|
{
|
|
|
|
error ("NISYNCH claim requires no parameters at line %i.",
|
|
|
|
trip->next->lineno);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2005-12-27 13:53:49 +00:00
|
|
|
if (claim == CLAIM_Niagree)
|
2004-07-25 19:24:50 +01:00
|
|
|
{
|
2005-12-27 13:53:49 +00:00
|
|
|
if (n != 0)
|
|
|
|
{
|
|
|
|
error ("NIAGREE claim requires no parameters at line %i.",
|
|
|
|
trip->next->lineno);
|
|
|
|
}
|
2004-07-25 19:24:50 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
/* create the event */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2007-01-29 17:20:45 +00:00
|
|
|
cl =
|
|
|
|
claimCreate (sys, thisProtocol, thisRole, claim, label, msg,
|
|
|
|
tc->lineno);
|
2005-12-27 13:53:49 +00:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 15:28:16 +01:00
|
|
|
//! Create hash functions
|
|
|
|
/**
|
|
|
|
* Assumption: hfuncs list in same order as tac.
|
|
|
|
*
|
|
|
|
* Note: Destroys tc contents, so please don't reuse afterwards.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
hashfunctions (Tac tcstart)
|
|
|
|
{
|
|
|
|
Termlist hfuncs;
|
|
|
|
Termlist hinvs;
|
|
|
|
Tac tc;
|
|
|
|
|
|
|
|
// As long as tc is intact.
|
|
|
|
levelDeclareConst (tcstart);
|
|
|
|
hfuncs = tacTermlist (tcstart->t1.tac);
|
|
|
|
if (level < 2)
|
|
|
|
knowledgeAddTermlist (sys->know, hfuncs);
|
|
|
|
|
|
|
|
for (tc = tcstart->t1.tac; tc != NULL; tc = tc->next)
|
|
|
|
{
|
|
|
|
tc->t1.sym = symbolNextFree (symbolSysConst ("_unhash-"));
|
|
|
|
}
|
|
|
|
levelDeclareConst (tcstart);
|
|
|
|
hinvs = tacTermlist (tcstart->t1.tac);
|
|
|
|
|
|
|
|
while (hfuncs != NULL)
|
|
|
|
{
|
|
|
|
if (hinvs == NULL)
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("Bug in hashfunction generation code. Please contact the authors.\n");
|
|
|
|
}
|
2013-04-26 10:36:41 +01:00
|
|
|
knowledgeAddInverseKeys (sys->know, hfuncs->term, hinvs->term);
|
2009-04-28 15:28:16 +01:00
|
|
|
hfuncs->term->stype = termlistAdd (NULL, TERM_Function);
|
2013-05-24 10:05:30 +01:00
|
|
|
if (tcstart->t3.tac == NULL)
|
|
|
|
{
|
|
|
|
// Not secret
|
|
|
|
knowledgeAddTerm (sys->know, hfuncs->term);
|
|
|
|
knowledgeAddPublicFunction (sys->know, hfuncs->term);
|
|
|
|
}
|
2009-04-28 15:28:16 +01:00
|
|
|
hinvs->term->stype = termlistAdd (NULL, TERM_Function);
|
|
|
|
hfuncs = hfuncs->next;
|
|
|
|
hinvs = hinvs->next;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
int
|
|
|
|
normalDeclaration (Tac tc)
|
|
|
|
{
|
|
|
|
switch (tc->op)
|
|
|
|
{
|
|
|
|
case TAC_VAR:
|
|
|
|
levelDeclareVar (tc);
|
2004-05-26 09:26:40 +01:00
|
|
|
if (level < 2 && tc->t3.tac == NULL)
|
|
|
|
knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_CONST:
|
|
|
|
levelDeclareConst (tc);
|
2004-05-26 09:26:40 +01:00
|
|
|
if (level < 2 && tc->t3.tac == NULL)
|
|
|
|
knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
|
2010-01-05 12:45:19 +00:00
|
|
|
if (level > 0)
|
|
|
|
{
|
|
|
|
globalError++;
|
|
|
|
warning_pre ();
|
|
|
|
eprintf ("const ");
|
|
|
|
termlistPrint (tacTermlist (tc->t1.tac));
|
|
|
|
eprintf
|
|
|
|
(" usage inside roles is deprecated. Please use 'fresh' instead on line %i.\n",
|
|
|
|
tc->lineno);
|
|
|
|
globalError--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TAC_FRESH:
|
|
|
|
levelDeclareConst (tc);
|
|
|
|
if (level < 2)
|
|
|
|
{
|
|
|
|
globalError++;
|
|
|
|
error_pre ();
|
|
|
|
eprintf ("fresh terms ");
|
|
|
|
termlistPrint (tacTermlist (tc->t1.tac));
|
|
|
|
eprintf (" should be declared inside roles,");
|
|
|
|
errorTac (tc->lineno); // exits Scyther here
|
|
|
|
globalError--;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_SECRET:
|
|
|
|
levelDeclareConst (tc);
|
|
|
|
break;
|
|
|
|
case TAC_COMPROMISED:
|
2004-05-26 09:26:40 +01:00
|
|
|
knowledgeAddTermlist (sys->know, tacTermlist (tc->t1.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_INVERSEKEYS:
|
2013-04-26 10:36:41 +01:00
|
|
|
knowledgeAddInverseKeys (sys->know, tacTerm (tc->t1.tac),
|
|
|
|
tacTerm (tc->t2.tac));
|
|
|
|
break;
|
|
|
|
case TAC_INVERSEKEYFUNCTIONS:
|
|
|
|
knowledgeAddInverseKeyFunctions (sys->know, tacTerm (tc->t1.tac),
|
|
|
|
tacTerm (tc->t2.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
2009-04-28 15:28:16 +01:00
|
|
|
case TAC_HASHFUNCTION:
|
|
|
|
hashfunctions (tc);
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
default:
|
|
|
|
/* abort with false */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-12-28 11:50:17 +00:00
|
|
|
//! Add all sorts of claims to this role
|
|
|
|
void
|
|
|
|
claimAddAll (const System sys, const Protocol protocol, const Role role)
|
|
|
|
{
|
|
|
|
/* first: secrecy claims for all locally declared things */
|
|
|
|
void addSecrecyList (Termlist tl)
|
|
|
|
{
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
2005-12-28 11:59:39 +00:00
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = deVar (tl->term);
|
|
|
|
if (realTermLeaf (t))
|
|
|
|
{
|
2005-12-28 12:04:00 +00:00
|
|
|
// Add a secrecy claim
|
2007-01-29 17:20:45 +00:00
|
|
|
claimCreate (sys, protocol, role, CLAIM_Secret, NULL, t, -1);
|
2005-12-28 11:59:39 +00:00
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 14:23:20 +01:00
|
|
|
if (!isHelperProtocol (protocol))
|
|
|
|
{
|
|
|
|
addSecrecyList (role->declaredconsts);
|
|
|
|
addSecrecyList (role->declaredvars);
|
|
|
|
|
|
|
|
/* full non-injective agreement and ni-synch */
|
|
|
|
claimCreate (sys, protocol, role, CLAIM_Alive, NULL, NULL, -1);
|
|
|
|
claimCreate (sys, protocol, role, CLAIM_Weakagree, NULL, NULL, -1);
|
|
|
|
claimCreate (sys, protocol, role, CLAIM_Niagree, NULL, NULL, -1);
|
|
|
|
claimCreate (sys, protocol, role, CLAIM_Nisynch, NULL, NULL, -1);
|
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 16:05:53 +00:00
|
|
|
//! Compile a role
|
|
|
|
/**
|
|
|
|
* Input: a name and a roledef tac
|
|
|
|
*
|
|
|
|
* Upon return, thisRole should contain the role definition
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
roleCompile (Term nameterm, Tac tc)
|
|
|
|
{
|
2004-11-16 12:51:23 +00:00
|
|
|
/* locate the role, protocol into thisRole */
|
|
|
|
/* scan through role list */
|
|
|
|
thisRole = thisProtocol->roles;
|
|
|
|
while (thisRole != NULL && !isTermEqual (thisRole->nameterm, nameterm))
|
|
|
|
{
|
|
|
|
thisRole = thisRole->next;
|
|
|
|
}
|
|
|
|
if (thisRole == NULL)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] undeclared role name ", tc->lineno);
|
2004-11-16 12:51:23 +00:00
|
|
|
termPrint (nameterm);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" in line ");
|
2004-11-16 12:51:23 +00:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* parse the content of the role */
|
|
|
|
levelInit ();
|
|
|
|
|
2005-09-09 11:05:29 +01:00
|
|
|
{
|
|
|
|
int firstEvent;
|
|
|
|
|
|
|
|
/* initiator/responder flag not set */
|
|
|
|
firstEvent = 1;
|
|
|
|
|
|
|
|
while (tc != NULL)
|
|
|
|
{
|
|
|
|
switch (tc->op)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
case TAC_RECV:
|
2005-09-09 11:05:29 +01:00
|
|
|
if (firstEvent)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
// First a recv, thus responder
|
2005-09-09 11:05:29 +01:00
|
|
|
/*
|
2012-04-25 08:53:07 +01:00
|
|
|
* Semantics: defaults (in role.c) to initiator _unless_ the first event is a recv,
|
2005-09-09 11:05:29 +01:00
|
|
|
* in which case we assume that the agent names are possibly received as variables
|
|
|
|
*/
|
|
|
|
thisRole->initiator = 0;
|
2006-03-14 11:37:28 +00:00
|
|
|
firstEvent = 0;
|
2005-09-09 11:05:29 +01:00
|
|
|
}
|
2012-04-25 08:53:07 +01:00
|
|
|
commEvent (RECV, tc);
|
2005-09-09 11:05:29 +01:00
|
|
|
break;
|
|
|
|
case TAC_SEND:
|
2006-03-14 11:37:28 +00:00
|
|
|
firstEvent = 0;
|
2005-09-09 11:05:29 +01:00
|
|
|
commEvent (SEND, tc);
|
|
|
|
break;
|
2012-11-21 10:28:40 +00:00
|
|
|
case TAC_MATCH:
|
2012-11-21 12:40:15 +00:00
|
|
|
if (tc->t3.value == true)
|
|
|
|
{
|
2013-06-19 20:51:52 +01:00
|
|
|
matchEvent (tc);
|
2012-11-21 12:40:15 +00:00
|
|
|
}
|
2013-06-19 20:51:52 +01:00
|
|
|
else
|
2012-11-21 12:40:15 +00:00
|
|
|
{
|
2013-06-19 20:51:52 +01:00
|
|
|
nonMatchEvent (tc);
|
2012-11-21 12:40:15 +00:00
|
|
|
}
|
2012-11-21 10:28:40 +00:00
|
|
|
break;
|
2005-09-09 11:05:29 +01:00
|
|
|
case TAC_CLAIM:
|
|
|
|
commEvent (CLAIM, tc);
|
|
|
|
break;
|
2006-07-27 11:44:12 +01:00
|
|
|
case TAC_KNOWS:
|
|
|
|
roleKnows (tc);
|
|
|
|
break;
|
2005-09-09 11:05:29 +01:00
|
|
|
default:
|
|
|
|
if (!normalDeclaration (tc))
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] illegal command %i in role ",
|
|
|
|
tc->lineno, tc->op);
|
2005-09-09 11:05:29 +01:00
|
|
|
termPrint (thisRole->nameterm);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" ");
|
2005-09-09 11:05:29 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tc = tc->next;
|
|
|
|
}
|
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
|
|
|
|
/* add any claims according to the switches */
|
|
|
|
|
|
|
|
if (switches.addreachableclaim)
|
|
|
|
{
|
2011-04-01 14:23:20 +01:00
|
|
|
if (!isHelperProtocol (thisProtocol))
|
|
|
|
{
|
|
|
|
claimCreate (sys, thisProtocol, thisRole, CLAIM_Reachable, NULL,
|
|
|
|
NULL, -1);
|
|
|
|
}
|
2005-12-28 11:50:17 +00:00
|
|
|
}
|
|
|
|
if (switches.addallclaims)
|
|
|
|
{
|
|
|
|
claimAddAll (sys, thisProtocol, thisRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* last bits */
|
2004-08-12 10:14:31 +01:00
|
|
|
compute_role_variables (sys, thisProtocol, thisRole);
|
2004-04-23 11:58:43 +01:00
|
|
|
levelDone ();
|
|
|
|
}
|
|
|
|
|
2006-07-27 11:44:12 +01:00
|
|
|
//! Initial role knowledge declaration
|
|
|
|
void
|
|
|
|
roleKnows (Tac tc)
|
|
|
|
{
|
2006-07-31 12:08:51 +01:00
|
|
|
sys->knowledgedefined = true; // apparently someone uses this, so we enable the check
|
2006-07-27 11:45:26 +01:00
|
|
|
thisRole->knows =
|
|
|
|
termlistConcat (thisRole->knows, tacTermlist (tc->t1.tac));
|
2006-07-27 11:44:12 +01:00
|
|
|
}
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
runInstanceCreate (Tac tc)
|
|
|
|
{
|
|
|
|
/* create an instance of an existing role
|
|
|
|
* tac1 is the dot-separated reference to the role.
|
|
|
|
* tac2 is the list of parameters to be filled in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Protocol p;
|
|
|
|
Role r;
|
|
|
|
Symbol psym, rsym;
|
|
|
|
Termlist instParams;
|
|
|
|
|
|
|
|
/* check whether we can still do it */
|
|
|
|
if (sys->maxruns >= maxruns)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* first, locate the protocol */
|
2004-05-26 09:26:40 +01:00
|
|
|
psym = tc->t1.tac->t1.sym;
|
2004-04-23 11:58:43 +01:00
|
|
|
p = sys->protocols;
|
2004-11-16 12:07:55 +00:00
|
|
|
while (p != NULL && TermSymb (p->nameterm) != psym)
|
2004-04-23 11:58:43 +01:00
|
|
|
p = p->next;
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf
|
|
|
|
("error: [%i] Trying to create a run of a non-declared protocol ",
|
|
|
|
tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
symbolPrint (psym);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" ");
|
2004-04-23 11:58:43 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* locate the role */
|
2004-05-26 09:26:40 +01:00
|
|
|
rsym = tc->t1.tac->t2.sym;
|
2004-04-23 11:58:43 +01:00
|
|
|
r = p->roles;
|
2004-11-16 12:07:55 +00:00
|
|
|
while (r != NULL && TermSymb (r->nameterm) != rsym)
|
2004-04-23 11:58:43 +01:00
|
|
|
r = r->next;
|
|
|
|
if (r == NULL)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] Protocol ", tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
symbolPrint (psym);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" has no role called ");
|
2004-04-23 11:58:43 +01:00
|
|
|
symbolPrint (rsym);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" ");
|
2004-04-23 11:58:43 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we now know what we are instancing, equal numbers? */
|
2004-05-26 09:26:40 +01:00
|
|
|
instParams = tacTermlist (tc->t2.tac);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (termlistLength (instParams) != termlistLength (p->rolenames))
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
|
|
|
eprintf
|
2007-01-29 17:20:45 +00:00
|
|
|
("error: [%i] Run instance has different number of parameters than protocol ",
|
|
|
|
tc->lineno);
|
2004-04-23 11:58:43 +01:00
|
|
|
termPrint (p->nameterm);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" ");
|
2004-04-23 11:58:43 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* equal numbers, so it seems to be safe */
|
2004-08-15 20:58:26 +01:00
|
|
|
roleInstance (sys, p, r, instParams, NULL); // technically, we don't need to do this for Arachne [fix later]
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* after creation analysis */
|
2007-01-16 17:22:51 +00:00
|
|
|
/* originator assumption for CLP ? */
|
2004-04-23 11:58:43 +01:00
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
2006-01-02 15:29:41 +00:00
|
|
|
//! Check whether the roles in a protocol are non-empty
|
|
|
|
void
|
|
|
|
checkProtocolRoles (void)
|
|
|
|
{
|
|
|
|
Role role;
|
|
|
|
Termlist badroles;
|
|
|
|
|
|
|
|
badroles = NULL;
|
|
|
|
role = thisProtocol->roles;
|
|
|
|
while (role != NULL)
|
|
|
|
{
|
|
|
|
if (role->roledef == NULL)
|
|
|
|
{
|
|
|
|
// Hey, this role is empty.
|
|
|
|
badroles = termlistAdd (badroles, role->nameterm);
|
|
|
|
}
|
|
|
|
role = role->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (badroles != NULL)
|
|
|
|
{
|
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: protocol ");
|
|
|
|
termPrint (thisProtocol->nameterm);
|
|
|
|
eprintf (" has empty role definitions for the roles: ");
|
|
|
|
termlistPrint (badroles);
|
|
|
|
eprintf ("\n");
|
|
|
|
globalError--;
|
|
|
|
termlistDelete (badroles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Compile a protocol description
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
protocolCompile (Symbol prots, Tac tc, Tac tcroles)
|
|
|
|
{
|
|
|
|
Protocol pr;
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
/* make new (empty) current protocol with name */
|
|
|
|
pr = protocolCreate (levelConst (prots));
|
|
|
|
thisProtocol = pr;
|
2006-08-08 13:30:29 +01:00
|
|
|
{
|
|
|
|
// check for double name declarations
|
|
|
|
Protocol prold;
|
|
|
|
|
|
|
|
prold = sys->protocols;
|
|
|
|
while (prold != NULL)
|
|
|
|
{
|
|
|
|
if (isTermEqual (pr->nameterm, prold->nameterm))
|
|
|
|
{
|
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] Double declaration of protocol ",
|
|
|
|
tc->lineno);
|
2006-08-08 13:30:29 +01:00
|
|
|
symbolPrint (prots);
|
|
|
|
eprintf (" ");
|
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
prold = prold->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* add protocol to list */
|
|
|
|
pr->next = sys->protocols;
|
|
|
|
sys->protocols = pr;
|
2004-08-27 11:08:03 +01:00
|
|
|
protocolCount++;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
levelInit ();
|
|
|
|
/* add the role names */
|
|
|
|
pr->rolenames = NULL;
|
|
|
|
while (tcroles != NULL)
|
|
|
|
{
|
2004-11-16 12:51:23 +00:00
|
|
|
Term rolename;
|
|
|
|
Role r;
|
|
|
|
|
2006-03-08 13:58:46 +00:00
|
|
|
rolename = levelVar (tcroles->t1.sym);
|
|
|
|
rolename->stype = termlistAdd (NULL, TERM_Agent);
|
|
|
|
|
2004-11-16 12:51:23 +00:00
|
|
|
/* add name to list of role names */
|
|
|
|
pr->rolenames = termlistAppend (pr->rolenames, rolename);
|
|
|
|
/* make new (empty) current protocol with name */
|
|
|
|
r = roleCreate (rolename);
|
|
|
|
/* add role to role list of the protocol */
|
|
|
|
r->next = thisProtocol->roles;
|
|
|
|
thisProtocol->roles = r;
|
|
|
|
|
|
|
|
/* next role name */
|
2004-04-23 11:58:43 +01:00
|
|
|
tcroles = tcroles->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the content of the protocol */
|
|
|
|
while (tc != NULL)
|
|
|
|
{
|
|
|
|
switch (tc->op)
|
|
|
|
{
|
|
|
|
case TAC_UNTRUSTED:
|
|
|
|
sys->untrusted =
|
2004-05-26 09:26:40 +01:00
|
|
|
termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_ROLE:
|
2004-05-26 09:26:40 +01:00
|
|
|
t = levelFind (tc->t1.sym, level);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (t != NULL)
|
|
|
|
{
|
2006-01-02 16:05:53 +00:00
|
|
|
// Compile a role
|
2004-05-26 09:26:40 +01:00
|
|
|
roleCompile (t, tc->t2.tac);
|
2006-01-02 16:05:53 +00:00
|
|
|
// singular?
|
|
|
|
if (tc->t3.value != 0)
|
|
|
|
{
|
|
|
|
thisRole->singular = true;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: undeclared role name");
|
2004-05-26 09:26:40 +01:00
|
|
|
symbolPrint (tc->t1.sym);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" in protocol ");
|
2004-04-23 11:58:43 +01:00
|
|
|
termPrint (pr->nameterm);
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError--;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!normalDeclaration (tc))
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] illegal command %i in protocol ",
|
|
|
|
tc->lineno, tc->op);
|
2004-04-23 11:58:43 +01:00
|
|
|
termPrint (thisProtocol->nameterm);
|
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tc = tc->next;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
|
|
|
|
/* new we should have parsed each protocol role. check this. */
|
|
|
|
checkProtocolRoles ();
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
levelDone ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tacProcess (Tac tc)
|
|
|
|
{
|
|
|
|
while (tc != NULL)
|
|
|
|
{
|
|
|
|
switch (tc->op)
|
|
|
|
{
|
|
|
|
case TAC_PROTOCOL:
|
2004-05-26 09:26:40 +01:00
|
|
|
protocolCompile (tc->t1.sym, tc->t2.tac, tc->t3.tac);
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_UNTRUSTED:
|
|
|
|
sys->untrusted =
|
2004-05-26 09:26:40 +01:00
|
|
|
termlistConcat (sys->untrusted, tacTermlist (tc->t1.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
break;
|
|
|
|
case TAC_RUN:
|
|
|
|
runInstanceCreate (tc);
|
|
|
|
break;
|
|
|
|
case TAC_USERTYPE:
|
|
|
|
defineUsertype (tc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!normalDeclaration (tc))
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] illegal command %i at the global level ",
|
|
|
|
tc->lineno, tc->op);
|
2004-04-23 11:58:43 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tc = tc->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
|
|
|
tacTerm (Tac tc)
|
|
|
|
{
|
2013-04-26 10:36:41 +01:00
|
|
|
Term t;
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
switch (tc->op)
|
|
|
|
{
|
2013-04-26 10:36:41 +01:00
|
|
|
case TAC_FCALL:
|
|
|
|
t = makeTermEncrypt (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
|
|
|
|
t->helper.fcall = true;
|
|
|
|
return t;
|
2004-04-23 11:58:43 +01:00
|
|
|
case TAC_ENCRYPT:
|
2004-05-26 09:26:40 +01:00
|
|
|
return makeTermEncrypt (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
case TAC_TUPLE:
|
2004-05-26 09:26:40 +01:00
|
|
|
return makeTermTuple (tacTerm (tc->t1.tac), tacTerm (tc->t2.tac));
|
2004-04-23 11:58:43 +01:00
|
|
|
case TAC_STRING:
|
|
|
|
{
|
2004-05-26 09:26:40 +01:00
|
|
|
Term t = symbolFind (tc->t1.sym);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (t == NULL)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] undeclared symbol ", tc->lineno);
|
2004-05-26 09:26:40 +01:00
|
|
|
symbolPrint (tc->t1.sym);
|
2004-04-23 11:58:43 +01:00
|
|
|
errorTac (tc->lineno);
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 15:28:16 +01:00
|
|
|
//! Extract termlist from tac
|
|
|
|
/**
|
|
|
|
* Note: termlist in same order as tac. This is required for correct working of functions such as 'hashfunctions'.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist
|
|
|
|
tacTermlist (Tac tc)
|
|
|
|
{
|
|
|
|
Termlist tl = NULL;
|
|
|
|
|
|
|
|
while (tc != NULL)
|
|
|
|
{
|
|
|
|
tl = termlistAppend (tl, tacTerm (tc));
|
|
|
|
tc = tc->next;
|
|
|
|
}
|
|
|
|
return tl;
|
|
|
|
}
|
2004-06-14 23:08:47 +01:00
|
|
|
|
2004-08-12 10:14:31 +01:00
|
|
|
//! Compute variables for a roles (for Arachne)
|
2008-01-28 14:23:40 +00:00
|
|
|
/**
|
|
|
|
* This also takes care of setting the hasUntypedVariable flag, if needed.
|
|
|
|
*/
|
2004-08-12 10:14:31 +01:00
|
|
|
void
|
|
|
|
compute_role_variables (const System sys, Protocol p, Role r)
|
|
|
|
{
|
|
|
|
if (r->variables == NULL)
|
|
|
|
{
|
|
|
|
// Not computed before, for some reason
|
|
|
|
Termlist tl;
|
2018-10-19 20:28:51 +01:00
|
|
|
Roledef rd;
|
2004-08-12 10:14:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
tl = NULL;
|
2018-10-19 20:28:51 +01:00
|
|
|
for (rd = r->roledef; rd != NULL; rd = rd->next)
|
|
|
|
{
|
|
|
|
tl = termlistAddVariables (tl, rd->from);
|
|
|
|
tl = termlistAddVariables (tl, rd->to);
|
|
|
|
tl = termlistAddVariables (tl, rd->message);
|
|
|
|
}
|
2004-08-12 10:14:31 +01:00
|
|
|
r->variables = tl;
|
|
|
|
|
2008-01-28 14:23:40 +00:00
|
|
|
/*
|
|
|
|
* Iterate over variables for type checks
|
|
|
|
*/
|
|
|
|
for (tl = r->variables; tl != NULL; tl = tl->next)
|
|
|
|
{
|
|
|
|
if (isOpenVariable (tl->term))
|
|
|
|
{
|
|
|
|
sys->hasUntypedVariable = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-18 21:22:55 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
eprintf ("All variables for role ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (" are ");
|
2008-01-28 14:23:40 +00:00
|
|
|
termlistPrint (r->variables);
|
2004-08-18 21:22:55 +01:00
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-12 10:14:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
//! Compute term list of rolenames involved in a given term list of labels
|
2004-11-16 12:07:55 +00:00
|
|
|
Termlist
|
2004-08-27 13:36:23 +01:00
|
|
|
compute_label_roles (Termlist labels)
|
|
|
|
{
|
|
|
|
Termlist roles;
|
|
|
|
|
|
|
|
roles = NULL;
|
|
|
|
while (labels != NULL)
|
|
|
|
{
|
|
|
|
Labelinfo linfo;
|
|
|
|
|
|
|
|
linfo = label_find (sys->labellist, labels->term);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (linfo == NULL)
|
2004-11-16 12:07:55 +00:00
|
|
|
error ("Label in prec list not found in label info list");
|
2004-08-27 13:36:23 +01:00
|
|
|
#endif
|
|
|
|
roles = termlistAddNew (roles, linfo->sendrole);
|
2012-04-25 08:53:07 +01:00
|
|
|
roles = termlistAddNew (roles, linfo->recvrole);
|
2004-08-27 13:36:23 +01:00
|
|
|
|
|
|
|
labels = labels->next;
|
|
|
|
}
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
2004-08-27 14:40:46 +01:00
|
|
|
//! Order the label roles for a given claim
|
|
|
|
void
|
|
|
|
order_label_roles (const Claimlist cl)
|
|
|
|
{
|
|
|
|
Termlist roles_remaining;
|
|
|
|
Termlist roles_ordered;
|
|
|
|
int distance;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (4))
|
|
|
|
{
|
|
|
|
eprintf ("Ordering label roles for claim ");
|
|
|
|
termPrint (cl->label);
|
|
|
|
eprintf ("; 0: ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
roles_remaining = termlistShallow (cl->roles);
|
|
|
|
roles_ordered = termlistAdd (NULL, cl->rolename);
|
2004-11-16 12:07:55 +00:00
|
|
|
roles_remaining =
|
|
|
|
termlistDelTerm (termlistFind (roles_remaining, cl->rolename));
|
2004-08-27 14:40:46 +01:00
|
|
|
|
|
|
|
distance = 0;
|
|
|
|
while (roles_remaining != NULL)
|
|
|
|
{
|
|
|
|
int scan_label (void *data)
|
2004-11-16 12:07:55 +00:00
|
|
|
{
|
|
|
|
Labelinfo linfo;
|
2005-05-17 19:45:01 +01:00
|
|
|
Termlist tl;
|
2004-08-27 14:40:46 +01:00
|
|
|
|
2004-11-16 12:07:55 +00:00
|
|
|
linfo = (Labelinfo) data;
|
2005-05-17 19:45:01 +01:00
|
|
|
if (linfo == NULL)
|
|
|
|
return 1;
|
|
|
|
tl = cl->prec;
|
|
|
|
if (inTermlist (tl, linfo->label))
|
2004-11-16 12:07:55 +00:00
|
|
|
{
|
|
|
|
if (linfo->protocol == cl->protocol)
|
|
|
|
{
|
|
|
|
// If it's not the same protocol, the labels can't match
|
2004-08-27 14:40:46 +01:00
|
|
|
|
2004-11-16 12:07:55 +00:00
|
|
|
// This function checks whether the newrole can connect to the connectedrole, and whether they fulfil their requirements.
|
|
|
|
void roles_test (const Term connectedrole, const Term newrole)
|
|
|
|
{
|
|
|
|
if (inTermlist (roles_ordered, connectedrole) &&
|
|
|
|
inTermlist (roles_remaining, newrole))
|
2004-08-27 14:40:46 +01:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2004-11-16 12:07:55 +00:00
|
|
|
if (DEBUGL (4))
|
|
|
|
{
|
|
|
|
eprintf (" ");
|
|
|
|
termPrint (newrole);
|
2004-08-27 14:40:46 +01:00
|
|
|
}
|
2004-11-16 12:07:55 +00:00
|
|
|
#endif
|
|
|
|
roles_ordered = termlistAppend (roles_ordered, newrole);
|
|
|
|
roles_remaining =
|
|
|
|
termlistDelTerm (termlistFind
|
|
|
|
(roles_remaining, newrole));
|
2004-08-27 14:40:46 +01:00
|
|
|
}
|
|
|
|
}
|
2004-11-16 12:07:55 +00:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
roles_test (linfo->sendrole, linfo->recvrole);
|
|
|
|
roles_test (linfo->recvrole, linfo->sendrole);
|
2004-11-16 12:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2004-08-27 14:40:46 +01:00
|
|
|
|
2007-01-06 18:01:36 +00:00
|
|
|
distance++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (4))
|
|
|
|
{
|
|
|
|
eprintf (" %i:", distance);
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-27 14:40:46 +01:00
|
|
|
list_iterate (sys->labellist, scan_label);
|
|
|
|
}
|
|
|
|
cl->roles = roles_ordered;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (4))
|
|
|
|
{
|
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-06-14 23:08:47 +01:00
|
|
|
//! Compute prec() sets for each claim.
|
2004-06-16 11:39:13 +01:00
|
|
|
/**
|
|
|
|
* Generates two auxiliary structures. First, a table that contains
|
|
|
|
* a mapping from all events to event/claim labels.
|
|
|
|
* A second table is used to compute the precedence order, and
|
|
|
|
* Warshall's algorithm is used to compute the transitive closure.
|
2004-08-27 12:52:43 +01:00
|
|
|
* Then, for each claim, the in the preceding labels occurring roles are stored,
|
|
|
|
* which is useful later.
|
2004-06-16 11:39:13 +01:00
|
|
|
*@returns For each claim in the claim list, a preceding label set is defined.
|
|
|
|
*/
|
2004-06-14 23:08:47 +01:00
|
|
|
void
|
|
|
|
compute_prec_sets (const System sys)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
Term *eventlabels; // array: maps events to labels
|
2006-02-26 15:00:58 +00:00
|
|
|
unsigned int *prec; // array: maps event*event to precedence
|
2004-08-09 11:05:58 +01:00
|
|
|
int size; // temp constant: rolecount * roleeventmax
|
2006-02-26 15:00:58 +00:00
|
|
|
int rowsize;
|
2004-08-09 11:05:58 +01:00
|
|
|
int r1, r2, ev1, ev2; // some counters
|
2004-06-14 23:08:47 +01:00
|
|
|
Claimlist cl;
|
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
// Assist: compute index from role, lev
|
2004-08-09 11:05:58 +01:00
|
|
|
int index (int r, int lev)
|
|
|
|
{
|
|
|
|
return r * sys->roleeventmax + lev;
|
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
// Assist: yield roledef from r, lev
|
2004-08-09 11:05:58 +01:00
|
|
|
Roledef roledef_re (int r, int lev)
|
|
|
|
{
|
|
|
|
Protocol pr;
|
|
|
|
Role ro;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
pr = sys->protocols;
|
|
|
|
ro = pr->roles;
|
|
|
|
while (r > 0 && ro != NULL)
|
|
|
|
{
|
|
|
|
ro = ro->next;
|
|
|
|
if (ro == NULL)
|
|
|
|
{
|
|
|
|
pr = pr->next;
|
|
|
|
if (pr != NULL)
|
|
|
|
{
|
|
|
|
ro = pr->roles;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ro = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r--;
|
|
|
|
}
|
|
|
|
if (ro != NULL)
|
|
|
|
{
|
|
|
|
rd = ro->roledef;
|
|
|
|
while (lev > 0 && rd != NULL)
|
|
|
|
{
|
|
|
|
rd = rd->next;
|
|
|
|
lev--;
|
|
|
|
}
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
// Assist: print matrix
|
2004-08-09 11:05:58 +01:00
|
|
|
void show_matrix (void)
|
|
|
|
{
|
|
|
|
int r1, r2, ev1, ev2;
|
|
|
|
|
|
|
|
r1 = 0;
|
|
|
|
while (r1 < sys->rolecount)
|
|
|
|
{
|
|
|
|
ev1 = 0;
|
|
|
|
while (ev1 < sys->roleeventmax)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("prec %i,%i: ", r1, ev1);
|
2004-08-09 11:05:58 +01:00
|
|
|
r2 = 0;
|
|
|
|
while (r2 < sys->rolecount)
|
|
|
|
{
|
|
|
|
ev2 = 0;
|
|
|
|
while (ev2 < sys->roleeventmax)
|
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("%i ",
|
2006-02-26 15:00:58 +00:00
|
|
|
BIT (prec + rowsize * index (r2, ev2),
|
|
|
|
index (r1, ev1)));
|
2004-08-09 11:05:58 +01:00
|
|
|
ev2++;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (" ");
|
2004-08-09 11:05:58 +01:00
|
|
|
r2++;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("\n");
|
2004-08-09 11:05:58 +01:00
|
|
|
ev1++;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("\n");
|
2004-08-09 11:05:58 +01:00
|
|
|
r1++;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("\n");
|
2004-08-09 11:05:58 +01:00
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Phase 1: Allocate structures and map to labels
|
|
|
|
*/
|
2006-01-02 15:29:41 +00:00
|
|
|
//eprintf ("Rolecount: %i\n", sys->rolecount);
|
|
|
|
//eprintf ("Maxevent : %i\n", sys->roleeventmax);
|
2004-06-16 11:39:13 +01:00
|
|
|
size = sys->rolecount * sys->roleeventmax;
|
2006-02-26 15:00:58 +00:00
|
|
|
rowsize = WORDSIZE (size);
|
2006-03-08 13:58:46 +00:00
|
|
|
eventlabels = malloc (size * sizeof (Term));
|
2006-02-26 15:00:58 +00:00
|
|
|
prec = (unsigned int *) CALLOC (1, rowsize * size * sizeof (unsigned int));
|
2004-06-16 11:39:13 +01:00
|
|
|
// Assign labels
|
|
|
|
r1 = 0;
|
|
|
|
while (r1 < sys->rolecount)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
ev1 = 0;
|
|
|
|
rd = roledef_re (r1, ev1);
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
eventlabels[index (r1, ev1)] = rd->label;
|
2004-07-12 14:57:59 +01:00
|
|
|
//termPrint (rd->label);
|
2006-01-02 15:29:41 +00:00
|
|
|
//eprintf ("\t");
|
2004-06-16 11:39:13 +01:00
|
|
|
ev1++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
2006-02-27 22:27:09 +00:00
|
|
|
while (ev1 < sys->roleeventmax)
|
|
|
|
{
|
|
|
|
eventlabels[index (r1, ev1)] = NULL;
|
|
|
|
ev1++;
|
|
|
|
}
|
2006-01-02 15:29:41 +00:00
|
|
|
//eprintf ("\n");
|
2004-06-16 11:39:13 +01:00
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
// Set simple precedence (progress within a role)
|
|
|
|
r1 = 0;
|
|
|
|
while (r1 < sys->rolecount)
|
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
ev1 = 1;
|
|
|
|
while (ev1 < (sys->roleeventmax))
|
2004-08-09 11:05:58 +01:00
|
|
|
{
|
2006-02-27 16:08:17 +00:00
|
|
|
SETBIT (prec + rowsize * index (r1, ev1 - 1), index (r1, ev1));
|
2004-06-16 11:39:13 +01:00
|
|
|
ev1++;
|
|
|
|
}
|
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
// Scan for label correspondence
|
|
|
|
r1 = 0;
|
|
|
|
while (r1 < sys->rolecount)
|
|
|
|
{
|
|
|
|
ev1 = 0;
|
|
|
|
while (ev1 < sys->roleeventmax)
|
|
|
|
{
|
|
|
|
Roledef rd1;
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
rd1 = roledef_re (r1, ev1);
|
2004-07-05 10:37:31 +01:00
|
|
|
if (rd1 != NULL && rd1->type == SEND)
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
|
|
|
r2 = 0;
|
|
|
|
while (r2 < sys->rolecount)
|
|
|
|
{
|
|
|
|
ev2 = 0;
|
|
|
|
while (ev2 < sys->roleeventmax)
|
|
|
|
{
|
|
|
|
Roledef rd2;
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
rd2 = roledef_re (r2, ev2);
|
2012-04-25 08:53:07 +01:00
|
|
|
if (rd2 != NULL && rd2->type == RECV
|
2004-08-09 11:05:58 +01:00
|
|
|
&& isTermEqual (rd1->label, rd2->label))
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
SETBIT (prec + rowsize * index (r1, ev1),
|
|
|
|
index (r2, ev2));
|
2004-06-16 11:39:13 +01:00
|
|
|
}
|
|
|
|
ev2++;
|
|
|
|
}
|
|
|
|
r2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev1++;
|
|
|
|
}
|
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
show_matrix ();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
/*
|
|
|
|
* Compute transitive closure (Warshall).
|
|
|
|
*/
|
2006-02-26 15:00:58 +00:00
|
|
|
transitive_closure (prec, size);
|
2004-06-16 11:39:13 +01:00
|
|
|
|
2006-02-26 15:00:58 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (5))
|
|
|
|
{
|
|
|
|
show_matrix ();
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Last phase: Process all individual claims
|
|
|
|
*/
|
2004-06-14 23:08:47 +01:00
|
|
|
cl = sys->claimlist;
|
|
|
|
while (cl != NULL)
|
|
|
|
{
|
2004-06-16 11:39:13 +01:00
|
|
|
Roledef rd;
|
|
|
|
Term label;
|
2004-07-25 19:24:50 +01:00
|
|
|
int claim_index;
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
label = cl->label;
|
|
|
|
// Locate r,lev from label, requires (TODO) unique labeling of claims!
|
|
|
|
r1 = 0;
|
|
|
|
ev1 = -1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ev1++;
|
|
|
|
if (ev1 == sys->roleeventmax)
|
|
|
|
{
|
|
|
|
ev1 = 0;
|
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
while (r1 < sys->rolecount
|
|
|
|
&& !isTermEqual (label, eventlabels[index (r1, ev1)]));
|
2006-02-27 22:27:09 +00:00
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
if (r1 == sys->rolecount)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
error
|
|
|
|
("Prec() setup: Could not find the event corresponding to a claim label.");
|
2004-06-16 11:39:13 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
rd = roledef_re (r1, ev1);
|
2004-06-16 11:39:13 +01:00
|
|
|
if (rd->type != CLAIM)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
error
|
|
|
|
("Prec() setup: First event with claim label doesn't seem to be a claim.");
|
2004-06-16 11:39:13 +01:00
|
|
|
}
|
|
|
|
// Store in claimlist structure
|
|
|
|
cl->r = r1;
|
|
|
|
cl->ev = ev1;
|
2004-08-14 20:19:23 +01:00
|
|
|
cl->roledef = rd;
|
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
/*
|
|
|
|
* We have found the claim roledef, and r1,ev1
|
|
|
|
* Now we compute the preceding label set
|
|
|
|
*/
|
|
|
|
cl->prec = NULL; // clear first
|
2004-08-09 11:05:58 +01:00
|
|
|
claim_index = index (r1, ev1);
|
2004-06-16 11:39:13 +01:00
|
|
|
r2 = 0;
|
|
|
|
while (r2 < sys->rolecount)
|
|
|
|
{
|
|
|
|
ev2 = 0;
|
2004-08-09 11:05:58 +01:00
|
|
|
rd = roledef_re (r2, ev2);
|
2004-06-16 11:39:13 +01:00
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2006-02-26 15:00:58 +00:00
|
|
|
if (BIT (prec + rowsize * index (r2, ev2), claim_index))
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
|
|
|
// This event precedes the claim
|
2004-08-09 11:05:58 +01:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
if (rd->type == RECV)
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
// Only store recv labels (but send would work as well)
|
2004-06-16 11:39:13 +01:00
|
|
|
cl->prec = termlistAdd (cl->prec, rd->label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rd = rd->next;
|
|
|
|
ev2++;
|
|
|
|
}
|
|
|
|
r2++;
|
|
|
|
}
|
2004-08-27 14:40:46 +01:00
|
|
|
|
2004-08-27 13:36:23 +01:00
|
|
|
/**
|
2004-08-27 14:40:46 +01:00
|
|
|
* ----------------------------------------
|
2004-08-27 13:36:23 +01:00
|
|
|
* cl->prec is done, now we infer cl->roles
|
2004-08-27 14:40:46 +01:00
|
|
|
* Next, we nicely order them
|
|
|
|
* ----------------------------------------
|
2004-08-27 13:36:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
cl->roles = compute_label_roles (cl->prec);
|
2004-08-27 14:40:46 +01:00
|
|
|
order_label_roles (cl);
|
2004-08-27 13:36:23 +01:00
|
|
|
|
2004-07-25 19:24:50 +01:00
|
|
|
/**
|
|
|
|
* ---------------------------
|
|
|
|
* Distinguish types of claims
|
|
|
|
* ---------------------------
|
|
|
|
*/
|
|
|
|
|
2004-07-24 21:30:00 +01:00
|
|
|
// For ni-synch, the preceding label sets are added to the synchronising_labels sets.
|
|
|
|
if (cl->type == CLAIM_Nisynch)
|
|
|
|
{
|
|
|
|
Termlist tl_scan;
|
|
|
|
|
|
|
|
tl_scan = cl->prec;
|
|
|
|
while (tl_scan != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->synchronising_labels =
|
|
|
|
termlistAddNew (sys->synchronising_labels, tl_scan->term);
|
2004-07-25 19:24:50 +01:00
|
|
|
tl_scan = tl_scan->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For ni-agree, the preceding set is also important, but we furthermore need a restricted
|
|
|
|
// synchronising_labels set
|
|
|
|
|
|
|
|
//@todo Fix ni-agree synchronising label sets
|
|
|
|
if (cl->type == CLAIM_Niagree)
|
|
|
|
{
|
|
|
|
int r_scan;
|
|
|
|
|
|
|
|
// Scan each role (except the current one) and pick out the last prec events.
|
|
|
|
r_scan = 0;
|
|
|
|
while (r_scan < sys->rolecount)
|
|
|
|
{
|
|
|
|
// Only other roles
|
|
|
|
if (r_scan != r1)
|
2004-07-24 21:30:00 +01:00
|
|
|
{
|
2004-07-25 19:24:50 +01:00
|
|
|
// Scan fully
|
|
|
|
int ev_scan;
|
|
|
|
Term t_buf;
|
|
|
|
|
|
|
|
t_buf = NULL;
|
|
|
|
ev_scan = 0;
|
|
|
|
while (ev_scan < sys->roleeventmax)
|
|
|
|
{
|
|
|
|
// if this event preceds the claim, replace the label term
|
2006-02-26 15:00:58 +00:00
|
|
|
if (BIT
|
|
|
|
(prec + rowsize * index (r_scan, ev_scan),
|
|
|
|
claim_index))
|
2004-07-25 19:24:50 +01:00
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
rd = roledef_re (r_scan, ev_scan);
|
2004-07-25 19:24:50 +01:00
|
|
|
if (rd->label != NULL)
|
|
|
|
{
|
|
|
|
t_buf = rd->label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ev_scan++;
|
|
|
|
}
|
|
|
|
// Store only the last label
|
|
|
|
if (t_buf != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->synchronising_labels =
|
|
|
|
termlistAddNew (sys->synchronising_labels, t_buf);
|
2004-07-25 19:24:50 +01:00
|
|
|
}
|
2004-07-24 21:30:00 +01:00
|
|
|
}
|
2004-07-25 19:24:50 +01:00
|
|
|
r_scan++;
|
2004-07-24 21:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2004-07-25 19:24:50 +01:00
|
|
|
|
2004-07-25 16:30:58 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Porparam = 100 (weirdness) [x][cc][debug] can turn of the synchronising label sets (override).
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.switchP == 100)
|
2004-07-25 16:30:58 +01:00
|
|
|
{
|
|
|
|
termlistDelete (sys->synchronising_labels);
|
|
|
|
sys->synchronising_labels = NULL;
|
2004-08-09 11:05:58 +01:00
|
|
|
warning
|
|
|
|
("Emptied synchronising labels set manually because --pp=100.");
|
2004-07-25 16:30:58 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-06-16 11:39:13 +01:00
|
|
|
// Check for empty stuff
|
|
|
|
//@todo This is for debugging, mainly.
|
|
|
|
if (cl->prec == NULL)
|
|
|
|
{
|
2005-12-28 14:25:06 +00:00
|
|
|
if (inTermlist (CLAIMS_dep_prec, cl->type))
|
|
|
|
{
|
|
|
|
/* this claim depends on prec, but it is empty! */
|
|
|
|
|
|
|
|
cl->warnings = true;
|
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: claim with label ");
|
|
|
|
termPrint (cl->label);
|
|
|
|
eprintf (" of role ");
|
|
|
|
termPrint (cl->rolename);
|
|
|
|
eprintf (" has an empty prec() set.\n");
|
|
|
|
globalError--;
|
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-27 13:36:23 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (3))
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("Preceding label set for r:%i, ev:%i = ", r1, ev1);
|
2004-08-27 13:36:23 +01:00
|
|
|
termlistPrint (cl->prec);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (", involving roles ");
|
2004-08-27 13:36:23 +01:00
|
|
|
termlistPrint (cl->roles);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf (", from protocol ");
|
2004-08-27 13:36:23 +01:00
|
|
|
p = (Protocol) cl->protocol;
|
|
|
|
termPrint (p->nameterm);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("\n");
|
2004-08-27 13:36:23 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-06-16 11:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed to next claim
|
|
|
|
cl = cl->next;
|
2004-06-14 23:08:47 +01:00
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
2006-03-08 13:58:46 +00:00
|
|
|
free (eventlabels);
|
2006-02-26 15:00:58 +00:00
|
|
|
FREE (prec);
|
2004-07-24 21:30:00 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2004-08-09 11:05:58 +01:00
|
|
|
if (DEBUGL (2))
|
2004-07-25 16:30:58 +01:00
|
|
|
{
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("Synchronising labels set: ");
|
2004-07-25 16:30:58 +01:00
|
|
|
termlistPrint (sys->synchronising_labels);
|
2006-01-02 15:29:41 +00:00
|
|
|
eprintf ("\n");
|
2004-07-25 16:30:58 +01:00
|
|
|
}
|
2004-07-24 21:30:00 +01:00
|
|
|
#endif
|
|
|
|
|
2004-06-14 23:08:47 +01:00
|
|
|
}
|
|
|
|
|
2005-12-27 13:44:12 +00:00
|
|
|
//! Check unused variables
|
2008-01-28 14:23:40 +00:00
|
|
|
/**
|
|
|
|
* Some of this code is duplicated in the code that computes the role variables, so
|
|
|
|
* that should be cleaned up some day. TODO.
|
|
|
|
*/
|
2005-12-27 13:44:12 +00:00
|
|
|
void
|
|
|
|
checkRoleVariables (const System sys, const Protocol p, const Role r)
|
|
|
|
{
|
|
|
|
Termlist vars;
|
|
|
|
Termlist declared;
|
2018-10-19 20:46:48 +01:00
|
|
|
Roledef rd;
|
2005-12-27 13:44:12 +00:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
/* Gather all variables occurring in the recvs */
|
2005-12-27 13:44:12 +00:00
|
|
|
vars = NULL;
|
2018-10-19 20:46:48 +01:00
|
|
|
for (rd = r->roledef; rd != NULL; rd = rd->next)
|
|
|
|
{
|
|
|
|
if (rd->type == RECV)
|
|
|
|
{
|
|
|
|
vars = termlistAddVariables (vars, rd->from);
|
|
|
|
vars = termlistAddVariables (vars, rd->to);
|
|
|
|
vars = termlistAddVariables (vars, rd->message);
|
|
|
|
}
|
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
/* Now, all variables for this role should be in the recvs */
|
2005-12-27 13:44:12 +00:00
|
|
|
declared = r->declaredvars;
|
|
|
|
while (declared != NULL)
|
|
|
|
{
|
|
|
|
if (!inTermlist (vars, declared->term))
|
|
|
|
{
|
2006-08-08 13:35:43 +01:00
|
|
|
if (switches.check)
|
|
|
|
{
|
|
|
|
// Warning
|
|
|
|
globalError++;
|
|
|
|
eprintf ("warning: variable ");
|
|
|
|
termPrint (declared->term);
|
|
|
|
eprintf (" was declared in role ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (",");
|
|
|
|
termPrint (r->nameterm);
|
2012-04-25 08:53:07 +01:00
|
|
|
eprintf (" but never used in a recv event.\n");
|
2006-08-08 13:35:43 +01:00
|
|
|
globalError--;
|
|
|
|
}
|
2005-12-27 13:44:12 +00:00
|
|
|
}
|
|
|
|
declared = declared->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
termlistDelete (vars);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check unused variables
|
|
|
|
/**
|
|
|
|
* This is checked per role
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
checkUnusedVariables (const System sys)
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
p = sys->protocols;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
Role r;
|
|
|
|
r = p->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
checkRoleVariables (sys, p, r);
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-06 08:52:13 +00:00
|
|
|
//! Is a role well-formed?
|
|
|
|
/**
|
|
|
|
* In line with the 2012 book, we check only that variables occur first in
|
|
|
|
* receives. This is needed to guarantee that the instantiated terms are ground
|
|
|
|
* (and hence, traces contain run terms).
|
|
|
|
*
|
|
|
|
* Returns true if the role is well-formed, false otherwise.
|
|
|
|
*
|
|
|
|
* The function outputs its own error messages, but does not (sys.)exit. This
|
|
|
|
* should be done by the calling function, in order to collect a complete error
|
|
|
|
* report for all roles.
|
|
|
|
*/
|
2006-07-31 12:08:51 +01:00
|
|
|
int
|
|
|
|
WellFormedRole (const System sys, Protocol p, Role r)
|
|
|
|
{
|
2012-12-06 08:52:13 +00:00
|
|
|
Termlist tl;
|
|
|
|
int allOkay;
|
|
|
|
|
|
|
|
allOkay = true;
|
|
|
|
for (tl = r->variables; tl != NULL; tl = tl->next)
|
|
|
|
{
|
|
|
|
if (!inTermlist (p->rolenames, tl->term))
|
2006-07-31 12:08:51 +01:00
|
|
|
{
|
2012-12-06 08:52:13 +00:00
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = firstEventWithTerm (r->roledef, tl->term);
|
|
|
|
if (rd->type != RECV)
|
|
|
|
{
|
|
|
|
// Not well-formed
|
|
|
|
globalError++;
|
|
|
|
error_pre ();
|
|
|
|
eprintf ("Protocol ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf (", role ");
|
|
|
|
termPrint (r->nameterm);
|
|
|
|
eprintf (" is not well-formed: the variable '");
|
|
|
|
termPrint (tl->term);
|
|
|
|
eprintf ("' should occur first in a receive event.\n");
|
|
|
|
globalError--;
|
|
|
|
|
|
|
|
// Store
|
|
|
|
allOkay = false;
|
|
|
|
}
|
2006-07-31 12:08:51 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-06 08:52:13 +00:00
|
|
|
return allOkay;
|
2006-07-31 12:08:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Well-formedness check
|
|
|
|
void
|
|
|
|
checkWellFormed (const System sys)
|
|
|
|
{
|
2012-12-06 08:52:13 +00:00
|
|
|
int allOkay;
|
|
|
|
|
|
|
|
allOkay = true;
|
|
|
|
|
2006-07-31 12:08:51 +01:00
|
|
|
int thisRole (Protocol p, Role r)
|
|
|
|
{
|
2012-12-06 08:52:13 +00:00
|
|
|
allOkay = allOkay && WellFormedRole (sys, p, r);
|
2006-07-31 12:30:08 +01:00
|
|
|
return true;
|
2006-07-31 12:08:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iterateRoles (sys, thisRole);
|
2012-12-06 08:52:13 +00:00
|
|
|
if (allOkay == false)
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("The protocol specification does not meet the well-formedness condition.");
|
|
|
|
}
|
2006-07-31 12:08:51 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 13:15:35 +00:00
|
|
|
//! Check matching role defs
|
|
|
|
int
|
2007-02-01 12:18:38 +00:00
|
|
|
checkEventMatch (const Roledef rd1, const Roledef rd2,
|
|
|
|
const Termlist rolenames)
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
if (!isTermEqual (rd1->from, rd2->from))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!isTermEqual (rd1->to, rd2->to))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-01 12:18:38 +00:00
|
|
|
if (!checkRoletermMatch (rd1->message, rd2->message, rolenames))
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-25 08:53:07 +01:00
|
|
|
//! Check label matchup for protocol p,r, roledef rd (which is a recv)
|
2007-01-29 13:15:35 +00:00
|
|
|
/**
|
|
|
|
* Any send with the same label should match
|
|
|
|
*/
|
|
|
|
void
|
2012-04-25 08:53:07 +01:00
|
|
|
checkLabelMatchThis (const System sys, const Protocol p, const Role recvrole,
|
|
|
|
const Roledef recvevent)
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
Role sendrole;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
sendrole = p->roles;
|
|
|
|
while (sendrole != NULL)
|
|
|
|
{
|
|
|
|
Roledef event;
|
|
|
|
|
|
|
|
event = sendrole->roledef;
|
|
|
|
while (event != NULL)
|
|
|
|
{
|
|
|
|
if (event->type == SEND)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
if (isTermEqual (event->label, recvevent->label))
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
// Same labels, so they should match up!
|
2012-04-25 08:53:07 +01:00
|
|
|
if (!checkEventMatch (event, recvevent, p->rolenames))
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
globalError++;
|
2012-04-25 08:53:07 +01:00
|
|
|
eprintf ("error: [%i]", recvevent->lineno);
|
2007-01-29 13:15:35 +00:00
|
|
|
if (sys->protocols != NULL)
|
|
|
|
{
|
|
|
|
if (sys->protocols->next != NULL)
|
|
|
|
{
|
|
|
|
eprintf (" Protocol ");
|
|
|
|
termPrint (sys->protocols->nameterm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eprintf (" events for label ");
|
|
|
|
termPrint (event->label);
|
|
|
|
eprintf (" do not match, in particular: \n");
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf ("error: [%i] ", event->lineno);
|
2007-01-29 13:15:35 +00:00
|
|
|
roledefPrint (event);
|
|
|
|
eprintf (" does not match\n");
|
2012-04-25 08:53:07 +01:00
|
|
|
eprintf ("error: [%i] ", recvevent->lineno);
|
|
|
|
roledefPrint (recvevent);
|
2007-01-29 13:15:35 +00:00
|
|
|
eprintf ("\n");
|
|
|
|
error_die ();
|
2007-01-29 15:17:11 +00:00
|
|
|
globalError--;
|
2007-01-29 13:15:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
found++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (DEBUGL (2))
|
|
|
|
{
|
|
|
|
eprintf ("Matching up label ");
|
|
|
|
termPrint (event->label);
|
|
|
|
eprintf (" to match: ");
|
|
|
|
roledefPrint (event);
|
|
|
|
eprintf (" <> ");
|
2012-04-25 08:53:07 +01:00
|
|
|
roledefPrint (recvevent);
|
2007-01-29 13:15:35 +00:00
|
|
|
eprintf ("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event = event->next;
|
|
|
|
}
|
|
|
|
sendrole = sendrole->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* How many did we find?
|
|
|
|
* 1 is normal, more is interesting (branching?)
|
|
|
|
* 0 is not good, nobody will send it
|
|
|
|
*/
|
|
|
|
if (found == 0)
|
|
|
|
{
|
2007-01-29 15:05:15 +00:00
|
|
|
globalError++;
|
2012-04-25 08:53:07 +01:00
|
|
|
eprintf ("error: [%i] for the recv event ", recvevent->lineno);
|
|
|
|
roledefPrint (recvevent);
|
2007-01-29 13:15:35 +00:00
|
|
|
eprintf (" of protocol ");
|
|
|
|
termPrint (p->nameterm);
|
|
|
|
eprintf
|
|
|
|
(" there is no corresponding send event (with the same label and matching content). Start the label name with '!' if this is intentional.\n");
|
|
|
|
error_die ();
|
2007-01-29 15:05:15 +00:00
|
|
|
globalError--;
|
2007-01-29 13:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check label matchup for protocol p
|
|
|
|
void
|
|
|
|
checkLabelMatchProtocol (const System sys, const Protocol p)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
// For each recv label the sends should match
|
2007-01-29 13:15:35 +00:00
|
|
|
Role r;
|
|
|
|
|
|
|
|
r = p->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = r->roledef;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2012-04-25 08:53:07 +01:00
|
|
|
if (rd->type == RECV)
|
2007-01-29 13:15:35 +00:00
|
|
|
{
|
|
|
|
// We don't check all, if they start with a bang we ignore them.
|
|
|
|
Labelinfo li;
|
|
|
|
|
|
|
|
li = label_find (sys->labellist, rd->label);
|
|
|
|
if (li != NULL)
|
|
|
|
{
|
|
|
|
if (!li->ignore)
|
|
|
|
{
|
|
|
|
checkLabelMatchThis (sys, p, r, rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-29 15:05:15 +00:00
|
|
|
globalError++;
|
2007-01-29 17:20:45 +00:00
|
|
|
eprintf
|
|
|
|
("error: [%i] cannot determine label information for ",
|
|
|
|
rd->lineno);
|
2007-01-29 13:15:35 +00:00
|
|
|
roledefPrint (rd);
|
|
|
|
eprintf ("\n");
|
|
|
|
error_die ();
|
2007-01-29 15:05:15 +00:00
|
|
|
globalError--;
|
2007-01-29 13:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check label matchup
|
|
|
|
void
|
|
|
|
checkLabelMatching (const System sys)
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
// For each protocol
|
|
|
|
p = sys->protocols;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
checkLabelMatchProtocol (sys, p);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-14 23:08:47 +01:00
|
|
|
//! Preprocess after system compilation
|
2004-08-09 11:05:58 +01:00
|
|
|
void
|
2004-06-14 23:08:47 +01:00
|
|
|
preprocess (const System sys)
|
|
|
|
{
|
2007-05-18 13:06:29 +01:00
|
|
|
/*
|
|
|
|
* Add default terms afterwards
|
|
|
|
*/
|
|
|
|
specialTermInitAfter (sys);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up keylevels
|
|
|
|
* */
|
|
|
|
symbol_fix_keylevels ();
|
|
|
|
|
2004-06-16 16:28:20 +01:00
|
|
|
/*
|
|
|
|
* init some counters
|
|
|
|
*/
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->rolecount = compute_rolecount (sys);
|
|
|
|
sys->roleeventmax = compute_roleeventmax (sys);
|
2004-06-16 16:28:20 +01:00
|
|
|
/*
|
|
|
|
* compute preceding label sets
|
|
|
|
*/
|
2004-08-09 11:05:58 +01:00
|
|
|
compute_prec_sets (sys);
|
2007-01-29 13:15:35 +00:00
|
|
|
/*
|
|
|
|
* check whether labels match up
|
|
|
|
*/
|
|
|
|
checkLabelMatching (sys);
|
2005-12-27 13:44:12 +00:00
|
|
|
/*
|
|
|
|
* check for ununsed variables
|
|
|
|
*/
|
2006-07-31 12:08:51 +01:00
|
|
|
if (switches.check)
|
|
|
|
{
|
|
|
|
checkUnusedVariables (sys);
|
|
|
|
}
|
2006-07-27 12:55:24 +01:00
|
|
|
/*
|
|
|
|
* Initial knowledge
|
|
|
|
*/
|
2006-07-31 12:08:51 +01:00
|
|
|
if (sys->knowledgedefined)
|
|
|
|
{
|
|
|
|
initialIntruderKnowledge (sys);
|
|
|
|
}
|
2007-05-18 13:06:29 +01:00
|
|
|
/*
|
|
|
|
* compute hidelevels
|
|
|
|
*
|
|
|
|
* Needs to be done *after* the initial intruder knowledge derivation.
|
|
|
|
*/
|
|
|
|
hidelevelCompute (sys);
|
2006-07-31 12:08:51 +01:00
|
|
|
/*
|
|
|
|
* Check well-formedness
|
|
|
|
*/
|
2012-12-06 08:52:13 +00:00
|
|
|
checkWellFormed (sys);
|
2004-06-14 23:08:47 +01:00
|
|
|
}
|