2005-12-03 16:12:58 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# If.py
|
|
|
|
#
|
|
|
|
# Objects and stuff for the intermediate format
|
|
|
|
#
|
|
|
|
firstone = True
|
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class Message(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class Constant(Message):
|
2005-12-03 17:39:35 +00:00
|
|
|
def __init__ (self,type,s,optprime=""):
|
2005-12-03 16:12:58 +00:00
|
|
|
self.type = type
|
2005-12-04 13:28:05 +00:00
|
|
|
self.prime = optprime
|
|
|
|
self.str = s
|
2005-12-03 16:12:58 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2005-12-04 13:28:05 +00:00
|
|
|
return self.str + self.prime
|
2005-12-03 16:12:58 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2005-12-03 17:39:35 +00:00
|
|
|
return str(self)
|
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class Variable(Constant):
|
2005-12-03 17:39:35 +00:00
|
|
|
pass
|
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class PublicKey(Constant):
|
2005-12-03 17:39:35 +00:00
|
|
|
pass
|
2005-12-03 16:12:58 +00:00
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class Composed(Message):
|
|
|
|
def __init__ (self,m1,m2):
|
|
|
|
self.left = m1
|
|
|
|
self.right = m2
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.left) + str(self.right)
|
2005-12-03 16:12:58 +00:00
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class PublicCrypt(Message):
|
|
|
|
def __init__ (self,key,message):
|
|
|
|
self.key = key
|
|
|
|
self.message = message
|
2005-12-03 16:12:58 +00:00
|
|
|
|
2005-12-03 17:39:35 +00:00
|
|
|
def __str__(self):
|
2005-12-04 13:28:05 +00:00
|
|
|
return "{" + str(self.message) + "}" + str(self.key) + " "
|
2005-12-03 17:39:35 +00:00
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class SymmetricCrypt(PublicCrypt):
|
|
|
|
pass
|
2005-12-03 16:12:58 +00:00
|
|
|
|
2005-12-04 13:28:05 +00:00
|
|
|
class XOR(Message):
|
|
|
|
def __init__ (self, m1,m2):
|
|
|
|
self.left = m1
|
|
|
|
self.right = m2
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.left) + " xor " + str(self.right)
|
2005-12-03 17:39:35 +00:00
|
|
|
|
2005-12-03 16:12:58 +00:00
|
|
|
class MsgList(list):
|
2005-12-04 13:28:05 +00:00
|
|
|
pass
|
2005-12-03 16:12:58 +00:00
|
|
|
|
|
|
|
class Fact(list):
|
|
|
|
def __repr__(self):
|
|
|
|
return "Fact<" + list.__repr__(self) + ">"
|
|
|
|
|
2005-12-03 16:48:10 +00:00
|
|
|
class GoalFact(Fact):
|
|
|
|
def __repr__(self):
|
|
|
|
return "Goal " + Fact.__repr__(self)
|
|
|
|
|
|
|
|
class PrincipalFact(Fact):
|
|
|
|
def __str__(self):
|
|
|
|
res = "Principal Fact:"
|
|
|
|
res += "\nStep " + str(self[0])
|
|
|
|
res += "\nReadNextFrom " + str(self[1])
|
|
|
|
res += "\nActor " + str(self[2])
|
|
|
|
res += "\nRunKnowledge " + str(self[3])
|
|
|
|
res += "\nKnowledge " + str(self[4])
|
|
|
|
#res += "\nBool " + str(self[5])
|
|
|
|
res += "\nSession " + str(self[6])
|
|
|
|
return res + "\n"
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
class TimeFact(Fact):
|
|
|
|
def __repr__(self):
|
|
|
|
return "Time " + Fact.__repr__(self)
|
|
|
|
|
|
|
|
class MessageFact(Fact):
|
|
|
|
def __str__(self):
|
|
|
|
res = "Message Fact:"
|
|
|
|
res += "\nStep " + str(self[0])
|
|
|
|
res += "\nRealSender " + str(self[1])
|
|
|
|
res += "\nClaimSender " + str(self[2])
|
|
|
|
res += "\nRecipient " + str(self[3])
|
|
|
|
res += "\nMessage " + str(self[4])
|
|
|
|
res += "\nSession " + str(self[5])
|
|
|
|
return res + "\n"
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
2005-12-03 16:12:58 +00:00
|
|
|
class State(list):
|
|
|
|
def __repr__(self):
|
|
|
|
return "State<" + list.__repr__(self) + ">"
|
|
|
|
|
|
|
|
class Label(object):
|
|
|
|
def __init__(self, name, category):
|
|
|
|
self.name = name
|
|
|
|
self.category = category
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "lb=" + self.name + ",type=" + self.category
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
class Rule(object):
|
|
|
|
def __init__(self,left=None,right=None):
|
|
|
|
self.left = left
|
|
|
|
self.right = right
|
|
|
|
self.label = None
|
|
|
|
|
|
|
|
def setLabel(self,label):
|
|
|
|
self.label = label
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
res = "Rule:"
|
|
|
|
if self.label != None:
|
|
|
|
res += " (" + str(self.label) +")"
|
|
|
|
res += "\n"
|
2005-12-03 16:48:10 +00:00
|
|
|
if self.left != None:
|
|
|
|
res += str(self.left) + "\n"
|
|
|
|
if self.right != None:
|
|
|
|
if self.left != None:
|
|
|
|
res += "=>\n"
|
|
|
|
res += str(self.right) + "\n"
|
|
|
|
res += ".\n"
|
2005-12-03 16:12:58 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
class InitialRule(Rule):
|
|
|
|
def __str__(self):
|
|
|
|
return "Initial " + Rule.__str__(self)
|
|
|
|
|
|
|
|
class MessageRule(Rule):
|
|
|
|
def __init__(self,l,r):
|
|
|
|
global firstone
|
|
|
|
|
|
|
|
Rule.__init__(self,l,r)
|
|
|
|
if firstone:
|
|
|
|
print str(self)
|
|
|
|
firstone = False
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Message " + Rule.__str__(self)
|
|
|
|
|
|
|
|
class GoalRule(Rule):
|
|
|
|
def __str__(self):
|
|
|
|
return "Goal " + Rule.__str__(self)
|
|
|
|
|
|
|
|
class CorrespondenceRule(GoalRule):
|
|
|
|
def __init__(self, l):
|
|
|
|
GoalRule.__init__(self,l,None)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Correspondence " + GoalRule.__str__(self)
|
|
|
|
|
|
|
|
class SecrecyRule(GoalRule):
|
|
|
|
def __init__(self, l):
|
|
|
|
GoalRule.__init__(self,l,None)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Secrecy " + GoalRule.__str__(self)
|
|
|
|
|
|
|
|
class STSecrecyRule(GoalRule):
|
|
|
|
def __init__(self, l):
|
|
|
|
GoalRule.__init__(self,l,None)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Short-term Secrecy " + GoalRule.__str__(self)
|
|
|
|
|
|
|
|
class AuthenticateRule(GoalRule):
|
|
|
|
def __init__(self, l):
|
|
|
|
GoalRule.__init__(self,l,None)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Authenticate " + GoalRule.__str__(self)
|
|
|
|
|
|
|
|
|