2020-10-27 21:10:55 +00:00
|
|
|
#!/usr/bin/env python3
|
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-02 13:59:57 +01:00
|
|
|
|
2010-05-15 21:56:48 +01:00
|
|
|
#---------------------------------------------------------------------------
|
2012-04-24 11:34:42 +01:00
|
|
|
# Try to get wxPython
|
2006-11-13 10:38:47 +00:00
|
|
|
try:
|
2020-10-27 21:09:03 +00:00
|
|
|
import wx
|
|
|
|
except ImportError as err:
|
2012-04-26 12:41:07 +01:00
|
|
|
from Scyther import Misc
|
2006-11-14 11:03:19 +00:00
|
|
|
|
2012-04-26 13:27:00 +01:00
|
|
|
errmsg = "Problem with importing the required [wxPython] package."
|
|
|
|
|
|
|
|
if 'No module' in str(err):
|
|
|
|
errmsg = """Could not find the required [wxPython] package.
|
2006-11-13 10:38:47 +00:00
|
|
|
Please install this package in order to use the graphical user
|
|
|
|
interface of Scyther.
|
2006-11-14 11:03:19 +00:00
|
|
|
The [wxPython] packages can be found at http://www.wxpython.org/
|
|
|
|
|
2010-05-15 21:56:48 +01:00
|
|
|
Ubuntu users: the wxPython packages are called 'python-wxgtk' followed by the
|
2012-04-26 13:27:00 +01:00
|
|
|
version number."""
|
2012-11-23 08:25:19 +00:00
|
|
|
elif ('32-bit mode' in str(err)) or ('no matching architecture' in str(err)):
|
2012-10-24 15:06:17 +01:00
|
|
|
import os
|
2012-04-26 13:27:00 +01:00
|
|
|
|
2012-10-24 15:06:17 +01:00
|
|
|
key = "VERSIONER_PYTHON_PREFER_32_BIT"
|
|
|
|
data = "yes"
|
|
|
|
|
|
|
|
keyfound = False
|
|
|
|
try:
|
2015-05-02 14:20:42 +01:00
|
|
|
import sys
|
2012-10-24 15:06:17 +01:00
|
|
|
if sys.environment[key] == data:
|
|
|
|
keyfound = True
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if keyfound:
|
|
|
|
"""
|
|
|
|
We already tried to set the environment variable, but it is still not working.
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
#print "Key found. good job. no success."
|
|
|
|
|
|
|
|
errmsg = """Problem with importing the required [wxPython] package.
|
|
|
|
|
|
|
|
Possibly the problem is caused by wxPython only working in 32-bit mode currently.
|
|
|
|
You can try the following on the command line:
|
|
|
|
|
|
|
|
$ export VERSIONER_PYTHON_PREFER_32_BIT=yes
|
|
|
|
$ ./scyther-gui.py"""
|
|
|
|
|
|
|
|
else:
|
|
|
|
"""
|
|
|
|
Key not found. Try if that works.
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
from subprocess import call
|
|
|
|
|
|
|
|
#print "Key not found. Trying to set it now."
|
|
|
|
# TODO: check for MAC's if we need something like 'pythonw'
|
|
|
|
call(sys.argv, shell=True, env={key: data})
|
|
|
|
sys.exit(0)
|
2012-04-26 13:27:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
Misc.panic("""
|
|
|
|
ERROR:
|
|
|
|
|
|
|
|
%s
|
2010-05-15 21:56:48 +01:00
|
|
|
|
2007-05-21 12:25:25 +01:00
|
|
|
Note that you can still use the Scyther binaries in the 'Scyther' directory.
|
2012-04-26 13:27:00 +01:00
|
|
|
|
|
|
|
The exact error was:
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
%s
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
""" % (errmsg,err))
|
|
|
|
|
|
|
|
|
2010-05-15 21:56:48 +01:00
|
|
|
|
2012-04-24 11:34:42 +01:00
|
|
|
#---------------------------------------------------------------------------
|
2020-10-27 21:11:24 +00:00
|
|
|
global WXPYTHON4
|
|
|
|
global WXPYTHONINFREQ
|
|
|
|
WXPYTHON4 = False
|
|
|
|
WXPYTHONINFREQ = wx
|
|
|
|
|
|
|
|
try:
|
|
|
|
import wx.adv
|
|
|
|
|
|
|
|
WXPYTHON4 = True
|
|
|
|
WXPYTHONINFREQ = wx.adv
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2012-04-26 12:41:07 +01:00
|
|
|
""" import externals """
|
|
|
|
import sys
|
2006-08-08 18:04:26 +01:00
|
|
|
import os
|
2006-08-07 16:06:10 +01:00
|
|
|
from optparse import OptionParser, SUPPRESS_HELP
|
2010-05-15 22:27:11 +01:00
|
|
|
from subprocess import *
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
2012-04-26 12:41:07 +01:00
|
|
|
|
|
|
|
""" Import scyther-gui components """
|
|
|
|
from Scyther import Scyther,Misc
|
|
|
|
from Gui import About,Preference,Mainwindow
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-07 13:59:22 +01:00
|
|
|
def parseArgs():
|
2006-08-07 16:06:10 +01:00
|
|
|
usage = "usage: %s [options] [inputfile]" % sys.argv[0]
|
|
|
|
description = "scyther-gui is a graphical user interface for the scyther protocol verification tool."
|
|
|
|
parser = OptionParser(usage=usage,description=description)
|
2006-08-07 13:59:22 +01:00
|
|
|
|
|
|
|
# command
|
2006-08-07 16:06:10 +01:00
|
|
|
parser.add_option("-V","--verify",dest="command",default=None,action="store_const",const="verify",
|
|
|
|
help="Immediately verify the claims of the protocol (requires input file)")
|
|
|
|
parser.add_option("-s","--state-space",dest="command",default=None,action="store_const",const="statespace",
|
|
|
|
help="Immediately generate the complete characterization of the protocol (requires input file)")
|
|
|
|
parser.add_option("-a","--auto-claims",dest="command",default=None,action="store_const",const="autoverify",
|
|
|
|
help="Immediately verified protocol using default claims (requires input file)")
|
2007-11-15 20:49:35 +00:00
|
|
|
#parser.add_option("-c","--check",dest="command",default=None,action="store_const",const="check",
|
|
|
|
# help="Immediately check protocol (requires input file)")
|
2006-08-07 13:59:22 +01:00
|
|
|
|
2007-10-08 13:52:50 +01:00
|
|
|
# License
|
|
|
|
parser.add_option("-l","--license",dest="license",default=False,action="store_const",const=True,
|
|
|
|
help="Show license")
|
|
|
|
|
2006-08-09 12:54:37 +01:00
|
|
|
# no-splash
|
|
|
|
parser.add_option("-N","--no-splash",dest="splashscreen",default=True,action="store_const",const=False,
|
|
|
|
help="Do not show the splash screen")
|
|
|
|
|
2006-08-07 16:06:10 +01:00
|
|
|
# misc debug etc (not shown in the --help output)
|
|
|
|
parser.add_option("","--test",dest="test",default=False,action="store_true",
|
|
|
|
help=SUPPRESS_HELP)
|
2006-08-07 13:59:22 +01:00
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2020-10-27 21:11:24 +00:00
|
|
|
class MySplashScreen(WXPYTHONINFREQ.SplashScreen):
|
2006-08-11 11:43:28 +01:00
|
|
|
def __init__(self,basedir):
|
|
|
|
path = os.path.join(basedir,"Images")
|
|
|
|
image = os.path.join(path,"scyther-splash.png")
|
|
|
|
bmp = wx.Image(image).ConvertToBitmap()
|
2006-08-02 13:59:57 +01:00
|
|
|
wx.SplashScreen.__init__(self, bmp,
|
|
|
|
wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
|
|
|
|
5000, None, -1)
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnClose)
|
|
|
|
self.fc = wx.FutureCall(2000, self.ShowMain)
|
|
|
|
|
|
|
|
def OnClose(self, evt):
|
|
|
|
# Make sure the default handler runs too so this window gets
|
|
|
|
# destroyed
|
|
|
|
evt.Skip()
|
|
|
|
self.Hide()
|
|
|
|
|
|
|
|
# if the timer is still running then go ahead and show the
|
|
|
|
# main frame now
|
|
|
|
if self.fc.IsRunning():
|
|
|
|
self.fc.Stop()
|
|
|
|
self.ShowMain()
|
|
|
|
|
|
|
|
|
|
|
|
def ShowMain(self):
|
|
|
|
if self.fc.IsRunning():
|
|
|
|
self.Raise()
|
|
|
|
|
|
|
|
|
2006-08-07 13:59:22 +01:00
|
|
|
#---------------------------------------------------------------------------
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-11 16:23:32 +01:00
|
|
|
def isSplashNeeded(opts):
|
|
|
|
if not opts.command:
|
|
|
|
if opts.splashscreen and not (Preference.get('splashscreen') in ['false','off','disable','0']):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
class ScytherApp(wx.App):
|
|
|
|
def OnInit(self):
|
2013-05-01 13:16:12 +01:00
|
|
|
import os, inspect
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-02 23:44:10 +01:00
|
|
|
wx.GetApp().SetAppName("Scyther-gui")
|
|
|
|
|
2013-05-01 13:16:12 +01:00
|
|
|
# Determine base directory (taking symbolic links into account)
|
|
|
|
cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() )))
|
|
|
|
basedir = os.path.split(cmd_file)[0]
|
|
|
|
|
2006-08-07 13:59:22 +01:00
|
|
|
# Parse arguments
|
|
|
|
(opts,args) = parseArgs()
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2007-10-08 13:52:50 +01:00
|
|
|
# License option may abort here
|
|
|
|
if opts.license:
|
2020-10-27 21:10:55 +00:00
|
|
|
print(Scyther.GetLicense())
|
2007-10-08 13:52:50 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2006-08-07 13:59:22 +01:00
|
|
|
# Load preferences file
|
2006-08-02 13:59:57 +01:00
|
|
|
Preference.init()
|
|
|
|
|
2006-08-11 11:43:28 +01:00
|
|
|
#"""
|
|
|
|
#Create and show the splash screen. It will then create and show
|
|
|
|
#the main frame when it is time to do so.
|
|
|
|
#
|
|
|
|
#The splash screen is disabled for automatic commands, and also
|
|
|
|
#by a setting in the preferences file.
|
|
|
|
#"""
|
2006-08-11 16:23:32 +01:00
|
|
|
#if isSplashNeeded(opts):
|
|
|
|
# splash = MySplashScreen(basedir)
|
|
|
|
# splash.Show()
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-07 13:59:22 +01:00
|
|
|
self.mainWindow = Mainwindow.MainWindow(opts,args)
|
2006-08-02 13:59:57 +01:00
|
|
|
self.SetTopWindow(self.mainWindow)
|
|
|
|
self.mainWindow.Show()
|
|
|
|
|
2006-08-11 16:23:32 +01:00
|
|
|
if isSplashNeeded(opts):
|
2007-01-27 22:52:22 +00:00
|
|
|
dlg = About.AboutScyther(self.mainWindow,basedir)
|
2006-08-11 16:23:32 +01:00
|
|
|
dlg.ShowModal()
|
|
|
|
dlg.Destroy()
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
return True
|
|
|
|
|
2020-10-27 22:51:42 +00:00
|
|
|
#def OnExit(self):
|
|
|
|
# """ Tear down """
|
|
|
|
# # Currently unused, but ought to return the same integer as the base class if overridden.
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-08 18:07:15 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2010-05-15 22:27:11 +01:00
|
|
|
def CheckRequirements():
|
|
|
|
""" Check for any required programs """
|
|
|
|
|
|
|
|
""" We need 'dot', in the graphviz package """
|
2013-12-09 14:24:57 +00:00
|
|
|
from Scyther import FindDot
|
|
|
|
|
|
|
|
FindDot.findDot() # If Graphviz is not found, this function will call panic to complain.
|
2010-05-15 22:27:11 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2006-08-08 18:07:15 +01:00
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
if __name__ == '__main__':
|
2010-05-15 22:27:11 +01:00
|
|
|
CheckRequirements()
|
2006-08-02 13:59:57 +01:00
|
|
|
scythergui = ScytherApp()
|
|
|
|
scythergui.MainLoop()
|
|
|
|
|
2007-01-27 22:52:22 +00:00
|
|
|
# vim: set ts=4 sw=4 et list lcs=tab\:>-:
|