11import logging
22
3+ from cryptojwt .exception import UnsupportedAlgorithm
4+
35from oidcmsg .time_util import utc_time_sans_frac
4- from ..exception import MessageException , NotForMe
6+ from ..exception import MessageException
7+ from ..exception import NotForMe
58from ..message import Message
69from ..message import REQUIRED_LIST_OF_STRINGS
710from ..message import SINGLE_OPTIONAL_STRING
811from ..message import SINGLE_REQUIRED_INT
912from ..message import SINGLE_REQUIRED_JSON
1013from ..message import SINGLE_REQUIRED_STRING
1114from ..oauth2 import ResponseMessage
12- from ..oidc import clear_verified_claims , verify_id_token
13- from ..oidc import verified_claim_name
14- from ..oidc import IdToken
1515from ..oidc import ID_TOKEN_VERIFY_ARGS
16+ from ..oidc import IdToken
1617from ..oidc import MessageWithIdToken
1718from ..oidc import SINGLE_OPTIONAL_IDTOKEN
18-
19+ from ..oidc import clear_verified_claims
20+ from ..oidc import verified_claim_name
21+ from ..oidc import verify_id_token
1922
2023logger = logging .getLogger (__name__ )
2124
@@ -25,7 +28,7 @@ class RefreshSessionRequest(MessageWithIdToken):
2528 c_param .update ({
2629 "redirect_url" : SINGLE_REQUIRED_STRING ,
2730 "state" : SINGLE_REQUIRED_STRING
28- })
31+ })
2932
3033
3134class RefreshSessionResponse (MessageWithIdToken , ResponseMessage ):
@@ -47,7 +50,7 @@ class EndSessionRequest(Message):
4750 "id_token_hint" : SINGLE_OPTIONAL_IDTOKEN ,
4851 "post_logout_redirect_uri" : SINGLE_OPTIONAL_STRING ,
4952 "state" : SINGLE_OPTIONAL_STRING
50- }
53+ }
5154
5255 def verify (self , ** kwargs ):
5356 super (EndSessionRequest , self ).verify (** kwargs )
@@ -111,7 +114,7 @@ def verify(self, **kwargs):
111114 raise ValueError ('Wrong member value in "events"' )
112115
113116 # There must be either a 'sub' or a 'sid', and may contain both
114- if not ('sub' in self or 'sid' in self ):
117+ if not ('sub' in self or 'sid' in self ):
115118 raise ValueError ('There MUST be either a "sub" or a "sid"' )
116119
117120 try :
@@ -141,6 +144,12 @@ def verify(self, **kwargs):
141144 if self ['iat' ] > (_now + _skew ):
142145 raise ValueError ('Invalid issued_at time' )
143146
147+ _allowed = kwargs .get ("allowed_sign_alg" )
148+ if _allowed and self .jws_header ['alg' ] != _allowed :
149+ _msg = "Wrong token signing algorithm, {} != {}" .format (
150+ self .jws_header ['alg' ], kwargs ["allowed_sign_alg" ])
151+ raise UnsupportedAlgorithm (_msg )
152+
144153 return True
145154
146155
@@ -155,7 +164,7 @@ class BackChannelLogoutRequest(Message):
155164
156165 c_param = {
157166 "logout_token" : SINGLE_REQUIRED_STRING
158- }
167+ }
159168
160169 def verify (self , ** kwargs ):
161170 super (BackChannelLogoutRequest , self ).verify (** kwargs )
0 commit comments