2004-11-18 14:47:44 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2004-11-19 09:53:51 +00:00
|
|
|
# Multi-protocol test using Scyther
|
|
|
|
#
|
|
|
|
# (c)2004 Cas Cremers
|
2004-11-18 14:47:44 +00:00
|
|
|
#
|
|
|
|
# Input of this script:
|
|
|
|
#
|
|
|
|
# - A number on the commandline of stuff to test
|
2004-12-17 15:54:48 +00:00
|
|
|
# - A list of files on stdin to be used (lines starting with '#' are
|
|
|
|
# ignored)
|
2004-11-19 10:36:46 +00:00
|
|
|
#
|
2004-11-19 13:25:30 +00:00
|
|
|
#
|
|
|
|
# Tips and tricks:
|
|
|
|
#
|
2004-11-19 10:36:46 +00:00
|
|
|
# Use e.g.
|
|
|
|
# $ ulimit -v 100000
|
|
|
|
# to counteract memory problems
|
2004-11-19 13:25:30 +00:00
|
|
|
#
|
|
|
|
# If you know where to look, use
|
|
|
|
# $ ls s*.spdl t*.spdl -1 | ./multiprotocoltest.py 2
|
|
|
|
# To verify combos of protocols starting with s and t
|
|
|
|
#
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2005-02-19 14:35:31 +00:00
|
|
|
import tuplesdo
|
|
|
|
import copy
|
2005-03-02 15:02:34 +00:00
|
|
|
import scythercache
|
|
|
|
from tempfile import NamedTemporaryFile
|
2005-01-20 15:47:23 +00:00
|
|
|
|
2004-11-19 09:53:51 +00:00
|
|
|
# ***********************
|
2005-03-02 15:29:46 +00:00
|
|
|
# EXPERIMENTS
|
2004-11-19 09:53:51 +00:00
|
|
|
# ***********************
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2005-03-02 15:29:46 +00:00
|
|
|
### Test 0-2
|
|
|
|
###------------------------------------------------------------------
|
|
|
|
TupleWidth = "2"
|
|
|
|
ScytherMethods = "--match=0 --arachne"
|
|
|
|
ScytherBounds = "--timer=5 --max-runs=5 --max-length=20"
|
|
|
|
|
|
|
|
### Test 1-2
|
|
|
|
###------------------------------------------------------------------
|
|
|
|
#TupleWidth = "2"
|
|
|
|
#ScytherMethods = "--match=1 --arachne"
|
|
|
|
#ScytherBounds = "--timer=5 --max-runs=5 --max-length=20"
|
|
|
|
|
|
|
|
|
|
|
|
# ***********************
|
|
|
|
# PARAMETERS
|
|
|
|
# ***********************
|
2005-01-14 18:24:28 +00:00
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
# Temporary files
|
2004-11-18 14:47:44 +00:00
|
|
|
TempFileList = "scyther-blap.tmp"
|
|
|
|
TempFileTuples = "scyther-blip.tmp"
|
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
# External programs
|
2004-11-18 14:47:44 +00:00
|
|
|
TupleProgram = "./tuples.py"
|
2004-11-21 15:45:12 +00:00
|
|
|
|
|
|
|
# Scyther parameters
|
2004-11-18 14:47:44 +00:00
|
|
|
ScytherDefaults = "--summary"
|
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
# Build a large part of the command line (for Scyther) already
|
2004-11-18 14:47:44 +00:00
|
|
|
ScytherArgs = ScytherDefaults + " " + ScytherMethods + " " + ScytherBounds
|
2005-03-02 15:21:55 +00:00
|
|
|
CommandPrefix = "scyther " + ScytherArgs
|
2004-11-21 15:45:12 +00:00
|
|
|
|
|
|
|
# Some default settings for Agents, untrusted e with sk(e) and k(a,e) etc.
|
2005-01-20 15:47:23 +00:00
|
|
|
IncludeProtocols = '../spdl/spdl-defaults.inc'
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
# Some protocols are causing troubles: this is a hard-coded filter to exclude
|
|
|
|
# the problem children. Unfair, yes. Practical, yes.
|
2005-01-14 18:24:28 +00:00
|
|
|
#SkipList = [ 'gong-nonce.spdl', 'gong-nonce-b.spdl', 'splice-as-hc.spdl', 'kaochow-palm.spdl' ]
|
|
|
|
SkipList = []
|
2004-11-21 15:45:12 +00:00
|
|
|
|
|
|
|
ClaimToResultMap = {} # maps protocol claims to correctness in singular tests (0,1)
|
|
|
|
ProtocolToFileMap = {} # maps protocol names to file names
|
|
|
|
ProtocolToStatusMap = {} # maps protocol names to status: 0 all false, 1 all correct, otherwise (2) mixed
|
|
|
|
ProtocolToEffectsMap = {} # maps protocols that help create multiple flaws, to the protocol names of the flaws they caused
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2005-02-19 14:35:31 +00:00
|
|
|
# Ugly hack. Works.
|
|
|
|
safetxt = " " * 20
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2004-11-19 09:53:51 +00:00
|
|
|
# ***********************
|
|
|
|
# MODULES
|
|
|
|
# ***********************
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
import commands
|
|
|
|
|
2004-11-18 14:47:44 +00:00
|
|
|
# ***********************
|
|
|
|
# LIBS
|
|
|
|
# ***********************
|
|
|
|
|
2004-11-19 09:53:51 +00:00
|
|
|
# GetKeys
|
|
|
|
#
|
|
|
|
# Given a mapping f and a value x, returns a list of keys
|
|
|
|
# k for which f(k) = x
|
|
|
|
def GetKeys (f, x):
|
|
|
|
res = []
|
|
|
|
for k in f.keys():
|
|
|
|
if f[k] == x:
|
|
|
|
res.append(k)
|
|
|
|
return res
|
|
|
|
|
2004-11-19 13:25:30 +00:00
|
|
|
# GetListKeys
|
|
|
|
#
|
|
|
|
# Given a mapping f and a list l, returns a list of keys
|
|
|
|
# k for which f(k) = x, x in l
|
|
|
|
def GetListKeys (f, l):
|
|
|
|
res = []
|
|
|
|
for x in l:
|
|
|
|
for y in GetKeys (f, x):
|
|
|
|
if y not in res:
|
|
|
|
res.append(y)
|
|
|
|
return res
|
|
|
|
|
2004-11-18 16:18:23 +00:00
|
|
|
# CommandLine
|
|
|
|
#
|
|
|
|
# Yield the commandline to test, given a list of protocols
|
|
|
|
def CommandLine (plist):
|
|
|
|
linelist = " ".join(plist)
|
2004-11-19 10:59:10 +00:00
|
|
|
return "cat " + IncludeProtocols + " " + linelist + " | " + CommandPrefix
|
2004-11-18 16:18:23 +00:00
|
|
|
|
2004-11-19 13:25:30 +00:00
|
|
|
# PrintProtStatus
|
|
|
|
#
|
|
|
|
# pretty-print the status of a protocol
|
|
|
|
def PrintProtStatus (file, prname):
|
|
|
|
file.write (prname + ": ")
|
2004-11-21 15:45:12 +00:00
|
|
|
if ProtocolToStatusMap[prname] == 0:
|
2004-11-19 13:25:30 +00:00
|
|
|
file.write ("All-Flawed")
|
2004-11-21 15:45:12 +00:00
|
|
|
elif ProtocolToStatusMap[prname] == 1:
|
2004-11-19 13:25:30 +00:00
|
|
|
file.write ("All-Correct")
|
|
|
|
else:
|
|
|
|
file.write ("Mixed")
|
2004-11-18 16:18:23 +00:00
|
|
|
|
2004-11-18 14:47:44 +00:00
|
|
|
# ScytherEval
|
|
|
|
#
|
|
|
|
# Take the list of protocols in plist, and give them to Scyther.
|
|
|
|
# Returns a dictionary of claim -> bool; where 1 means that it is
|
|
|
|
# correct, and 0 means that it is false (i.e. there exists an attack)
|
|
|
|
def ScytherEval (plist):
|
|
|
|
results = {}
|
2004-11-19 10:36:46 +00:00
|
|
|
|
|
|
|
# Flush before trying (possibly fatal) external commands
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
2005-03-02 15:02:34 +00:00
|
|
|
# Combine protocol list to an input
|
|
|
|
input = ""
|
|
|
|
for fn in plist:
|
|
|
|
f = open(fn, "r")
|
|
|
|
input = input + f.read()
|
|
|
|
f.close()
|
|
|
|
|
2004-11-19 10:36:46 +00:00
|
|
|
# Use Scyther
|
2005-03-02 15:02:34 +00:00
|
|
|
(status,scout) = scythercache.eval(ScytherArgs,input)
|
2004-11-19 10:36:46 +00:00
|
|
|
|
|
|
|
if status == 1 or status < 0:
|
|
|
|
# Something went wrong
|
|
|
|
print "*** Error when checking [" + CommandLine (plist) + "]\n"
|
|
|
|
return results
|
|
|
|
|
|
|
|
lines = scout.splitlines()
|
2004-11-18 14:47:44 +00:00
|
|
|
for line in lines:
|
|
|
|
data = line.split()
|
2004-11-18 15:50:54 +00:00
|
|
|
if len(data) > 6 and data[0] == 'claim':
|
2004-11-18 14:47:44 +00:00
|
|
|
claim = " ".join(data[1:4])
|
|
|
|
tag = data[6]
|
|
|
|
value = -1
|
|
|
|
if tag == 'failed:':
|
|
|
|
value = 0
|
|
|
|
if tag == 'correct:':
|
|
|
|
value = 1
|
|
|
|
if value == -1:
|
2004-11-18 16:07:58 +00:00
|
|
|
raise IOError, 'Scyther output for ' + commandline + ', line ' + line + ' cannot be parsed.'
|
2004-11-18 14:47:44 +00:00
|
|
|
results[claim] = value
|
|
|
|
return results
|
|
|
|
|
|
|
|
# ScytherEval1
|
|
|
|
#
|
|
|
|
# The above, but do the preprocessing for a single protocol
|
|
|
|
def ScytherEval1 (protocol):
|
2004-11-18 15:06:41 +00:00
|
|
|
results = ScytherEval ([protocol])
|
2004-11-19 09:53:51 +00:00
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
# Add the claim to the list of ClaimToResultMap
|
2004-11-18 16:07:58 +00:00
|
|
|
for claim in results.keys():
|
2004-11-21 15:45:12 +00:00
|
|
|
if ClaimToResultMap.has_key(claim):
|
2004-11-19 09:53:51 +00:00
|
|
|
# Claim occurs in two protocols; determine the
|
|
|
|
# files
|
2004-11-21 15:45:12 +00:00
|
|
|
file1 = ProtocolToFileMap[claim.split()[0]]
|
2004-11-19 09:53:51 +00:00
|
|
|
file2 = protocol
|
|
|
|
raise IOError, 'Claim occurs in two protocols: ' + claim + ", in files (" + file1 + ") and (" + file2 + ")"
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2004-11-19 09:53:51 +00:00
|
|
|
# Add the filename to the protocol mappings
|
|
|
|
prname = claim.split()[0]
|
2004-11-21 15:45:12 +00:00
|
|
|
if ProtocolToFileMap.has_key(prname):
|
2004-11-19 13:25:30 +00:00
|
|
|
# We already wrote this down
|
|
|
|
#
|
|
|
|
# TODO The mapping should not conflict, but we don't
|
|
|
|
# check that now (covered by claim duplication # in a sense)
|
|
|
|
#
|
|
|
|
# Compare previous result, maybe mixed
|
2004-11-21 15:45:12 +00:00
|
|
|
if ProtocolToStatusMap[prname] <> results[claim]:
|
|
|
|
ProtocolToStatusMap[prname] = 2
|
2004-11-19 13:25:30 +00:00
|
|
|
else:
|
|
|
|
# New one, store the first result
|
2004-11-21 15:45:12 +00:00
|
|
|
ProtocolToFileMap[prname] = protocol
|
|
|
|
ProtocolToStatusMap[prname] = results[claim]
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
ClaimToResultMap.update (results)
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
# Show progress of i (0..n)
|
|
|
|
#
|
|
|
|
LastProgress = {}
|
|
|
|
ProgressBarWidth = 50
|
|
|
|
|
|
|
|
def ShowProgress (i,n,txt):
|
2004-11-19 11:22:03 +00:00
|
|
|
def IntegerPart (x):
|
|
|
|
return int (( x * i ) / n)
|
|
|
|
|
|
|
|
percentage = IntegerPart (100)
|
|
|
|
factor = IntegerPart (ProgressBarWidth)
|
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
showme = 0
|
|
|
|
if LastProgress.has_key(n):
|
|
|
|
if LastProgress[n]<>(factor,txt):
|
|
|
|
showme = 1
|
|
|
|
else:
|
|
|
|
showme = 1
|
|
|
|
if showme == 1:
|
|
|
|
bar = "\r["
|
|
|
|
i = 0
|
|
|
|
while i < ProgressBarWidth:
|
|
|
|
if i <= factor:
|
|
|
|
bar = bar + "*"
|
|
|
|
else:
|
|
|
|
bar = bar + "."
|
|
|
|
i = i+1
|
2004-11-19 11:22:03 +00:00
|
|
|
bar = bar + "] %3d%% " % percentage + txt
|
2004-11-19 10:13:08 +00:00
|
|
|
sys.stderr.write(bar)
|
|
|
|
sys.stderr.flush()
|
2004-11-18 15:50:54 +00:00
|
|
|
LastProgress[n] = (factor, txt)
|
|
|
|
|
|
|
|
def ClearProgress (n,txt):
|
2004-11-19 11:22:03 +00:00
|
|
|
bar = " " * (1 + ProgressBarWidth + 2 + 5 + len(txt))
|
2004-11-19 10:13:08 +00:00
|
|
|
sys.stderr.write("\r" + bar + "\r")
|
|
|
|
sys.stderr.flush()
|
2004-11-18 15:50:54 +00:00
|
|
|
|
|
|
|
|
2005-03-02 14:28:41 +00:00
|
|
|
def DescribeContextBrief (filep, protocols, claim, prefix):
|
|
|
|
|
|
|
|
filep.write (prefix)
|
|
|
|
|
|
|
|
prlist = []
|
|
|
|
for prfile in protocols:
|
|
|
|
prnames = GetKeys (ProtocolToFileMap, prfile)
|
|
|
|
prlist = prlist + prnames
|
|
|
|
newprname = claim.split()[0]
|
|
|
|
filep.write ("\t" + newprname)
|
|
|
|
|
|
|
|
filep.write ("\t" + claim)
|
|
|
|
|
|
|
|
prlistclean = []
|
|
|
|
prliststr = ""
|
|
|
|
for pn in prlist:
|
|
|
|
if pn not in prlistclean:
|
|
|
|
if pn != newprname:
|
|
|
|
prlistclean.append(pn)
|
|
|
|
prliststr = prliststr + "\t" + pn
|
|
|
|
filep.write (prliststr)
|
|
|
|
|
|
|
|
filep.write ("\n")
|
|
|
|
|
2004-11-19 09:53:51 +00:00
|
|
|
def DescribeContext (filep, protocols, claim):
|
|
|
|
def DC_Claim(cl,v):
|
|
|
|
if v == 0:
|
2004-11-19 13:25:30 +00:00
|
|
|
filep.write ("- " + cl + " : false in both cases")
|
2004-11-19 09:53:51 +00:00
|
|
|
elif v == 1:
|
2004-11-19 13:25:30 +00:00
|
|
|
filep.write ("+ " + cl + " : correct in both cases")
|
2004-11-19 09:53:51 +00:00
|
|
|
elif v == 2:
|
|
|
|
filep.write ("* " + cl + " : newly false in multi-protocol test")
|
|
|
|
else:
|
|
|
|
filep.write ("???")
|
|
|
|
filep.write ("\n")
|
|
|
|
|
|
|
|
filep.write ("-- Attack description.\n\n")
|
|
|
|
filep.write ("Involving the protocols:\n")
|
|
|
|
|
|
|
|
for prfile in protocols:
|
2004-11-21 15:45:12 +00:00
|
|
|
prnames = GetKeys (ProtocolToFileMap, prfile)
|
2004-11-19 09:53:51 +00:00
|
|
|
filep.write ("- " + prfile + ": " + ",".join(prnames) + "\n")
|
|
|
|
newprname = claim.split()[0]
|
2004-11-21 15:45:12 +00:00
|
|
|
newprfile = ProtocolToFileMap[newprname]
|
2004-11-19 09:53:51 +00:00
|
|
|
filep.write ("The new attack occurs in " + newprfile + ": " + newprname)
|
|
|
|
|
|
|
|
filep.write ("\n\n")
|
|
|
|
filep.write (" $ " + CommandLine (protocols) + "\n")
|
|
|
|
filep.write ("\n")
|
|
|
|
DC_Claim (claim, 2)
|
|
|
|
|
|
|
|
# Determine, for each protocol name within the list of files,
|
|
|
|
# which claims fall under it, and show their previous status
|
|
|
|
|
2004-11-21 15:45:12 +00:00
|
|
|
for prname in ProtocolToFileMap:
|
2004-11-19 09:53:51 +00:00
|
|
|
# Protocol name
|
2004-11-21 15:45:12 +00:00
|
|
|
if ProtocolToFileMap[prname] in protocols:
|
2004-11-19 09:53:51 +00:00
|
|
|
# prname is a protocol name within the scope
|
|
|
|
# first print isolation correct files (skipping
|
|
|
|
# the claim one, because that is obvious)
|
2004-11-19 13:25:30 +00:00
|
|
|
|
|
|
|
# construct list of claims for this protocol
|
2004-11-19 09:53:51 +00:00
|
|
|
cllist = []
|
2004-11-21 15:45:12 +00:00
|
|
|
for cl in ClaimToResultMap.keys():
|
2004-11-19 09:53:51 +00:00
|
|
|
if cl.split()[0] == prname:
|
2004-11-21 15:45:12 +00:00
|
|
|
cllist.append( (cl,ClaimToResultMap[cl]) )
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2004-11-19 13:25:30 +00:00
|
|
|
# We want to show some details, in any case of
|
|
|
|
# the protocol of the claim. However, if the
|
|
|
|
# partner protocol is completely correct or
|
|
|
|
# completely false, we summarize.
|
|
|
|
summary = 0
|
|
|
|
all = 0
|
|
|
|
if claim.split()[0] <> prname:
|
|
|
|
count = [0,0]
|
|
|
|
for cl,v in cllist:
|
|
|
|
count[v] = count[v]+1
|
|
|
|
if count[0] == 0 and count[1] > 0:
|
|
|
|
all = 1
|
|
|
|
summary = 1
|
|
|
|
if count[1] == 0 and count[0] > 0:
|
|
|
|
all = 0
|
|
|
|
summary = 1
|
|
|
|
|
|
|
|
if summary == 1:
|
|
|
|
DC_Claim (cl.split()[0] + " *ALL*", all)
|
|
|
|
else:
|
|
|
|
for cl,v in cllist:
|
|
|
|
if v == 1 and cl <> claim:
|
|
|
|
DC_Claim(cl,1)
|
|
|
|
for cl,v in cllist:
|
|
|
|
if v == 0 and cl <> claim:
|
|
|
|
DC_Claim(cl,0)
|
2004-11-19 09:53:51 +00:00
|
|
|
filep.write ("\n")
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
|
|
|
# Determine whether the attack is really only for this combination of protocols (and not with less)
|
|
|
|
#
|
|
|
|
# returns 0 if it could be done with less also
|
|
|
|
# returns 1 if it really requires these protocols
|
|
|
|
#
|
|
|
|
def RequiresAllProtocols (protocols, claim):
|
|
|
|
# check for single results
|
|
|
|
if ClaimToResultMap[claim] == 0:
|
|
|
|
# claim was always false
|
|
|
|
return 0
|
|
|
|
# check for simple cases
|
|
|
|
if int(TupleWidth) <= 2:
|
|
|
|
# nothing to remove
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# test the claims when removing some others
|
|
|
|
# for TupleWidth size list, we can remove TupleWidth-1
|
|
|
|
# protocols, and test
|
|
|
|
clprname = claim.split()[0]
|
|
|
|
claimfile = ProtocolToFileMap[clprname]
|
|
|
|
for redundantfile in protocols:
|
|
|
|
if redundantfile != claimfile:
|
|
|
|
# for this particular option, construct a list
|
|
|
|
simplercase = copy.copy(protocols)
|
|
|
|
simplercase.remove(redundantfile)
|
|
|
|
# now test the validity of the claim
|
|
|
|
simplerresults = ScytherEval (simplercase)
|
|
|
|
if simplerresults[claim] == 0:
|
|
|
|
# Redundant protocol was not necessary for attack!
|
|
|
|
return 0
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
|
|
|
# Signal that there is an attack, claim X using protocols Y
|
|
|
|
#
|
|
|
|
# Returns number of new attacks found
|
|
|
|
#
|
|
|
|
def SignalAttack (protocols, claim):
|
|
|
|
if RequiresAllProtocols (protocols, claim) == 0:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
ClearProgress (TupleCount, safetxt)
|
2005-03-02 14:28:41 +00:00
|
|
|
outs = "***\t" + str(newattacks)
|
|
|
|
outs = outs + "\t" + str(processed) + "/" + str(TupleCount)
|
2005-02-19 14:35:31 +00:00
|
|
|
for helper in GetListKeys (ProtocolToFileMap, protocols):
|
|
|
|
clprname = claim.split()[0]
|
|
|
|
if helper <> clprname:
|
|
|
|
if helper not in ProtocolToEffectsMap.keys():
|
|
|
|
# new
|
|
|
|
ProtocolToEffectsMap[helper] = [clprname]
|
|
|
|
else:
|
|
|
|
# already noted as helper, add destruction now
|
|
|
|
if clprname not in ProtocolToEffectsMap[helper]:
|
|
|
|
ProtocolToEffectsMap[helper].append(clprname)
|
|
|
|
#
|
|
|
|
# TODO
|
|
|
|
#
|
|
|
|
# Generate output to recreate/draw the
|
|
|
|
# attack, and maybe add this to a big
|
|
|
|
# error log thingy. Furthermore,
|
|
|
|
# explicitly recreate the commandline
|
|
|
|
# and the claim that is newly violated
|
2005-03-02 14:28:41 +00:00
|
|
|
DescribeContextBrief (sys.stdout, protocols, claim, outs)
|
2005-02-19 14:35:31 +00:00
|
|
|
|
|
|
|
return 1
|
2004-11-18 14:47:44 +00:00
|
|
|
|
|
|
|
# ***********************
|
|
|
|
# MAIN CODE
|
|
|
|
# ***********************
|
|
|
|
|
|
|
|
# Pass std input to temporary file (list of protocol files)
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Determines:
|
|
|
|
# ProtocolCount
|
2005-01-20 15:47:23 +00:00
|
|
|
# ProtocolFileList[0..count-1]
|
2004-11-18 14:47:44 +00:00
|
|
|
#
|
|
|
|
# Furthermore, TempFileList is created.
|
|
|
|
|
2005-01-14 18:24:28 +00:00
|
|
|
# Where should we start (if this is a number)
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
StartPercentage = int (sys.argv[1])
|
|
|
|
if StartPercentage < 0 or StartPercentage > 100:
|
|
|
|
print "Illegal range for starting percentage (0-100):", StartPercentage
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
else:
|
|
|
|
StartPercentage = 0
|
2004-11-18 14:47:44 +00:00
|
|
|
|
|
|
|
# Read stdin into list and count, send to file
|
|
|
|
loop = 1
|
|
|
|
ProtocolCount = 0
|
2005-01-20 15:47:23 +00:00
|
|
|
ProtocolFileList = []
|
2004-11-18 14:47:44 +00:00
|
|
|
outp = open(TempFileList, 'w')
|
|
|
|
while loop:
|
|
|
|
line = sys.stdin.readline()
|
|
|
|
if line != '':
|
|
|
|
# not the end of the input
|
|
|
|
cleanline = string.strip(line)
|
2004-12-17 15:54:48 +00:00
|
|
|
if cleanline != '' and cleanline[0] != '#' and cleanline not in SkipList:
|
2004-11-18 15:50:54 +00:00
|
|
|
# not a blank line, not forbidden
|
2005-01-20 15:47:23 +00:00
|
|
|
ProtocolFileList.append(cleanline)
|
2004-11-18 14:47:44 +00:00
|
|
|
ProtocolCount = ProtocolCount + 1
|
|
|
|
outp.write(line)
|
|
|
|
else:
|
|
|
|
# end of the input
|
|
|
|
loop = 0
|
|
|
|
outp.close()
|
|
|
|
|
|
|
|
# Caching of single-protocol results for speed gain.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# The script first computes the singular results for all the protocols
|
|
|
|
# and stores this in an array, or something like that.
|
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
print "Evaluating tuples of", TupleWidth, "for", ProtocolCount, "protocols, using the command '" + CommandPrefix + "'"
|
2004-11-18 14:47:44 +00:00
|
|
|
i = 0
|
|
|
|
while i < ProtocolCount:
|
2005-01-20 15:47:23 +00:00
|
|
|
ShowProgress (i, ProtocolCount,ProtocolFileList[i]+safetxt)
|
|
|
|
ScytherEval1 ( ProtocolFileList[i] )
|
2004-11-18 14:47:44 +00:00
|
|
|
i = i + 1
|
2004-11-18 15:50:54 +00:00
|
|
|
ClearProgress(ProtocolCount, safetxt)
|
2004-11-18 16:14:31 +00:00
|
|
|
print "Evaluated single results."
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2004-11-19 13:25:30 +00:00
|
|
|
# Show classification
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
2004-11-21 15:45:12 +00:00
|
|
|
print "Correct protocols: ", GetKeys (ProtocolToStatusMap, 1)
|
|
|
|
print "Partly flawed protocols: ", GetKeys (ProtocolToStatusMap, 2)
|
|
|
|
print "Completely flawed protocols: ", GetKeys (ProtocolToStatusMap, 0)
|
2004-11-19 13:25:30 +00:00
|
|
|
|
2004-11-18 14:47:44 +00:00
|
|
|
# Computation of combined list.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# We use the tuple script to generate the list of tuples we need.
|
|
|
|
# We use a temporary file (again) to store that list.
|
|
|
|
# This requires that 'tuples.py' is in the same directory.
|
|
|
|
|
|
|
|
lstatus=os.system(TupleProgram + ' ' + TupleWidth + ' <' + TempFileList + ' >' + TempFileTuples)
|
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
inp = open(TempFileTuples, 'r')
|
|
|
|
TupleCount = 0
|
|
|
|
for x in inp:
|
|
|
|
TupleCount = TupleCount + 1
|
|
|
|
inp.close()
|
2004-11-18 16:14:31 +00:00
|
|
|
print "Commencing test for", TupleCount, "protocol combinations."
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2004-11-18 14:47:44 +00:00
|
|
|
# Testing of protocol tuples
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# We take the list of tuples and test each combination.
|
|
|
|
|
2004-11-18 15:06:41 +00:00
|
|
|
inp = open(TempFileTuples, 'r')
|
|
|
|
processed = 0
|
|
|
|
newattacks = 0
|
2005-01-14 18:24:28 +00:00
|
|
|
StartSkip = 0
|
|
|
|
|
|
|
|
# Possibly skip some
|
|
|
|
if StartPercentage > 0:
|
|
|
|
StartSkip = int ((TupleCount * StartPercentage) / 100)
|
|
|
|
print "Resuming. Skipping the first", StartSkip,"tuples."
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check all these protocols
|
|
|
|
#
|
2004-11-18 15:06:41 +00:00
|
|
|
for tline in inp:
|
2005-01-14 18:24:28 +00:00
|
|
|
if (processed >= StartSkip):
|
|
|
|
#
|
|
|
|
# Get the next tuple
|
|
|
|
#
|
|
|
|
protocols = tline.split()
|
|
|
|
ShowProgress (processed, TupleCount, " ".join(protocols) + safetxt)
|
|
|
|
#
|
2005-02-19 14:35:31 +00:00
|
|
|
# Determine whether there are valid claims at all in
|
|
|
|
# this set of file names
|
2005-01-14 18:24:28 +00:00
|
|
|
#
|
2005-02-19 14:35:31 +00:00
|
|
|
has_valid_claims = 0
|
|
|
|
for prname in GetListKeys (ProtocolToFileMap, protocols):
|
|
|
|
if ProtocolToStatusMap[prname] != 0:
|
|
|
|
has_valid_claims = 1
|
|
|
|
if has_valid_claims == 1:
|
|
|
|
#
|
|
|
|
# Use Scyther to verify the claims
|
|
|
|
#
|
|
|
|
results = ScytherEval ( protocols )
|
|
|
|
#
|
|
|
|
# Now we have the results for this combination.
|
|
|
|
# Check whether any of these claims is 'newly false'
|
|
|
|
#
|
|
|
|
for claim,value in results.items():
|
|
|
|
if value == 0:
|
|
|
|
# Apparently this claim is false now (there is
|
|
|
|
# an attack)
|
|
|
|
newattacks = newattacks + SignalAttack (protocols, claim)
|
|
|
|
|
2004-11-18 15:06:41 +00:00
|
|
|
# Next!
|
|
|
|
processed = processed + 1
|
2004-11-19 13:25:30 +00:00
|
|
|
inp.close()
|
2004-11-18 15:06:41 +00:00
|
|
|
|
2004-11-18 15:50:54 +00:00
|
|
|
ClearProgress (TupleCount, safetxt)
|
2004-11-18 15:06:41 +00:00
|
|
|
print "Processed", processed,"tuple combinations in total."
|
2005-01-14 18:24:28 +00:00
|
|
|
if StartSkip > 0:
|
|
|
|
print "In this session, checked the last",(processed - StartSkip),"tuples. "
|
2004-11-18 16:07:58 +00:00
|
|
|
print "Found", newattacks, "new attacks."
|
2004-11-19 13:25:30 +00:00
|
|
|
if newattacks > 0:
|
|
|
|
print " These were helped by:"
|
2004-11-21 15:45:12 +00:00
|
|
|
for helper in ProtocolToEffectsMap.keys():
|
2004-11-19 13:25:30 +00:00
|
|
|
sys.stdout.write (" ")
|
|
|
|
PrintProtStatus (sys.stdout, helper)
|
2004-11-21 15:45:12 +00:00
|
|
|
sys.stdout.write (". This possibly breaks " + str(ProtocolToEffectsMap[helper]) + "\n")
|
2004-11-19 13:25:30 +00:00
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|