2004-04-23 11:58:43 +01:00
|
|
|
/*
|
|
|
|
* LaTeX output component
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "memory.h"
|
|
|
|
#include "modelchecker.h"
|
|
|
|
#include "tracebuf.h"
|
|
|
|
#include "varbuf.h"
|
|
|
|
#include "output.h"
|
2004-05-19 09:44:27 +01:00
|
|
|
#include "latex.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Multiplication factor for distance between events in an MSC diagram.
|
2004-04-23 11:58:43 +01:00
|
|
|
#define EVENTSPACE 1
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Similarity factor required for connecting arrows. Ranges from 0 to 1.
|
2004-04-23 11:58:43 +01:00
|
|
|
#define LINKTHRESHOLD 0.95
|
|
|
|
|
|
|
|
extern const char *progname;
|
|
|
|
extern const char *releasetag;
|
|
|
|
extern int globalLatex;
|
|
|
|
extern Term TERM_Function;
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
/*! Additional information for an events. */
|
2004-04-23 12:03:07 +01:00
|
|
|
struct traceinfo
|
|
|
|
{
|
|
|
|
int match;
|
|
|
|
int position;
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* global variables for this module */
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Additional information for each event in the trace.
|
2004-04-23 11:58:43 +01:00
|
|
|
struct traceinfo *tinfo;
|
2004-05-14 18:29:26 +01:00
|
|
|
//! The maximum run number involved, plus 1.
|
2004-04-23 11:58:43 +01:00
|
|
|
int width;
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Landscape/portrait switch. Currently not used.
|
2004-04-23 11:58:43 +01:00
|
|
|
int landscape = 0;
|
2004-05-14 18:29:26 +01:00
|
|
|
|
|
|
|
//! Phase of MSC production.
|
|
|
|
/**
|
|
|
|
* In pass 1, the widths of the boxes are determined.
|
|
|
|
* In pass 2 the actual MSC is constructed.
|
|
|
|
*/
|
2004-05-13 15:49:04 +01:00
|
|
|
int pass;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* code */
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Start the latex output.
|
|
|
|
/** Prints some headers, and
|
|
|
|
* the command line that was used, as comments.
|
|
|
|
*@param sys The system buffer.
|
|
|
|
*@param argv The command line arguments as they were passed to the tool.
|
|
|
|
*@param argc The number of arguments.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexInit (const System sys, int argc, char **argv)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
int i;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("%%\n");
|
|
|
|
printf ("%% LaTeX output generated by %s\n", progname);
|
|
|
|
printf ("%% Input:\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* print command line */
|
|
|
|
printf ("%% $");
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
printf (" %s", argv[i]);
|
|
|
|
printf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("%%\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
/* comment macro (used for debugging) */
|
|
|
|
printf ("\\newcommand{\\comment}[1]{}\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Close up any LaTeX output.
|
|
|
|
/**
|
|
|
|
*@param sys The system state.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexDone (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 14:23:33 +01:00
|
|
|
/* closing of the document */
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Print a term using LaTeX and highlighting.
|
|
|
|
/**
|
|
|
|
* Basically a recode of termPrint, now specific using latex codes and with a
|
2004-05-19 09:39:39 +01:00
|
|
|
* highlighting feature. There is still some obsolete code to show variable mappings in a term.
|
2004-05-14 18:29:26 +01:00
|
|
|
*@param term a term to be printed.
|
|
|
|
*@param highlight a list of terms to be highlighted.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
latexTermPrint (Term term, Termlist highlight)
|
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
if (term == NULL)
|
|
|
|
{
|
|
|
|
printf ("Empty term");
|
|
|
|
return;
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
#ifdef DEBUG
|
2004-04-23 12:03:07 +01:00
|
|
|
if (!DEBUGL (1))
|
|
|
|
{
|
|
|
|
term = deVar (term);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
#else
|
2004-04-23 12:03:07 +01:00
|
|
|
term = deVar (term);
|
2004-04-23 11:58:43 +01:00
|
|
|
#endif
|
2004-04-23 12:03:07 +01:00
|
|
|
if (realTermLeaf (term))
|
|
|
|
{
|
|
|
|
if (inTermlist (highlight, term))
|
|
|
|
printf ("\\mathbf{");
|
2004-11-16 12:06:36 +00:00
|
|
|
symbolPrint (TermSymb(term));
|
2004-04-23 12:03:07 +01:00
|
|
|
if (realTermVariable (term))
|
|
|
|
printf ("V");
|
2004-11-16 12:06:36 +00:00
|
|
|
if (TermRunid(term) >= 0)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-11-16 12:06:36 +00:00
|
|
|
printf ("\\sharp%i", TermRunid(term));
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
if (term->subst != NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\\rightarrow");
|
|
|
|
latexTermPrint (term->subst, highlight);
|
|
|
|
}
|
|
|
|
if (inTermlist (highlight, term))
|
|
|
|
printf ("}");
|
|
|
|
}
|
|
|
|
if (realTermTuple (term))
|
|
|
|
{
|
|
|
|
printf ("(");
|
2004-05-19 09:44:27 +01:00
|
|
|
latexTermTuplePrint (term, highlight);
|
2004-04-23 12:03:07 +01:00
|
|
|
printf (")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (realTermEncrypt (term))
|
|
|
|
{
|
2004-11-16 12:06:36 +00:00
|
|
|
if (isTermLeaf (TermKey(term))
|
|
|
|
&& inTermlist (TermKey(term)->stype, TERM_Function))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
/* function application */
|
2004-11-16 12:06:36 +00:00
|
|
|
latexTermPrint (TermKey(term), highlight);
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("(");
|
2004-11-16 12:06:36 +00:00
|
|
|
latexTermTuplePrint (TermOp(term), highlight);
|
2004-04-23 12:03:07 +01:00
|
|
|
printf (")");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* normal encryption */
|
|
|
|
printf ("\\{");
|
2004-11-16 12:06:36 +00:00
|
|
|
latexTermTuplePrint (TermOp(term), highlight);
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\\}_{");
|
2004-11-16 12:06:36 +00:00
|
|
|
latexTermPrint (TermKey(term), highlight);
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("}");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-19 09:39:39 +01:00
|
|
|
//! Print an inner (tuple) term using LaTeX, without brackets.
|
|
|
|
/**
|
|
|
|
* The tuple printing only works correctly for normalized terms.
|
|
|
|
* If not, they might are displayed as "((x,y),z)". Maybe that is even
|
|
|
|
* desirable to distinguish them.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
latexTermTuplePrint (Term term, Termlist hl)
|
|
|
|
{
|
|
|
|
if (term == NULL)
|
|
|
|
{
|
|
|
|
printf ("Empty term");
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
term = deVar (term);
|
2004-05-19 09:39:39 +01:00
|
|
|
while (realTermTuple (term))
|
|
|
|
{
|
|
|
|
// To remove any brackets, change this into latexTermTuplePrint.
|
2004-11-16 12:06:36 +00:00
|
|
|
latexTermPrint (TermOp1(term), hl);
|
2004-05-19 09:39:39 +01:00
|
|
|
printf (",");
|
2004-11-16 12:06:36 +00:00
|
|
|
term = deVar (TermOp2(term));
|
2004-05-19 09:39:39 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
latexTermPrint (term, hl);
|
2004-05-19 09:39:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Print a termlist in LaTeX using highlighting.
|
|
|
|
/**
|
|
|
|
* Extending LaTeX term printing to term list printing, again with highlight
|
2004-05-12 15:45:50 +01:00
|
|
|
* list parameter.
|
2004-05-14 18:29:26 +01:00
|
|
|
*@param tl A term list to print.
|
|
|
|
*@param highlight Any terms to be highlighted.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
latexTermlistPrint (Termlist tl, Termlist highlight)
|
|
|
|
{
|
|
|
|
if (tl == NULL)
|
|
|
|
{
|
2004-05-12 16:16:11 +01:00
|
|
|
printf ("\\emptyset");
|
2004-04-23 11:58:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
latexTermPrint (tl->term, highlight);
|
|
|
|
tl = tl->next;
|
|
|
|
if (tl != NULL)
|
2004-04-23 12:03:07 +01:00
|
|
|
printf (", ");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Display the timers and states traversed using LaTeX.
|
2004-05-21 13:32:57 +01:00
|
|
|
/**
|
|
|
|
* Obsolete: we will now only print timers on stderr.
|
|
|
|
*/
|
2004-05-12 15:45:50 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexTimers (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Start drawing MSC environment.
|
|
|
|
/**
|
|
|
|
* Includes printing title.
|
|
|
|
*@param protocolnames A termlist with protocol name terms.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
2004-04-23 15:11:51 +01:00
|
|
|
latexMSCStart (Termlist protocolnames)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
if (landscape)
|
|
|
|
printf ("\\begin{landscape}\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 15:11:51 +01:00
|
|
|
printf ("\\begin{msc}{attack on $");
|
2004-05-12 16:19:40 +01:00
|
|
|
termlistPrint (protocolnames);
|
2004-04-23 15:11:51 +01:00
|
|
|
printf ("$}\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Close drawing MSC
|
2004-05-12 15:45:50 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexMSCEnd ()
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\\end{msc}\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (landscape)
|
|
|
|
printf ("\\end{landscape}\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
/**
|
2004-05-12 15:45:50 +01:00
|
|
|
* Declare the MSC stick for a single instance of a run participating in an
|
|
|
|
* attack.
|
2004-05-13 11:06:21 +01:00
|
|
|
* This involves layout of the partners roles, and the agent etc.
|
2004-05-14 18:29:26 +01:00
|
|
|
*@param sys System state.
|
|
|
|
*@param run The run to be declared.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexDeclInst (const System sys, int run)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-05-13 11:06:21 +01:00
|
|
|
Term myAgent;
|
|
|
|
Term myRole;
|
|
|
|
Termlist roles;
|
|
|
|
int first;
|
|
|
|
|
|
|
|
myAgent = agentOfRun (sys, run);
|
|
|
|
myRole = sys->runs[run].role->nameterm;
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass == 1)
|
|
|
|
{
|
|
|
|
printf ("\\maxlength{\\maxmscinst}{");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("\\declinst{run%i}{", run);
|
|
|
|
}
|
2004-05-13 11:06:21 +01:00
|
|
|
|
|
|
|
/* display above assumptions */
|
|
|
|
roles = sys->runs[run].protocol->rolenames;
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass == 2)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("assumes $");
|
|
|
|
first = 1;
|
|
|
|
while (roles != NULL)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (!isTermEqual (myRole, roles->term))
|
|
|
|
{
|
|
|
|
if (!first)
|
2004-08-09 11:05:58 +01:00
|
|
|
printf (", ");
|
2004-05-13 15:49:04 +01:00
|
|
|
else
|
2004-08-09 11:05:58 +01:00
|
|
|
first = 0;
|
|
|
|
termPrint (agentOfRunRole (sys, run, roles->term));
|
|
|
|
printf (": ");
|
2004-05-13 15:49:04 +01:00
|
|
|
termPrint (roles->term);
|
|
|
|
}
|
|
|
|
roles = roles->next;
|
2004-05-13 11:06:21 +01:00
|
|
|
}
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("$}{");
|
2004-05-13 11:06:21 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
|
2004-05-13 11:06:21 +01:00
|
|
|
/* display agent and role */
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("$\\mathbf{");
|
2004-05-13 11:06:21 +01:00
|
|
|
termPrint (myAgent);
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("}: ");
|
2004-05-13 11:06:21 +01:00
|
|
|
termPrint (myRole);
|
2004-08-09 11:05:58 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("$}\n");
|
2004-05-13 11:06:21 +01:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
termDelete (myAgent);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Add vertical space in MSC diagrams.
|
|
|
|
/**
|
2004-05-12 15:45:50 +01:00
|
|
|
* Make some space in the diagram by nextlevels.
|
|
|
|
* TODO: can be incorporated in nextlevel[param] without loop.
|
2004-05-14 18:29:26 +01:00
|
|
|
*@param amount the line integer.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexEventSpace (int amount)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-05-26 13:17:09 +01:00
|
|
|
int i;
|
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass < 2)
|
|
|
|
{
|
|
|
|
/* not printing */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
//printf("%% number of newlines: %d\n",amount);
|
|
|
|
for (i = 0; i < EVENTSPACE * amount; i++)
|
|
|
|
printf ("\\nextlevel\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! MSC message print.
|
|
|
|
/**
|
2004-05-12 15:45:50 +01:00
|
|
|
* Print an arrow with message from event i to event j, as defined in the
|
|
|
|
* tracebuffer. If either i or j are -1, the intruder is meant.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexMessagePrint (struct tracebuf *tb, int from, int to)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
Term sendTerm = NULL;
|
|
|
|
Term readTerm = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass < 2)
|
|
|
|
{
|
|
|
|
/* no measurement of messages yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (from == -1 && to == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from != -1)
|
|
|
|
{
|
|
|
|
sendTerm = tb->event[from]->message;
|
|
|
|
}
|
|
|
|
if (to != -1)
|
|
|
|
{
|
|
|
|
readTerm = tb->event[to]->message;
|
|
|
|
}
|
|
|
|
if (from == -1 && to != -1)
|
|
|
|
{
|
2004-05-12 15:45:50 +01:00
|
|
|
/* message from intruder into system */
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("\\mess{$");
|
2004-04-23 12:03:07 +01:00
|
|
|
termPrint (readTerm);
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("$}{eve}{run%d}\n", tb->run[to]);
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
else if (from != -1 && to == -1)
|
|
|
|
{
|
2004-05-12 15:45:50 +01:00
|
|
|
/* message from system to intruder */
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("\\mess{$");
|
2004-04-23 12:03:07 +01:00
|
|
|
termPrint (sendTerm);
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("$}{run%d}{eve}\n", tb->run[from]);
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
else if (from != -1 && to != -1)
|
|
|
|
{
|
2004-05-12 15:45:50 +01:00
|
|
|
/* message from one agent to another, possibly transformed */
|
2004-04-23 12:03:07 +01:00
|
|
|
|
|
|
|
printf ("\\mess{$");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
termPrint (sendTerm);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (!isTermEqual (sendTerm, readTerm))
|
|
|
|
{
|
|
|
|
printf ("\\rightarrow");
|
|
|
|
termPrint (readTerm);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
|
|
|
|
printf ("$}{run%d", tb->run[from]);
|
|
|
|
printf ("}{run%d}[%d]", tb->run[to],
|
|
|
|
EVENTSPACE * (tinfo[to].position - tinfo[from].position));
|
|
|
|
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-05-12 15:45:50 +01:00
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
/**
|
2004-05-12 15:56:45 +01:00
|
|
|
* hmm? TODO apparently, some other variant used, with duplicate handling of
|
|
|
|
* lost and found ??? But only using lost... weirdness.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexMessagePrintHighlight (struct tracebuf *tb, int from, int to,
|
|
|
|
Termlist highlight)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
Term sendTerm = NULL;
|
|
|
|
Term readTerm = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass < 2)
|
|
|
|
{
|
|
|
|
/* no measurements on message width yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (from == -1 && to == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (from != -1)
|
|
|
|
{
|
|
|
|
sendTerm = tb->event[from]->message;
|
|
|
|
}
|
|
|
|
if (to != -1)
|
|
|
|
{
|
|
|
|
readTerm = tb->event[to]->message;
|
|
|
|
}
|
|
|
|
if (from == -1 && to != -1)
|
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
/* TODO redundant */
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\\found{$");
|
|
|
|
latexTermPrint (readTerm, highlight);
|
|
|
|
printf ("$}{}{run%d}\n", tb->run[to]);
|
|
|
|
}
|
|
|
|
else if (from != -1 && to == -1)
|
|
|
|
{
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("\\mess{$");
|
2004-04-23 12:03:07 +01:00
|
|
|
latexTermPrint (sendTerm, highlight);
|
2004-05-12 15:56:45 +01:00
|
|
|
printf ("$}{run%d}{eve}\n", tb->run[from]);
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
else if (from != -1 && to != -1)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf ("\\mess{$");
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
latexTermPrint (sendTerm, highlight);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (!isTermEqual (sendTerm, readTerm))
|
|
|
|
{
|
|
|
|
printf ("\\rightarrow");
|
|
|
|
latexTermPrint (readTerm, highlight);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
|
|
|
|
printf ("$}{run%d", tb->run[from]);
|
|
|
|
printf ("}{run%d}[%d]", tb->run[to],
|
|
|
|
EVENTSPACE * (tinfo[to].position - tinfo[from].position));
|
|
|
|
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-05-12 15:45:50 +01:00
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Display claim violation.
|
|
|
|
/**
|
|
|
|
* For now, only secrecy: TODO
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
latexClaim (struct tracebuf *tb, int run, Termlist tl)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass == 1)
|
|
|
|
{
|
|
|
|
printf ("\\maxlength{\\maxmsccondition}{");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("\\condition{");
|
|
|
|
}
|
|
|
|
printf ("$\\neg secret ");
|
2004-04-23 12:03:07 +01:00
|
|
|
termlistPrint (tl);
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("$}");
|
|
|
|
if (pass == 1)
|
|
|
|
{
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("{run%d}\n", run);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Determine matching send event.
|
|
|
|
/**
|
2004-05-12 15:45:50 +01:00
|
|
|
* Given a read event, tries to find a corresponding send event in the trace
|
2004-05-14 18:29:26 +01:00
|
|
|
* buffer. Currently unused.
|
2004-05-12 15:45:50 +01:00
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int
|
|
|
|
latexCorrespondingSend (struct tracebuf *tb, int rd)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int labelMatch = 0;
|
|
|
|
int toMatch = 0;
|
|
|
|
int fromMatch = 0;
|
|
|
|
int tofromMatch = 0;
|
|
|
|
int messageMatch = 0;
|
|
|
|
int nMatches = 0;
|
|
|
|
int maxNMatches = 0;
|
|
|
|
|
|
|
|
int readEvent = rd;
|
|
|
|
int sendEvent = -1;
|
|
|
|
int bestSendEvent = -1;
|
|
|
|
|
|
|
|
for (sendEvent = readEvent; sendEvent >= 0; sendEvent--)
|
|
|
|
{
|
|
|
|
if (tb->event[sendEvent]->type == SEND)
|
|
|
|
{
|
|
|
|
/* do all the different kind of matchings first */
|
|
|
|
|
|
|
|
labelMatch =
|
|
|
|
isTermEqual (tb->event[sendEvent]->label,
|
|
|
|
tb->event[readEvent]->label);
|
|
|
|
toMatch =
|
|
|
|
isTermEqual (tb->event[sendEvent]->to, tb->event[readEvent]->to);
|
|
|
|
fromMatch =
|
|
|
|
isTermEqual (tb->event[sendEvent]->from,
|
|
|
|
tb->event[readEvent]->from);
|
|
|
|
tofromMatch = toMatch || fromMatch;
|
|
|
|
messageMatch =
|
|
|
|
isTermEqual (tb->event[sendEvent]->message,
|
|
|
|
tb->event[readEvent]->message);
|
|
|
|
|
|
|
|
/* calculate the score */
|
|
|
|
|
|
|
|
nMatches = labelMatch + tofromMatch + messageMatch;
|
|
|
|
|
|
|
|
if (nMatches == 3)
|
|
|
|
{
|
|
|
|
/* bingo! success on all matches */
|
|
|
|
|
|
|
|
//printf("Found perfect match: %d\n", s);
|
|
|
|
bestSendEvent = sendEvent;
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
if (nMatches > maxNMatches)
|
|
|
|
{
|
|
|
|
if (labelMatch && messageMatch)
|
|
|
|
{
|
|
|
|
/* strongest restriction: message and label should match */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
else if (messageMatch)
|
|
|
|
{
|
|
|
|
/* if label AND message don't match: */
|
|
|
|
/* at least message should match */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
|
|
|
}
|
|
|
|
else if (labelMatch)
|
|
|
|
{
|
|
|
|
/* if message doesn't match */
|
|
|
|
/* the label should matches */
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
maxNMatches = nMatches;
|
|
|
|
bestSendEvent = sendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
//bestSendEvent = NULL;
|
|
|
|
if (bestSendEvent == -1)
|
|
|
|
{
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int u;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (u = 0; u < rd; u++)
|
|
|
|
{
|
|
|
|
if (tb->event[u]->type == SEND)
|
|
|
|
{
|
|
|
|
//knowledgePrint(sys->traceKnow[u]);
|
|
|
|
if (inKnowledge
|
|
|
|
(tb->know[u + 1], tb->event[readEvent]->message))
|
|
|
|
{
|
|
|
|
bestSendEvent = u;
|
|
|
|
break;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (bestSendEvent == -1)
|
|
|
|
{
|
|
|
|
printf ("%% Could not find a matching SEND\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
return bestSendEvent;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Determine matching send event.
|
|
|
|
/**
|
2004-05-12 15:45:50 +01:00
|
|
|
* Simplified variant of finding the matching send event.
|
|
|
|
* However, if it is introduced at a non-send event, things start to break
|
|
|
|
* done. REVIEW later.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
int
|
|
|
|
latexCorrespondingSend2 (struct tracebuf *tb, int readEvent)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
int u;
|
|
|
|
|
|
|
|
for (u = tb->length - 1; u >= 0; u--)
|
|
|
|
{
|
|
|
|
if (tb->event[u]->type == SEND)
|
|
|
|
{
|
|
|
|
if (!inKnowledge (tb->know[u], tb->event[readEvent]->message))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
printf("%% term[");
|
|
|
|
printf("]#%d is introduced at traceEvent[%d] ",readEvent,u);
|
|
|
|
printf("\n");
|
|
|
|
*/
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Display knowledge in LaTeX.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
|
|
|
knowledgePrintLatex (Knowledge know)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
Termlist tl;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
if (know == NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
printf ("\\emptyset");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
else
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
tl = knowledgeSet (know);
|
2004-05-12 16:19:40 +01:00
|
|
|
latexTermlistPrint (tl, NULL);
|
2004-04-23 12:03:07 +01:00
|
|
|
termlistDelete (tl);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-14 18:29:26 +01:00
|
|
|
//! Display the attack in the systems attack buffer using LaTeX.
|
2004-05-12 15:45:50 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
attackDisplayLatex (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
int i;
|
|
|
|
struct tracebuf *tb;
|
|
|
|
int *runPosition;
|
|
|
|
int currRun;
|
|
|
|
int position;
|
|
|
|
int eventSize;
|
|
|
|
Termlist tl;
|
|
|
|
Termlist newtl;
|
|
|
|
Termlist claimDetails;
|
|
|
|
Termlist highlights = NULL;
|
|
|
|
int cKnowledge;
|
|
|
|
int bestSend;
|
|
|
|
|
|
|
|
tb = sys->attack;
|
|
|
|
if (tb == NULL)
|
|
|
|
{
|
|
|
|
printf ("Attack pointer empty: nothing to display.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
/* set variables */
|
|
|
|
varbufSet (sys, tb->variables);
|
|
|
|
|
|
|
|
/* Rebuild knowledge. Strange, this ought to be good.
|
|
|
|
* Maybe reconstruct dependencies as well. */
|
|
|
|
tracebufRebuildKnow (tb);
|
|
|
|
|
|
|
|
/* Make a comment in which the trace is displayed, for debugging etc. */
|
|
|
|
printf ("\n\\comment{ TRACE\n\n");
|
|
|
|
printf ("Length: %i\n", tb->length);
|
|
|
|
printf ("Reallength: %i\n", tb->reallength);
|
|
|
|
printf ("\n");
|
|
|
|
i = 0;
|
|
|
|
while (i <= tb->length)
|
|
|
|
{
|
|
|
|
printf ("Knowledge %i:\n", i);
|
|
|
|
knowledgePrint (tb->know[i]);
|
|
|
|
printf (" [Inverses]: ");
|
|
|
|
knowledgeInversesPrint (tb->know[i]);
|
|
|
|
printf ("\n\n");
|
|
|
|
if (i < tb->length)
|
|
|
|
{
|
|
|
|
printf ("Event %i\t[", i);
|
|
|
|
switch (tb->status[i])
|
|
|
|
{
|
|
|
|
case S_UNK:
|
|
|
|
printf ("?");
|
|
|
|
break;
|
|
|
|
case S_RED:
|
|
|
|
printf ("redundant");
|
|
|
|
break;
|
|
|
|
case S_TOD:
|
|
|
|
printf ("to do");
|
|
|
|
break;
|
|
|
|
case S_OKE:
|
|
|
|
printf ("okay");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("illegal status code");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf ("]\t");
|
|
|
|
termPrint (tb->event[i]->message);
|
|
|
|
printf ("\t#%i", tb->run[i]);
|
|
|
|
printf ("\n");
|
|
|
|
roledefPrint (tb->event[i]);
|
|
|
|
printf ("\n\n");
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
printf ("}\n\n");
|
|
|
|
|
|
|
|
tinfo =
|
|
|
|
(struct traceinfo *) memAlloc ((tb->length + 1) *
|
|
|
|
sizeof (struct traceinfo));
|
|
|
|
|
2004-05-12 15:45:50 +01:00
|
|
|
/*
|
|
|
|
* Determine width, which is the 1+max(runid involved in the attack)
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
width = 1;
|
|
|
|
for (i = 0; i < tb->length; i++)
|
|
|
|
{
|
2004-05-12 15:45:50 +01:00
|
|
|
// TODO: I would expect here a redundancy test
|
2004-04-23 12:03:07 +01:00
|
|
|
if (tb->run[i] >= width)
|
|
|
|
width = tb->run[i] + 1;
|
|
|
|
}
|
|
|
|
|
2004-05-12 15:45:50 +01:00
|
|
|
/*
|
|
|
|
* Initialise tinfo arrays.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = 0; i < tb->length; i++)
|
|
|
|
{
|
|
|
|
tb->link[i] = -1;
|
|
|
|
tinfo[i].match = -1;
|
|
|
|
tinfo[i].position = i;
|
|
|
|
}
|
|
|
|
tinfo[i].match = -1;
|
|
|
|
tinfo[i].position = i;
|
|
|
|
|
2004-05-12 15:45:50 +01:00
|
|
|
/*
|
|
|
|
* Init array of positions (ordering) of the MSC lines.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
runPosition = (int *) memAlloc (width * sizeof (int));
|
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
runPosition[i] = 0;
|
|
|
|
}
|
2004-05-12 15:45:50 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine corresponding sends and thus links
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
for (i = tb->length - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (tb->status[i] != S_RED)
|
|
|
|
{
|
|
|
|
if (tb->event[i]->type == READ && !tb->event[i]->internal)
|
|
|
|
{
|
|
|
|
bestSend = latexCorrespondingSend2 (tb, i);
|
|
|
|
printf ("%% match: %d <-> %d\n", i, bestSend);
|
|
|
|
if (bestSend == -1)
|
2004-05-12 15:45:50 +01:00
|
|
|
continue; // TODO major ugliness
|
2004-04-23 12:03:07 +01:00
|
|
|
|
|
|
|
tb->link[i] = bestSend;
|
|
|
|
tb->link[bestSend] = i;
|
|
|
|
}
|
|
|
|
if (tb->event[i]->type == CLAIM)
|
|
|
|
{
|
|
|
|
claimDetails =
|
|
|
|
claimViolationDetails (sys, tb->run[i], tb->event[i],
|
|
|
|
tb->know[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("\\comment{ claimDetails :\n");
|
|
|
|
termlistPrint (claimDetails);
|
|
|
|
printf ("\n}\n");
|
|
|
|
|
|
|
|
// landscape = (width > 4); // not for the time being
|
|
|
|
|
2004-05-12 15:45:50 +01:00
|
|
|
/*
|
|
|
|
* Apparently unlinks things that do not meet the threshold.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
position = 0;
|
|
|
|
currRun = 0;
|
|
|
|
eventSize = 0;
|
|
|
|
for (i = 0; i < tb->length; i++)
|
|
|
|
{
|
|
|
|
if (tb->status[i] != S_RED)
|
|
|
|
{
|
|
|
|
tinfo[i].position = position;
|
|
|
|
eventSize = 1;
|
|
|
|
currRun = tb->run[i];
|
|
|
|
|
|
|
|
switch (tb->event[i]->type)
|
|
|
|
{
|
|
|
|
case SEND:
|
|
|
|
position++;
|
|
|
|
tinfo[i].position++;
|
|
|
|
break;
|
|
|
|
case READ:
|
|
|
|
if (tb->link[i] != -1)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-04-23 12:03:07 +01:00
|
|
|
if (termDistance
|
|
|
|
(tb->event[i]->message,
|
|
|
|
tb->event[tb->link[i]]->message) < LINKTHRESHOLD)
|
|
|
|
{
|
|
|
|
/* disconnect read-send */
|
|
|
|
tb->link[tb->link[i]] = -1;
|
|
|
|
tb->link[i] = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (runPosition[currRun] <= tinfo[tb->link[i]].position
|
|
|
|
&& currRun != tb->run[tb->link[i]])
|
|
|
|
{
|
|
|
|
printf ("\\comment{\n");
|
|
|
|
termPrint (tb->event[i]->message);
|
|
|
|
printf ("\n");
|
|
|
|
termPrint (tb->event[tb->link[i]]->message);
|
|
|
|
printf ("\n");
|
|
|
|
printf ("%% termDistance: %f\n",
|
|
|
|
termDistance (tb->event[i]->message,
|
|
|
|
tb->event[tb->link[i]]->
|
|
|
|
message));
|
|
|
|
printf ("}\n");
|
|
|
|
tinfo[i].position = tinfo[tb->link[i]].position;
|
|
|
|
eventSize = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
if (tb->event[i]->internal)
|
|
|
|
{
|
|
|
|
eventSize = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLAIM:
|
|
|
|
if (claimDetails != NULL && claimDetails != (Termlist) - 1)
|
|
|
|
{
|
|
|
|
eventSize = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventSize = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(tb->event[i]->type == READ && tb->event[i]->internal))
|
|
|
|
runPosition[currRun] = tinfo[i].position + eventSize;
|
|
|
|
/* printf("%% Event %d at %d\n", i, position); */
|
|
|
|
position += eventSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* ------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Start of MSC creation (2-phase)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------
|
|
|
|
*/
|
2004-04-23 15:11:51 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* 2 pass for widths */
|
|
|
|
|
|
|
|
for (pass = 1; pass <= 2; pass++)
|
2004-04-23 15:11:51 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("%% Pass %i\n\n", pass);
|
2004-05-13 15:49:04 +01:00
|
|
|
|
|
|
|
if (pass == 1)
|
2004-04-23 15:11:51 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("\\maxlength{\\maxmscaction}{knows}\n");
|
|
|
|
printf ("\\maxlength{\\maxmscaction}{creates}\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-26 13:17:09 +01:00
|
|
|
Termlist protocolnames;
|
|
|
|
Term pname;
|
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* slightly stretch measurements */
|
|
|
|
printf ("\\addtolength{\\maxmscall}{2\\mscspacer}\n");
|
|
|
|
printf ("\\addtolength{\\maxmscaction}{\\mscspacer}\n");
|
|
|
|
printf ("\\addtolength{\\maxmscinst}{\\mscspacer}\n");
|
|
|
|
printf ("\\addtolength{\\maxmsccondition}{\\mscspacer}\n");
|
|
|
|
|
|
|
|
/* put out computed widths */
|
2004-08-09 11:05:58 +01:00
|
|
|
|
2004-05-21 18:52:06 +01:00
|
|
|
printf ("\\setlength{\\envinstdist}{0.7\\maxmscall}\n");
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("\\setlength{\\instdist}{\\maxmscall}\n");
|
|
|
|
printf ("\\setlength{\\actionwidth}{\\maxmscaction}\n");
|
|
|
|
printf ("\\setlength{\\instwidth}{\\maxmscinst}\n");
|
|
|
|
printf ("\\setlength{\\conditionoverlap}{0.5\\maxmsccondition}\n");
|
|
|
|
|
|
|
|
/* create MSC title, involving protocol names and such. */
|
|
|
|
|
2004-05-26 13:17:09 +01:00
|
|
|
protocolnames = NULL;
|
2004-05-13 15:49:04 +01:00
|
|
|
for (i = 0; i < width; i++)
|
2004-04-23 15:11:51 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (runPosition[i] > 0)
|
|
|
|
{
|
|
|
|
pname = sys->runs[i].protocol->nameterm;
|
|
|
|
if (!inTermlist (protocolnames, pname))
|
|
|
|
{
|
|
|
|
protocolnames = termlistAppend (protocolnames, pname);
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 15:11:51 +01:00
|
|
|
}
|
2004-05-13 15:49:04 +01:00
|
|
|
latexMSCStart (protocolnames);
|
|
|
|
termlistDelete (protocolnames);
|
2004-04-23 15:11:51 +01:00
|
|
|
}
|
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* declare instances */
|
2004-04-23 15:11:51 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
{
|
|
|
|
if (runPosition[i] > 0)
|
|
|
|
latexDeclInst (sys, i);
|
|
|
|
}
|
|
|
|
/* Add the intruder instance */
|
|
|
|
if (pass == 2)
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\declinst{eve}{}{");
|
2004-05-13 15:49:04 +01:00
|
|
|
else
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\maxlength{\\maxmscinst}{");
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("{\\bf Eve}: Intruder}\n\n");
|
2004-04-23 12:03:07 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* Print the local constants for each instance */
|
2004-05-13 11:06:21 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
for (i = 0; i < width; i++)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (runPosition[i] > 0)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
Termlist tl = sys->runs[i].locals;
|
|
|
|
int first = 1;
|
|
|
|
while (tl != NULL)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
/* detect whether it's really local to this run */
|
|
|
|
Term t = deVar (tl->term);
|
2004-11-16 12:06:36 +00:00
|
|
|
if (isTermLeaf (t) && TermRunid(t) == i)
|
2004-05-13 11:06:21 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
if (pass == 1)
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\maxlength{\\maxmscaction}{$");
|
2004-05-13 15:49:04 +01:00
|
|
|
else
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\ActionBox{creates \\\\\n$");
|
2004-05-13 15:49:04 +01:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf (", ");
|
|
|
|
}
|
|
|
|
termPrint (tl->term);
|
2004-05-13 11:06:21 +01:00
|
|
|
}
|
2004-05-13 15:49:04 +01:00
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
if (pass == 1)
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("$}\n");
|
2004-05-13 11:06:21 +01:00
|
|
|
else
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("$}{run%i}\n", i);
|
2004-05-13 11:06:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* Print the initial intruder knowledge */
|
2004-05-12 16:07:33 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass == 2)
|
|
|
|
{
|
|
|
|
printf ("\\ActionBox{");
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("knows \\\\\n$");
|
|
|
|
knowledgePrintLatex (tb->know[0]);
|
|
|
|
printf ("$}");
|
2004-05-13 15:49:04 +01:00
|
|
|
printf ("{eve}\n");
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\nextlevel[3]\n");
|
|
|
|
printf ("\n");
|
2004-05-13 15:49:04 +01:00
|
|
|
}
|
2004-05-12 16:07:33 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* print the events in the attack */
|
2004-04-23 15:11:51 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
//for (j=-1; j<=sys->step; j++)
|
|
|
|
position = 0;
|
|
|
|
cKnowledge = 0;
|
|
|
|
for (i = 0; i < tb->length; i++)
|
2004-04-23 12:03:07 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (tb->status[i] != S_RED)
|
2004-04-23 12:03:07 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
latexEventSpace (tinfo[i].position - position);
|
|
|
|
if (tinfo[i].position >= position)
|
2004-04-23 12:03:07 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
position = tinfo[i].position;
|
|
|
|
}
|
|
|
|
switch (tb->event[i]->type)
|
|
|
|
{
|
|
|
|
case SEND:
|
|
|
|
newtl = knowledgeNew (tb->know[i], tb->know[i + 1]);
|
|
|
|
highlights = NULL;
|
|
|
|
/* Build a Termlist of terms that from the claimViolationDetails,
|
|
|
|
that appear in the knowledge */
|
|
|
|
if (newtl != NULL)
|
2004-04-23 12:03:07 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
tl = claimDetails;
|
|
|
|
while (tl != NULL)
|
2004-04-23 12:03:07 +01:00
|
|
|
{
|
2004-05-13 15:49:04 +01:00
|
|
|
if (inTermlist (newtl, tl->term))
|
|
|
|
{
|
|
|
|
highlights = termlistAdd (highlights, tl->term);
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
2004-05-13 15:49:04 +01:00
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
2004-05-12 15:56:45 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (tb->link[i] != -1 && i < tb->length)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
latexMessagePrintHighlight (tb, i, tb->link[i],
|
|
|
|
highlights);
|
2004-05-13 15:49:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
latexMessagePrintHighlight (tb, i, -1, highlights); //lost message
|
|
|
|
}
|
2004-04-23 12:03:07 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
/* maybe extra knowledge? */
|
|
|
|
if (newtl != NULL)
|
|
|
|
{
|
|
|
|
/* print what was learned */
|
2004-05-12 16:13:21 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
if (pass == 1)
|
|
|
|
{
|
|
|
|
printf ("\\maxlength{\\maxmscaction}{");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\nextlevel[1]\n");
|
|
|
|
printf ("\\ActionBox{learns \\\\\n");
|
2004-05-13 15:49:04 +01:00
|
|
|
}
|
|
|
|
printf ("$");
|
|
|
|
cKnowledge++;
|
|
|
|
latexTermlistPrint (newtl, highlights);
|
|
|
|
printf ("$}");
|
|
|
|
if (pass == 1)
|
|
|
|
{
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("{eve}\n");
|
2004-08-09 11:05:58 +01:00
|
|
|
printf ("\\nextlevel[2]\n");
|
2004-05-13 15:49:04 +01:00
|
|
|
}
|
|
|
|
}
|
2004-05-12 16:19:40 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
termlistDelete (highlights);
|
2004-04-23 12:03:07 +01:00
|
|
|
|
2004-05-13 15:49:04 +01:00
|
|
|
break;
|
|
|
|
case READ:
|
|
|
|
if (tb->event[i]->internal)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (tb->link[i] == -1)
|
|
|
|
{
|
|
|
|
latexMessagePrint (tb, -1, i); //found message
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLAIM:
|
|
|
|
if (claimDetails != NULL && claimDetails != (Termlist) - 1)
|
|
|
|
{
|
|
|
|
latexClaim (tb, tb->run[i], claimDetails);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2004-08-09 11:05:58 +01:00
|
|
|
break; //kannie!
|
2004-04-23 12:03:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-13 15:49:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* close up diagrams
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
latexEventSpace (2);
|
|
|
|
latexMSCEnd ();
|
2004-05-13 15:49:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* free used memory
|
|
|
|
*/
|
|
|
|
|
2004-04-23 12:03:07 +01:00
|
|
|
memFree (runPosition, width * sizeof (int));
|
|
|
|
memFree (tinfo, (tb->length + 1) * sizeof (struct traceinfo));
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|