- 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:
parent
6cd4d3d7b6
commit
70a718807e
@ -60,7 +60,12 @@ class ScytherThread(threading.Thread):
|
|||||||
scyther.setInput(self.spdl)
|
scyther.setInput(self.spdl)
|
||||||
|
|
||||||
# verification start
|
# verification start
|
||||||
|
try:
|
||||||
claims = scyther.verify()
|
claims = scyther.verify()
|
||||||
|
except Scyther.Error.ScytherError, el:
|
||||||
|
claims = None
|
||||||
|
pass
|
||||||
|
|
||||||
summary = str(scyther)
|
summary = str(scyther)
|
||||||
|
|
||||||
return (scyther, claims, summary)
|
return (scyther, claims, summary)
|
||||||
|
@ -9,6 +9,22 @@ class Error(Exception):
|
|||||||
"""Base class for exceptions in this module."""
|
"""Base class for exceptions in this module."""
|
||||||
pass
|
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):
|
class InputError(Error):
|
||||||
"""Exception raised for errors in the input.
|
"""Exception raised for errors in the input.
|
||||||
|
|
||||||
|
@ -193,9 +193,9 @@ class Scyther(object):
|
|||||||
raise Error.NoBinaryError
|
raise Error.NoBinaryError
|
||||||
|
|
||||||
# Sanitize input somewhat
|
# Sanitize input somewhat
|
||||||
if not spdl or spdl == "":
|
if spdl == "":
|
||||||
# Scyther hickups on completely empty input
|
# Scyther hickups on completely empty input
|
||||||
spdl = None
|
spdl = "\n"
|
||||||
|
|
||||||
# Generate temporary files for the output.
|
# Generate temporary files for the output.
|
||||||
# Requires Python 2.3 though.
|
# Requires Python 2.3 though.
|
||||||
@ -275,6 +275,7 @@ class Scyther(object):
|
|||||||
self.warnings = []
|
self.warnings = []
|
||||||
for l in errors.splitlines():
|
for l in errors.splitlines():
|
||||||
line = l.strip()
|
line = l.strip()
|
||||||
|
if len(line) > 0:
|
||||||
# filter out any non-errors (say maybe only claim etc) and count
|
# filter out any non-errors (say maybe only claim etc) and count
|
||||||
# them.
|
# them.
|
||||||
if line.startswith("claim\t"):
|
if line.startswith("claim\t"):
|
||||||
@ -288,6 +289,8 @@ class Scyther(object):
|
|||||||
self.errors.append(line)
|
self.errors.append(line)
|
||||||
|
|
||||||
self.errorcount = len(self.errors)
|
self.errorcount = len(self.errors)
|
||||||
|
if self.errorcount > 0:
|
||||||
|
raise Error.ScytherError(self.errors)
|
||||||
|
|
||||||
# process output
|
# process output
|
||||||
self.output = output
|
self.output = output
|
||||||
@ -310,14 +313,19 @@ class Scyther(object):
|
|||||||
else:
|
else:
|
||||||
return self.output
|
return self.output
|
||||||
|
|
||||||
def verifyOne(self,cl):
|
def verifyOne(self,cl=None):
|
||||||
"""
|
"""
|
||||||
Verify just a single claim with an ID retrieved from the
|
Verify just a single claim with an ID retrieved from the
|
||||||
procedure below, 'scanClaims', or a full claim object
|
procedure below, 'scanClaims', or a full claim object
|
||||||
"""
|
"""
|
||||||
|
if cl:
|
||||||
|
# We accept either a claim or a claim id
|
||||||
if isinstance(cl,Claim.Claim):
|
if isinstance(cl,Claim.Claim):
|
||||||
cl = cl.id
|
cl = cl.id
|
||||||
return self.verify("--filter=%s" % cl)
|
return self.verify("--filter=%s" % cl)
|
||||||
|
else:
|
||||||
|
# If no claim, then its just normal verification
|
||||||
|
return self.verify()
|
||||||
|
|
||||||
def scanClaims(self):
|
def scanClaims(self):
|
||||||
"""
|
"""
|
||||||
|
15
gui/mpa.py
15
gui/mpa.py
@ -8,9 +8,11 @@ Scyther Python API (contained in the Scyther subdirectory)
|
|||||||
In this example, multi-protocol attack analysis is performed on a small
|
In this example, multi-protocol attack analysis is performed on a small
|
||||||
test set.
|
test set.
|
||||||
|
|
||||||
|
Author: Cas Cremers
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Scyther.Scyther as Scyther
|
from Scyther import Scyther
|
||||||
|
|
||||||
def MyScyther(protocollist,filter=None):
|
def MyScyther(protocollist,filter=None):
|
||||||
"""
|
"""
|
||||||
@ -19,12 +21,11 @@ def MyScyther(protocollist,filter=None):
|
|||||||
will be evaluated.
|
will be evaluated.
|
||||||
"""
|
"""
|
||||||
s = Scyther.Scyther()
|
s = Scyther.Scyther()
|
||||||
|
# untyped matching
|
||||||
s.options = "--match=2"
|
s.options = "--match=2"
|
||||||
if filter:
|
|
||||||
s.options += " --filter=%s" % (filter)
|
|
||||||
for protocol in protocollist:
|
for protocol in protocollist:
|
||||||
s.addFile(protocol)
|
s.addFile(protocol)
|
||||||
s.verify()
|
s.verifyOne(filter)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +43,6 @@ def getCorrectIsolatedClaims(protocolset):
|
|||||||
# verify protocol in isolation
|
# verify protocol in isolation
|
||||||
s = MyScyther([protocol])
|
s = MyScyther([protocol])
|
||||||
# investigate the results
|
# investigate the results
|
||||||
if not s.errors:
|
|
||||||
goodprotocols.append(protocol)
|
goodprotocols.append(protocol)
|
||||||
for claim in s.claims:
|
for claim in s.claims:
|
||||||
if claim.okay:
|
if claim.okay:
|
||||||
@ -124,7 +124,7 @@ def findAllMPA(protocolset,maxcount=3):
|
|||||||
findMPA(protocolset,protocol,claimid,maxcount=3)
|
findMPA(protocolset,protocol,claimid,maxcount=3)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main():
|
||||||
"""
|
"""
|
||||||
Simple test case with a few protocols
|
Simple test case with a few protocols
|
||||||
"""
|
"""
|
||||||
@ -137,5 +137,8 @@ if __name__ == '__main__':
|
|||||||
print "Analysis complete."
|
print "Analysis complete."
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set ts=4 sw=4 et list lcs=tab\:>-:
|
||||||
|
@ -24,11 +24,8 @@ from optparse import OptionParser, SUPPRESS_HELP
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
""" Import scyther-gui components """
|
""" Import scyther-gui components """
|
||||||
import Gui.About as About
|
from Gui import About,Preference,Mainwindow,Misc
|
||||||
import Gui.Preference as Preference
|
from Scyther import Scyther
|
||||||
import Gui.Mainwindow as Mainwindow
|
|
||||||
import Gui.Misc as Misc
|
|
||||||
import Scyther.Scyther as Scyther
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user