def _send_auth_with_retries(self, state_id, msg, retries_left): user_name = msg.find_avp(*avp.resolve('User-Name')).value visited_plmn = msg.find_avp(*avp.resolve('Visited-PLMN-Id')).value request_eutran_info = msg.find_avp( *avp.resolve('Requested-EUTRAN-Authentication-Info'), ) num_requested_eutran_vectors = request_eutran_info.find_avp( *avp.resolve('Number-Of-Requested-Vectors'), ).value immediate_response_preferred = request_eutran_info.find_avp( *avp.resolve('Immediate-Response-Preferred'), ).value resync_info = request_eutran_info.find_avp( *avp.resolve('Re-Synchronization-Info'), ) request = AuthenticationInformationRequest( user_name=user_name, visited_plmn=visited_plmn, num_requested_eutran_vectors=num_requested_eutran_vectors, immediate_response_preferred=immediate_response_preferred, resync_info=resync_info.value if resync_info else None, ) future = self._client.AuthenticationInformation.future( request, self.grpc_timeout, ) future.add_done_callback( lambda answer: self._loop.call_soon_threadsafe( self._relay_auth_answer, state_id, msg, answer, retries_left, ), )
def test_auth_request(self): """ Tests that we convert incoming Diameter AIR to gRPC AuthenticationInformation call """ # Mock out Collect.future result = Mock() self._proxy_client.AuthenticationInformation.future.side_effect = [ result, ] user_name = '1' visited_plmn_id = b'(Y' num_request_vectors = 1 immediate_response_preferred = True resync_info = b'123456789' req = self._auth_req( user_name, visited_plmn_id, num_request_vectors, immediate_response_preferred, resync_info, ) # Encode request message into buffer req_buf = bytearray(req.length) req.encode(req_buf, 0) request = AuthenticationInformationRequest( user_name=user_name, visited_plmn=visited_plmn_id, num_requested_eutran_vectors=num_request_vectors, immediate_response_preferred=immediate_response_preferred, resync_info=resync_info, ) self._server.data_received(req_buf) self.assertEqual( self._proxy_client.AuthenticationInformation.future.call_count, 1, ) req, _ = self._proxy_client.AuthenticationInformation.future.call_args self.assertEqual(repr(request), repr(req[0]))
def send_air(client, args): """ Sends an AIR (authentication information request) via gRPC to the S6aProxy. """ req = AuthenticationInformationRequest() req.user_name = args.user_name req.visited_plmn = args.visited_plmn req.num_requested_eutran_vectors = args.num_requested_eutran_vectors req.immediate_response_preferred = args.immediate_response_preferred req.resync_info = args.resync_info print("sending AIR:\n %s" % req) try: answer = client.AuthenticationInformation(req) print('answer:\nerror code: %d' % answer.error_code) print('got %d E-UTRAN vector(s)' % len(answer.eutran_vectors)) for i, vector in enumerate(answer.eutran_vectors): print('vector %d' % (i + 1)) print("\tRAND = ", vector.rand) print("\tXRES = ", vector.xres) print("\tAUTN = ", vector.autn) print("\tKASME = ", vector.kasme) except grpc.RpcError as e: print("gRPC failed with %s: %s" % (e.code(), e.details()))