Implemented equality/pattern matching support.
Introduced a new event: match(pattern,groundterm) This event can only be executed if pattern can be matched to groundterm. Variable substitutions are persistent with respect to later events in the same role. Currently implemented as syntactic sugar, essentially unfolded in role R to: fresh x; send ( R,R, { groundterm }x ); recv ( R,R, { pattern }x ); This work is not complete yet in the send that the output still contains the unfolding. Ideally, the graph rendered detects this syntactic sugar and renders a simplified event. This should be possible on the basis of the label name prefix. Conflicts: src/compiler.c src/parser.y src/scanner.l src/tac.h
This commit is contained in:
parent
9c9c6758f2
commit
d4faeacd1e
@ -764,6 +764,59 @@ claimCreate (const System sys, const Protocol protocol, const Role role,
|
||||
return cl;
|
||||
}
|
||||
|
||||
//! 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 */
|
||||
nsymb = symbolNextFree(TermSymb(TERM_Hidden));
|
||||
tvar = symbolDeclare(nsymb,false);
|
||||
//tvar->stype = termlistAdd(NULL,TERM_Nonce);
|
||||
|
||||
/* Make the concrete messages */
|
||||
mpat = tacTerm (tc->t1.tac);
|
||||
mmsg = tacTerm (tc->t2.tac);
|
||||
msg1 = makeTermEncrypt(mmsg,tvar);
|
||||
msg2 = makeTermEncrypt(mpat,tvar);
|
||||
|
||||
/* Declare the const */
|
||||
thisRole->declaredconsts = termlistAdd(thisRole->declaredconsts, tvar);
|
||||
|
||||
/* And send & recv combo (implementing the syntactic sugar) */
|
||||
label1 = freshTermPrefix(LABEL_Match);
|
||||
linfo = label_create (label1, thisProtocol);
|
||||
sys->labellist = list_append (sys->labellist, linfo);
|
||||
myrole = thisRole->nameterm;
|
||||
|
||||
/* add send event */
|
||||
thisRole->roledef = roledefAdd (thisRole->roledef, SEND, label1, myrole, myrole, msg1, NULL);
|
||||
markLastRoledef (thisRole->roledef, tc->lineno);
|
||||
/* add recv event */
|
||||
thisRole->roledef = roledefAdd (thisRole->roledef, RECV, label1, myrole, myrole, msg2, NULL);
|
||||
markLastRoledef (thisRole->roledef, tc->lineno);
|
||||
}
|
||||
|
||||
//! Parse a communication event tc of type event, and add a role definition event for it.
|
||||
void
|
||||
commEvent (int event, Tac tc)
|
||||
@ -1185,6 +1238,9 @@ roleCompile (Term nameterm, Tac tc)
|
||||
firstEvent = 0;
|
||||
commEvent (SEND, tc);
|
||||
break;
|
||||
case TAC_MATCH:
|
||||
matchEvent (tc);
|
||||
break;
|
||||
case TAC_CLAIM:
|
||||
commEvent (CLAIM, tc);
|
||||
break;
|
||||
|
10
src/parser.y
10
src/parser.y
@ -57,6 +57,7 @@ int yylex(void);
|
||||
%token HASHFUNCTION
|
||||
%token KNOWS
|
||||
%token TRUSTED
|
||||
%token MATCH
|
||||
|
||||
%type <tac> spdlcomplete
|
||||
%type <tac> spdlrep
|
||||
@ -196,6 +197,15 @@ event : READT label '(' termlist ')' ';'
|
||||
t->t2.tac = $4;
|
||||
$$ = t;
|
||||
}
|
||||
| MATCH '(' term ',' term ')' ';'
|
||||
{
|
||||
/* first argument is pattern, second should be
|
||||
* ground term */
|
||||
Tac t= tacCreate(TAC_MATCH);
|
||||
t->t1.tac = $3;
|
||||
t->t2.tac = $5;
|
||||
$$ = t;
|
||||
}
|
||||
| CLAIMT optlabel '(' termlist ')' ';'
|
||||
/* TODO maybe claims should be in the syntax */
|
||||
{ Tac t = tacCreate(TAC_CLAIM);
|
||||
|
@ -160,6 +160,7 @@ role { return ROLE; }
|
||||
read { return READT; }
|
||||
recv { return RECVT; }
|
||||
send { return SENDT; }
|
||||
match { return MATCH; }
|
||||
var { return VAR; }
|
||||
const { return CONST; }
|
||||
fresh { return FRESH; }
|
||||
|
@ -71,6 +71,8 @@ Term TERM_PK;
|
||||
Term TERM_SK;
|
||||
Term TERM_K;
|
||||
|
||||
Term LABEL_Match;
|
||||
|
||||
Termlist CLAIMS_dep_prec;
|
||||
|
||||
//! Init special terms
|
||||
@ -118,6 +120,9 @@ specialTermInit (const System sys)
|
||||
knowledgeAddInverse (sys->know, TERM_PK, TERM_SK);
|
||||
knowledgeAddTerm (sys->know, TERM_PK);
|
||||
|
||||
/* Define a prefix for labels for the match function */
|
||||
langcons (LABEL_Match, "!Match", TERM_Hidden);
|
||||
|
||||
/* Construct a list of claims that depend on prec being not-empty */
|
||||
/* basically all authentication claims */
|
||||
CLAIMS_dep_prec = termlistAdd (NULL, CLAIM_Niagree);
|
||||
|
@ -63,6 +63,8 @@ extern Term TERM_PK;
|
||||
extern Term TERM_SK;
|
||||
extern Term TERM_K;
|
||||
|
||||
extern Term LABEL_Match;
|
||||
|
||||
extern Termlist CLAIMS_dep_prec;
|
||||
|
||||
void specialTermInit (const System sys);
|
||||
|
Loading…
Reference in New Issue
Block a user