diff --git a/README.md b/README.md index 5175223..2c28eb6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ tool for security protocol analysis. Its intended audience are interested users and future developers of the Scyther tool, as well as protocol modelers. For installation and usage instructions of the Scyther tool see: -. +. Installing from source ---------------------- @@ -16,7 +16,7 @@ Windows and MAC OS X should be equally feasible. Note that the below instructions are written from a Linux/Ubuntu perspective, and probably need modifications for other platforms. -Scyther is written partly in Python 2 (for the GUI, using wxPython) and +Scyther is written partly in Python 3 (for the GUI, using wxPython) and partly in C (for the backend). In order to run the tool from a repository checkout, it is required to diff --git a/dist/build-arch-tag b/dist/build-arch-tag index ff5b02e..9740a7a 100755 --- a/dist/build-arch-tag +++ b/dist/build-arch-tag @@ -106,9 +106,8 @@ then elif [ $ARCH = "mac" ] then - # Make for ppc and intel, and combine into universal binary + # Make for intel BIN="scyther-mac" - cmake $CMFLAGS -D TARGETOS=MacPPC . && make cmake $CMFLAGS -D TARGETOS=MacIntel . && make cmake $CMFLAGS . && make scyther-mac fi diff --git a/gui/Changelog.txt b/gui/Changelog.txt index b50b647..d48d51b 100644 --- a/gui/Changelog.txt +++ b/gui/Changelog.txt @@ -1,6 +1,17 @@ Scyther changelog =============================== +Scyther 1.2 +------------------------------- + +This release mostly serves to modernize the dependencies and simplify install +on modern versions of the three supported platforms. + + * Updated python code to use Python 3, dropping the Python 2 requirement. + * [Gui] Updated to support (and require) wxPython 4.0 or later. + * Updated install instructions. + * Updated copyright notices. + Scyther 1.1.2 ------------------------------- @@ -62,7 +73,7 @@ Major new features: Additional protocol models: -See for a +See for a more high-level overview of selected protocol models. * IEEE 802.16e/WIMAX: PKMv2rsa and variants diff --git a/gui/Gui/About.py b/gui/Gui/About.py index b415c55..404a829 100644 --- a/gui/Gui/About.py +++ b/gui/Gui/About.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -50,7 +50,7 @@ def setBaseDir(mybasedir): class AboutScyther(wx.Dialog): def __init__(self,parent,mybasedir=None): - from Version import SCYTHER_GUI_VERSION + from .Version import SCYTHER_GUI_VERSION global basedir self.text = ''' @@ -65,13 +65,13 @@ class AboutScyther(wx.Dialog):

For news and updates visit the Scyther pages at - - http://www.cs.ox.ac.uk/people/cas.cremers/scyther/index.html + + https://people.cispa.io/cas.cremers/scyther/index.html

License

Scyther : An automatic verifier for security protocols.
- Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers

