- Improved error handling: any Scyther errors now raise an exception.

This can be dealt with accordingly. If no error occurs, we can just
  nicely assume the output is a claim list or something similar.
This commit is contained in:
ccremers 2007-01-27 21:42:16 +00:00
parent 6cd4d3d7b6
commit 70a718807e
5 changed files with 62 additions and 33 deletions

View File

@ -60,7 +60,12 @@ class ScytherThread(threading.Thread):
scyther.setInput(self.spdl)
# verification start
try:
claims = scyther.verify()
except Scyther.Error.ScytherError, el:
claims = None
pass
summary = str(scyther)
return (scyther, claims, summary)

View File

@ -9,6 +9,22 @@ class Error(Exception):
"""Base class for exceptions in this module."""
pass
class ScytherError(Error):
"""Exception raised for errors generated by the backend
Attributes:
errorlist -- list of error lines are retrieved from the
backend
"""
def __init__(self, errorlist):
self.errorlist = errorlist
def __str__(self):
s = "Scyther backend reported the following errors:\n"
s = s + "\n".join(self.errorlist)
return s
class InputError(Error):
"""Exception raised for errors in the input.

View File

@ -193,9 +193,9 @@ class Scyther(object):
raise Error.NoBinaryError
# Sanitize input somewhat
if not spdl or spdl == "":
if spdl == "":
# Scyther hickups on completely empty input
spdl = None
spdl = "\n"
# Generate temporary files for the output.
# Requires Python 2.3 though.
@ -275,6 +275,7 @@ class Scyther(object):
self.warnings = []
for l in errors.splitlines():
line = l.strip()
if len(line) > 0:
# filter out any non-errors (say maybe only claim etc) and count
# them.
if line.startswith("claim\t"):
@ -288,6 +289,8 @@ class Scyther(object):
self.errors.append(line)
self.errorcount = len(self.errors)
if self.errorcount > 0:
raise Error.ScytherError(self.errors)
# process output
self.output = output
@ -310,14 +313,19 @@ class Scyther(object):
else:
return self.output
def verifyOne(self,cl):
def verifyOne(self,cl=None):
"""
Verify just a single claim with an ID retrieved from the
procedure below, 'scanClaims', or a full claim object
"""
if cl:
# We accept either a claim or a claim id
if isinstance(cl,Claim.Claim):
cl = cl.id
return self.verify("--filter=%s" % cl)
else:
# If no claim, then its just normal verification
return self.verify()
def scanClaims(self):
"""

View File

@ -8,9 +8,11 @@ Scyther Python API (contained in the Scyther subdirectory)
In this example, multi-protocol attack analysis is performed on a small
test set.
Author: Cas Cremers
"""
import Scyther.Scyther as Scyther
from Scyther import Scyther
def MyScyther(protocollist,filter=None):
"""
@ -19,12 +21,11 @@ def MyScyther(protocollist,filter=None):
will be evaluated.
"""
s = Scyther.Scyther()
# untyped matching
s.options = "--match=2"
if filter:
s.options += " --filter=%s" % (filter)
for protocol in protocollist:
s.addFile(protocol)
s.verify()
s.verifyOne(filter)
return s
@ -42,7 +43,6 @@ def getCorrectIsolatedClaims(protocolset):
# verify protocol in isolation
s = MyScyther([protocol])
# investigate the results
if not s.errors:
goodprotocols.append(protocol)
for claim in s.claims:
if claim.okay:
@ -124,7 +124,7 @@ def findAllMPA(protocolset,maxcount=3):
findMPA(protocolset,protocol,claimid,maxcount=3)
if __name__ == '__main__':
def main():
"""
Simple test case with a few protocols
"""
@ -137,5 +137,8 @@ if __name__ == '__main__':
print "Analysis complete."
if __name__ == '__main__':
main()
# vim: set ts=4 sw=4 et list lcs=tab\:>-:

View File

@ -24,11 +24,8 @@ from optparse import OptionParser, SUPPRESS_HELP
#---------------------------------------------------------------------------
""" Import scyther-gui components """
import Gui.About as About
import Gui.Preference as Preference
import Gui.Mainwindow as Mainwindow
import Gui.Misc as Misc
import Scyther.Scyther as Scyther
from Gui import About,Preference,Mainwindow,Misc
from Scyther import Scyther
#---------------------------------------------------------------------------