2006-08-11 09:34:22 +01:00
|
|
|
#!/usr/bin/python
|
2007-06-11 13:09:24 +01:00
|
|
|
"""
|
|
|
|
Scyther : An automatic verifier for security protocols.
|
2013-10-05 23:56:12 +01:00
|
|
|
Copyright (C) 2007-2013 Cas Cremers
|
2007-06-11 13:09:24 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
"""
|
|
|
|
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
""" Import externals """
|
|
|
|
import wx
|
2006-08-11 09:54:43 +01:00
|
|
|
import sys
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
""" Import scyther-gui components """
|
|
|
|
import Preference
|
|
|
|
import Scyther.Claim as Claim
|
|
|
|
|
2006-08-11 09:54:43 +01:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyGrid(wx.GridBagSizer):
|
|
|
|
|
2006-08-11 16:23:32 +01:00
|
|
|
def __init__(self,parent):
|
|
|
|
wx.GridBagSizer.__init__(self,hgap=5, vgap=5)
|
2006-08-11 09:54:43 +01:00
|
|
|
self.ypos = 0
|
2006-08-11 16:23:32 +01:00
|
|
|
self.parent = parent
|
2006-08-11 09:54:43 +01:00
|
|
|
|
|
|
|
def stepAdd(self,ctrl,txt):
|
2006-12-15 13:45:09 +00:00
|
|
|
self.Add(txt,(self.ypos,0),flag=wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
|
2006-08-11 16:23:32 +01:00
|
|
|
self.Add(ctrl,(self.ypos,1),flag=wx.ALIGN_LEFT)
|
2006-08-11 09:54:43 +01:00
|
|
|
self.ypos += 1
|
|
|
|
|
2006-08-11 16:23:32 +01:00
|
|
|
def lineAdd(self):
|
2006-12-15 13:45:09 +00:00
|
|
|
return
|
2006-08-11 16:23:32 +01:00
|
|
|
line = wx.StaticLine(self.parent,-1)
|
2006-08-11 16:36:23 +01:00
|
|
|
# Currently it is not expanded, and thus invisible.
|
|
|
|
self.Add(line,pos=(self.ypos,0),span=(1,2),flag=wx.TOP|wx.BOTTOM)
|
2006-08-11 16:23:32 +01:00
|
|
|
self.ypos += 1
|
|
|
|
|
|
|
|
def titleAdd(self,title,firstLine=True):
|
|
|
|
if firstLine:
|
|
|
|
self.lineAdd()
|
|
|
|
self.ypos += 1
|
|
|
|
txt = wx.StaticText(self.parent,-1,title)
|
2006-08-11 16:36:23 +01:00
|
|
|
font = wx.Font(12,wx.DEFAULT,wx.NORMAL,wx.BOLD)
|
2006-08-11 16:23:32 +01:00
|
|
|
txt.SetFont(font)
|
2006-12-15 13:45:09 +00:00
|
|
|
self.Add(txt,pos=(self.ypos,0),span=(1,2),flag=wx.ALIGN_LEFT)
|
2006-08-11 16:23:32 +01:00
|
|
|
self.ypos += 1
|
|
|
|
self.lineAdd()
|
2006-08-11 09:54:43 +01:00
|
|
|
|
2006-08-11 09:34:22 +01:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SettingsWindow(wx.Panel):
|
|
|
|
|
|
|
|
def __init__(self,parent,daddy):
|
|
|
|
wx.Panel.__init__(self,parent,-1)
|
|
|
|
self.win = daddy
|
2006-12-15 13:45:09 +00:00
|
|
|
|
|
|
|
# layout the stuff
|
2006-08-11 16:23:32 +01:00
|
|
|
grid = MyGrid(self)
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
grid.titleAdd("Verification parameters",False)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
# Bound on the number of runs
|
|
|
|
self.maxruns = int(Preference.get('maxruns','5'))
|
2006-12-15 13:45:09 +00:00
|
|
|
txt = wx.StaticText(self,-1,"Maximum number of runs\n(0 disables bound)")
|
2006-08-11 09:34:22 +01:00
|
|
|
ctrl = wx.SpinCtrl(self, -1, "",style=wx.RIGHT)
|
|
|
|
ctrl.SetRange(0,100)
|
|
|
|
ctrl.SetValue(self.maxruns)
|
|
|
|
self.Bind(wx.EVT_SPINCTRL,self.EvtRuns,ctrl)
|
2006-08-11 09:54:43 +01:00
|
|
|
grid.stepAdd(ctrl,txt)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
# Matchin options
|
|
|
|
self.match = int(Preference.get('match','0'))
|
|
|
|
claimoptions = ['typed matching','find basic type flaws','find all type flaws']
|
|
|
|
r2 = wx.StaticText(self,-1,"Matching type")
|
|
|
|
l2 = self.ch = wx.Choice(self,-1,choices=claimoptions)
|
|
|
|
l2.SetSelection(self.match)
|
|
|
|
self.Bind(wx.EVT_CHOICE,self.EvtMatch,l2)
|
2006-08-11 09:54:43 +01:00
|
|
|
grid.stepAdd(l2,r2)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
### MISC expert stuff
|
2006-08-11 16:23:32 +01:00
|
|
|
grid.titleAdd("Advanced parameters")
|
2006-08-11 09:34:22 +01:00
|
|
|
|
2008-07-29 23:03:46 +01:00
|
|
|
# Continue after finding the first attack
|
2008-08-25 15:59:15 +01:00
|
|
|
self.prune = int(Preference.get('prune','2'))
|
|
|
|
claimoptions = ['Find all attacks','Find first attack','Find best attack']
|
|
|
|
r8 = wx.StaticText(self,-1,"Search pruning")
|
2008-07-29 23:03:46 +01:00
|
|
|
l8 = self.ch = wx.Choice(self,-1,choices=claimoptions)
|
2008-08-25 15:59:15 +01:00
|
|
|
l8.SetSelection(self.prune)
|
|
|
|
self.Bind(wx.EVT_CHOICE,self.EvtPrune,l8)
|
2008-07-29 23:03:46 +01:00
|
|
|
grid.stepAdd(l8,r8)
|
|
|
|
|
2006-11-23 11:28:51 +00:00
|
|
|
# Bound on the number of patterns
|
|
|
|
self.maxattacks = int(Preference.get('maxattacks','10'))
|
2006-12-15 13:45:09 +00:00
|
|
|
r9 = wx.StaticText(self,-1,"Maximum number of patterns\nper claim")
|
2006-08-11 09:34:22 +01:00
|
|
|
l9 = wx.SpinCtrl(self, -1, "",style=wx.RIGHT)
|
|
|
|
l9.SetRange(0,100)
|
|
|
|
l9.SetValue(self.maxattacks)
|
|
|
|
self.Bind(wx.EVT_SPINCTRL,self.EvtMaxAttacks,l9)
|
2006-08-11 09:54:43 +01:00
|
|
|
grid.stepAdd(l9,r9)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
self.misc = Preference.get('scytheroptions','')
|
2006-12-15 13:45:09 +00:00
|
|
|
r10 = wx.StaticText(self,-1,"Additional backend parameters")
|
2006-08-11 09:54:43 +01:00
|
|
|
l10 = wx.TextCtrl(self,-1,self.misc,size=(200,-1))
|
2006-08-11 09:34:22 +01:00
|
|
|
self.Bind(wx.EVT_TEXT,self.EvtMisc,l10)
|
2006-08-11 09:54:43 +01:00
|
|
|
grid.stepAdd(l10,r10)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
2006-08-11 09:54:43 +01:00
|
|
|
### Graph output stuff
|
2006-08-11 16:23:32 +01:00
|
|
|
grid.titleAdd("Graph output parameters")
|
2006-08-11 09:54:43 +01:00
|
|
|
|
|
|
|
# Bound on the number of classes/attacks
|
|
|
|
if sys.platform.startswith("lin"):
|
|
|
|
defsize = 14
|
|
|
|
else:
|
|
|
|
defsize = 11
|
|
|
|
self.fontsize = int(Preference.get('fontsize',defsize))
|
2006-12-15 13:45:09 +00:00
|
|
|
txt = wx.StaticText(self,-1,"Attack graph font size\n(in points)")
|
2006-08-11 09:54:43 +01:00
|
|
|
ctrl = wx.SpinCtrl(self, -1, "",style=wx.RIGHT)
|
|
|
|
ctrl.SetRange(6,32)
|
|
|
|
ctrl.SetValue(self.fontsize)
|
|
|
|
self.Bind(wx.EVT_SPINCTRL,self.EvtFontsize,ctrl)
|
|
|
|
grid.stepAdd(ctrl,txt)
|
|
|
|
|
|
|
|
### Combine
|
2006-08-11 16:23:32 +01:00
|
|
|
grid.lineAdd()
|
2006-08-11 09:34:22 +01:00
|
|
|
self.SetSizer(grid)
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
|
|
|
|
def EvtMatch(self,evt):
|
|
|
|
self.match = evt.GetInt()
|
|
|
|
|
|
|
|
def EvtRuns(self,evt):
|
|
|
|
self.maxruns = evt.GetInt()
|
|
|
|
|
2006-08-11 09:54:43 +01:00
|
|
|
def EvtFontsize(self,evt):
|
|
|
|
self.fontsize = evt.GetInt()
|
|
|
|
|
2008-08-25 15:59:15 +01:00
|
|
|
def EvtPrune(self,evt):
|
|
|
|
self.prune = evt.GetInt()
|
|
|
|
Preference.set('prune',self.prune)
|
2008-07-29 23:03:46 +01:00
|
|
|
|
2006-08-11 09:34:22 +01:00
|
|
|
def EvtMaxAttacks(self,evt):
|
|
|
|
self.maxattacks = evt.GetInt()
|
|
|
|
|
|
|
|
def EvtMisc(self,evt):
|
|
|
|
self.misc = evt.GetString()
|
|
|
|
|
|
|
|
def ScytherArguments(self,mode):
|
|
|
|
""" Note: constructed strings should have a space at the end to
|
|
|
|
correctly separate the options.
|
|
|
|
"""
|
|
|
|
|
|
|
|
tstr = ""
|
|
|
|
|
|
|
|
# Number of runs
|
|
|
|
tstr += "--max-runs=%s " % (str(self.maxruns))
|
|
|
|
# Matching type
|
|
|
|
tstr += "--match=%s " % (str(self.match))
|
2008-08-25 15:59:15 +01:00
|
|
|
# Prune (has to go BEFORE max attacks)
|
|
|
|
tstr += "--prune=%s" % (str(self.prune))
|
2006-08-11 09:34:22 +01:00
|
|
|
# Max attacks/classes
|
|
|
|
if self.maxattacks != 0:
|
|
|
|
tstr += "--max-attacks=%s " % (str(self.maxattacks))
|
|
|
|
|
|
|
|
# Verification type
|
|
|
|
if mode == "check":
|
|
|
|
tstr += "--check "
|
|
|
|
elif mode == "autoverify":
|
|
|
|
tstr += "--auto-claims "
|
2007-05-18 13:06:29 +01:00
|
|
|
elif mode == "characterize":
|
2006-08-11 09:34:22 +01:00
|
|
|
tstr += "--state-space "
|
|
|
|
|
|
|
|
# Anything else?
|
|
|
|
if self.misc != "":
|
|
|
|
tstr += " " + self.misc + " "
|
|
|
|
|
2007-05-18 13:06:29 +01:00
|
|
|
return str(tstr) # turn it into a str (might have been unicode weirdness)
|
2006-08-11 09:34:22 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|