This program is free software; you can redistribute it and/or diff --git a/gui/Gui/Attackwindow.py b/gui/Gui/Attackwindow.py index 4a6ca70..41aa1e0 100644 --- a/gui/Gui/Attackwindow.py +++ b/gui/Gui/Attackwindow.py @@ -1,8 +1,8 @@ #!/usr/bin/python -from __future__ import division # 2.2+-only + # 2.2+-only """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -25,14 +25,14 @@ from __future__ import division # 2.2+-only """ Import externals """ import wx import os -from Misc import * +from .Misc import * #--------------------------------------------------------------------------- """ Import scyther-gui components """ -import Icon -import Preference -import Error +from . import Icon +from . import Preference +from . import Error #--------------------------------------------------------------------------- try: @@ -54,7 +54,7 @@ class AttackDisplay(wx.ScrolledWindow): wx.ScrolledWindow.__init__(self,parent,id=-1) self.Bind(wx.EVT_SIZE, self.OnSize) - self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1)) + self.Image = wx.StaticBitmap(self, -1, wx.Bitmap(1,1)) self.box = wx.BoxSizer(wx.VERTICAL) self.box.Add(self.Image,1,wx.ALIGN_CENTER) self.hbox = wx.BoxSizer(wx.HORIZONTAL) @@ -74,7 +74,7 @@ class AttackDisplay(wx.ScrolledWindow): Preference.doNotUsePIL() raise Error.PILError else: - print "Unknown file type %s." % (self.filetype) + print("Unknown file type %s." % (self.filetype)) # TODO self.Bind(wxSizeEvent self.update(True) @@ -93,9 +93,7 @@ class AttackDisplay(wx.ScrolledWindow): # This is needed, don't ask me why. self.SetScrollbars(0,0,0,0,0,0) - size = self.GetClientSize() - framewidth = size.width - frameheight = size.height + (framewidth,frameheight) = self.GetClientSize() (virtualwidth,virtualheight) = (framewidth,frameheight) def makefit(width,height): @@ -120,14 +118,14 @@ class AttackDisplay(wx.ScrolledWindow): if self.attack.filetype == "png": bmp = self.original - if not bmp.Ok(): - bmp = wx.EmptyImage(1,1) + if not bmp.IsOk(): + bmp = wx.Image(1,1) else: (originalwidth,originalheight) = (bmp.GetWidth(), bmp.GetHeight()) if self.win.fit: (factor, virtualwidth, virtualheight) = makefit(originalwidth,originalheight) bmp = self.original.Scale(virtualwidth,virtualheight) - self.Image.SetBitmap(wx.BitmapFromImage(bmp)) + self.Image.SetBitmap(wx.Bitmap(bmp)) elif self.attack.filetype == "ps": pil = self.original.copy() @@ -144,7 +142,7 @@ class AttackDisplay(wx.ScrolledWindow): self.Image.SetBitmap(image.ConvertToBitmap()) else: - print "Unknown file type %s." % (self.attack.filetype) + print("Unknown file type %s." % (self.attack.filetype)) self.SetVirtualSize((virtualwidth,virtualheight)) @@ -200,16 +198,15 @@ class AttackDisplay(wx.ScrolledWindow): (p,r,l) = self.win.claim.triplet() prefix = "pattern-%s_%s_%s-%s" % (p,r,l,self.attack.id) suggested = "%s.%s" % (prefix,ext) - res = self.askUserForFilename(style=wx.SAVE, wildcard="*.%s" % (ext), defaultFile = "%s" % (suggested)) + res = self.askUserForFilename(style=wx.FD_SAVE, wildcard="*.%s" % (ext), defaultFile = "%s" % (suggested)) return res - def exportImage(self, type,ext=None): + def exportImage(self, imgtype, ext=None): if ext == None: - ext = type + ext = imgtype res = self.saveFileName(ext) if res != None: - cmd = "dot -T%s" % (type) - cmdpushwrite(cmd,self.attack.scytherDot,res) + dotOutputWrite(self.attack.scytherDot,res,["-T" + imgtype]) def OnExportPng(self, event): self.exportImage("png") diff --git a/gui/Gui/Editor.py b/gui/Gui/Editor.py index b3e093f..1c0c48b 100644 --- a/gui/Gui/Editor.py +++ b/gui/Gui/Editor.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -176,7 +176,7 @@ class EditorStc(Editor): line = line - 1 # Start at 0 in stc, but on screen count is 1 pos = self.control.GetLineIndentPosition(line) last = self.control.GetLineEndPosition(line) - self.control.StartStyling(pos,31) + self.control.StartStyling(pos) self.control.SetStyling(last-pos,self.errorstyle) def ClearErrors(self): diff --git a/gui/Gui/Error.py b/gui/Gui/Error.py index b6b2905..af807cb 100644 --- a/gui/Gui/Error.py +++ b/gui/Gui/Error.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/gui/Gui/Icon.py b/gui/Gui/Icon.py index 2f4f26f..4e4d2e1 100644 --- a/gui/Gui/Icon.py +++ b/gui/Gui/Icon.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ import sys #--------------------------------------------------------------------------- """ Import scyther-gui components """ -import Misc +from . import Misc #--------------------------------------------------------------------------- diff --git a/gui/Gui/Mainwindow.py b/gui/Gui/Mainwindow.py index 0e99167..763955d 100644 --- a/gui/Gui/Mainwindow.py +++ b/gui/Gui/Mainwindow.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,12 +28,12 @@ import os.path #--------------------------------------------------------------------------- """ Import scyther-gui components """ -import Settingswindow -import Scytherthread -import Icon -import About -import Editor -import Preference +from . import Settingswindow +from . import Scytherthread +from . import Icon +from . import About +from . import Editor +from . import Preference #--------------------------------------------------------------------------- @@ -288,7 +288,7 @@ class MainWindow(wx.Frame): def OnOpen(self, event): if self.ConfirmLoss("Open"): - if self.askUserForFilename(style=wx.OPEN, + if self.askUserForFilename(style=wx.FD_OPEN, **self.defaultFileDialogOptions()): textfile = open(os.path.join(self.dirname, self.filename), 'r') self.editor.SetText(textfile.read()) @@ -298,7 +298,7 @@ class MainWindow(wx.Frame): return False def OnSaveAs(self, event): - if self.askUserForFilename(defaultFile=self.filename, style=wx.SAVE, + if self.askUserForFilename(defaultFile=self.filename, style=wx.FD_SAVE, **self.defaultFileDialogOptions()): self.OnSave(event) os.chdir(self.dirname) diff --git a/gui/Gui/Makeimage.py b/gui/Gui/Makeimage.py index 220996f..e8d898d 100644 --- a/gui/Gui/Makeimage.py +++ b/gui/Gui/Makeimage.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -34,8 +34,8 @@ from Scyther import Misc as MiscScyther from Scyther import FindDot """ Import scyther-gui components """ -import Temporary -import Preference +from . import Temporary +from . import Preference #--------------------------------------------------------------------------- try: @@ -118,42 +118,32 @@ def makeImageDot(dotdata,attackthread=None): if Preference.usePIL(): # If we have the PIL library, we can do postscript! great # stuff. - type = "ps" + imgtype = "ps" ext = ".ps" else: # Ye olde pnge file - type = "png" + imgtype = "png" ext = ".png" - # Retrieve dot command path - dotcommand = FindDot.findDot() - - # command to write to temporary file - (fd2,fpname2) = Temporary.tempcleaned(ext) - f = os.fdopen(fd2,'w') - + # Write dot source file into temporary file to simplify dealing with graphviz invocation across platforms + (fd_in,fpname_in) = Temporary.tempcleaned(ext) + f_in = os.fdopen(fd_in,'w') + if attackthread: + writeGraph(attackthread,dotdata,f_in) + else: + f_in.write(dotdata) + f_in.close() + # Set up command - cmd = "%s -T%s" % (dotcommand,type) + dotcommand = FindDot.findDot() + cmd = [dotcommand, "-T" + imgtype, fpname_in] # execute command - p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE) + (fd_out,fpname_out) = Temporary.tempcleaned(ext) + p = Popen(cmd, stdout=fd_out) + p.wait() - - if attackthread: - writeGraph(attackthread,dotdata,p.stdin) - else: - p.stdin.write(dotdata) - - p.stdin.close() - - for l in p.stdout.read(): - f.write(l) - - p.stdout.close() - f.flush() - f.close() - - return (fpname2, type) + return (fpname_out, imgtype) def makeImage(attack,attackthread=None): @@ -161,10 +151,10 @@ def makeImage(attack,attackthread=None): """ This should clearly be a method of 'attack' """ - (name,type) = makeImageDot(attack.scytherDot,attackthread) + (name,imgtype) = makeImageDot(attack.scytherDot,attackthread) # if this is done, store and report attack.file = name - attack.filetype = type + attack.filetype = imgtype def testImage(): diff --git a/gui/Gui/Misc.py b/gui/Gui/Misc.py index f255124..a77b1a7 100644 --- a/gui/Gui/Misc.py +++ b/gui/Gui/Misc.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -25,22 +25,29 @@ """ Import externals """ import os.path -from subprocess import Popen,PIPE +from subprocess import Popen,PIPE,run +from shlex import quote + +""" Import scyther components """ +from Scyther import FindDot + +""" Import scyther-gui components """ +from . import Temporary #--------------------------------------------------------------------------- def confirm(question): answer = '' while answer not in ('y','n'): - print question, - answer = raw_input().lower() + print(question, end=' ') + answer = input().lower() return answer == 'y' def exists(func,list): - return len(filter(func,list)) > 0 + return len(list(filter(func,list))) > 0 def forall(func,list): - return len(filter(func,list)) == len(list) + return len(list(filter(func,list))) == len(list) def uniq(li): result = [] @@ -67,24 +74,36 @@ def mypath(file): basedir = os.path.split(cmd_file)[0] return os.path.join(basedir,file) -# commands: push data in, get fp.write out -def cmdpushwrite(cmd,data,fname): +# Write string to tempfile, return (filedescriptor,name) +def stringToTempfile(data,ext="tmp"): """ - Feed stdin data to cmd, write the output to a freshly created file - 'fname'. The file is flushed and closed at the end. + Take data (a string) and write it to a safe temporary file. + Return the resulting filedescriptor and name as a pair. """ - fp = open(fname,'w') - # execute command - p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE) - (cin,cout) = (p.stdin, p.stdout) + (fd,fpname) = Temporary.tempcleaned(ext) + f = os.fdopen(fd,'w') + f.write(data) + f.close() - cin.write(data) - cin.close() - for l in cout.read(): - fp.write(l) - cout.close() - fp.flush() - fp.close() + return (fd, fpname) + + +# commands: push data in as file named argument to dot, get fp.write out +def dotOutputWrite(data,fname,cmd=[]): + """ + Feed stdin data to cmd array, write the output to a freshly + created file 'fname'. The file is flushed and closed at the end. + + TODO: In reality, this particular dot data was already written to another temp file when rendering the attack graph. We should be reusing that file instead of writing a new one. + """ + (fd_in,fpname_in) = stringToTempfile(data,ext="dot") + + dotcommand = FindDot.findDot() + execcmd = [dotcommand] + cmd + ["-o" + quote(fname), quote(fpname_in)] + print (execcmd) + + # execute command + run(execcmd) #--------------------------------------------------------------------------- # vim: set ts=4 sw=4 et list lcs=tab\:>-: diff --git a/gui/Gui/Preference.py b/gui/Gui/Preference.py index 90db531..fcd8553 100644 --- a/gui/Gui/Preference.py +++ b/gui/Gui/Preference.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -49,7 +49,7 @@ from time import localtime,strftime #--------------------------------------------------------------------------- """ Import scyther-gui components """ -import Makeimage +from . import Makeimage #--------------------------------------------------------------------------- @@ -127,7 +127,7 @@ class Preferences(dict): """ Copy dict into self. """ - for x in d.keys(): + for x in list(d.keys()): self[x] = d[x] def parse(self,line): @@ -164,13 +164,13 @@ class Preferences(dict): fp.close() def show(self): - print "Preferences:" - for k in self.keys(): - print "%s=%s" % (k, self[k]) + print("Preferences:") + for k in list(self.keys()): + print("%s=%s" % (k, self[k])) def save(self): - print "Saving preferences" + print("Saving preferences") prefpath = preflocs[-1] if not os.access(prefpath,os.W_OK): os.makedirs(prefpath) @@ -215,7 +215,7 @@ def init(): def get(key,alt=None): global prefs - if key in prefs.keys(): + if key in list(prefs.keys()): return prefs[key] else: return alt @@ -223,7 +223,7 @@ def get(key,alt=None): def getkeys(): global prefs - return prefs.keys() + return list(prefs.keys()) def set(key,value): global prefs diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index 5691c44..0924e85 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -33,11 +33,11 @@ import Scyther.Error from Scyther.Misc import * """ Import scyther-gui components """ -import Preference -import Attackwindow -import Icon -import Error -import Makeimage +from . import Preference +from . import Attackwindow +from . import Icon +from . import Error +from . import Makeimage #--------------------------------------------------------------------------- if Preference.havePIL: @@ -114,7 +114,7 @@ class ScytherThread(threading.Thread): # verification start try: claims = scyther.verify(storePopen=self.storePopen) - except Scyther.Error.ScytherError, el: + except Scyther.Error.ScytherError as el: claims = None pass @@ -185,7 +185,7 @@ class VerificationWindow(wx.Dialog): sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5) line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) + sizer.Add(line, 0, wx.GROW|wx.RIGHT|wx.TOP, 5) btnsizer = wx.StdDialogButtonSizer() @@ -217,7 +217,7 @@ class ErrorWindow(wx.Dialog): sizer.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5) line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) + sizer.Add(line, 0, wx.GROW|wx.RIGHT|wx.TOP, 5) etxt = "" prefix = "error: " @@ -230,7 +230,7 @@ class ErrorWindow(wx.Dialog): sizer.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5) line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) + sizer.Add(line, 0, wx.GROW|wx.RIGHT|wx.TOP, 5) btnsizer = wx.StdDialogButtonSizer() @@ -464,13 +464,13 @@ class ScytherRun(object): # which makes error reporting somewhat easier try: Scyther.Scyther.Check() - except Scyther.Error.BinaryError, e: + except Scyther.Error.BinaryError as e: # e.file is the supposed location of the binary text = "Could not find Scyther binary at\n%s" % (e.file) Error.ShowAndExit(text) # start the thread - self.verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) + self.verifywin.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) self.verifywin.Bind(wx.EVT_CLOSE, self.closer) self.verifywin.Bind(wx.EVT_WINDOW_DESTROY, self.closer) self.verifywin.Bind(wx.EVT_BUTTON, self.closer, id=wx.ID_CANCEL) @@ -520,12 +520,12 @@ class ScytherRun(object): def allDone(): if resultwin: - resultwin.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) + resultwin.SetCursor(wx.Cursor(wx.CURSOR_ARROW)) resultwin.SetStatusText("Done.") resultwin.Center() resultwin.Show(True) - resultwin.SetCursor(wx.StockCursor(wx.CURSOR_ARROWWAIT)) + resultwin.SetCursor(wx.Cursor(wx.CURSOR_ARROWWAIT)) wx.Yield() diff --git a/gui/Gui/Settingswindow.py b/gui/Gui/Settingswindow.py index 5bc5fa9..1638ead 100644 --- a/gui/Gui/Settingswindow.py +++ b/gui/Gui/Settingswindow.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,7 +28,7 @@ import sys #--------------------------------------------------------------------------- """ Import scyther-gui components """ -import Preference +from . import Preference import Scyther.Claim as Claim #--------------------------------------------------------------------------- diff --git a/gui/Gui/Temporary.py b/gui/Gui/Temporary.py index 61c2466..74d5dd5 100644 --- a/gui/Gui/Temporary.py +++ b/gui/Gui/Temporary.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/gui/Gui/Version.py b/gui/Gui/Version.py index 9eeb04b..b1a9cb9 100644 --- a/gui/Gui/Version.py +++ b/gui/Gui/Version.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/gui/Gui/__init__.py b/gui/Gui/__init__.py index 6995b43..98d2996 100644 --- a/gui/Gui/__init__.py +++ b/gui/Gui/__init__.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/gui/INSTALL.md b/gui/INSTALL.md index 41f49be..f1109bd 100644 --- a/gui/INSTALL.md +++ b/gui/INSTALL.md @@ -24,8 +24,7 @@ from the command line) then you need only the first. http://www.python.org/download/ - Scyther does not support Python 3. You are therefore recommended to - choose the latest production release of Python 2, e.g., Python 2.7. + Scyther requires **Python 3** now, and no longer supports Python 2. * **Mac OS X** @@ -41,35 +40,20 @@ from the command line) then you need only the first. 3. ### wxPython libraries ### The GUI user interface uses the wxPython libraries. + The recommended way of installing is through `pip` and described this page: - http://www.wxpython.org/download.php + https://www.wxpython.org/download.php - There are many different wxPython packages. You should choose a 32-bit - package that matches your Python version (e.g., 2.7). It is - recommended to select the unicode version from the stable releases. + This version of Scyther requires at least **wxPython 4.0**. Note that older versions of Scyther did not work with wxPython 4. - As of writing (May 2013) the following links lead to the appropriate - wxPython packages for Python 2.7: - - * **Windows** - - http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.12.1-py27.exe - - * **Mac OS X** - - http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-unicode-2.8.12.1-universal-py2.7.dmg - - Note that this package is in an old format and you will probably - get a warning "Package is damaged". This can be resolved by: - - ``` - $ sudo installer -pkg /Volume/.../wxPython2.8-osx-unicode-universal-py2.7.pkg/ -target / - ``` - - * **Ubuntu/Debian Linux** - - http://wiki.wxpython.org/InstallingOnUbuntuOrDebian + For Ubuntu users, it is important to add an additional parameter, e.g., for Ubuntu 20.04, the recommended pip install is: + ``` + $ sudo apt install python-pip + $ pip install -U \ + -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04 \ + wxPython + ``` Running Scyther --------------- @@ -78,13 +62,13 @@ Extract the Scyther archive and navigate to the extracted directory. Start Scyther by executing the file - scyther-gui.py + `scyther-gui.py` in the main directory of the extracted archive. * **Mac OS X** - Right-click the file 'scyther-gui.py' and select "Open with" and + Right-click the file `scyther-gui.py` and select "Open with" and then "Python Launcher". diff --git a/gui/Protocols/IKE/make-mpa.py b/gui/Protocols/IKE/make-mpa.py index c75984d..67f969b 100755 --- a/gui/Protocols/IKE/make-mpa.py +++ b/gui/Protocols/IKE/make-mpa.py @@ -19,7 +19,7 @@ def scanThis(fn,f,rewritelist,cnt): mapping.append((lhs,rhs)) fp = open(fn,"r") - for rl in fp.xreadlines(): + for rl in fp: l = rl if f != None: l = f(l) @@ -34,7 +34,7 @@ def convertEm(f=None,path=".",rewritelist=[],newdir=".",oldext="",newext=None): cnt = 1 for fn in fl: ffn = os.path.join(path,fn) - print "Processing",ffn + print("Processing",ffn) s = scanThis(ffn,f,rewritelist,cnt) if newext == None: fn2 = fn @@ -44,7 +44,7 @@ def convertEm(f=None,path=".",rewritelist=[],newdir=".",oldext="",newext=None): fp = open(ffn2,"w") fp.write(s) fp.close() - print "Produced",ffn2 + print("Produced",ffn2) cnt = cnt+1 def preprocess(s): @@ -55,7 +55,7 @@ def preprocess(s): def main(): convertEm(f=preprocess,rewritelist=["@OracleA","@executability","@OracleB"],path=".",newdir="mpa",oldext=".spdl") - print "Done." + print("Done.") if __name__ == '__main__': main() diff --git a/gui/Protocols/IKE/scanner.py b/gui/Protocols/IKE/scanner.py index bc529ac..4e075f3 100755 --- a/gui/Protocols/IKE/scanner.py +++ b/gui/Protocols/IKE/scanner.py @@ -34,8 +34,8 @@ def stripRowEnd(l): # Assume ends with \\, split by dtl endstr = "\\\\" if not l.endswith(endstr): - print "Error: some line does not end with \\\\" - print ">>%s<<" % (l) + print("Error: some line does not end with \\\\") + print(">>%s<<" % (l)) sys.exit(-1) return l[:-len(endstr)] @@ -63,7 +63,7 @@ def scanAttackFile(fn): prot = None role = None claim = None - for rawline in fp.xreadlines(): + for rawline in fp: l = rawline.strip() @@ -94,7 +94,7 @@ def scanAttackFile(fn): attl[i] = x[1:-1] ak = (prot,role,claim) - if ak not in attackmap.keys(): + if ak not in list(attackmap.keys()): attackmap[ak] = set() attackmap[ak].add(tuple(attl)) @@ -136,7 +136,7 @@ def mpaTable(attackmap): s += "\\begin{longtable}{|l|lll|l|}\n" s += "\\hline\n" for kk in sorted(ALLCLAIMS): - if kk not in attackmap.keys(): + if kk not in list(attackmap.keys()): continue (prot,role,claim) = kk @@ -174,7 +174,7 @@ def mpaTable2(attackmap,tabtype="tabular",options=""): # To find the number of columns, we first need to find all protocols involved in two-protocol attacks involved = set() - for kk in attackmap.keys(): + for kk in list(attackmap.keys()): for atl in attackmap[kk]: # convert tuple back to list att = list(atl) @@ -210,7 +210,7 @@ def mpaTable2(attackmap,tabtype="tabular",options=""): s += "\\hline\n" last = None for kk in sorted(ALLCLAIMS): - if kk not in attackmap.keys(): + if kk not in list(attackmap.keys()): continue (prot,role,claim) = kk @@ -256,7 +256,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""): involved = set() allkeys = set() for (attackmap,symbs) in attackmaps: - for kk in attackmap.keys(): + for kk in list(attackmap.keys()): allkeys.add(kk) for atl in attackmap[kk]: # convert tuple back to list @@ -298,7 +298,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""): s += "\\hline\n" last = None for kk in sorted(ALLCLAIMS): - if kk not in attackmap.keys(): + if kk not in list(attackmap.keys()): continue (prot,role,claim) = kk @@ -313,7 +313,7 @@ def mpaTable3(attackmaps,tabtype="tabular",options=""): se = tuple([ch]) sl += "& " for (attackmap,symb) in attackmaps: - if kk in attackmap.keys(): + if kk in list(attackmap.keys()): if se in attackmap[kk]: sl += symb break @@ -341,7 +341,7 @@ def scanClaimList(fn): fp = open("gen-%s-claims.txt" % (fn),"r") claimmap = {} - for rawline in fp.xreadlines(): + for rawline in fp: l = rawline.strip() @@ -380,7 +380,7 @@ def scanClaimFile(fn): fp = open("gen-%s-correctclaims.tex" % (fn),"r") claimmap = {} - for rawline in fp.xreadlines(): + for rawline in fp: l = rawline.strip() @@ -396,7 +396,7 @@ def scanClaimFile(fn): if not FFUNC(prot): continue - if prot not in claimmap.keys(): + if prot not in list(claimmap.keys()): claimmap[prot] = {} cll = splitStrip(dtl[1],";") @@ -404,7 +404,7 @@ def scanClaimFile(fn): for dt in cll: (role,claim) = roleClaim(dt) - if role not in claimmap[prot].keys(): + if role not in list(claimmap[prot].keys()): claimmap[prot][role] = set() claimmap[prot][role].add(claim) @@ -420,7 +420,7 @@ def scanClaimFile(fn): def getRoleClaims(rcmap): rc = set() - for role in rcmap.keys(): + for role in list(rcmap.keys()): for claim in rcmap[role]: rc.add((role,claim)) @@ -459,8 +459,8 @@ def typeScanMatrix(cml,onlyChanged = False): alltrue = True for (txt,cm) in cml: verdict = badverdict - if prot in cm.keys(): - if role in cm[prot].keys(): + if prot in list(cm.keys()): + if role in list(cm[prot].keys()): if claim in cm[prot][role]: verdict = goodverdict if verdict == badverdict: @@ -518,8 +518,8 @@ def typeScanMatrix2(cml,onlyChanged = False,additive = False): res = "" for (txt,cm) in cml: verdict = badverdict - if prot in cm.keys(): - if role in cm[prot].keys(): + if prot in list(cm.keys()): + if role in list(cm[prot].keys()): if claim in cm[prot][role]: verdict = goodverdict if verdict == badverdict: @@ -582,8 +582,8 @@ def typeScanMatrix3(hd1,hd2,cml,f,onlyChanged = False,tabletype="longtable"): resl = [] for cm in cml: verdict = badverdict - if prot in cm.keys(): - if role in cm[prot].keys(): + if prot in list(cm.keys()): + if role in list(cm[prot].keys()): if claim in cm[prot][role]: verdict = goodverdict if verdict == badverdict: @@ -660,11 +660,11 @@ def docWrite(fn,tex,author=None,title=None): def docMake(fn,tex,author=None,title=None): - import commands + import subprocess docWrite(fn,tex,author,title) cmd = "pdflatex %s" % (fn) - commands.getoutput(cmd) + subprocess.getoutput(cmd) def f1(resl): txtl = [] diff --git a/gui/Protocols/multi-NSL/multinsl-generator.py b/gui/Protocols/multi-NSL/multinsl-generator.py index ad44870..a3fb274 100755 --- a/gui/Protocols/multi-NSL/multinsl-generator.py +++ b/gui/Protocols/multi-NSL/multinsl-generator.py @@ -32,7 +32,7 @@ def parseArgs(): parser.print_help() sys.exit(0) if opts.protocol not in ["nsl","bke","nsl-priv-noprop","nsl-pub-nap","bke-nap"]: - print "I don't know the %s protocol." % (opts.protocol) + print("I don't know the %s protocol." % (opts.protocol)) sys.exit(0) return (opts,args) @@ -158,7 +158,7 @@ def message1 (label,inrole): return msg else: - print "Hmm, I don't know how to create the first message for protocol %s" % (opts.protocol) + print("Hmm, I don't know how to create the first message for protocol %s" % (opts.protocol)) def message2 (label,inrole): global P,variant,opts @@ -205,7 +205,7 @@ def message2 (label,inrole): return msg else: - print "Hmm, I don't know how to create the final message for protocol %s" % (opts.protocol) + print("Hmm, I don't know how to create the final message for protocol %s" % (opts.protocol)) def message (label,inrole): global P,opts @@ -338,7 +338,7 @@ def main(): global opts (opts,args) = parseArgs() - print protocol(args) + print(protocol(args)) # Only if main stuff if __name__ == '__main__': diff --git a/gui/Protocols/multi-NSL/test-heuristics.py b/gui/Protocols/multi-NSL/test-heuristics.py index 34c03fc..7ce2f94 100755 --- a/gui/Protocols/multi-NSL/test-heuristics.py +++ b/gui/Protocols/multi-NSL/test-heuristics.py @@ -7,11 +7,11 @@ # and sincerely hope on gives a complete proof. # we slowly refine the tests. # -import commands +import subprocess def startset(): mainlist = [11, 15] - print "Starting with", mainlist + print("Starting with", mainlist) return mainlist def tuplingchoice(heur,variant,P,runs,latupling): @@ -37,15 +37,15 @@ def tuplingchoice(heur,variant,P,runs,latupling): #s += " | scyther -a -r%i --summary" % runs # Show what we're doing - print s + print(s) #s += " | grep \"complete\"" - out = commands.getoutput(s) + out = subprocess.getoutput(s) if out == "": #print "Okay" return False else: - print out + print(out) return True def testvariant(h,v,p,r): @@ -55,11 +55,11 @@ def testvariant(h,v,p,r): return tuplingchoice (h,v,p,r, True) def scan(testlist, P, runs): - print "Testing using P %i and %i runs." % (P,runs) + print("Testing using P %i and %i runs." % (P,runs)) for i in testlist: - print "Testing protocol %i." % (i) + print("Testing protocol %i." % (i)) for h in range (0,32): - print "Heuristic %i:" % (h) + print("Heuristic %i:" % (h)) testvariant (h,i,P,runs) def main(): diff --git a/gui/Protocols/multi-NSL/test-variants.py b/gui/Protocols/multi-NSL/test-variants.py index ae00ce7..e1ba7ee 100755 --- a/gui/Protocols/multi-NSL/test-variants.py +++ b/gui/Protocols/multi-NSL/test-variants.py @@ -6,13 +6,13 @@ # We test all variants [0..31] until we are sure they work. Thus, # we slowly refine the tests. # -import commands +import subprocess def startset(): - return range(0,32) + return list(range(0,32)) mainlist = [11, 15] - print "Starting with", mainlist + print("Starting with", mainlist) return mainlist def tuplingchoice(variant,P,runs,latupling): @@ -30,7 +30,7 @@ def tuplingchoice(variant,P,runs,latupling): #s += " | scyther -a -r%i --summary" % runs #print s s += " | grep \"Fail\"" - out = commands.getoutput(s) + out = subprocess.getoutput(s) if out == "": #print "Okay" return True @@ -53,15 +53,15 @@ def removeattacks (testlist, P, runs): return okaylist def scan(testlist, P, runs): - print "Testing using P %i and %i runs." % (P,runs) + print("Testing using P %i and %i runs." % (P,runs)) results = removeattacks (testlist, P, runs) if len(results) < len(testlist): attacked = [] for i in range(0,len(testlist)): if testlist[i] not in results: attacked.append(testlist[i]) - print "Using P %i and %i runs, we find attacks on %s" % (P,runs, str(attacked)) - print "Therefore, we are left with %i candidates: " % (len(results)), results + print("Using P %i and %i runs, we find attacks on %s" % (P,runs, str(attacked))) + print("Therefore, we are left with %i candidates: " % (len(results)), results) return results @@ -71,9 +71,9 @@ def main(): for rundiff in range(0,5): candidates = scan(candidates,P,P+rundiff) - print - print "Good variants:" - print candidates + print() + print("Good variants:") + print(candidates) main() diff --git a/gui/README.md b/gui/README.md index 706df8d..7334b81 100644 --- a/gui/README.md +++ b/gui/README.md @@ -3,7 +3,7 @@ The Scyther tool Scyther is a tool for the symbolic analysis of security protocols. It is developed by Cas Cremers, and is available from -. +. The below instructions apply only to the *distribution version* of the Scyther tool. If you are working from the source files, some paths may be @@ -45,11 +45,15 @@ availabe from Manual ------ -We are currently rewriting the manual. The current (incomplete) +The manual is lagging behind. The current (incomplete) distribution version of the manual can be found here: * [./scyther-manual.pdf](scyther-manual.pdf) +However, have a look at the book if you are interested: + + * [https://doi.org/10.1007/978-3-540-70545-1_38](Our book on security protocols and the theory behind Scyther) + Protocol Models --------------- diff --git a/gui/Scripts/regression-test.py b/gui/Scripts/regression-test.py index beabc74..841d425 100755 --- a/gui/Scripts/regression-test.py +++ b/gui/Scripts/regression-test.py @@ -2,7 +2,7 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -52,7 +52,7 @@ def evaluate(fn,prefix=""): fstderr.seek(0) res = "" - for l in fstdout.xreadlines(): + for l in fstdout: res += prefix + l.strip() + "\n" #for l in fstderr.xreadlines(): # print l @@ -72,7 +72,7 @@ def main(): cnt = 1 tres = "" for (prefix,fn) in sorted(fl): - print "Evaluating %s (%i/%i)" % (fn,cnt,len(fl)) + print("Evaluating %s (%i/%i)" % (fn,cnt,len(fl))) res = evaluate(prefix+fn, "%s\t" % (fn)) fp.write(res) tres += res @@ -83,7 +83,7 @@ def main(): fp.write(tres) fp.close() - print res + print(res) diff --git a/gui/Scripts/scytherview.py b/gui/Scripts/scytherview.py index 9973867..00baee9 100755 --- a/gui/Scripts/scytherview.py +++ b/gui/Scripts/scytherview.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -30,7 +30,7 @@ # Note 2: this code assumes that both scyther-linux and dot can be found in the # environment (i.e. PATH variable) # -import os,sys,commands +import os,sys,subprocess import os.path tempcount = 0 @@ -59,7 +59,7 @@ def scyther_to_dotfile(): tmpdotfile = generateTemp('dot') command = "%s --plain --dot-output %s > %s" % (scythername, args, tmpdotfile) - output = commands.getoutput(command) + output = subprocess.getoutput(command) return (output,tmpdotfile) def dotfile_to_pdffile(dotfile,outfile=None): @@ -72,10 +72,10 @@ def dotfile_to_pdffile(dotfile,outfile=None): # it fit to a landscape page dotdata = open(dotfile, "r") f = None - for line in dotdata.xreadlines(): + for line in dotdata: if (line.find('digraph') == 0): f = os.popen("dot -Gsize='11.0,8.0' -Gratio=fill -Tps >>%s" % (tmp),'w') - print >>f, line + print(line, file=f) dotdata.close() if not f: @@ -96,18 +96,18 @@ def dotfile_to_pdffile(dotfile,outfile=None): def main(): (output,dotfile) = scyther_to_dotfile() - print output + print(output) pdffile = dotfile_to_pdffile(dotfile) os.unlink(dotfile) if pdffile: - commands.getoutput("kpdf %s" % pdffile) + subprocess.getoutput("kpdf %s" % pdffile) os.unlink(pdffile) else: - print "No graphs generated." + print("No graphs generated.") if __name__ == '__main__': if len(sys.argv) > 1: main() else: - print "Please provide the name of an input file." + print("Please provide the name of an input file.") diff --git a/gui/Scyther/Attack.py b/gui/Scyther/Attack.py index d07ee6e..fa98c8c 100644 --- a/gui/Scyther/Attack.py +++ b/gui/Scyther/Attack.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,10 +21,10 @@ # Attack # -import Trace -import Term +from . import Trace +from . import Term #import Classification -from Misc import * +from .Misc import * class Attack(object): def __init__(self): @@ -47,7 +47,7 @@ class Attack(object): def getInvolvedAgents(self): result = [] for run in self.semiTrace.runs: - for agent in run.roleAgents.values(): + for agent in list(run.roleAgents.values()): result.append(agent) return uniq(result) diff --git a/gui/Scyther/Claim.py b/gui/Scyther/Claim.py index c048789..ee8ba4d 100644 --- a/gui/Scyther/Claim.py +++ b/gui/Scyther/Claim.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,7 +21,7 @@ # Claim # -import Term +from . import Term def stateDescription(okay,n=1,caps=False): if okay: diff --git a/gui/Scyther/Error.py b/gui/Scyther/Error.py index 88f5db8..f8de063 100644 --- a/gui/Scyther/Error.py +++ b/gui/Scyther/Error.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/gui/Scyther/FindDot.py b/gui/Scyther/FindDot.py index c70c3ff..ab0b195 100644 --- a/gui/Scyther/FindDot.py +++ b/gui/Scyther/FindDot.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ import sys import os #--------------------------------------------------------------------------- """ Import internals """ -import Misc +from . import Misc #--------------------------------------------------------------------------- DOTLOCATION = None @@ -41,8 +41,9 @@ def testDot(fpath): try: cmd = "%s -V" % (fpath) (sts,sout,serr) = Misc.safeCommandOutput(cmd) + if sts != -1: - if "version" in sout + serr: + if "version" in str(sout) + str(serr): return True except: pass diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index e41abd8..830a7a5 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -40,15 +40,15 @@ You need at least Python 2.4 to use this program. def confirm(question): answer = '' while answer not in ('y','n'): - print question, - answer = raw_input().lower() + print(question, end=' ') + answer = input().lower() return answer == 'y' def exists(func,list): - return len(filter(func,list)) > 0 + return len(list(filter(func,list))) > 0 def forall(func,list): - return len(filter(func,list)) == len(list) + return len(list(filter(func,list))) == len(list) def uniq(li): result = [] @@ -93,21 +93,19 @@ def getShell(): """ Determine if we want a shell for Popen """ - if sys.platform.startswith("win"): - shell=False - else: - # Needed to handle the string input correctly (as opposed to a sequence where the first element is the executable) - # This is not needed on Windows, where it has a different effect altogether. - # See http://docs.python.org/library/subprocess.html?highlight=subprocess#module-subprocess - shell=True - return shell + return False def safeCommandOutput(cmd, storePopen=None): """ Execute a command and return (sts,sout,serr). Meant for short outputs, as output is stored in memory and not written to a file. """ - p = Popen(cmd, shell=getShell(), stdout=PIPE, stderr=PIPE) + + if isinstance(cmd, str): + import shlex + cmd = shlex.split(cmd) + + p = Popen(cmd, stdout=PIPE, stderr=PIPE) if storePopen != None: storePopen(p) (sout,serr) = p.communicate() @@ -119,16 +117,20 @@ def safeCommand(cmd, storePopen=None): version, I hope. """ try: - p = Popen(cmd, shell=getShell()) + if isinstance(cmd, str): + import shlex + cmd = shlex.split(cmd) + + p = Popen(cmd) if storePopen != None: storePopen(p) sts = p.wait() - except KeyboardInterrupt, EnvironmentError: + except KeyboardInterrupt as EnvironmentError: raise except: - print "Wile processing [%s] we had an" % (cmd) - print "unexpected error:", sys.exc_info()[0] - print + print("Wile processing [%s] we had an" % (cmd)) + print("unexpected error:", sys.exc_info()[0]) + print() sts = -1 raise # For now still raise @@ -142,15 +144,15 @@ def panic(text): """ try: - import Tkinter + import tkinter except: - print text + print(text) sys.exit(-1) - print text + print(text) - root = Tkinter.Tk() - w = Tkinter.Label(root, justify=Tkinter.LEFT, padx = 10, text=text) + root = tkinter.Tk() + w = tkinter.Label(root, justify=tkinter.LEFT, padx = 10, text=text) w.pack() root.mainloop() diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 0de9bb6..a5336c6 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,7 +28,7 @@ import os import os.path import sys -import StringIO +import io import tempfile try: import hashlib @@ -40,10 +40,10 @@ except ImportError: #--------------------------------------------------------------------------- """ Import scyther components """ -import XMLReader -import Error -import Claim -from Misc import * +from . import XMLReader +from . import Error +from . import Claim +from .Misc import * #--------------------------------------------------------------------------- @@ -77,7 +77,7 @@ def getCacheDir(): # Check if user chose the path cachedirkey = "SCYTHERCACHEDIR" - if cachedirkey in os.environ.keys(): + if cachedirkey in list(os.environ.keys()): tmpdir = os.environ[cachedirkey] if tmpdir == "": # Special value: if the variable is present, but equals the empty string, we disable caching. @@ -126,7 +126,7 @@ def CheckSanity(program): """ if not os.path.isfile(program): - raise Error.BinaryError, program + raise Error.BinaryError(program) #--------------------------------------------------------------------------- @@ -149,7 +149,7 @@ def EnsureString(x,sep=" "): return sep.join(newlist) else: - raise Error.StringListError, x + raise Error.StringListError(x) #--------------------------------------------------------------------------- @@ -177,7 +177,7 @@ def getScytherBackend(): else: """ Unsupported""" - raise Error.UnknownPlatformError, sys.platform + raise Error.UnknownPlatformError(sys.platform) program = os.path.join(getBinDir(),scythername) return program @@ -294,14 +294,18 @@ class Scyther(object): # Apparently we are supporsed to be able to use the cache m = hashlib.sha256() + + def muppet(m, s): + m.update(s.encode('utf-8')) + if spdl == None: - m.update("[spdl:None]") + muppet(m, "[spdl:None]") else: - m.update(spdl) + muppet(m, spdl) if args == None: - m.update("[args:None]") + muppet(m, "[args:None]") else: - m.update(args) + muppet(m, args) uid = m.hexdigest() @@ -392,14 +396,13 @@ class Scyther(object): self.guessFileNames(spdl=spdl) # Generate temporary files for the output. - # Requires Python 2.3 though. (fde,fne) = tempfile.mkstemp() # errors (fdo,fno) = tempfile.mkstemp() # output if spdl: (fdi,fni) = tempfile.mkstemp() # input # Write (input) file - fhi = os.fdopen(fdi,'w+b') + fhi = os.fdopen(fdi,'w+') fhi.write(spdl) fhi.close() @@ -495,7 +498,7 @@ class Scyther(object): # whoohee, xml self.validxml = True - xmlfile = StringIO.StringIO(output) + xmlfile = io.StringIO(output) reader = XMLReader.XMLReader() self.claims = reader.readXML(xmlfile) @@ -595,10 +598,10 @@ def FindProtocols(path="",filterProtocol=None): Note: Unix only! Will not work under windows. """ - import commands + import subprocess cmd = "find %s -iname '*.spdl'" % (path) - plist = commands.getoutput(cmd).splitlines() + plist = subprocess.getoutput(cmd).splitlines() nlist = [] for prot in plist: if filterProtocol != None: diff --git a/gui/Scyther/Term.py b/gui/Scyther/Term.py index 9369aa2..af601ad 100644 --- a/gui/Scyther/Term.py +++ b/gui/Scyther/Term.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,8 +20,8 @@ # # Term # -import Trace -from Misc import * +from . import Trace +from .Misc import * class InvalidTerm(TypeError): "Exception used to indicate that a given term is invalid" diff --git a/gui/Scyther/Trace.py b/gui/Scyther/Trace.py index 31e31cc..4759015 100644 --- a/gui/Scyther/Trace.py +++ b/gui/Scyther/Trace.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,7 +20,7 @@ # # Trace # -from Misc import * +from .Misc import * class InvalidAction(TypeError): "Exception used to indicate that a given action is invalid" @@ -79,7 +79,7 @@ class SemiTrace(object): def getPrecedingEvents(self,event,previous=[]): # If it is cached return cached version if event.preceding != None: - return filter(lambda x: x not in previous,event.preceding) + return [x for x in event.preceding if x not in previous] preceding = [] for prec in event.getBefore(): preceding.append(prec) @@ -90,7 +90,7 @@ class SemiTrace(object): preceding.extend(self.getPrecedingEvents(fol)) preceding = uniq(preceding) event.preceding = preceding - preceding = filter(lambda x: x not in previous,preceding) + preceding = [x for x in preceding if x not in previous] return preceding # Returns -1 if the first event has to be before the second one @@ -175,7 +175,7 @@ class ProtocolDescription(object): # Find event by label def findEvent(self,eventlabel,eventType=None): - for (role,descr) in self.roledescr.items(): + for (role,descr) in list(self.roledescr.items()): for event in descr: if event.label == eventlabel: if eventType == None or isinstance(event,eventType): @@ -206,7 +206,7 @@ class ProtocolDescription(object): # that are in the precedingEvents of a certain event def getPrecedingLabelSet(self,eventlabel): events = self.getPrecedingEvents(eventlabel) - events = filter(lambda x: isinstance(x,EventRead),events) + events = [x for x in events if isinstance(x,EventRead)] return [x.label for x in events] # Calculate the roles in preceding labelset that is all roles that @@ -219,7 +219,7 @@ class ProtocolDescription(object): def __str__(self): s = '' - for x in self.roledescr.values(): + for x in list(self.roledescr.values()): for e in x: s += str(e) + "\n" return s @@ -318,7 +318,7 @@ class EventClaim(Event): # agents def ignore(self): for untrusted in self.run.attack.untrusted: - if untrusted in self.run.roleAgents.values(): + if untrusted in list(self.run.roleAgents.values()): return True return False diff --git a/gui/Scyther/XMLReader.py b/gui/Scyther/XMLReader.py index 439b7bc..487b9b5 100644 --- a/gui/Scyther/XMLReader.py +++ b/gui/Scyther/XMLReader.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,24 +20,13 @@ # # XMLReader # -# Note: -# This requires python elementtree to work -# See: http://effbot.org/zone/element-index.htm -# -# On Fedora Core you can install this by installing the python-elementtree rpm -# Things will be a lot faster and consume less memory if you install the -# cElementTree module -# -# In python 2.5 cElementTree is in the core, so you don't need to install -# extra packages -# import sys # Check for cElementTree presence. Otherwise use ElementTree. useiter = True try: - # python 2.5 has cElementTree in the core + # cElementTree is in Python since version 2.5 import xml.etree.cElementTree as cElementTree except: # try the old way @@ -48,7 +37,7 @@ except: try: from elementtree import ElementTree except ImportError: - print """ + print(""" ERROR: Could not locate either the [elementtree] or the [cElementTree] package. @@ -56,7 +45,7 @@ Please install one of them in order to work with the Scyther python interface. The [cElementTree] packages can be found at http://effbot.org/zone/celementtree.htm Note that you can still use the Scyther binaries in the 'Bin' directory. - """ + """) sys.exit(1) ## Simply pick cElementTree @@ -65,11 +54,17 @@ Note that you can still use the Scyther binaries in the 'Bin' directory. #useiter = False #from elementtree import ElementTree -import Term -import Attack -import Trace -import Claim - +from . import Term +from . import Attack +from . import Trace +from . import Claim + +def getchildren(xml): + """ + (c)elementree xml objects used to have a getchildren() method, but this has been deprecated. This function provides similar functionality. The only catch is that the list/iter replacements also contain the object itself, so we need to filter this. + """ + return [ x for x in list(xml) if x != xml ] + class XMLReader(object): def __init__ (self): @@ -123,8 +118,8 @@ class XMLReader(object): # If this is a term variable read it directly if (xml.tag in ('tuple','const','apply','encrypt','var')): return self.readSubTerm(xml) - # Otherwise read from it's first child - children = xml.getchildren() + # Otherwise read from its first child + children = getchildren(xml) assert(len(children) == 1) return self.readSubTerm(children[0]) @@ -148,7 +143,7 @@ class XMLReader(object): # value return Term.TermVariable(name,None) else: - raise Term.InvalidTerm, "Invalid term type in XML: %s" % tag.tag + raise Term.InvalidTerm("Invalid term type in XML: %s" % tag.tag) def readEvent(self,xml): label = self.readTerm(xml.find('label')) @@ -188,7 +183,7 @@ class XMLReader(object): pass return Trace.EventClaim(index,label,followlist,role,etype,argument) else: - raise Trace.InvalidAction, "Invalid action in XML: %s" % (xml.get('type')) + raise Trace.InvalidAction("Invalid action in XML: %s" % (xml.get('type'))) def readRun(self,xml): assert(xml.tag == 'run') @@ -249,7 +244,7 @@ class XMLReader(object): def readClaim(self, xml): claim = Claim.Claim() - for event in xml.getchildren(): + for event in getchildren(xml): if event.tag == 'claimtype': claim.claimtype = self.readTerm(event) elif event.tag == 'label': @@ -276,7 +271,7 @@ class XMLReader(object): elif event.tag == 'timebound': claim.timebound = True else: - print >>sys.stderr,"Warning unknown tag in claim: %s" % claim.tag + print("Warning unknown tag in claim: %s" % claim.tag, file=sys.stderr) claim.analyze() return claim @@ -288,7 +283,7 @@ class XMLReader(object): # A state contains 4 direct child nodes: # broken, system, variables and semitrace # optionally a fifth: dot - for event in xml.getchildren(): + for event in getchildren(xml): if event.tag == 'broken': attack.broken.append((self.readTerm(event.find('claim')), self.readTerm(event.find('label')))) @@ -353,6 +348,6 @@ class XMLReader(object): # this list self.varlist = attack.variables else: - print >>sys.stderr,"Warning unknown tag in attack: %s" % event.tag + print("Warning unknown tag in attack: %s" % event.tag, file=sys.stderr) return attack diff --git a/gui/Scyther/__init__.py b/gui/Scyther/__init__.py index 1fa659c..b6c350c 100644 --- a/gui/Scyther/__init__.py +++ b/gui/Scyther/__init__.py @@ -1,6 +1,6 @@ """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -22,7 +22,7 @@ # # Set prefix for __all__ # -import Scyther +from . import Scyther # Provide scope __all__ = ["Scyther"] diff --git a/gui/Time/test.py b/gui/Time/test.py index 50ea49e..482a0ad 100755 --- a/gui/Time/test.py +++ b/gui/Time/test.py @@ -34,17 +34,17 @@ import sys try: from constraint import * except: - print "Could not import constraint solver module." - print "For more information, visit" - print " http://labix.org/python-constraint" + print("Could not import constraint solver module.") + print("For more information, visit") + print(" http://labix.org/python-constraint") sys.exit() #--------------------------------------------------------------------------- def test(): problem = Problem() - problem.addVariables(range(0, 16), range(1, 16+1)) - problem.addConstraint(AllDifferentConstraint(), range(0, 16)) + problem.addVariables(list(range(0, 16)), list(range(1, 16+1))) + problem.addConstraint(AllDifferentConstraint(), list(range(0, 16))) problem.addConstraint(ExactSumConstraint(34), [0,5,10,15]) problem.addConstraint(ExactSumConstraint(34), [3,6,9,12]) for row in range(4): @@ -54,7 +54,7 @@ def test(): problem.addConstraint(ExactSumConstraint(34), [col+4*i for i in range(4)]) solutions = problem.getSolutions() - print solutions + print(solutions) #--------------------------------------------------------------------------- diff --git a/gui/generate-attack-graphs.py b/gui/generate-attack-graphs.py index bad12b1..46c3946 100755 --- a/gui/generate-attack-graphs.py +++ b/gui/generate-attack-graphs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -109,7 +109,7 @@ def render_best_attack(fn,cid): render_dot(dotfile,"png") render_dot(dotfile,"pdf") - print "%s; %s" % (fn,cl) + print("%s; %s" % (fn,cl)) def main(): diff --git a/gui/json-scyther.py b/gui/json-scyther.py index b8e23bd..d96fc19 100755 --- a/gui/json-scyther.py +++ b/gui/json-scyther.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -48,9 +48,9 @@ def fileandline(fn,linenos): ln = 1 done = 0 sz = len(linenos) - for l in fp.xreadlines(): + for l in fp: if str(ln) in linenos: - print l + print(l) scyther_json(l) done = done + 1 if done >= sz: diff --git a/gui/make-bsub.py b/gui/make-bsub.py index 0897da1..22877cf 100755 --- a/gui/make-bsub.py +++ b/gui/make-bsub.py @@ -18,7 +18,7 @@ Arguments: def countlines(fn): count = 0 fh = open(fn,'r') - for l in fh.xreadlines(): + for l in fh: count = count + 1 fh.close() return count @@ -26,7 +26,7 @@ def countlines(fn): def marker(jobcount,todo): left = todo - jobcount dperc = int((100 * jobcount) / todo) - print "echo \"Sent %i out of %i jobs, hence %i left. %i%% done.\"" % (jobcount,todo,left,dperc) + print("echo \"Sent %i out of %i jobs, hence %i left. %i%% done.\"" % (jobcount,todo,left,dperc)) def main(fn,step,optlist): @@ -39,7 +39,7 @@ def main(fn,step,optlist): jobcount = 0 done = 0 - for l in fh.xreadlines(): + for l in fh: if buf == 0: s = "bsub %s ./json-scyther.py %s" % (" ".join(optlist),fn) s += " %i" % (ln) diff --git a/gui/progressbarDummy.py b/gui/progressbarDummy.py index 9ddd7e9..e230c72 100644 --- a/gui/progressbarDummy.py +++ b/gui/progressbarDummy.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -36,13 +36,13 @@ class ProgressBar(object): def start(self): if self.widgets: if len(self.widgets) > 0: - print self.widgets[0], + print(self.widgets[0], end=' ') def update(self,count): pass def finish(self): - print " Done." + print(" Done.") def SimpleProgress(): diff --git a/gui/scyther-gui.py b/gui/scyther-gui.py index 2c36c03..249b7eb 100755 --- a/gui/scyther-gui.py +++ b/gui/scyther-gui.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ # Try to get wxPython try: import wx -except ImportError,err: +except ImportError as err: from Scyther import Misc errmsg = "Problem with importing the required [wxPython] package." @@ -35,7 +35,7 @@ interface of Scyther. The [wxPython] packages can be found at http://www.wxpython.org/ Ubuntu users: the wxPython packages are called 'python-wxgtk' followed by the -version number.""" +version number. This version of Scyther requires at least wxPython version 4.0.""" elif ('32-bit mode' in str(err)) or ('no matching architecture' in str(err)): import os @@ -92,8 +92,26 @@ The exact error was: """ % (errmsg,err)) - #--------------------------------------------------------------------------- +global WXPYTHON4 +global WXPYTHONINFREQ +WXPYTHON4 = False +WXPYTHONINFREQ = wx + +try: + import wx.adv + + WXPYTHON4 = True + WXPYTHONINFREQ = wx.adv +except ImportError: + Misc.panic(""" +ERROR: + +Found wxPython libraries, but they seem to be too old (pre-4.0 wxPython). This means you cannot use the graphical user interface. To fix this, please ensure that you have at least wxPython 4.0 installed such that it is loaded by the wx import of python3. + +Note that you can currently still use the Scyther binaries in the 'Scyther' directory. +""") + """ import externals """ import sys import os @@ -139,7 +157,7 @@ def parseArgs(): #--------------------------------------------------------------------------- -class MySplashScreen(wx.SplashScreen): +class MySplashScreen(WXPYTHONINFREQ.SplashScreen): def __init__(self,basedir): path = os.path.join(basedir,"Images") image = os.path.join(path,"scyther-splash.png") @@ -193,7 +211,7 @@ class ScytherApp(wx.App): # License option may abort here if opts.license: - print Scyther.GetLicense() + print(Scyther.GetLicense()) sys.exit(0) # Load preferences file @@ -221,8 +239,9 @@ class ScytherApp(wx.App): return True - def OnExit(self): - """ Tear down """ + #def OnExit(self): + # """ Tear down """ + # # Currently unused, but ought to return the same integer as the base class if overridden. #--------------------------------------------------------------------------- diff --git a/gui/scyther.py b/gui/scyther.py index ef99d75..c82b740 100755 --- a/gui/scyther.py +++ b/gui/scyther.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -50,8 +50,8 @@ def simpleRun(args): if __name__ == '__main__': pars = sys.argv[1:] if len(pars) == 0: - print usage() + print(usage()) else: - print simpleRun(" ".join(pars)) + print(simpleRun(" ".join(pars))) diff --git a/gui/test-delta.py b/gui/test-delta.py index 863d13b..1cbe811 100755 --- a/gui/test-delta.py +++ b/gui/test-delta.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -48,7 +48,7 @@ TEST2 = "--max-runs=4" #--------------------------------------------------------------------------- """ Import externals """ -import commands +import subprocess #--------------------------------------------------------------------------- @@ -128,7 +128,7 @@ def findProtocols(): """ cmd = "find -iname '*.spdl'" - plist = commands.getoutput(cmd).splitlines() + plist = subprocess.getoutput(cmd).splitlines() nlist = [] for prot in plist: if filterProtocol(prot): @@ -143,35 +143,35 @@ def main(): global TEST0,TEST1,TEST2 list = findProtocols() - print "Performing delta analysis" - print - print "String 0 (used for both): '%s'" % TEST0 - print "String 1: '%s'" % TEST1 - print "String 2: '%s'" % TEST2 - print - print "After filtering, we are left with the following protocols:", list - print + print("Performing delta analysis") + print() + print("String 0 (used for both): '%s'" % TEST0) + print("String 1: '%s'" % TEST1) + print("String 2: '%s'" % TEST2) + print() + print("After filtering, we are left with the following protocols:", list) + print() maxcount = len(list) count = 1 delta = 0 for prot in list: perc = (100 * count) / maxcount - print "[%i%%] %s: " % (perc,prot), + print("[%i%%] %s: " % (perc,prot), end=' ') res = ScytherDiff(prot) if res != None: - print - print "-" * 72 - print prot - print "-" * 72 - print res + print() + print("-" * 72) + print(prot) + print("-" * 72) + print(res) delta = delta + 1 else: - print "No interesting delta found." + print("No interesting delta found.") count = count + 1 - print - print "Analysis complete." - print "%i out of %i protocols differed [%i%%]." % (delta,maxcount,(100 * delta)/maxcount) + print() + print("Analysis complete.") + print("%i out of %i protocols differed [%i%%]." % (delta,maxcount,(100 * delta)/maxcount)) if __name__ == '__main__': diff --git a/gui/test-mpa.py b/gui/test-mpa.py index bf5a344..d3d8693 100755 --- a/gui/test-mpa.py +++ b/gui/test-mpa.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -44,14 +44,14 @@ try: except ImportError: from progressbarDummy import * PROGRESSBAR = False - print """ + print(""" Missing the progressbar library. It can be downloaded from: http://code.google.com/p/python-progressbar/ -""" +""") FOUND = [] ALLMPA = [] @@ -227,7 +227,7 @@ def MyScyther(protocollist,filt=None,options=[],checkpickle=True): # arguments to call s.options = (" ".join(sorted(uniq(opts)))).strip() if OPTS.debug: - print s.options + print(s.options) for protocol in sorted(protocollist): s.addFile(protocol) @@ -356,7 +356,7 @@ def verifyMPAlist(mpalist,claimid,options=[]): global OPTS, ARGS if OPTS.debug: - print time.asctime(), mpalist, claimid, options + print(time.asctime(), mpalist, claimid, options) if not verifyMPAattack(mpalist,claimid,options): global FOUND @@ -367,7 +367,7 @@ def verifyMPAlist(mpalist,claimid,options=[]): # This is an MPA attack! if OPTS.debug: - print "I've found a multi-protocol attack on claim %s in the context %s." % (claimid,str(mpalist)) + print("I've found a multi-protocol attack on claim %s in the context %s." % (claimid,str(mpalist))) att = Attack(claim,mpalist) FOUND.append(att) @@ -442,9 +442,9 @@ def foundToDicts(attacklist = []): pn = str(att.protocol()) cl = att.claimid() - if pn not in res.keys(): + if pn not in list(res.keys()): res[pn] = {} - if cl not in res[pn].keys(): + if cl not in list(res[pn].keys()): res[pn][cl] = set() res[pn][cl].add(att) return res @@ -464,13 +464,13 @@ def findAllMPA(protocolset,options=[],mpaoptions=[]): # Find all correct claims in each protocol (protocolset,correct,cpcount) = getCorrectIsolatedClaims(protocolset,options) - print "Investigating %i correct claims in %i protocols." % (len(correct), cpcount) + print("Investigating %i correct claims in %i protocols." % (len(correct), cpcount)) mpaprots = [] res = [] if len(correct) == 0: - print "Nothing to do." + print("Nothing to do.") return res if OPTS.verbose: @@ -479,27 +479,27 @@ def findAllMPA(protocolset,options=[],mpaoptions=[]): """ pmapclaims = {} for (protocol,claimid) in correct: - if protocol not in pmapclaims.keys(): + if protocol not in list(pmapclaims.keys()): pmapclaims[protocol] = set() pmapclaims[protocol].add(claimid) - print "Protocols with correct claims:" - if len(pmapclaims.keys()) == 0: - print " None." + print("Protocols with correct claims:") + if len(list(pmapclaims.keys())) == 0: + print(" None.") else: - for pk in pmapclaims.keys(): - print " %s, %s" % (pk, pmapclaims[pk]) - print + for pk in list(pmapclaims.keys()): + print(" %s, %s" % (pk, pmapclaims[pk])) + print() left = set() for p in protocolset: - if p not in pmapclaims.keys(): + if p not in list(pmapclaims.keys()): left.add(p) - print "Protocols with no correct claims:" + print("Protocols with no correct claims:") if len(left) == 0: - print " None." + print(" None.") else: for p in left: - print " %s" % (p) - print + print(" %s" % (p)) + print() # output of all claims (only if latex required) @@ -528,7 +528,7 @@ def findAllMPA(protocolset,options=[],mpaoptions=[]): if OPTS.latex: pmapclaims = {} for (protocol,claimid) in correct: - if protocol not in pmapclaims.keys(): + if protocol not in list(pmapclaims.keys()): pmapclaims[protocol] = set() pmapclaims[protocol].add(claimid) @@ -640,19 +640,19 @@ def findAllMPA(protocolset,options=[],mpaoptions=[]): fp.write("\\end{tabular}\n") fp.close() - print "-" * 70 - print "Summary:" - print - print "We scanned %i protocols with options [%s]." % (len(protocolset),options) - print "We found %i correct claims." % (len(correct)) - print "We then scanned combinations of at most %i protocols with options [%s]." % (OPTS.maxprotocols,alloptions) + print("-" * 70) + print("Summary:") + print() + print("We scanned %i protocols with options [%s]." % (len(protocolset),options)) + print("We found %i correct claims." % (len(correct))) + print("We then scanned combinations of at most %i protocols with options [%s]." % (OPTS.maxprotocols,alloptions)) if OPTS.pickle: - print "However, just precomputing now, hence we are not drawing any conclusions." + print("However, just precomputing now, hence we are not drawing any conclusions.") else: - print "We found %i MPA attacks." % (len(FOUND)) - print "The attacks involve the claims of %i protocols." % (len(mpaprots)) - print "-" * 70 - print + print("We found %i MPA attacks." % (len(FOUND))) + print("The attacks involve the claims of %i protocols." % (len(mpaprots))) + print("-" * 70) + print() return res @@ -674,37 +674,37 @@ def showDiff(reslist): Show difference between (opts,mpaopts,attacklist) tuples in list """ if len(reslist) == 0: - print "Comparison list is empty" + print("Comparison list is empty") return (opt1,mpaopt1,al1) = reslist[0] - print "-" * 70 - print "Base case: attacks for \n [%s]:" % (opt1 + mpaopt1) - print - print len(al1) + print("-" * 70) + print("Base case: attacks for \n [%s]:" % (opt1 + mpaopt1)) + print() + print(len(al1)) for a in al1: - print "Base attack: %s" % (a) + print("Base attack: %s" % (a)) - print "-" * 70 - print + print("-" * 70) + print() for i in range(0,len(reslist)-1): (opt1,mpaopt1,al1) = reslist[i] (opt2,mpaopt2,al2) = reslist[i+1] - print "-" * 70 - print "Comparing the attacks for \n [%s] with\n [%s]:" % (opt1 + mpaopt1, opt2 + mpaopt2) - print - print len(al1), len(al2) + print("-" * 70) + print("Comparing the attacks for \n [%s] with\n [%s]:" % (opt1 + mpaopt1, opt2 + mpaopt2)) + print() + print(len(al1), len(al2)) for a in al2: if a not in al1: - print "Added attack: %s" % (a) + print("Added attack: %s" % (a)) for a in al1: if a not in al2: - print "Removed attack: %s" % (a) + print("Removed attack: %s" % (a)) - print "-" * 70 - print + print("-" * 70) + print() @@ -758,7 +758,7 @@ def exploreTree( i, choices , l, options = [], mpaoptions = []): res = [] for (txt,arg) in cl: - print "For choice %i, selecting options %s" % (i,txt) + print("For choice %i, selecting options %s" % (i,txt)) if mpaonly: o1 = [] o2 = arg @@ -811,23 +811,23 @@ def fullScan(l, options = [], mpaoptions = []): invprots.add(str(prot)) if not OPTS.pickle: - print "The bottom line: we found %i protocols with multi-protocol attacks from a set of %i protocols." % (len(attprots),len(allprots)) - print + print("The bottom line: we found %i protocols with multi-protocol attacks from a set of %i protocols." % (len(attprots),len(allprots))) + print() - print "Multi-protocol attacks were found on:" + print("Multi-protocol attacks were found on:") for prot in sorted(list(allprots & attprots)): - print " %s" % (prot) - print + print(" %s" % (prot)) + print() - print "No multi-protocol attacks were found on these protocols, but they caused MPA attacks:" + print("No multi-protocol attacks were found on these protocols, but they caused MPA attacks:") for prot in sorted(list((allprots - attprots) & invprots)): - print " %s" % (prot) - print + print(" %s" % (prot)) + print() - print "These protocols were not involved in any MPA attacks:" + print("These protocols were not involved in any MPA attacks:") for prot in sorted(list((allprots - attprots) - invprots)): - print " %s\t[%s]" % (prot,PROTNAMETOFILE[prot]) - print + print(" %s\t[%s]" % (prot,PROTNAMETOFILE[prot])) + print() @@ -864,7 +864,7 @@ def bigTest(): nl = l # Report list - print "Performing multi-protocol analysis for the following protocols:", nl + print("Performing multi-protocol analysis for the following protocols:", nl) fullScan(l) diff --git a/scripts/if2spdl/If.py b/scripts/if2spdl/If.py index f8ca181..f47d21b 100644 --- a/scripts/if2spdl/If.py +++ b/scripts/if2spdl/If.py @@ -318,8 +318,8 @@ class MessageRule(Rule): self.after = fact if self.before == None or self.after == None: - print "Warning: rule does not have both principal facts." - print self + print("Warning: rule does not have both principal facts.") + print(self) def __str__(self): return "Message " + Rule.__str__(self) diff --git a/scripts/if2spdl/Ifparser.py b/scripts/if2spdl/Ifparser.py index d659cb5..84fd370 100755 --- a/scripts/if2spdl/Ifparser.py +++ b/scripts/if2spdl/Ifparser.py @@ -275,14 +275,14 @@ def typeSwitch(line): elif res[3] == "typed": typeversion = True else: - print "Cannot determine whether typed or untyped." + print("Cannot determine whether typed or untyped.") raise ParseException str = "Detected " if not typedversion: str += "un" str += "typed version." - print str + print(str) # Parse a number of lines, including the first line with the type switch def linesParse(lines): @@ -303,9 +303,9 @@ def fileParse(filename): # Main code def main(): - print "Testing Ifparser module" - print - print fileParse("NSPK_LOWE.if") + print("Testing Ifparser module") + print() + print(fileParse("NSPK_LOWE.if")) if __name__ == '__main__': main() diff --git a/scripts/if2spdl/Spdl.py b/scripts/if2spdl/Spdl.py index 22e5f02..195b684 100644 --- a/scripts/if2spdl/Spdl.py +++ b/scripts/if2spdl/Spdl.py @@ -199,7 +199,7 @@ def sanitizeRole(protocol, role): msgto = knowbefore[i] if msgfrom != msgto: ### TEST - print "Substituting %s by %s" % (str(msgfrom), str(msgto)) + print("Substituting %s by %s" % (str(msgfrom), str(msgto))) # In all subsequent terms... TODO or # just the next one? for j in range(n+1, len(rules)): @@ -237,7 +237,7 @@ def sanitizeRole(protocol, role): replacelist.append( (t,msg) ) role.constants.append(msg) ### TEST - print "Substituting %s by %s" % (str(t), str(msg)) + print("Substituting %s by %s" % (str(t), str(msg))) # Apply replacelist if len(replacelist) > 0: for ev in role.events: @@ -280,7 +280,7 @@ def extractRoles(protocol): # hrule has been picked. Work back from here # first make up a name if len(hrule.getActors()) != 1: - print "Warning: weird actor list for hrule:", hrule.getActors() + print("Warning: weird actor list for hrule:", hrule.getActors()) name = "X" actor = None else: @@ -316,7 +316,7 @@ def extractRoles(protocol): # Loop detection if rule in role.rules: # This is a loop TODO - print "Warning: loop detected for role", role.name + print("Warning: loop detected for role", role.name) scan = False # Current setting: stop scan else: # No loop, prepend diff --git a/scripts/if2spdl/Trace.py b/scripts/if2spdl/Trace.py index d335b6d..d9f2f5c 100644 --- a/scripts/if2spdl/Trace.py +++ b/scripts/if2spdl/Trace.py @@ -60,7 +60,7 @@ class SemiTrace(object): def getPrecedingEvents(self,event,previous=[]): # If it is cached return cached version if event.preceding != None: - return filter(lambda x: x not in previous,event.preceding) + return [x for x in event.preceding if x not in previous] preceding = [] for prec in event.getBefore(): preceding.append(prec) @@ -71,7 +71,7 @@ class SemiTrace(object): preceding.extend(self.getPrecedingEvents(fol)) preceding = uniq(preceding) event.preceding = preceding - preceding = filter(lambda x: x not in previous,preceding) + preceding = [x for x in preceding if x not in previous] return preceding # Returns -1 if the first event has to be before the second one @@ -150,7 +150,7 @@ class ProtocolDescription(object): # Find event by label def findEvent(self,eventlabel,eventType=None): - for (role,descr) in self.roledescr.items(): + for (role,descr) in list(self.roledescr.items()): for event in descr: if event.label == eventlabel: if eventType == None or isinstance(event,eventType): @@ -181,7 +181,7 @@ class ProtocolDescription(object): # that are in the precedingEvents of a certain event def getPrecedingLabelSet(self,eventlabel): events = self.getPrecedingEvents(eventlabel) - events = filter(lambda x: isinstance(x,EventRead),events) + events = [x for x in events if isinstance(x,EventRead)] return [x.label for x in events] # Calculate the roles in preceding labelset that is all roles that @@ -194,7 +194,7 @@ class ProtocolDescription(object): def __str__(self): s = '' - for x in self.roledescr.values(): + for x in list(self.roledescr.values()): for e in x: s += str(e) + "\n" return s @@ -279,7 +279,7 @@ class EventClaim(Event): # agents def ignore(self): for untrusted in self.run.attack.untrusted: - if untrusted in self.run.roleAgents.values(): + if untrusted in list(self.run.roleAgents.values()): return True return False diff --git a/scripts/if2spdl/if2spdl.py b/scripts/if2spdl/if2spdl.py index 5caa6d7..9cf26eb 100755 --- a/scripts/if2spdl/if2spdl.py +++ b/scripts/if2spdl/if2spdl.py @@ -6,7 +6,7 @@ import Spdl def main(): protocol = Ifparser.fileParse("NSPK_LOWE.if") - print Spdl.generator(protocol) + print(Spdl.generator(protocol)) if __name__ == "__main__": main() diff --git a/scripts/if2spdl/misc.py b/scripts/if2spdl/misc.py index 755a815..3d5d9b7 100644 --- a/scripts/if2spdl/misc.py +++ b/scripts/if2spdl/misc.py @@ -5,15 +5,15 @@ def confirm(question): answer = '' while answer not in ('y','n'): - print question, - answer = raw_input().lower() + print(question, end=' ') + answer = input().lower() return answer == 'y' def exists(func,list): - return len(filter(func,list)) > 0 + return len(list(filter(func,list))) > 0 def forall(func,list): - return len(filter(func,list)) == len(list) + return len(list(filter(func,list))) == len(list) def uniq(li): result = [] diff --git a/scripts/if2spdl/parser.py b/scripts/if2spdl/parser.py index 8181e94..5f6551f 100755 --- a/scripts/if2spdl/parser.py +++ b/scripts/if2spdl/parser.py @@ -205,13 +205,13 @@ def ifParser(): def labeledruleAction(s,l,t): if t[0][3] == "Protocol_Rules": - print "-----------------" - print "- Detected rule -" - print "-----------------" + print("-----------------") + print("- Detected rule -") + print("-----------------") - print t[0] - print t[1] - print + print(t[0]) + print(t[1]) + print() labeledrule.setParseAction(labeledruleAction) @@ -233,17 +233,17 @@ def typeSwitch(line): elif res[3] == "typed": typeversion = True else: - print "Cannot determine whether typed or untyped." + print("Cannot determine whether typed or untyped.") raise ParseException except: - print "Unexpected error while determining (un)typedness of the line", line + print("Unexpected error while determining (un)typedness of the line", line) str = "Detected " if not typedversion: str += "un" str += "typed version." - print str + print(str) # Parse an entire file, including the first one def linesParse(lines): diff --git a/scripts/if2spdl/pyparsing.py b/scripts/if2spdl/pyparsing.py index 7fbea94..dbe852a 100644 --- a/scripts/if2spdl/pyparsing.py +++ b/scripts/if2spdl/pyparsing.py @@ -24,7 +24,7 @@ # Todo: # - add pprint() - pretty-print output of defined BNF # -from __future__ import generators + __doc__ = \ """ @@ -79,13 +79,13 @@ def _ustr(obj): # it won't break any existing code. return str(obj) - except UnicodeEncodeError, e: + except UnicodeEncodeError as e: # The Python docs (http://docs.python.org/ref/customization.html#l2h-182) # state that "The return value must be a string object". However, does a # unicode object (being a subclass of basestring) count as a "string # object"? # If so, then return a unicode object: - return unicode(obj) + return str(obj) # Else encode it... but how? There are many choices... :) # Replace unprintables with escape codes? #return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors') @@ -125,7 +125,7 @@ class ParseBaseException(Exception): elif( aname == "line" ): return line( self.loc, self.pstr ) else: - raise AttributeError, aname + raise AttributeError(aname) def __str__( self ): return "%s (at char %d), (line:%d, col:%d)" % ( self.msg, self.loc, self.lineno, self.column ) @@ -198,7 +198,7 @@ class ParseResults(object): name = _ustr(name) # will always return a str, but use _ustr for consistency self.__name = name if toklist: - if isinstance(toklist,basestring): + if isinstance(toklist,str): toklist = [ toklist ] if asList: if isinstance(toklist,ParseResults): @@ -235,25 +235,25 @@ class ParseResults(object): del self.__toklist[i] def __contains__( self, k ): - return self.__tokdict.has_key(k) + return k in self.__tokdict def __len__( self ): return len( self.__toklist ) def __iter__( self ): return iter( self.__toklist ) def keys( self ): """Returns all named result keys.""" - return self.__tokdict.keys() + return list(self.__tokdict.keys()) def items( self ): """Returns all named result keys and values as a list of tuples.""" - return [(k,v[-1][0]) for k,v in self.__tokdict.items()] + return [(k,v[-1][0]) for k,v in list(self.__tokdict.items())] def values( self ): """Returns all named result values.""" - return [ v[-1][0] for v in self.__tokdict.values() ] + return [ v[-1][0] for v in list(self.__tokdict.values()) ] def __getattr__( self, name ): if name not in self.__slots__: - if self.__tokdict.has_key( name ): + if name in self.__tokdict: if self.__modal: return self.__tokdict[name][-1][0] else: @@ -266,7 +266,7 @@ class ParseResults(object): if other.__tokdict: offset = len(self.__toklist) addoffset = ( lambda a: (a<0 and offset) or (a+offset) ) - otherdictitems = [(k,(v[0],addoffset(v[1])) ) for (k,vlist) in other.__tokdict.items() for v in vlist] + otherdictitems = [(k,(v[0],addoffset(v[1])) ) for (k,vlist) in list(other.__tokdict.items()) for v in vlist] for k,v in otherdictitems: self[k] = v if isinstance(v[0],ParseResults): @@ -313,7 +313,7 @@ class ParseResults(object): def asDict( self ): """Returns the named parse results as dictionary.""" - return dict( self.items() ) + return dict( list(self.items()) ) def copy( self ): """Returns a new copy of a ParseResults object.""" @@ -328,7 +328,7 @@ class ParseResults(object): """Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.""" nl = "\n" out = [] - namedItems = dict( [ (v[1],k) for (k,vlist) in self.__tokdict.items() for v in vlist ] ) + namedItems = dict( [ (v[1],k) for (k,vlist) in list(self.__tokdict.items()) for v in vlist ] ) nextLevelIndent = indent + " " # collapse out indents if formatting is not desired @@ -376,7 +376,7 @@ class ParseResults(object): def __lookup(self,sub): - for k,vlist in self.__tokdict.items(): + for k,vlist in list(self.__tokdict.items()): for v,loc in vlist: if sub is v: return k @@ -394,8 +394,8 @@ class ParseResults(object): return None elif (len(self) == 1 and len(self.__tokdict) == 1 and - self.__tokdict.values()[0][0][1] in (0,-1)): - return self.__tokdict.keys()[0] + list(self.__tokdict.values())[0][0][1] in (0,-1)): + return list(self.__tokdict.keys())[0] else: return None @@ -423,13 +423,13 @@ def line( loc, strg ): return strg[lastCR+1:] def _defaultStartDebugAction( instring, loc, expr ): - print "Match",expr,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) ) + print("Match",expr,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )) def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ): - print "Matched",expr,"->",toks.asList() + print("Matched",expr,"->",toks.asList()) def _defaultExceptionDebugAction( instring, loc, expr, exc ): - print "Exception raised:", exc + print("Exception raised:", exc) def nullDebugAction(*args): """'Do-nothing' debug action, to suppress debugging output during parsing.""" @@ -547,8 +547,8 @@ class ParserElement(object): try: loc,tokens = self.parseImpl( instring, loc, doActions ) except IndexError: - raise ParseException, ( instring, len(instring), self.errmsg, self ) - except ParseException, err: + raise ParseException( instring, len(instring), self.errmsg, self) + except ParseException as err: #~ print "Exception raised:", err if (self.debugActions[2] ): self.debugActions[2]( instring, tokensStart, self, err ) @@ -561,7 +561,7 @@ class ParserElement(object): try: loc,tokens = self.parseImpl( instring, loc, doActions ) except IndexError: - raise ParseException, ( instring, len(instring), self.errmsg, self ) + raise ParseException( instring, len(instring), self.errmsg, self) else: loc,tokens = self.parseImpl( instring, loc, doActions ) @@ -579,7 +579,7 @@ class ParserElement(object): self.resultsName, asList=self.saveAsList and isinstance(tokens,(ParseResults,list)), modal=self.modalResults ) - except ParseException, err: + except ParseException as err: #~ print "Exception raised in user parse action:", err if (self.debugActions[2] ): self.debugActions[2]( instring, tokensStart, self, err ) @@ -670,49 +670,49 @@ class ParserElement(object): def __add__(self, other ): """Implementation of + operator - returns And""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return And( [ self, other ] ) def __radd__(self, other ): """Implementation of += operator""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return other + self def __or__(self, other ): """Implementation of | operator - returns MatchFirst""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return MatchFirst( [ self, other ] ) def __ror__(self, other ): """Implementation of |= operator""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return other | self def __xor__(self, other ): """Implementation of ^ operator - returns Or""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return Or( [ self, other ] ) def __rxor__(self, other ): """Implementation of ^= operator""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return other ^ self def __and__(self, other ): """Implementation of & operator - returns Each""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return Each( [ self, other ] ) def __rand__(self, other ): """Implementation of right-& operator""" - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return other & self @@ -985,7 +985,7 @@ class Word(Token): if max > 0: self.maxLen = max else: - self.maxLen = sys.maxint + self.maxLen = sys.maxsize if exact > 0: self.maxLen = exact @@ -1064,7 +1064,7 @@ class CharsNotIn(Token): if max > 0: self.maxLen = max else: - self.maxLen = sys.maxint + self.maxLen = sys.maxsize if exact > 0: self.maxLen = exact @@ -1143,7 +1143,7 @@ class White(Token): if max > 0: self.maxLen = max else: - self.maxLen = sys.maxint + self.maxLen = sys.maxsize if exact > 0: self.maxLen = exact @@ -1197,7 +1197,7 @@ class GoToColumn(PositionToken): def parseImpl( self, instring, loc, doActions=True ): thiscol = col( loc, instring ) if thiscol > self.col: - raise ParseException, ( instring, loc, "Text not in expected column", self ) + raise ParseException( instring, loc, "Text not in expected column", self) newloc = loc + self.col - thiscol ret = instring[ loc: newloc ] return newloc, ret @@ -1287,7 +1287,7 @@ class ParseExpression(ParserElement): super(ParseExpression,self).__init__(savelist) if isinstance( exprs, list ): self.exprs = exprs - elif isinstance( exprs, basestring ): + elif isinstance( exprs, str ): self.exprs = [ Literal( exprs ) ] else: self.exprs = [ exprs ] @@ -1390,12 +1390,12 @@ class And(ParseExpression): loc, resultlist = self.exprs[0].parse( instring, loc, doActions ) for e in self.exprs[1:]: loc, exprtokens = e.parse( instring, loc, doActions ) - if exprtokens or exprtokens.keys(): + if exprtokens or list(exprtokens.keys()): resultlist += exprtokens return loc, resultlist def __iadd__(self, other ): - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return self.append( other ) #And( [ self, other ] ) @@ -1435,11 +1435,11 @@ class Or(ParseExpression): for e in self.exprs: try: loc2 = e.tryParse( instring, loc ) - except ParseException, err: + except ParseException as err: if err.loc > maxExcLoc: maxException = err maxExcLoc = err.loc - except IndexError, err: + except IndexError as err: if len(instring) > maxExcLoc: maxException = ParseException(instring,len(instring),e.errmsg,self) maxExcLoc = len(instring) @@ -1454,7 +1454,7 @@ class Or(ParseExpression): return maxMatchExp.parse( instring, loc, doActions ) def __ixor__(self, other ): - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return self.append( other ) #Or( [ self, other ] ) @@ -1492,11 +1492,11 @@ class MatchFirst(ParseExpression): try: ret = e.parse( instring, loc, doActions ) return ret - except ParseException, err: + except ParseException as err: if err.loc > maxExcLoc: maxException = err maxExcLoc = err.loc - except IndexError, err: + except IndexError as err: if len(instring) > maxExcLoc: maxException = ParseException(instring,len(instring),e.errmsg,self) maxExcLoc = len(instring) @@ -1506,7 +1506,7 @@ class MatchFirst(ParseExpression): raise maxException def __ior__(self, other ): - if isinstance( other, basestring ): + if isinstance( other, str ): other = Literal( other ) return self.append( other ) #MatchFirst( [ self, other ] ) @@ -1580,13 +1580,13 @@ class Each(ParseExpression): finalResults = ParseResults([]) for r in resultlist: dups = {} - for k in r.keys(): - if k in finalResults.keys(): + for k in list(r.keys()): + if k in list(finalResults.keys()): tmp = ParseResults(finalResults[k]) tmp += ParseResults(r[k]) dups[k] = tmp finalResults += ParseResults(r) - for k,v in dups.items(): + for k,v in list(dups.items()): finalResults[k] = v return loc, finalResults @@ -1609,7 +1609,7 @@ class ParseElementEnhance(ParserElement): """Abstract subclass of ParserElement, for combining and post-processing parsed tokens.""" def __init__( self, expr, savelist=False ): super(ParseElementEnhance,self).__init__(savelist) - if isinstance( expr, basestring ): + if isinstance( expr, str ): expr = Literal(expr) self.expr = expr self.strRepr = None @@ -1739,7 +1739,7 @@ class ZeroOrMore(ParseElementEnhance): if hasIgnoreExprs: loc = self.skipIgnorables( instring, loc ) loc, tmptokens = self.expr.parse( instring, loc, doActions ) - if tmptokens or tmptokens.keys(): + if tmptokens or list(tmptokens.keys()): tokens += tmptokens except (ParseException,IndexError): pass @@ -1772,7 +1772,7 @@ class OneOrMore(ParseElementEnhance): if hasIgnoreExprs: loc = self.skipIgnorables( instring, loc ) loc, tmptokens = self.expr.parse( instring, loc, doActions ) - if tmptokens or tmptokens.keys(): + if tmptokens or list(tmptokens.keys()): tokens += tmptokens except (ParseException,IndexError): pass @@ -1928,7 +1928,7 @@ class Upcase(TokenConverter): DeprecationWarning,stacklevel=2) def postParse( self, instring, loc, tokenlist ): - return map( string.upper, tokenlist ) + return list(map( string.upper, tokenlist )) class Combine(TokenConverter): @@ -1957,7 +1957,7 @@ class Combine(TokenConverter): del retToks[:] retToks += ParseResults([ "".join(tokenlist._asStringList(self.joinString)) ], modal=self.modalResults) - if self.resultsName and len(retToks.keys())>0: + if self.resultsName and len(list(retToks.keys()))>0: return [ retToks ] else: return retToks @@ -1991,7 +1991,7 @@ class Dict(TokenConverter): else: dictvalue = tok.copy() #ParseResults(i) del dictvalue[0] - if len(dictvalue)!= 1 or (isinstance(dictvalue,ParseResults) and dictvalue.keys()): + if len(dictvalue)!= 1 or (isinstance(dictvalue,ParseResults) and list(dictvalue.keys())): tokenlist[ikey] = (dictvalue,i) else: tokenlist[ikey] = (dictvalue[0],i) @@ -2074,13 +2074,13 @@ empty = Empty().setName("empty") _escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1]) _printables_less_backslash = "".join([ c for c in printables if c not in r"\]" ]) -_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:unichr(int(t[0],16))) -_escapedOctChar = Combine( Suppress(_bslash) + Word("0","01234567") ).setParseAction(lambda s,l,t:unichr(int(t[0],8))) +_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:chr(int(t[0],16))) +_escapedOctChar = Combine( Suppress(_bslash) + Word("0","01234567") ).setParseAction(lambda s,l,t:chr(int(t[0],8))) _singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(_printables_less_backslash,exact=1) _charRange = Group(_singleChar + Suppress("-") + _singleChar) _reBracketExpr = "[" + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]" -_expanded = lambda p: (isinstance(p,ParseResults) and ''.join([ unichr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p) +_expanded = lambda p: (isinstance(p,ParseResults) and ''.join([ chr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p) def srange(s): r"""Helper to easily define string ranges for use in Word construction. Borrows @@ -2120,11 +2120,11 @@ def removeQuotes(s,l,t): def upcaseTokens(s,l,t): """Helper parse action to convert tokens to upper case.""" - return map( str.upper, t ) + return list(map( str.upper, t )) def downcaseTokens(s,l,t): """Helper parse action to convert tokens to lower case.""" - return map( str.lower, t ) + return list(map( str.lower, t )) def _makeTags(tagStr, xml): """Internal helper to construct opening and closing tag expressions, given a tag name""" @@ -2185,20 +2185,20 @@ commaSeparatedList = delimitedList( Optional( quotedString | _commasepitem, defa if __name__ == "__main__": def test( teststring ): - print teststring,"->", + print(teststring,"->", end=' ') try: tokens = simpleSQL.parseString( teststring ) tokenlist = tokens.asList() - print tokenlist - print "tokens = ", tokens - print "tokens.columns =", tokens.columns - print "tokens.tables =", tokens.tables - print tokens.asXML("SQL",True) - except ParseException, err: - print err.line - print " "*(err.column-1) + "^" - print err - print + print(tokenlist) + print("tokens = ", tokens) + print("tokens.columns =", tokens.columns) + print("tokens.tables =", tokens.tables) + print(tokens.asXML("SQL",True)) + except ParseException as err: + print(err.line) + print(" "*(err.column-1) + "^") + print(err) + print() selectToken = CaselessLiteral( "select" ) fromToken = CaselessLiteral( "from" ) diff --git a/src/GetOS.cmake b/src/GetOS.cmake index d1b023f..981ed7a 100644 --- a/src/GetOS.cmake +++ b/src/GetOS.cmake @@ -8,7 +8,6 @@ # # Win32 # Unix -# MacPPC # MacIntel # First we find out the current operating system @@ -20,7 +19,7 @@ else (WIN32) # Not windows, is it a mac? if (APPLE) # TODO: A mac, but what architecture? - # For now we assume intel (Christoph Sprenger's machine) + # For now we assume intel set (Source_OS "MacIntel") else (APPLE) # Not a mac, not windows diff --git a/src/arachne.c b/src/arachne.c index ce0898e..bca476e 100644 --- a/src/arachne.c +++ b/src/arachne.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/arachne.h b/src/arachne.h index feafb11..4f9a6bd 100644 --- a/src/arachne.h +++ b/src/arachne.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/binding.c b/src/binding.c index cbe5294..bf8056d 100644 --- a/src/binding.c +++ b/src/binding.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/binding.h b/src/binding.h index 6cca4c8..3218fd9 100644 --- a/src/binding.h +++ b/src/binding.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/bool.h b/src/bool.h index 8a3ed5b..c2b8a56 100644 --- a/src/bool.h +++ b/src/bool.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/claim.c b/src/claim.c index 97604b2..f445bc4 100644 --- a/src/claim.c +++ b/src/claim.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/claim.h b/src/claim.h index f22f9fc..b73de32 100644 --- a/src/claim.h +++ b/src/claim.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/color.c b/src/color.c index 30a736c..554f44d 100644 --- a/src/color.c +++ b/src/color.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/color.h b/src/color.h index f48a02a..64e890c 100644 --- a/src/color.h +++ b/src/color.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/compiler.c b/src/compiler.c index a74bc4c..cae46a3 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/compiler.h b/src/compiler.h index 39a801d..fed2555 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/cost.c b/src/cost.c index 12cff12..67152e8 100644 --- a/src/cost.c +++ b/src/cost.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/cost.h b/src/cost.h index a4d11df..40f5e5b 100644 --- a/src/cost.h +++ b/src/cost.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/debug.c b/src/debug.c index b8f3320..763753b 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/debug.h b/src/debug.h index e526406..a873e74 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/depend.c b/src/depend.c index 5680963..a64f6de 100644 --- a/src/depend.c +++ b/src/depend.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/depend.h b/src/depend.h index a4fbaef..cf8e71b 100644 --- a/src/depend.h +++ b/src/depend.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/describe-version.py b/src/describe-version.py index ea5cc52..a903a55 100755 --- a/src/describe-version.py +++ b/src/describe-version.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -48,6 +48,6 @@ def getDescription(): if __name__ == '__main__': tag = getDescription() writeTag(tag) - print tag + print(tag) diff --git a/src/dotout.c b/src/dotout.c index 5259fea..d7c98bf 100644 --- a/src/dotout.c +++ b/src/dotout.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/dotout.h b/src/dotout.h index 3c19263..37deb57 100644 --- a/src/dotout.h +++ b/src/dotout.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/error.c b/src/error.c index 041feee..6b524da 100644 --- a/src/error.c +++ b/src/error.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/error.h b/src/error.h index 1bac926..70e9162 100644 --- a/src/error.h +++ b/src/error.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/find-unused-functions.py b/src/find-unused-functions.py index dac13b3..6c83a07 100755 --- a/src/find-unused-functions.py +++ b/src/find-unused-functions.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import commands +import subprocess import sys @@ -33,26 +33,26 @@ def main(): """ Force indent """ cmd = "indent *.c *.h" - output = commands.getoutput(cmd) + output = subprocess.getoutput(cmd) """ Force ctags """ cmd = "ctags *.c *.h" - output = commands.getoutput(cmd) + output = subprocess.getoutput(cmd) excludes = ['scanner.c','scanner.h','parser.c','parser.h'] fnames = findfunctions(excludes) - for fname in fnames.keys(): + for fname in list(fnames.keys()): """ The ..* construct makes sure that function definitions are skipped (based on the indent settings """ cmd = "grep '..*%s' *.c" % (fname) #print cmd - output = commands.getoutput(cmd).splitlines() + output = subprocess.getoutput(cmd).splitlines() if len(output) <= mincount: - print "%s\t%s" % (fnames[fname],fname) + print("%s\t%s" % (fnames[fname],fname)) if len(output) > 0: - print output + print(output) if __name__ == '__main__': main() diff --git a/src/heuristic.c b/src/heuristic.c index f00b5c7..7640c87 100644 --- a/src/heuristic.c +++ b/src/heuristic.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/heuristic.h b/src/heuristic.h index 9537764..a5982c9 100644 --- a/src/heuristic.h +++ b/src/heuristic.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/hidelevel.c b/src/hidelevel.c index f572701..17a6cc1 100644 --- a/src/hidelevel.c +++ b/src/hidelevel.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/hidelevel.h b/src/hidelevel.h index 2b3f6b9..1f0bbe4 100644 --- a/src/hidelevel.h +++ b/src/hidelevel.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/intruderknowledge.c b/src/intruderknowledge.c index 1b7278d..7c609f7 100644 --- a/src/intruderknowledge.c +++ b/src/intruderknowledge.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/intruderknowledge.h b/src/intruderknowledge.h index 27f5e21..ecc2a9a 100644 --- a/src/intruderknowledge.h +++ b/src/intruderknowledge.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/knowledge.c b/src/knowledge.c index 300d61f..6903491 100644 --- a/src/knowledge.c +++ b/src/knowledge.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/knowledge.h b/src/knowledge.h index c02fcbc..953cb94 100644 --- a/src/knowledge.h +++ b/src/knowledge.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/label.c b/src/label.c index 7adcc2e..f9a1b18 100644 --- a/src/label.c +++ b/src/label.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/label.h b/src/label.h index de408ed..021ee3f 100644 --- a/src/label.h +++ b/src/label.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/list.c b/src/list.c index 44754cf..d12fa6c 100644 --- a/src/list.c +++ b/src/list.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/list.h b/src/list.h index 1d94a46..fcd9a99 100644 --- a/src/list.h +++ b/src/list.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/main.c b/src/main.c index b97d73c..f7a8846 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/mgu.c b/src/mgu.c index 463b027..f11a59a 100644 --- a/src/mgu.c +++ b/src/mgu.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/mgu.h b/src/mgu.h index 4ca2f2c..7af41f2 100644 --- a/src/mgu.h +++ b/src/mgu.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/mymalloc.h b/src/mymalloc.h index 8f928f7..6cd55ff 100644 --- a/src/mymalloc.h +++ b/src/mymalloc.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/parser.y b/src/parser.y index 93e6ccb..3dd0716 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/pheading.h b/src/pheading.h index e20070c..6a4c641 100644 --- a/src/pheading.h +++ b/src/pheading.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/prune_bounds.c b/src/prune_bounds.c index 4af4444..45bcfaa 100644 --- a/src/prune_bounds.c +++ b/src/prune_bounds.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/prune_bounds.h b/src/prune_bounds.h index 630a958..7493126 100644 --- a/src/prune_bounds.h +++ b/src/prune_bounds.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/prune_theorems.c b/src/prune_theorems.c index 54852d8..c20e5cd 100644 --- a/src/prune_theorems.c +++ b/src/prune_theorems.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/prune_theorems.h b/src/prune_theorems.h index 9859940..5db14b2 100644 --- a/src/prune_theorems.h +++ b/src/prune_theorems.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/regression-tests/Makefile b/src/regression-tests/Makefile index c2bd104..425cad0 100644 --- a/src/regression-tests/Makefile +++ b/src/regression-tests/Makefile @@ -1,5 +1,5 @@ results: - ./regression-test.py + python3 ./regression-test.py .PHONY: results diff --git a/src/regression-tests/regression-test.py b/src/regression-tests/regression-test.py index 8c7c8fb..133281f 100755 --- a/src/regression-tests/regression-test.py +++ b/src/regression-tests/regression-test.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Scyther : An automatic verifier for security protocols. -Copyright (C) 2007-2013 Cas Cremers +Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -99,7 +99,7 @@ def runTests(fn,destdir="."): fp = open(fn,'r') tests = [] clen = 0 - for l in fp.xreadlines(): + for l in fp: if l.startswith("#") or l.startswith("%"): continue d = l.strip() @@ -110,8 +110,8 @@ def runTests(fn,destdir="."): clen = clen + 1 fp.close() - print "Running %i tests." % (clen) - print "Destination: %s" % (destdir) + print(("Running %i tests." % (clen))) + print(("Destination: %s" % (destdir))) cnt = 1 setting = "" for l in tests: @@ -121,10 +121,10 @@ def runTests(fn,destdir="."): if len(setting.strip()) == 0: setting = "" - print "Changing global setting to \"%s\"" % (setting) + print(("Changing global setting to \"%s\"" % (setting))) else: - print "%i/%i: Evaluating %s" % (cnt,clen,l+setting) + print(("%i/%i: Evaluating %s" % (cnt,clen,l+setting))) runTest(l+setting,destdir) cnt = cnt + 1 diff --git a/src/role.c b/src/role.c index 33e8347..99d0d10 100644 --- a/src/role.c +++ b/src/role.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/role.h b/src/role.h index 5669c51..03a4afa 100644 --- a/src/role.h +++ b/src/role.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/scanner.l b/src/scanner.l index 89c93fd..18c8edc 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -49,6 +49,7 @@ struct stringlist { typedef struct stringlist* Stringlist; static Stringlist allocatedStrings = NULL; +static int MAXNAMELENGTH = 4096; int mylineno = 0; @@ -226,6 +227,7 @@ Symbol mkstring(char *name) char* s; Stringlist sl; int len; + int buflen; if (( t = lookup(name)) != NULL) { @@ -233,9 +235,15 @@ Symbol mkstring(char *name) } // make new name len = strlen(name); - s = (char *)malloc(len+1); + if (len >= MAXNAMELENGTH) + { + // The buffer length MAXNAMELENGTH is somewhat arbitrary, and feel free to change the constant, but it prevents oddly large memory allocations. + error ("The maximum name length is %i, but found %i characters for [%s]", MAXNAMELENGTH, len, name ); + } + buflen = len; + s = (char *)malloc(buflen+1); sl = (Stringlist) malloc(sizeof(struct stringlist)); - strncpy(s,name,len); + strncpy(s,name,buflen); sl->next = allocatedStrings; allocatedStrings = sl; sl->string = s; diff --git a/src/scantags.py b/src/scantags.py index 0d27c29..be66fa8 100755 --- a/src/scantags.py +++ b/src/scantags.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import commands +import subprocess import sys class Tag(object): @@ -70,11 +70,11 @@ def tagoccurs(problems,tag,filter=[]): """ cmd = "grep \"\\<%s\\>\" *.[chly]" % tag - (reslist,count) = outToRes(commands.getoutput(cmd),[tag.filename]) + (reslist,count) = outToRes(subprocess.getoutput(cmd),[tag.filename]) if (len(reslist) == 0) and (count < 2): if tag.filename not in filter: # this might be a problem, store it - if tag.filename not in problems.keys(): + if tag.filename not in list(problems.keys()): problems[tag.filename] = {} problems[tag.filename][tag.id] = count @@ -82,36 +82,36 @@ def tagoccurs(problems,tag,filter=[]): def tagreport(problems): - for fn in problems.keys(): - print "file: %s" % fn - for t in problems[fn].keys(): - print "\t%i\t%s" % (problems[fn][t],t) + for fn in list(problems.keys()): + print("file: %s" % fn) + for t in list(problems[fn].keys()): + print("\t%i\t%s" % (problems[fn][t],t)) def main(): # Generate tags - print "Generating tags using 'ctags'" + print("Generating tags using 'ctags'") cmd = "ctags *.c *.h *.l *.y" - commands.getoutput(cmd) + subprocess.getoutput(cmd) # Analyze results - print "Analyzing results" + print("Analyzing results") filter = ["scanner.c","parser.c"] tags = gettags() problems = {} total = len(tags) count = 0 steps = 20 - print "_ " * (steps) + print("_ " * (steps)) for t in tags: problems = tagoccurs(problems,t,filter) count = count + 1 if count % (total / steps) == 0: - print "^", + print("^", end=' ') sys.stdout.flush() - print - print + print() + print() tagreport (problems) diff --git a/src/specialterm.c b/src/specialterm.c index fdf8e3d..b712f5d 100644 --- a/src/specialterm.c +++ b/src/specialterm.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/specialterm.h b/src/specialterm.h index 07055bf..a5cc111 100644 --- a/src/specialterm.h +++ b/src/specialterm.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/states.c b/src/states.c index 6e06999..02863e7 100644 --- a/src/states.c +++ b/src/states.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/states.h b/src/states.h index 974f7f3..5902f99 100644 --- a/src/states.h +++ b/src/states.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/switches.c b/src/switches.c index 0e04e8f..e01042b 100644 --- a/src/switches.c +++ b/src/switches.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -1476,7 +1476,7 @@ switcher (const int process, int index, int commandline) printf ("Compiled with debugging support.\n"); #endif } - printf ("Copyright (C) 2007-2013 Cas Cremers\n\n"); + printf ("Copyright (C) 2007-2020 Cas Cremers\n\n"); printf ("Scyther comes with ABSOLUTELY NO WARRANTY.\n"); printf ("This is free software, and you are welcome\n"); printf ("to redistribute it under certain conditions.\n"); @@ -1497,7 +1497,7 @@ switcher (const int process, int index, int commandline) { printf ("Scyther : An automatic verifier for security protocols.\n"); - printf ("Copyright (C) 2007-2013 Cas Cremers\n"); + printf ("Copyright (C) 2007-2020 Cas Cremers\n"); printf ("\n"); printf ("This program is free software; you can redistribute it and/or\n"); @@ -1856,7 +1856,7 @@ process_switches (int commandline) printf ("Try '%s --help' for more information, or visit:\n", progname); printf - (" http://www.cs.ox.ac.uk/people/cas.cremers/scyther/index.html\n"); + (" https://people.cispa.io/cas.cremers/scyther/\n"); exit (0); } else diff --git a/src/switches.h b/src/switches.h index 6d450eb..345d08c 100644 --- a/src/switches.h +++ b/src/switches.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/symbol.c b/src/symbol.c index d8a7b7b..946a0cc 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/symbol.h b/src/symbol.h index 4f18bb2..d27591d 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/system.c b/src/system.c index 0d7b68b..cd88f1f 100644 --- a/src/system.c +++ b/src/system.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/system.h b/src/system.h index 4a6f708..2e3099f 100644 --- a/src/system.h +++ b/src/system.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/tac.c b/src/tac.c index 3552b68..f55d79e 100644 --- a/src/tac.c +++ b/src/tac.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/tac.h b/src/tac.h index 2e0222a..fb9e2f7 100644 --- a/src/tac.h +++ b/src/tac.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/tempfile.c b/src/tempfile.c index 98808a6..1dea3be 100644 --- a/src/tempfile.c +++ b/src/tempfile.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/tempfile.h b/src/tempfile.h index c3daef6..5fbad6c 100644 --- a/src/tempfile.h +++ b/src/tempfile.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/term.c b/src/term.c index 6bdd1b6..dabd878 100644 --- a/src/term.c +++ b/src/term.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/term.h b/src/term.h index 4f17ca7..cc97bcb 100644 --- a/src/term.h +++ b/src/term.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/termlist.c b/src/termlist.c index 36db8ee..3d83710 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/termlist.h b/src/termlist.h index ab4335b..f7f6894 100644 --- a/src/termlist.h +++ b/src/termlist.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/termmap.c b/src/termmap.c index 9a83e08..0e01262 100644 --- a/src/termmap.c +++ b/src/termmap.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/termmap.h b/src/termmap.h index 89fce47..1ee5511 100644 --- a/src/termmap.h +++ b/src/termmap.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/timer.c b/src/timer.c index 1c9d94a..f8efc10 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/timer.h b/src/timer.h index 931266a..8452791 100644 --- a/src/timer.h +++ b/src/timer.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/type.c b/src/type.c index 17d2840..9043765 100644 --- a/src/type.c +++ b/src/type.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/type.h b/src/type.h index c145b4d..2aecc8a 100644 --- a/src/type.h +++ b/src/type.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/warshall.c b/src/warshall.c index 25c354a..eed9c95 100644 --- a/src/warshall.c +++ b/src/warshall.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/warshall.h b/src/warshall.h index bfc9a66..dd0ec5a 100644 --- a/src/warshall.h +++ b/src/warshall.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/xmlout.c b/src/xmlout.c index 6b01062..4a88c9f 100644 --- a/src/xmlout.c +++ b/src/xmlout.c @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/xmlout.h b/src/xmlout.h index 3f74700..1a08f74 100644 --- a/src/xmlout.h +++ b/src/xmlout.h @@ -1,6 +1,6 @@ /* * Scyther : An automatic verifier for security protocols. - * Copyright (C) 2007-2013 Cas Cremers + * Copyright (C) 2007-2020 Cas Cremers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/testing/ffgg_n/ffgg_n.py b/testing/ffgg_n/ffgg_n.py index d620de3..b6ca7f4 100755 --- a/testing/ffgg_n/ffgg_n.py +++ b/testing/ffgg_n/ffgg_n.py @@ -1,7 +1,7 @@ #!/usr/bin/python """ Scyther : An automatic verifier for security protocols. - Copyright (C) 2007-2013 Cas Cremers + Copyright (C) 2007-2020 Cas Cremers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -88,7 +88,7 @@ protocol ffgg%i(A,B) if __name__ == '__main__': if len(sys.argv) > 1: - print ffgg(int(sys.argv[1])) + print(ffgg(int(sys.argv[1]))) else: - print "Please provide a number n to generate ffgg_n" + print("Please provide a number n to generate ffgg_n")