diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index dc8338d..d3272ea 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -60,7 +60,12 @@ class ScytherThread(threading.Thread): scyther.setInput(self.spdl) # verification start - claims = scyther.verify() + try: + claims = scyther.verify() + except Scyther.Error.ScytherError, el: + claims = None + pass + summary = str(scyther) return (scyther, claims, summary) diff --git a/gui/Scyther/Error.py b/gui/Scyther/Error.py index 1ab5718..d498a35 100644 --- a/gui/Scyther/Error.py +++ b/gui/Scyther/Error.py @@ -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. diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 3c8b551..c1c06c5 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -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,19 +275,22 @@ class Scyther(object): self.warnings = [] for l in errors.splitlines(): line = l.strip() - # filter out any non-errors (say maybe only claim etc) and count - # them. - if line.startswith("claim\t"): - # Claims are lost, reconstructed from the XML output - continue - if line.startswith("warning"): - # Warnings are stored seperately - self.warnings.append(line) - continue - # otherwise it is an error - self.errors.append(line) + if len(line) > 0: + # filter out any non-errors (say maybe only claim etc) and count + # them. + if line.startswith("claim\t"): + # Claims are lost, reconstructed from the XML output + continue + if line.startswith("warning"): + # Warnings are stored seperately + self.warnings.append(line) + continue + # otherwise it is an error + 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 isinstance(cl,Claim.Claim): - cl = cl.id - return self.verify("--filter=%s" % cl) + 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): """ diff --git a/gui/mpa.py b/gui/mpa.py index a3aff20..90c8fa6 100755 --- a/gui/mpa.py +++ b/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 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,11 +43,10 @@ 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: - correctclaims.append((protocol,claim.id)) + goodprotocols.append(protocol) + for claim in s.claims: + if claim.okay: + correctclaims.append((protocol,claim.id)) return (goodprotocols,correctclaims) def verifyMPAlist(mpalist,claimid): @@ -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\:>-: diff --git a/gui/scyther-gui.py b/gui/scyther-gui.py index 66d30c3..c34f60d 100755 --- a/gui/scyther-gui.py +++ b/gui/scyther-gui.py @@ -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 #---------------------------------------------------------------------------