@@ -526,13 +526,9 @@ def _doIdRes(self, message, endpoint):
526526 if user_setup_url is not None :
527527 return SetupNeededResponse (endpoint , user_setup_url )
528528
529- signed = message .getArg (OPENID_NS , 'signed' )
530- if signed :
531- signed_list = signed .split (',' )
532- else :
533- signed_list = []
534-
535529 try :
530+ signed_list = self ._idResCheckSignature (message ,
531+ endpoint .server_url )
536532 self ._idResCheckForFields (message , signed_list )
537533 except ValueError , e :
538534 return FailureResponse (endpoint , e .args [0 ])
@@ -553,13 +549,14 @@ def _doIdRes(self, message, endpoint):
553549 return FailureResponse (
554550 endpoint , fmt % (endpoint .delegate , server_id2 ))
555551
556- assoc_handle = message .getArg (OPENID_NS , 'assoc_handle' )
557- assoc = self .store .getAssociation (endpoint .server_url , assoc_handle )
552+ # XXX: association-type specific
553+ signed_fields = ['openid.' + f for f in signed_list ]
554+ return SuccessResponse (endpoint , message , signed_fields )
558555
559- # Fail if the identity field is present but not signed
560- if endpoint . identity_url is not None and 'identity' not in signed_list :
561- msg = '"openid.identity" not signed'
562- return FailureResponse ( endpoint , msg )
556+
557+ def _idResCheckSignature ( self , message , server_url ) :
558+ assoc_handle = message . getArg ( OPENID_NS , 'assoc_handle' )
559+ assoc = self . store . getAssociation ( server_url , assoc_handle )
563560
564561 if assoc :
565562 if assoc .getExpiresIn () <= 0 :
@@ -568,26 +565,22 @@ def _doIdRes(self, message, endpoint):
568565 # automatically opens the possibility for
569566 # denial-of-service by a server that just returns expired
570567 # associations (or really short-lived associations)
571- msg = 'Association with %s expired' % (endpoint .server_url ,)
572- return FailureResponse (endpoint , msg )
573-
574- # Check the signature
575- v_sig = assoc .signDict (signed_list , message .toPostArgs ())
568+ raise ValueError ('Association with %s expired' % (server_url ,))
576569
577- if v_sig != message . getArg ( OPENID_NS , 'sig' ):
578- return FailureResponse ( endpoint , 'Bad signature' )
570+ if not assoc . checkMessageSignature ( message ):
571+ raise ValueError ( 'Bad signature' )
579572
580573 else :
581574 # It's not an association we know about. Stateless mode is our
582575 # only possible path for recovery.
583576 # XXX - async framework will not want to block on this call to
584577 # _checkAuth.
585- if not self ._checkAuth (message , endpoint .server_url ):
586- return FailureResponse (endpoint ,
587- 'Server denied check_authentication' )
578+ if not self ._checkAuth (message , server_url ):
579+ raise ValueError ('Server denied check_authentication' )
588580
589- signed_fields = ['openid.' + f for f in signed_list ]
590- return SuccessResponse (endpoint , message , signed_fields )
581+ # XXX: association-type specific
582+ signed = message .getArg (OPENID_NS , 'signed' )
583+ return signed .split (',' )
591584
592585
593586 def _idResCheckForFields (self , message , signed_list ):
0 commit comments