2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
|
|
|
* Copyright (C) 2007 Cas Cremers
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
|
|
|
|
/* externally used:
|
|
|
|
*/
|
|
|
|
|
|
|
|
Term TERM_Agent;
|
|
|
|
Term TERM_Function;
|
|
|
|
Term TERM_Hidden;
|
|
|
|
Term TERM_Type;
|
|
|
|
Term TERM_Nonce;
|
|
|
|
Term TERM_Ticket;
|
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;
|
|
|
|
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;
|
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
|
|
|
|
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");
|
|
|
|
|
|
|
|
langcons (TERM_Agent, "Agent", TERM_Type);
|
|
|
|
langcons (TERM_Function, "Function", TERM_Type);
|
|
|
|
langcons (TERM_Nonce, "Nonce", TERM_Type);
|
|
|
|
langcons (TERM_Ticket, "Ticket", 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);
|
|
|
|
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);
|
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
|
|
|
|
|
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);
|
|
|
|
knowledgeAddInverse (sys->know, TERM_PK, TERM_SK);
|
|
|
|
knowledgeAddTerm (sys->know, TERM_PK);
|
|
|
|
|
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);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|