Skip to content

Commit 225c0e7

Browse files
author
Kevin Turner
committed
[project @ server.server.Signatory.sign: preserve sign-all-edness in fallback case]
1 parent 231d5aa commit 225c0e7

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

‎openid/server/server.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,12 +954,23 @@ def sign(self, response):
954954
assoc_handle = response.request.assoc_handle
955955
if assoc_handle:
956956
# normal mode
957-
assoc = self.getAssociation(assoc_handle, dumb=False)
958-
if not assoc:
957+
# disabling expiration check because even if the association
958+
# is expired, we still need to know some properties of the
959+
# association so that we may preserve those properties when
960+
# creating the fallback association. (i.e. SIGNALL)
961+
assoc = self.getAssociation(assoc_handle, dumb=False,
962+
checkExpiration=False)
963+
964+
if not assoc or assoc.expiresIn <= 0:
959965
# fall back to dumb mode
960966
signed_response.fields.setArg(
961967
OPENID_NS, 'invalidate_handle', assoc_handle)
962-
assoc = self.createAssociation(dumb=True)
968+
assoc_type = assoc and assoc.assoc_type or 'HMAC-SHA1'
969+
if assoc and assoc.expiresIn <= 0:
970+
# now do the clean-up that the disabled checkExpiration
971+
# code didn't get to do.
972+
self.invalidate(assoc_handle, dumb=False)
973+
assoc = self.createAssociation(dumb=True, assoc_type=assoc_type)
963974
else:
964975
# dumb mode.
965976
assoc = self.createAssociation(dumb=True)

‎openid/test/test_server.py‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,13 +1139,60 @@ def test_signExpired(self):
11391139
self.failUnless(sresponse.fields.getArg(OPENID_NS, 'sig'))
11401140

11411141
# make sure the expired association is gone
1142-
self.failIf(self.store.getAssociation(self._normal_key, assoc_handle))
1142+
self.failIf(self.store.getAssociation(self._normal_key, assoc_handle),
1143+
"expired association is still retrievable.")
11431144

11441145
# make sure the new key is a dumb mode association
11451146
self.failUnless(self.store.getAssociation(self._dumb_key, new_assoc_handle))
11461147
self.failIf(self.store.getAssociation(self._normal_key, new_assoc_handle))
11471148
self.failUnless(self.messages)
11481149

1150+
def test_signExpiredSignAll(self):
1151+
request = server.OpenIDRequest()
1152+
request.namespace = OPENID2_NS
1153+
assoc_handle = '{assoc}{lookatme}'
1154+
1155+
expired_assoc = association.Association.fromExpiresIn(
1156+
-10, assoc_handle, 'sekrit', 'HMAC-SHA1-SIGNALL')
1157+
1158+
self.failUnless(expired_assoc.sign_all)
1159+
self.store.storeAssociation(self._normal_key, expired_assoc)
1160+
self.failUnless(self.store.getAssociation(self._normal_key, assoc_handle))
1161+
1162+
request.assoc_handle = assoc_handle
1163+
response = server.OpenIDResponse(request)
1164+
response.fields = Message.fromOpenIDArgs({
1165+
'foo': 'amsigned',
1166+
'bar': 'notsigned',
1167+
'azu': 'alsosigned',
1168+
})
1169+
sresponse = self.signatory.sign(response)
1170+
1171+
new_assoc_handle = sresponse.fields.getArg(OPENID_NS, 'assoc_handle')
1172+
self.failUnless(new_assoc_handle)
1173+
self.failIfEqual(new_assoc_handle, assoc_handle)
1174+
1175+
self.failUnlessEqual(
1176+
sresponse.fields.getArg(OPENID_NS, 'invalidate_handle'),
1177+
assoc_handle)
1178+
1179+
# make sure the new key is a dumb mode association
1180+
new_assoc = self.store.getAssociation(self._dumb_key, new_assoc_handle)
1181+
self.failUnless(new_assoc)
1182+
self.failIf(self.store.getAssociation(self._normal_key,
1183+
new_assoc_handle))
1184+
# and the new key is a sign-all key like the old one was.
1185+
self.failUnless(new_assoc.sign_all)
1186+
1187+
# make sure the expired association is gone
1188+
self.failIf(self.store.getAssociation(self._normal_key, assoc_handle))
1189+
1190+
1191+
self.failUnlessEqual(sresponse.fields.getArg(OPENID_NS, 'signed', None),
1192+
None)
1193+
self.failUnless(sresponse.fields.getArg(OPENID_NS, 'sig'))
1194+
1195+
11491196
def test_signInvalidHandle(self):
11501197
request = server.OpenIDRequest()
11511198
request.namespace = OPENID2_NS

0 commit comments

Comments
 (0)