2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
2012-04-24 12:56:51 +01:00
|
|
|
* Copyright (C) 2007-2012 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.
|
|
|
|
*/
|
|
|
|
|
2005-06-16 15:10:07 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "term.h"
|
2005-12-28 14:25:06 +00:00
|
|
|
#include "termlist.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "compiler.h"
|
2007-01-06 14:45:29 +00:00
|
|
|
#include "error.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some macros
|
|
|
|
*/
|
|
|
|
#define langhide(x,y) x = levelConst(symbolSysConst(" _" y "_ "))
|
2007-05-18 13:06:29 +01:00
|
|
|
#define langtype(x,y) x->stype = termlistAdd(x->stype,y)
|
2005-06-16 15:10:07 +01:00
|
|
|
#define langcons(x,y,z) x = levelConst(symbolSysConst(y)); langtype(x,z)
|
2012-07-09 10:24:42 +01:00
|
|
|
#define symmEveKey(a,b) knowledgeAddTerm (sys->know, makeTermEncrypt ( makeTermTuple(a, b), TERM_K ) );
|
|
|
|
|
2005-06-16 15:10:07 +01:00
|
|
|
|
|
|
|
/* externally used:
|
|
|
|
*/
|
|
|
|
|
|
|
|
Term TERM_Agent;
|
|
|
|
Term TERM_Function;
|
|
|
|
Term TERM_Hidden;
|
2012-10-02 12:43:30 +01:00
|
|
|
Term TERM_CoOld;
|
|
|
|
Term TERM_CoNew;
|
|
|
|
Term TERM_DeEx;
|
|
|
|
Term TERM_DeNew;
|
2005-06-16 15:10:07 +01:00
|
|
|
Term TERM_Type;
|
|
|
|
Term TERM_Nonce;
|
|
|
|
Term TERM_Ticket;
|
2011-01-04 14:48:49 +00:00
|
|
|
Term TERM_SessionKey;
|
2005-11-12 21:13:00 +00:00
|
|
|
Term TERM_Data;
|
2005-06-16 15:10:07 +01:00
|
|
|
|
|
|
|
Term TERM_Claim;
|
|
|
|
Term CLAIM_Secret;
|
2011-01-04 14:18:22 +00:00
|
|
|
Term CLAIM_Alive;
|
|
|
|
Term CLAIM_Weakagree;
|
2005-06-16 15:10:07 +01:00
|
|
|
Term CLAIM_Nisynch;
|
|
|
|
Term CLAIM_Niagree;
|
|
|
|
Term CLAIM_Empty;
|
2005-12-28 11:50:17 +00:00
|
|
|
Term CLAIM_Reachable;
|
2011-01-04 14:17:52 +00:00
|
|
|
Term CLAIM_SID;
|
|
|
|
Term CLAIM_SKR;
|
2011-01-04 14:10:14 +00:00
|
|
|
Term CLAIM_Commit;
|
|
|
|
Term CLAIM_Running;
|
2012-11-21 12:40:15 +00:00
|
|
|
Term CLAIM_Notequal;
|
2005-06-16 15:10:07 +01:00
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
Term AGENT_Alice;
|
|
|
|
Term AGENT_Bob;
|
|
|
|
Term AGENT_Charlie;
|
|
|
|
Term AGENT_Dave;
|
|
|
|
Term AGENT_Eve;
|
2010-11-10 10:15:00 +00:00
|
|
|
Term TERM_PK;
|
|
|
|
Term TERM_SK;
|
|
|
|
Term TERM_K;
|
2007-05-18 13:06:29 +01:00
|
|
|
|
2012-11-21 10:28:40 +00:00
|
|
|
Term LABEL_Match;
|
|
|
|
|
2005-12-28 14:25:06 +00:00
|
|
|
Termlist CLAIMS_dep_prec;
|
|
|
|
|
2005-06-16 15:10:07 +01:00
|
|
|
//! Init special terms
|
|
|
|
/**
|
|
|
|
* This is called by compilerInit
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
specialTermInit (const System sys)
|
|
|
|
{
|
|
|
|
/* Init system constants */
|
|
|
|
|
|
|
|
langhide (TERM_Type, "Type");
|
|
|
|
langhide (TERM_Hidden, "Hidden");
|
|
|
|
langhide (TERM_Claim, "Claim");
|
2012-10-02 12:43:30 +01:00
|
|
|
langhide (TERM_CoOld, "Co(Old)");
|
|
|
|
langhide (TERM_CoNew, "Co(New)");
|
|
|
|
langhide (TERM_DeEx, "DeEx");
|
|
|
|
langhide (TERM_DeNew, "DeNew");
|
2005-06-16 15:10:07 +01:00
|
|
|
|
|
|
|
langcons (TERM_Agent, "Agent", TERM_Type);
|
|
|
|
langcons (TERM_Function, "Function", TERM_Type);
|
|
|
|
langcons (TERM_Nonce, "Nonce", TERM_Type);
|
|
|
|
langcons (TERM_Ticket, "Ticket", TERM_Type);
|
2011-01-04 14:48:49 +00:00
|
|
|
langcons (TERM_SessionKey, "SessionKey", TERM_Type);
|
2005-11-12 21:13:00 +00:00
|
|
|
langcons (TERM_Data, "Data", TERM_Type);
|
2005-06-16 15:10:07 +01:00
|
|
|
|
|
|
|
langcons (CLAIM_Secret, "Secret", TERM_Claim);
|
2011-01-04 14:18:22 +00:00
|
|
|
langcons (CLAIM_Alive, "Alive", TERM_Claim);
|
|
|
|
langcons (CLAIM_Weakagree, "Weakagree", TERM_Claim);
|
2005-06-16 15:10:07 +01:00
|
|
|
langcons (CLAIM_Nisynch, "Nisynch", TERM_Claim);
|
|
|
|
langcons (CLAIM_Niagree, "Niagree", TERM_Claim);
|
|
|
|
langcons (CLAIM_Empty, "Empty", TERM_Claim);
|
2005-12-28 11:50:17 +00:00
|
|
|
langcons (CLAIM_Reachable, "Reachable", TERM_Claim);
|
2012-11-21 12:40:15 +00:00
|
|
|
langcons (CLAIM_Notequal, "NotEqual", TERM_Claim);
|
2005-12-28 14:25:06 +00:00
|
|
|
|
2011-01-04 14:17:52 +00:00
|
|
|
langcons (CLAIM_SID, "SID", TERM_Claim); // claim specifying session ID
|
|
|
|
langcons (CLAIM_SKR, "SKR", TERM_Claim); // claim specifying session key : doubles as secrecy claim
|
|
|
|
|
2011-01-04 14:10:14 +00:00
|
|
|
langcons (CLAIM_Commit, "Commit", TERM_Claim); // claim specifying session agreement for a subset of data items
|
|
|
|
langcons (CLAIM_Running, "Running", TERM_Claim); // claim for signaling data item possession (checked by commit)
|
|
|
|
|
2010-11-10 10:15:00 +00:00
|
|
|
/* Define default PKI using PK/SK/K */
|
|
|
|
langcons (TERM_PK, "pk", TERM_Function);
|
|
|
|
langcons (TERM_SK, "sk", TERM_Function);
|
|
|
|
langcons (TERM_K, "k", TERM_Function);
|
2013-04-26 10:36:41 +01:00
|
|
|
knowledgeAddInverseKeyFunctions (sys->know, TERM_PK, TERM_SK);
|
2010-11-10 10:15:00 +00:00
|
|
|
knowledgeAddTerm (sys->know, TERM_PK);
|
|
|
|
|
2012-11-21 10:28:40 +00:00
|
|
|
/* Define a prefix for labels for the match function */
|
|
|
|
langcons (LABEL_Match, "!Match", TERM_Hidden);
|
|
|
|
|
2005-12-28 14:25:06 +00:00
|
|
|
/* Construct a list of claims that depend on prec being not-empty */
|
|
|
|
/* basically all authentication claims */
|
|
|
|
CLAIMS_dep_prec = termlistAdd (NULL, CLAIM_Niagree);
|
|
|
|
CLAIMS_dep_prec = termlistAdd (CLAIMS_dep_prec, CLAIM_Nisynch);
|
2011-01-04 14:18:22 +00:00
|
|
|
CLAIMS_dep_prec = termlistAdd (CLAIMS_dep_prec, CLAIM_Alive);
|
|
|
|
CLAIMS_dep_prec = termlistAdd (CLAIMS_dep_prec, CLAIM_Weakagree);
|
2005-06-16 15:10:07 +01:00
|
|
|
}
|
2006-01-17 16:18:26 +00:00
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
//! After compilation (so the user gets the first choice)
|
|
|
|
void
|
|
|
|
specialTermInitAfter (const System sys)
|
|
|
|
{
|
2011-09-08 13:49:48 +01:00
|
|
|
Term SKE;
|
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
langcons (AGENT_Alice, "Alice", TERM_Agent);
|
|
|
|
langcons (AGENT_Bob, "Bob", TERM_Agent);
|
|
|
|
langcons (AGENT_Charlie, "Charlie", TERM_Agent);
|
|
|
|
langcons (AGENT_Dave, "Dave", TERM_Agent);
|
|
|
|
langcons (AGENT_Eve, "Eve", TERM_Agent);
|
|
|
|
|
|
|
|
knowledgeAddTerm (sys->know, AGENT_Alice);
|
|
|
|
knowledgeAddTerm (sys->know, AGENT_Bob);
|
|
|
|
knowledgeAddTerm (sys->know, AGENT_Charlie);
|
|
|
|
knowledgeAddTerm (sys->know, AGENT_Dave);
|
|
|
|
knowledgeAddTerm (sys->know, AGENT_Eve);
|
|
|
|
|
2012-07-09 10:24:42 +01:00
|
|
|
// Make special Eve keys and add to initial knowledge
|
2011-09-08 13:49:48 +01:00
|
|
|
SKE = makeTermEncrypt (AGENT_Eve, TERM_SK);
|
|
|
|
knowledgeAddTerm (sys->know, SKE);
|
2012-07-09 10:24:42 +01:00
|
|
|
symmEveKey (AGENT_Alice, AGENT_Eve);
|
|
|
|
symmEveKey (AGENT_Bob, AGENT_Eve);
|
|
|
|
symmEveKey (AGENT_Charlie, AGENT_Eve);
|
|
|
|
symmEveKey (AGENT_Eve, AGENT_Alice);
|
2007-05-18 13:06:29 +01:00
|
|
|
sys->untrusted = termlistAddNew (sys->untrusted, AGENT_Eve);
|
|
|
|
}
|
|
|
|
|
2006-01-17 16:18:26 +00:00
|
|
|
//! Determine whether this is a leaf construct with a ticket in it
|
|
|
|
int
|
|
|
|
isTicketTerm (Term t)
|
|
|
|
{
|
|
|
|
if (t != NULL)
|
|
|
|
{
|
|
|
|
if (realTermLeaf (t))
|
|
|
|
{
|
|
|
|
if (inTermlist (t->stype, TERM_Ticket))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (realTermVariable (t))
|
|
|
|
{
|
|
|
|
return isTicketTerm (t->subst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Determine whether this is a term with a Ticket in it
|
|
|
|
int
|
|
|
|
hasTicketSubterm (Term t)
|
|
|
|
{
|
|
|
|
// Doesn't work yet
|
|
|
|
return true;
|
|
|
|
}
|