- Added some notes.

- Added extraction of asymmetric keys.
This commit is contained in:
ccremers 2005-12-05 14:58:35 +00:00
parent f3f381cb36
commit 40d5991ad0
4 changed files with 50 additions and 70 deletions

View File

@ -22,6 +22,9 @@ class Message(object):
return msgto return msgto
else: else:
return self return self
def aKeys(self):
return []
class Constant(Message): class Constant(Message):
def __init__ (self,type,s,optprime=""): def __init__ (self,type,s,optprime=""):
@ -74,7 +77,10 @@ class Composed(Message):
new.right = self.right.substitute(msgfrom, msgto) new.right = self.right.substitute(msgfrom, msgto)
return new return new
class PublicCrypt(Message): def aKeys(self):
return self.left.aKeys() + self.right.aKeys()
class SPCrypt(Message):
def __init__ (self,key,message): def __init__ (self,key,message):
self.key = key self.key = key
self.message = message self.message = message
@ -97,8 +103,14 @@ class PublicCrypt(Message):
new.message = self.message.substitute(msgfrom, msgto) new.message = self.message.substitute(msgfrom, msgto)
return new return new
def aKeys(self):
return self.message.aKeys() + self.key.aKeys()
class SymmetricCrypt(PublicCrypt): class PublicCrypt(SPCrypt):
def aKeys(self):
return self.message.aKeys() + [self.key]
class SymmetricCrypt(SPCrypt):
pass pass
class XOR(Composed): class XOR(Composed):

View File

@ -67,6 +67,7 @@ class Role(object):
self.knowledge = If.MsgList([]) self.knowledge = If.MsgList([])
self.constants = If.MsgList([]) self.constants = If.MsgList([])
self.variables = If.MsgList([]) self.variables = If.MsgList([])
self.asymmetric = If.MsgList([]) # Asymmetric keys
def prependRule(self,rule): def prependRule(self,rule):
self.rules = [rule] + self.rules self.rules = [rule] + self.rules
@ -95,6 +96,16 @@ class Role(object):
def appendEvent(self, event): def appendEvent(self, event):
self.event += [event] self.event += [event]
def substitute(self, msgfrom, msgto):
def subst(o):
o = o.substitute(msgfrom, msgto)
subst(self.events)
subst(self.knowledge)
subst(self.constants)
subst(self.variables)
subst(self.asymmetric)
def inTerms(self): def inTerms(self):
l = [] l = []
@ -113,16 +124,10 @@ class Role(object):
res += "\trole " + self.name + "\n" res += "\trole " + self.name + "\n"
res += "\t{\n" res += "\t{\n"
res += pfc + "Rule list based messages\n\n"
res += pfc + "Asymmetric keys: " + str(self.asymmetric) + "\n"
# TODO declare constants, variables
res += pfc + "Constants and variables\n"
res += pf + "const " + self.constants.spdl() + ";\n"
res += pf + "var " + self.variables.spdl() + ";\n"
res += "\n"
# Message sequence (based on rules) # Message sequence (based on rules)
res += pfc + "Rule list based messages\n"
res += pfc + "Knowledge before: " + str(self.rules[0].before.knowledge) + "\n" res += pfc + "Knowledge before: " + str(self.rules[0].before.knowledge) + "\n"
for rule in self.rules: for rule in self.rules:
# Read # Read
@ -136,6 +141,14 @@ class Role(object):
res += pfc + action("send",rule.sendFact) + ";\n" res += pfc + action("send",rule.sendFact) + ";\n"
res += "\n" res += "\n"
# TODO declare constants, variables
res += pfc + "Constants and variables\n"
if len(self.constants) > 0:
res += pf + "const " + self.constants.spdl() + ";\n"
if len(self.variables) > 0:
res += pf + "var " + self.variables.spdl() + ";\n"
res += "\n"
# Message sequence (based on event list) # Message sequence (based on event list)
res += pfc + "Event list based messages\n" res += pfc + "Event list based messages\n"
for event in self.events: for event in self.events:
@ -230,12 +243,20 @@ def sanitizeRole(protocol, role):
noncecounter = noncecounter + 1 noncecounter = noncecounter + 1
replacelist.append( (t,msg) ) replacelist.append( (t,msg) )
role.constants.append(msg) role.constants.append(msg)
### TEST
print "Substituting %s by %s" % (str(t), str(msg))
# Apply replacelist # Apply replacelist
if len(replacelist) > 0: if len(replacelist) > 0:
for ev in role.events: for ev in role.events:
for (f,t) in replacelist: for (f,t) in replacelist:
ev.substitute(f,t) ev.substitute(f,t)
# Extract keys
akeys = []
for ev in role.events:
akeys += ev.message.aKeys()
role.asymmetric = uniq(akeys)

View File

@ -1,60 +0,0 @@
#!/usr/bin/python
import pprint
def unfold(arg):
for x in arg:
pprint.pprint(x)
def intruderKnowledge(x):
print "Intruder knowledge"
print x[0], str(x[1])
def scenario(x):
print "Scenario",x,"ignoring for now"
def initialState(arg):
arg = arg[0] # One level deeper (has no implication rule)
print "Initial State"
print len(arg)
for x in arg:
if x[0] == "h":
print "Some stupid semi time thing"
if x[0] == "i":
intruderKnowledge(x),"ignoring for now"
elif x[0] == "w":
scenario(x)
# Ignore for now
def protocolRules(arg):
return
# Goals: ignored for now
def goal(arg):
return
def labeledRule(lr):
type = None
label = None
if lr[0] == "lb":
label = lr[1]
if lr[2] == "type":
type = lr[3]
arg = lr[4]
if type == "Init":
initialState(arg)
elif type == "Protocol_Rules":
protocolRules(arg)
elif type == "Goal":
goal(arg)
def generateSpdl(ll):
if ll[0] == "option":
print "Option [" + ll[1] + "]"
for i in ll[2]:
labeledRule(i)
return
print "Not understood element: "
print ll[0]

View File

@ -9,4 +9,11 @@ Regarding the AVISPA IF report:
STSecrecy STSecrecy
matching_request matching_request
Regarding translation:
- Read/Send tuples with knowledge updates are horrible.
Assuming a 1-1 mapping from after knowledge of step n with before
knowledge of step n+1.
- Public key status in role defs is that of a variable, possible fixes
by substitutions from the scenario. That is plain ugly: scenario is
needed to explain meaning of role definition.