2004-11-18 14:47:44 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2004-11-19 09:53:51 +00:00
|
|
|
# Multi-protocol test using Scyther
|
|
|
|
#
|
2005-03-04 16:56:55 +00:00
|
|
|
# Typical big test: './multiprotocoltest.py -a -s -B' , go and drink some
|
|
|
|
# coffee. Drink some more. Go on holiday. Break leg. Return. Heal.
|
|
|
|
# Return to computer to find great results and/or system crash.
|
|
|
|
#
|
2004-11-19 09:53:51 +00:00
|
|
|
# (c)2004 Cas Cremers
|
2004-11-18 14:47:44 +00:00
|
|
|
#
|
2004-11-19 09:53:51 +00:00
|
|
|
# ***********************
|
2005-03-02 16:28:09 +00:00
|
|
|
# MODULES
|
2004-11-19 09:53:51 +00:00
|
|
|
# ***********************
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2005-03-02 16:28:09 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
import commands
|
|
|
|
import copy
|
|
|
|
from optparse import OptionParser
|
2005-03-02 15:29:46 +00:00
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
# My own stuff
|
2005-03-02 16:28:09 +00:00
|
|
|
import tuplesdo
|
2005-03-04 15:36:37 +00:00
|
|
|
import scythertest
|
2005-03-02 16:28:09 +00:00
|
|
|
import protocollist
|
2005-03-02 15:29:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# ***********************
|
|
|
|
# PARAMETERS
|
|
|
|
# ***********************
|
2005-01-14 18:24:28 +00:00
|
|
|
|
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-03-08 14:29:30 +00:00
|
|
|
ReportedAttackList = [] # stores attacks that have already been reported.
|
2005-03-04 16:23:22 +00:00
|
|
|
CommandPrefix = ""
|
2005-03-02 20:23:43 +00:00
|
|
|
ArgumentsList = [] # argument lists that have been displayed onscreen
|
2005-03-02 19:57:05 +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-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):
|
2005-03-04 16:23:22 +00:00
|
|
|
global options
|
|
|
|
|
2004-11-19 10:36:46 +00:00
|
|
|
# Flush before trying (possibly fatal) external commands
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
2005-03-08 14:07:36 +00:00
|
|
|
args = scythertest.default_arguments(plist, int(options.match), int(options.bounds))
|
2005-03-02 19:57:05 +00:00
|
|
|
n = len(plist)
|
2005-03-03 12:36:01 +00:00
|
|
|
if not (n,args) in ArgumentsList:
|
|
|
|
ArgumentsList.append((n,args))
|
|
|
|
print "Testing",n,"tuples using",args
|
|
|
|
|
2005-03-08 14:07:36 +00:00
|
|
|
return scythertest.default_parsed(plist, int(options.match), int(options.bounds))
|
2004-11-18 14:47:44 +00:00
|
|
|
|
|
|
|
# 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 = {}
|
2005-03-04 16:56:55 +00:00
|
|
|
ProgressBarWidth = 38
|
2004-11-18 15:50:54 +00:00
|
|
|
|
|
|
|
def ShowProgress (i,n,txt):
|
2005-03-04 16:23:22 +00:00
|
|
|
global options
|
|
|
|
|
2004-11-19 11:22:03 +00:00
|
|
|
def IntegerPart (x):
|
|
|
|
return int (( x * i ) / n)
|
|
|
|
|
2005-03-02 20:12:06 +00:00
|
|
|
if not options.progressbar:
|
|
|
|
return
|
2004-11-19 11:22:03 +00:00
|
|
|
percentage = IntegerPart (100)
|
|
|
|
factor = IntegerPart (ProgressBarWidth)
|
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
showme = False
|
2004-11-18 15:50:54 +00:00
|
|
|
if LastProgress.has_key(n):
|
|
|
|
if LastProgress[n]<>(factor,txt):
|
2005-03-04 16:23:22 +00:00
|
|
|
showme = True
|
2004-11-18 15:50:54 +00:00
|
|
|
else:
|
2005-03-04 16:23:22 +00:00
|
|
|
showme = True
|
|
|
|
if showme:
|
2004-11-18 15:50:54 +00:00
|
|
|
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):
|
2005-03-04 16:23:22 +00:00
|
|
|
global options
|
|
|
|
|
2005-03-02 20:12:06 +00:00
|
|
|
if not options.progressbar:
|
|
|
|
return
|
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):
|
2005-03-08 14:29:30 +00:00
|
|
|
global ReportedAttackList
|
2005-03-02 14:28:41 +00:00
|
|
|
|
2005-03-08 14:29:30 +00:00
|
|
|
# compute string
|
|
|
|
outstr = "\t" + claim
|
2005-03-02 14:28:41 +00:00
|
|
|
|
|
|
|
prlist = []
|
|
|
|
for prfile in protocols:
|
|
|
|
prnames = GetKeys (ProtocolToFileMap, prfile)
|
|
|
|
prlist = prlist + prnames
|
|
|
|
|
|
|
|
|
2005-03-02 20:17:21 +00:00
|
|
|
newprname = claim.split()[0]
|
2005-03-02 14:28:41 +00:00
|
|
|
prlistclean = []
|
|
|
|
for pn in prlist:
|
|
|
|
if pn not in prlistclean:
|
|
|
|
if pn != newprname:
|
|
|
|
prlistclean.append(pn)
|
2005-03-08 14:29:30 +00:00
|
|
|
outstr = outstr + "\t" + pn
|
|
|
|
|
|
|
|
# determine whether we did that already
|
|
|
|
if not outstr in ReportedAttackList:
|
|
|
|
ReportedAttackList.append(outstr)
|
|
|
|
# print
|
|
|
|
filep.write (prefix)
|
|
|
|
filep.write (outstr)
|
|
|
|
filep.write ("\n")
|
|
|
|
# a new attack!
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
# 0 new attacks
|
|
|
|
return 0
|
2005-03-02 14:28:41 +00:00
|
|
|
|
|
|
|
|
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.
|
2005-03-04 16:23:22 +00:00
|
|
|
summary = False
|
2004-11-19 13:25:30 +00:00
|
|
|
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
|
2005-03-04 16:23:22 +00:00
|
|
|
summary = True
|
2004-11-19 13:25:30 +00:00
|
|
|
if count[1] == 0 and count[0] > 0:
|
|
|
|
all = 0
|
2005-03-04 16:23:22 +00:00
|
|
|
summary = True
|
2004-11-19 13:25:30 +00:00
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
if summary:
|
2004-11-19 13:25:30 +00:00
|
|
|
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):
|
2005-03-11 20:27:57 +00:00
|
|
|
|
2005-02-19 14:35:31 +00:00
|
|
|
# check for single results
|
|
|
|
if ClaimToResultMap[claim] == 0:
|
2005-03-11 20:27:57 +00:00
|
|
|
# claim was always false (already attack on single prot.)
|
|
|
|
return False
|
2005-02-19 14:35:31 +00:00
|
|
|
# check for simple cases
|
2005-03-04 16:23:22 +00:00
|
|
|
if TupleWidth <= 2:
|
2005-02-19 14:35:31 +00:00
|
|
|
# nothing to remove
|
2005-03-11 20:27:57 +00:00
|
|
|
return True
|
2005-02-19 14:35:31 +00:00
|
|
|
|
|
|
|
# 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)
|
2005-03-09 12:28:15 +00:00
|
|
|
if claim in simplerresults.keys() and simplerresults[claim] == 0:
|
2005-02-19 14:35:31 +00:00
|
|
|
# Redundant protocol was not necessary for attack!
|
2005-03-11 20:27:57 +00:00
|
|
|
return False
|
|
|
|
return True
|
2005-02-19 14:35:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
2005-03-11 20:27:57 +00:00
|
|
|
if not RequiresAllProtocols (protocols, claim):
|
2005-02-19 14:35:31 +00:00
|
|
|
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-08 14:29:30 +00:00
|
|
|
return DescribeContextBrief (sys.stdout, protocols, claim, outs)
|
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-03-04 16:56:55 +00:00
|
|
|
def multiprotocol_test(ProtocolFileList, width, match):
|
2005-03-04 16:23:22 +00:00
|
|
|
global options
|
2005-03-04 16:56:55 +00:00
|
|
|
global processed, newattacks
|
2005-03-04 16:23:22 +00:00
|
|
|
global TupleWidth, TupleCount
|
2005-03-04 16:56:55 +00:00
|
|
|
global ClaimToResultMap, ProtocolToFileMap, ProtocolToStatusMap, ProtocolToEffectsMap
|
2005-03-04 16:23:22 +00:00
|
|
|
|
2005-03-04 16:56:55 +00:00
|
|
|
TupleWidth = width
|
2005-03-04 16:23:22 +00:00
|
|
|
ProtocolCount = len(ProtocolFileList)
|
2005-03-04 16:56:55 +00:00
|
|
|
ScytherMethods = "--match=" + str(match)
|
2005-03-04 16:23:22 +00:00
|
|
|
|
2005-03-04 16:56:55 +00:00
|
|
|
# Reset mem
|
|
|
|
ClaimToResultMap = {}
|
|
|
|
ProtocolToFileMap = {}
|
|
|
|
ProtocolToStatusMap = {}
|
|
|
|
ProtocolToEffectsMap = {}
|
2005-03-04 16:23:22 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
TupleCount = tuplesdo.tuples_count(ProtocolCount, TupleWidth)
|
|
|
|
print "Evaluating", TupleCount, "tuples of", TupleWidth, "for", ProtocolCount, "protocols."
|
|
|
|
i = 0
|
|
|
|
while i < ProtocolCount:
|
|
|
|
ShowProgress (i, ProtocolCount,ProtocolFileList[i]+safetxt)
|
|
|
|
ScytherEval1 ( ProtocolFileList[i] )
|
|
|
|
i = i + 1
|
|
|
|
ClearProgress(ProtocolCount, safetxt)
|
|
|
|
print "Evaluated single results."
|
|
|
|
|
|
|
|
# Show classification
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
print "Correct protocols: ", GetKeys (ProtocolToStatusMap, 1)
|
|
|
|
print "Partly flawed protocols: ", GetKeys (ProtocolToStatusMap, 2)
|
|
|
|
print "Completely flawed protocols: ", GetKeys (ProtocolToStatusMap, 0)
|
2004-11-18 14:47:44 +00:00
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
# Testing of protocol tuples
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# We take the list of tuples and test each combination.
|
2004-11-18 15:50:54 +00:00
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
processed = 0
|
|
|
|
newattacks = 0
|
2005-01-14 18:24:28 +00:00
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
#
|
|
|
|
# Check all these protocols
|
|
|
|
#
|
|
|
|
def process(protocols):
|
2005-03-04 16:56:55 +00:00
|
|
|
global processed, newattacks
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get the next tuple
|
|
|
|
#
|
|
|
|
ShowProgress (processed, TupleCount, " ".join(protocols) + safetxt)
|
|
|
|
#
|
|
|
|
# Determine whether there are valid claims at all in
|
|
|
|
# this set of file names
|
|
|
|
#
|
|
|
|
has_valid_claims = False
|
|
|
|
for prname in GetListKeys (ProtocolToFileMap, protocols):
|
|
|
|
if ProtocolToStatusMap[prname] != 0:
|
|
|
|
has_valid_claims = True
|
|
|
|
if has_valid_claims:
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
2005-03-04 16:56:55 +00:00
|
|
|
# Use Scyther to verify the claims
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
2005-03-04 16:56:55 +00:00
|
|
|
results = ScytherEval ( protocols )
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
2005-03-04 16:56:55 +00:00
|
|
|
# Now we have the results for this combination.
|
|
|
|
# Check whether any of these claims is 'newly false'
|
2005-02-19 14:35:31 +00:00
|
|
|
#
|
2005-03-04 16:56:55 +00:00
|
|
|
for claim,value in results.items():
|
|
|
|
if value == 0:
|
|
|
|
# Apparently this claim is false now (there is
|
|
|
|
# an attack)
|
|
|
|
newattacks = newattacks + SignalAttack (protocols, claim)
|
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
# Next!
|
|
|
|
processed = processed + 1
|
|
|
|
|
|
|
|
tuplesdo.tuples_do(process,ProtocolFileList,TupleWidth)
|
|
|
|
|
|
|
|
ClearProgress (TupleCount, safetxt)
|
|
|
|
print "Processed", processed,"tuple combinations in total."
|
|
|
|
print "Found", newattacks, "new attacks."
|
|
|
|
if newattacks > 0:
|
|
|
|
print " These were helped by:"
|
|
|
|
for helper in ProtocolToEffectsMap.keys():
|
|
|
|
sys.stdout.write (" ")
|
|
|
|
PrintProtStatus (sys.stdout, helper)
|
|
|
|
sys.stdout.write (". This possibly breaks " + str(ProtocolToEffectsMap[helper]) + "\n")
|
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
2005-03-04 16:56:55 +00:00
|
|
|
# Yell some stuff
|
|
|
|
|
|
|
|
def banner(str):
|
|
|
|
print
|
|
|
|
print "*" * 40
|
|
|
|
print "\t" + str
|
|
|
|
print "*" * 40
|
|
|
|
print
|
|
|
|
|
|
|
|
# Magical recursive unfolding of tests
|
|
|
|
|
|
|
|
def the_great_houdini(list,width,match):
|
|
|
|
global options
|
|
|
|
|
2005-03-08 14:07:36 +00:00
|
|
|
# Empty list
|
2005-03-04 16:56:55 +00:00
|
|
|
if list == []:
|
2005-03-08 14:07:36 +00:00
|
|
|
the_great_houdini(protocollist.select(int(options.protocols)),width,match)
|
|
|
|
# Unfold sequence of tuple widths
|
|
|
|
elif options.sequence:
|
2005-03-04 16:56:55 +00:00
|
|
|
options.sequence = False
|
|
|
|
banner ("Testing multiple tuple widths")
|
|
|
|
for n in range(2,4):
|
|
|
|
banner ("Testing tuple width %i" % n)
|
|
|
|
the_great_houdini(list,n,match)
|
|
|
|
options.sequence = True
|
2005-03-08 14:07:36 +00:00
|
|
|
# Unfold matching methods
|
|
|
|
elif options.allmatch:
|
2005-03-04 16:56:55 +00:00
|
|
|
options.allmatch = False
|
|
|
|
banner ("Testing multiple match methods")
|
|
|
|
for m in range(0,3):
|
2005-03-08 14:07:36 +00:00
|
|
|
options.match = m
|
2005-03-04 16:56:55 +00:00
|
|
|
banner ("Testing match %i" % m)
|
|
|
|
the_great_houdini(list,width,m)
|
|
|
|
options.allmatch = True
|
2005-03-08 14:07:36 +00:00
|
|
|
# Last but not least: test
|
|
|
|
else:
|
|
|
|
multiprotocol_test(list,width,match)
|
2005-03-04 16:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
global options
|
|
|
|
global processed, newattacks
|
|
|
|
global TestCount
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
scythertest.default_options(parser)
|
|
|
|
parser.add_option("-t","--tuplewidth", dest="tuplewidth",
|
|
|
|
default = 2,
|
|
|
|
help = "number of concurrent protocols to test, >=2")
|
|
|
|
parser.add_option("-s","--sequence", dest="sequence",
|
|
|
|
default = False,
|
|
|
|
action = "store_true",
|
|
|
|
help = "test for two and three tuples")
|
|
|
|
parser.add_option("-a","--allmatch", dest="allmatch",
|
|
|
|
default = False,
|
|
|
|
action = "store_true",
|
|
|
|
help = "test for all matching methods")
|
|
|
|
parser.add_option("-p","--protocols", dest="protocols",
|
|
|
|
default = 0,
|
|
|
|
help = "protocol selection (0: all, 1:literature only)")
|
|
|
|
parser.add_option("-B","--disable-progressbar", dest="progressbar",
|
|
|
|
default = "True",
|
|
|
|
action = "store_false",
|
|
|
|
help = "suppress a progress bar")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
2005-03-11 13:44:16 +00:00
|
|
|
scythertest.process_default_options(options)
|
2005-03-04 16:56:55 +00:00
|
|
|
|
|
|
|
the_great_houdini(args, int(options.tuplewidth), int(options.match))
|
|
|
|
|
2005-03-04 16:23:22 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|