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-07-24 16:05:20 +01:00
|
|
|
#ifndef SYSTEM
|
|
|
|
#define SYSTEM
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "termmap.h"
|
|
|
|
#include "termlist.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "knowledge.h"
|
2004-07-21 11:35:39 +01:00
|
|
|
#include "states.h"
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "role.h"
|
2004-08-15 12:55:22 +01:00
|
|
|
#include "list.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
#define runPointerGet(sys,run) sys->runs[run].index
|
|
|
|
#define runPointerSet(sys,run,newp) sys->runs[run].index = newp
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
enum outputs
|
2007-01-27 11:07:45 +00:00
|
|
|
{ EMPTY, ATTACK, STATESPACE, SUMMARY, PROOF };
|
2004-07-29 14:08:27 +01:00
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Protocol definition.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct protocol
|
|
|
|
{
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Name of the protocol encoded in a term.
|
2004-04-23 11:58:43 +01:00
|
|
|
Term nameterm;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! List of role definitions.
|
2004-04-23 11:58:43 +01:00
|
|
|
Role roles;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! List of role names.
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist rolenames;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! List of local terms for this protocol.
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist locals;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Pointer to next protocol.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct protocol *next;
|
2007-01-29 17:20:45 +00:00
|
|
|
int lineno; //!< Line number of definition (for errors)?
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Shorthand for protocol pointer.
|
2004-04-23 11:58:43 +01:00
|
|
|
typedef struct protocol *Protocol;
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Run container.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct run
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
Protocol protocol; //!< Protocol of this run.
|
|
|
|
Role role; //!< Role of this run.
|
|
|
|
int step; //!< Current execution point in the run (integer)
|
2006-02-26 15:00:58 +00:00
|
|
|
int rolelength; //!< Length of role
|
2006-03-15 21:30:19 +00:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
Roledef index; //!< Current execution point in the run (roledef pointer)
|
|
|
|
Roledef start; //!< Head of the run definition.
|
|
|
|
Knowledge know; //!< Current knowledge of the run.
|
2006-03-15 21:30:19 +00:00
|
|
|
|
2006-03-15 08:51:08 +00:00
|
|
|
Termlist rho; //!< As in semantics (copies in artefacts)
|
|
|
|
Termlist sigma; //!< As in semantics (copies in artefacts)
|
|
|
|
Termlist constants; //!< As in semantics (copies in artefacts)
|
2006-03-15 21:30:19 +00:00
|
|
|
|
2006-03-15 08:51:08 +00:00
|
|
|
Termlist locals; //!< Locals of the run (will be deprecated eventually)
|
2006-03-15 21:30:19 +00:00
|
|
|
Termlist artefacts; //!< Stuff created especially for this run, which can also include tuples (anything allocated)
|
2004-08-15 20:58:26 +01:00
|
|
|
Termlist substitutions; //!< The substitutions as they came from the roledef unifier
|
2006-03-15 21:30:19 +00:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
int prevSymmRun; //!< Used for symmetry reduction. Either -1, or the previous run with the same role def and at least a single parameter.
|
2012-04-25 08:53:07 +01:00
|
|
|
int firstNonAgentRecv; //!< Used for symmetry reductions for equal agents runs; -1 if there is no candidate.
|
2004-08-09 11:05:58 +01:00
|
|
|
int firstReal; //!< 1 if a choose was inserted, otherwise 0
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Shorthand for run pointer.
|
2004-04-23 11:58:43 +01:00
|
|
|
typedef struct run *Run;
|
|
|
|
|
2006-02-21 20:29:05 +00:00
|
|
|
//! Structure for information on special terms (cacheing)
|
|
|
|
struct hiddenterm
|
|
|
|
{
|
|
|
|
Term term;
|
|
|
|
unsigned int hideminimum;
|
|
|
|
unsigned int hideprotocol;
|
|
|
|
unsigned int hideknowledge;
|
|
|
|
struct hiddenterm *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Pointer shorthand
|
|
|
|
typedef struct hiddenterm *Hiddenterm;
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! The main state structure.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct system
|
|
|
|
{
|
2004-05-15 13:33:01 +01:00
|
|
|
int step; //!< Step in trace during exploration. Can be managed globally
|
|
|
|
Knowledge know; //!< Knowledge in currect step of system.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct parameters *parameters; // misc
|
|
|
|
/* static run info, maxruns */
|
|
|
|
Run runs;
|
|
|
|
|
|
|
|
/* global */
|
2004-05-15 13:33:01 +01:00
|
|
|
int maxruns; //!< Number of runs in the system.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* properties */
|
2004-05-15 13:33:01 +01:00
|
|
|
Termlist secrets; //!< Integrate secrets list into system.
|
2004-08-09 11:05:58 +01:00
|
|
|
Termlist synchronising_labels; //!< List of labels that might synchronise.
|
2004-05-15 13:33:01 +01:00
|
|
|
int shortestattack; //!< Length of shortest attack trace.
|
|
|
|
int maxtracelength; //!< helps to remember the length of the last trace.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* traversal */
|
2004-05-15 13:33:01 +01:00
|
|
|
int traverse; //!< Traversal method.
|
|
|
|
int explore; //!< Boolean: explore states after actions or not.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* counters */
|
2004-07-30 13:04:38 +01:00
|
|
|
states_t states; //!< States traversed
|
2004-07-21 11:35:39 +01:00
|
|
|
states_t interval; //!< Used to update state printing at certain intervals
|
|
|
|
states_t claims; //!< Number of claims encountered.
|
|
|
|
states_t failed; //!< Number of claims failed.
|
2005-06-07 14:40:56 +01:00
|
|
|
int attackid; //!< Global counter of attacks (used for assigning identifiers) within this Scyther call.
|
2006-04-02 13:29:02 +01:00
|
|
|
int num_regular_runs; //!< Number of regular runs
|
|
|
|
int num_intruder_runs; //!< Number of intruder runs
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* protocol definition */
|
2004-06-16 11:39:13 +01:00
|
|
|
Protocol protocols; //!< List of protocols in the system
|
|
|
|
Termlist locals; //!< List of local terms
|
|
|
|
Termlist variables; //!< List of all variables
|
2006-07-27 12:55:24 +01:00
|
|
|
Termlist agentnames; //!< List of all agent names (trusted and untrusted)
|
2004-06-16 11:39:13 +01:00
|
|
|
Termlist untrusted; //!< List of untrusted agent names
|
2006-02-21 20:29:05 +00:00
|
|
|
Termlist globalconstants; //!< List of global constants
|
|
|
|
Hiddenterm hidden; //!< List of hiddenterm constructs for Hidelevel lemma
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-06-14 23:08:47 +01:00
|
|
|
/* protocol preprocessing */
|
2004-06-16 11:39:13 +01:00
|
|
|
int rolecount; //!< Number of roles in the system
|
|
|
|
int roleeventmax; //!< Maximum number of events in a single role
|
2004-07-28 12:39:08 +01:00
|
|
|
int lastChooseRun; //!< Last run with a choose event
|
2004-06-16 11:39:13 +01:00
|
|
|
Claimlist claimlist; //!< List of claims in the system, with occurrence counts
|
2004-08-27 12:52:43 +01:00
|
|
|
List labellist; //!< List of labelinfo stuff
|
2006-07-31 12:08:51 +01:00
|
|
|
int knowledgedefined; //!< True if knowledge is defined for some role (which triggers well-formedness check etc.)
|
2008-01-28 14:23:40 +00:00
|
|
|
int hasUntypedVariable; //!< True if there is a variable in the role specification that can contain constructors
|
2004-06-14 23:08:47 +01:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* constructed trace pointers, static */
|
2004-06-16 11:39:13 +01:00
|
|
|
Roledef *traceEvent; //!< Trace roledefs: MaxRuns * maxRoledef
|
|
|
|
int *traceRun; //!< Trace run ids: MaxRuns * maxRoledef
|
|
|
|
Knowledge *traceKnow; //!< Trace intruder knowledge: Maxruns * maxRoledef
|
2004-07-21 11:35:39 +01:00
|
|
|
states_t *traceNode; //!< Trace node traversal: Maxruns * maxRoledef
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-15 12:55:22 +01:00
|
|
|
/* Arachne assistance */
|
|
|
|
List bindings; //!< List of bindings
|
2005-05-02 14:38:45 +01:00
|
|
|
Claimlist current_claim; //!< The claim under current investigation
|
2007-01-16 17:22:51 +00:00
|
|
|
Termlist trustedRoles; //!< Roles that should be trusted for this claim (the default, NULL, means all)
|
2012-10-02 12:43:30 +01:00
|
|
|
Termlist proofstate; //!< State of the proof markers
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct system *System;
|
|
|
|
|
2006-02-21 20:29:05 +00:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
System systemInit ();
|
|
|
|
void systemReset (const System sys);
|
2004-07-28 12:39:08 +01:00
|
|
|
void systemRuns (const System sys);
|
2004-07-20 13:41:56 +01:00
|
|
|
System systemDuplicate (const System fromsys);
|
|
|
|
void systemDestroy (const System sys);
|
|
|
|
void systemDone (const System sys);
|
|
|
|
void ensureValidRun (const System sys, int run);
|
2004-04-23 11:58:43 +01:00
|
|
|
void runPrint (Roledef rd);
|
2004-07-20 13:41:56 +01:00
|
|
|
void runsPrint (const System sys);
|
2004-04-23 11:58:43 +01:00
|
|
|
Term agentOfRunRole (const System sys, const int run, const Term role);
|
|
|
|
Term agentOfRun (const System sys, const int run);
|
|
|
|
void roleInstance (const System sys, const Protocol protocol, const Role role,
|
2004-08-15 20:58:26 +01:00
|
|
|
const Termlist paramlist, Termlist substlist);
|
2004-08-10 16:02:37 +01:00
|
|
|
void roleInstanceDestroy (const System sys);
|
2004-07-20 13:41:56 +01:00
|
|
|
void systemStart (const System sys);
|
2004-04-23 11:58:43 +01:00
|
|
|
void indent ();
|
|
|
|
|
|
|
|
Protocol protocolCreate (Term nameterm);
|
|
|
|
void locVarPrint (Termlist tl);
|
|
|
|
void protocolPrint (Protocol p);
|
|
|
|
void protocolsPrint (Protocol p);
|
2004-07-20 13:41:56 +01:00
|
|
|
int untrustedAgent (const System sys, Termlist agents);
|
2005-06-07 16:02:27 +01:00
|
|
|
void commandlinePrint (FILE * stream);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
int compute_rolecount (const System sys);
|
|
|
|
int compute_roleeventmax (const System sys);
|
|
|
|
|
2005-07-01 14:25:54 +01:00
|
|
|
int isAgentTrusted (const System sys, Term agent);
|
|
|
|
int isAgentlistTrusted (const System sys, Termlist agents);
|
|
|
|
int isRunTrusted (const System sys, const int run);
|
2004-07-28 12:39:08 +01:00
|
|
|
|
2006-02-27 16:08:17 +00:00
|
|
|
int iterateRuns (const System sys, int (*callback) (int r));
|
|
|
|
int iterateRegularRuns (const System sys, int (*callback) (int r));
|
|
|
|
int iterateEvents (const System sys, const int run,
|
|
|
|
int (*callback) (Roledef rd, int ev));
|
2006-05-26 12:27:05 +01:00
|
|
|
int iterateAllEvents (const System sys,
|
|
|
|
int (*callback) (int run, Roledef rd, int ev));
|
2006-02-27 16:08:17 +00:00
|
|
|
int iterateEventsType (const System sys, const int run, const int evtype,
|
|
|
|
int (*callback) (Roledef rd, int ev));
|
|
|
|
int iterateLocalToOther (const System sys, const int myrun,
|
|
|
|
int (*callback) (Term t));
|
2006-07-27 11:44:12 +01:00
|
|
|
int iterateRoles (const System sys, int (*callback) (Protocol p, Role r));
|
2006-02-27 16:08:17 +00:00
|
|
|
int firstOccurrence (const System sys, const int r, Term t, int evtype);
|
2006-03-08 15:12:58 +00:00
|
|
|
Roledef eventRoledef (const System sys, const int run, const int ev);
|
2006-04-02 13:07:25 +01:00
|
|
|
int countInitiators (const System sys);
|
2006-03-31 09:24:41 +01:00
|
|
|
int selfResponder (const System sys, const int run);
|
|
|
|
int selfResponders (const System sys);
|
2006-03-28 15:45:02 +01:00
|
|
|
int selfInitiator (const System sys, const int run);
|
|
|
|
int selfInitiators (const System sys);
|
2007-01-06 14:45:29 +00:00
|
|
|
int enoughAttacks (const System sys);
|
2011-04-01 14:23:20 +01:00
|
|
|
int isHelperProtocol (Protocol p);
|
2011-04-01 14:24:14 +01:00
|
|
|
int agentsUniqueRoles (const System sys);
|
2006-02-27 16:08:17 +00:00
|
|
|
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
//! Equality for run structure naming
|
|
|
|
/**
|
|
|
|
* For the modelchecker, there was an index called step. In Strand Space
|
|
|
|
* terminology, something like that is the height of the strand.
|
|
|
|
*/
|
|
|
|
#define height step
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
#endif
|