2007-06-11 13:09:24 +01:00
|
|
|
"""
|
|
|
|
Scyther : An automatic verifier for security protocols.
|
|
|
|
Copyright (C) 2007 Cas Cremers
|
|
|
|
|
|
|
|
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
|
|
|
#
|
|
|
|
# Claim
|
|
|
|
#
|
|
|
|
|
|
|
|
import Term
|
|
|
|
|
2006-08-09 13:08:53 +01:00
|
|
|
def stateDescription(okay,n=1,caps=False):
|
|
|
|
if okay:
|
2007-05-18 13:06:29 +01:00
|
|
|
s = "trace pattern"
|
2006-08-09 13:08:53 +01:00
|
|
|
if n != 1:
|
2007-05-18 13:06:29 +01:00
|
|
|
s += "s"
|
2006-08-09 13:08:53 +01:00
|
|
|
else:
|
|
|
|
s = "attack"
|
|
|
|
if n != 1:
|
|
|
|
s += "s"
|
|
|
|
if caps:
|
|
|
|
s = s[0].upper() + s[1:]
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
class Claim(object):
|
|
|
|
def __init__(self):
|
2006-08-08 14:03:02 +01:00
|
|
|
self.id = None # a unique id string, consisting of 'protocol,label'
|
2006-08-02 13:59:57 +01:00
|
|
|
self.claimtype = None
|
|
|
|
self.label = None
|
2006-08-02 22:56:14 +01:00
|
|
|
self.shortlabel = None
|
2006-08-02 13:59:57 +01:00
|
|
|
self.protocol = None
|
|
|
|
self.role = None
|
|
|
|
self.parameter = None
|
|
|
|
self.failed = 0
|
|
|
|
self.count = 0
|
|
|
|
self.states = 0
|
|
|
|
self.complete = False
|
|
|
|
self.timebound = False
|
|
|
|
self.attacks = []
|
|
|
|
self.state = False # if true, it is a state, not an attack
|
2006-08-02 22:56:14 +01:00
|
|
|
self.okay = None # true if good, false if bad
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
# derived info
|
|
|
|
self.foundstates = False
|
|
|
|
self.foundproof = False
|
|
|
|
|
|
|
|
def analyze(self):
|
2006-08-02 22:56:14 +01:00
|
|
|
|
|
|
|
# determine short label
|
|
|
|
# We need the rightmost thingy here
|
|
|
|
label = self.label
|
|
|
|
while isinstance(label,Term.TermTuple):
|
|
|
|
label = label[1]
|
|
|
|
self.shortlabel = label
|
|
|
|
|
|
|
|
# determine id
|
2006-08-08 14:03:02 +01:00
|
|
|
self.id = "%s,%s" % (self.protocol,self.shortlabel)
|
2006-08-02 22:56:14 +01:00
|
|
|
|
|
|
|
# some additional properties
|
2006-08-02 13:59:57 +01:00
|
|
|
if str(self.claimtype) == 'Reachable':
|
|
|
|
self.state = True
|
|
|
|
if self.failed > 0:
|
|
|
|
self.foundstates = True
|
|
|
|
if self.complete:
|
|
|
|
self.foundproof = True
|
|
|
|
|
2006-08-02 22:56:14 +01:00
|
|
|
# status
|
|
|
|
# normally, with attacks, okay means none
|
|
|
|
self.okay = (self.failed == 0)
|
|
|
|
if self.state:
|
|
|
|
# but the logic reverses when it is states and not
|
|
|
|
# attacks...
|
|
|
|
self.okay = (not self.okay)
|
|
|
|
|
2006-08-09 13:11:55 +01:00
|
|
|
def stateName(self,count=1,caps=False):
|
|
|
|
return stateDescription(self.state,count,caps)
|
2006-08-02 13:59:57 +01:00
|
|
|
|
2006-08-10 16:48:12 +01:00
|
|
|
def getRank(self):
|
|
|
|
"""
|
|
|
|
Return claim rank
|
|
|
|
0 - really failed
|
|
|
|
1 - probably failed
|
|
|
|
2 - probably okay
|
|
|
|
3 - really okay
|
|
|
|
"""
|
2006-08-10 17:15:38 +01:00
|
|
|
n = len(self.attacks)
|
2006-08-10 16:48:12 +01:00
|
|
|
if not self.okay:
|
|
|
|
# not okay
|
2006-08-10 17:15:38 +01:00
|
|
|
if (self.state and self.complete) or ((not self.state) and (n > 0)):
|
2006-08-10 16:48:12 +01:00
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
# okay!
|
2006-08-10 17:15:38 +01:00
|
|
|
if not ((self.state and (n > 0)) or ((not self.state) and self.complete)):
|
2006-08-10 16:48:12 +01:00
|
|
|
return 2
|
|
|
|
else:
|
|
|
|
return 3
|
2006-08-10 16:49:07 +01:00
|
|
|
|
2006-08-11 10:41:12 +01:00
|
|
|
def getVerified(self):
|
|
|
|
"""
|
|
|
|
returns an element of [None,'Verified','Falsified']
|
|
|
|
"""
|
|
|
|
opts = ['Falsified',None,None,'Verified']
|
|
|
|
return opts[self.getRank()]
|
|
|
|
|
|
|
|
|
|
|
|
def getColour(self):
|
|
|
|
"""
|
|
|
|
Returns a colour that expresses the state
|
|
|
|
"""
|
2006-08-11 10:49:34 +01:00
|
|
|
colours = ['#FF0000',
|
2006-08-11 10:58:20 +01:00
|
|
|
'#800000',
|
|
|
|
'#005800',
|
|
|
|
'#00B000']
|
|
|
|
return colours[self.getRank()]
|
|
|
|
|
|
|
|
def getOkay(self):
|
|
|
|
"""
|
|
|
|
Returns a very brief statement about the claim.
|
|
|
|
|
|
|
|
Originally the two mid options had a question mark appended, but
|
|
|
|
from a users' point of view this might only be more confusing,
|
|
|
|
so I took them out again.
|
|
|
|
"""
|
|
|
|
colours = ['Fail',
|
|
|
|
'Fail',
|
|
|
|
'Ok',
|
|
|
|
'Ok']
|
2006-08-11 10:41:12 +01:00
|
|
|
return colours[self.getRank()]
|
|
|
|
|
2006-08-10 16:26:15 +01:00
|
|
|
def getComment(self):
|
|
|
|
"""
|
|
|
|
returns a sentence describing the results for this claim
|
|
|
|
"""
|
|
|
|
n = len(self.attacks)
|
|
|
|
atxt = self.stateName(n)
|
|
|
|
remark = ""
|
|
|
|
if not self.complete:
|
|
|
|
if n == 0:
|
|
|
|
# no attacks, no states within bounds
|
|
|
|
remark = "No %s within bounds" % (atxt)
|
|
|
|
else:
|
|
|
|
# some attacks/states within bounds
|
|
|
|
remark = "At least %i %s" % (n,atxt)
|
|
|
|
else:
|
|
|
|
if n == 0:
|
|
|
|
# no attacks, no states
|
|
|
|
remark = "No %s" % (atxt)
|
|
|
|
else:
|
|
|
|
# there exist n states/attacks (within any number of runs)
|
|
|
|
remark = "Exactly %i %s" % (n,atxt)
|
|
|
|
return remark + "."
|
|
|
|
|
2007-01-27 13:08:24 +00:00
|
|
|
def triplet(self):
|
|
|
|
"""
|
|
|
|
Return protocol,role,label triplet
|
|
|
|
"""
|
|
|
|
return (self.protocol, self.role, self.shortlabel)
|
2006-08-10 16:39:09 +01:00
|
|
|
|
2010-12-27 21:30:58 +00:00
|
|
|
def describe(self):
|
|
|
|
s = str(self.claimtype)
|
|
|
|
if self.parameter:
|
|
|
|
s+= "(%s)" % self.parameter
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
def roledescribe(self):
|
|
|
|
return "%s: %s" % (self.role,self.describe())
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
def __str__(self):
|
2006-08-10 16:26:15 +01:00
|
|
|
"""
|
|
|
|
Resulting string
|
|
|
|
"""
|
2011-01-18 16:05:07 +00:00
|
|
|
s = "claim id [%s], %s" % (self.id,self.describe())
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
# determine status
|
2006-08-10 17:15:38 +01:00
|
|
|
s+= "\t: %s" % self.getComment()
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|