def _add_nonce(self, response): """ Store a nonce from a response we received. :param twisted.web.iweb.IResponse response: The HTTP response. :return: The response, unmodified. """ nonce = response.headers.getRawHeaders(REPLAY_NONCE_HEADER, [None])[0] with LOG_JWS_ADD_NONCE(raw_nonce=nonce) as action: if nonce is None: return _fail_and_consume( response, errors.ClientError(str(errors.MissingNonce(response))), ) else: try: decoded_nonce = Header._fields['nonce'].decode( nonce.decode('ascii')) action.add_success_fields(nonce=decoded_nonce) except DeserializationError as error: return _fail_and_consume(response, errors.BadNonce(nonce, error)) self._nonces.add(decoded_nonce) return response
def _add_nonce(self, response): if self.REPLAY_NONCE_HEADER in response.headers: nonce = response.headers[self.REPLAY_NONCE_HEADER] try: decoded_nonce = jws.Header._fields['nonce'].decode(nonce) except jose.DeserializationError as error: raise errors.BadNonce(nonce, error) logger.debug('Storing nonce: %s', nonce) self._nonces.add(decoded_nonce) else: raise errors.MissingNonce(response)
def _add_nonce(self, response): if self.REPLAY_NONCE_HEADER in response.headers: nonce = response.headers[self.REPLAY_NONCE_HEADER] error = jws.Header.validate_nonce(nonce) if error is None: logger.debug('Storing nonce: %r', nonce) self._nonces.add(nonce) else: raise errors.BadNonce(nonce, error) else: raise errors.MissingNonce(response)