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:
Cas Cremers 2012-11-21 11:28:40 +01:00
parent 9c9c6758f2
commit d4faeacd1e
6 changed files with 76 additions and 1 deletions

View File

@ -764,6 +764,59 @@ claimCreate (const System sys, const Protocol protocol, const Role role,
return cl; 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. //! Parse a communication event tc of type event, and add a role definition event for it.
void void
commEvent (int event, Tac tc) commEvent (int event, Tac tc)
@ -1185,6 +1238,9 @@ roleCompile (Term nameterm, Tac tc)
firstEvent = 0; firstEvent = 0;
commEvent (SEND, tc); commEvent (SEND, tc);
break; break;
case TAC_MATCH:
matchEvent (tc);
break;
case TAC_CLAIM: case TAC_CLAIM:
commEvent (CLAIM, tc); commEvent (CLAIM, tc);
break; break;

View File

@ -57,6 +57,7 @@ int yylex(void);
%token HASHFUNCTION %token HASHFUNCTION
%token KNOWS %token KNOWS
%token TRUSTED %token TRUSTED
%token MATCH
%type <tac> spdlcomplete %type <tac> spdlcomplete
%type <tac> spdlrep %type <tac> spdlrep
@ -196,6 +197,15 @@ event : READT label '(' termlist ')' ';'
t->t2.tac = $4; t->t2.tac = $4;
$$ = t; $$ = 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 ')' ';' | CLAIMT optlabel '(' termlist ')' ';'
/* TODO maybe claims should be in the syntax */ /* TODO maybe claims should be in the syntax */
{ Tac t = tacCreate(TAC_CLAIM); { Tac t = tacCreate(TAC_CLAIM);

View File

@ -160,6 +160,7 @@ role { return ROLE; }
read { return READT; } read { return READT; }
recv { return RECVT; } recv { return RECVT; }
send { return SENDT; } send { return SENDT; }
match { return MATCH; }
var { return VAR; } var { return VAR; }
const { return CONST; } const { return CONST; }
fresh { return FRESH; } fresh { return FRESH; }

View File

@ -71,6 +71,8 @@ Term TERM_PK;
Term TERM_SK; Term TERM_SK;
Term TERM_K; Term TERM_K;
Term LABEL_Match;
Termlist CLAIMS_dep_prec; Termlist CLAIMS_dep_prec;
//! Init special terms //! Init special terms
@ -118,6 +120,9 @@ specialTermInit (const System sys)
knowledgeAddInverse (sys->know, TERM_PK, TERM_SK); knowledgeAddInverse (sys->know, TERM_PK, TERM_SK);
knowledgeAddTerm (sys->know, TERM_PK); 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 */ /* Construct a list of claims that depend on prec being not-empty */
/* basically all authentication claims */ /* basically all authentication claims */
CLAIMS_dep_prec = termlistAdd (NULL, CLAIM_Niagree); CLAIMS_dep_prec = termlistAdd (NULL, CLAIM_Niagree);

View File

@ -63,6 +63,8 @@ extern Term TERM_PK;
extern Term TERM_SK; extern Term TERM_SK;
extern Term TERM_K; extern Term TERM_K;
extern Term LABEL_Match;
extern Termlist CLAIMS_dep_prec; extern Termlist CLAIMS_dep_prec;
void specialTermInit (const System sys); void specialTermInit (const System sys);

View File

@ -50,7 +50,8 @@ enum tactypes
TAC_HASHFUNCTION, TAC_HASHFUNCTION,
TAC_UNTRUSTED, TAC_UNTRUSTED,
TAC_COMPROMISED, TAC_COMPROMISED,
TAC_USERTYPE TAC_USERTYPE,
TAC_MATCH
}; };
//! Structure to hold the compilation tree nodes //! Structure to hold the compilation tree nodes