Exemplo n.º 1
0
 private void AuthenticateClient(ClientAuthenticationResponse msg)
 {
     this.authenticationActor.Tell(new RequestAuthenticationCommand()
     {
         ReplyTo = this.Self,
         Token   = msg.AuthenticationToken,
         AuthenticationChallenge = this.state.AuthenticationChallenge,
     });
 }
Exemplo n.º 2
0
        private void ProcessAuthenticationRequest(ServerAuthenticationRequest request, string signingKey)
        {
            var    offlineTokenProvider = new OfflineTokenProvider("", signingKey);
            string token = offlineTokenProvider.CreateJWTToken(request.AuthenticationChallenge, DateTime.UtcNow.AddMinutes(15));
            var    cmdClientAuthenticationResponse = new ClientAuthenticationResponse()
            {
                AuthenticationToken = token
            };

            ReliableMessaging.OnSendFrame(new UdpTransferFrame(FrameType.ClientAuthenticationResponse, cmdClientAuthenticationResponse.Serialize()));
        }
Exemplo n.º 3
0
        private IActorRef CreateAuthenticatedActor(TestProbe authenticationProbe, TestProbe clientSocketProbe)
        {
            //setup
            const uint   CLIENTID         = 1234567890;
            const string TOKEN            = "TOKEN";
            string       EXPECTEDRESPONSE = $"HELLO {CLIENTID}";

            var testeeRef          = Sys.ActorOf(Props.Create(() => new ClientTwinActor(clientSocketProbe, authenticationProbe, defaultEndpoint, defaultShardRegionArea, defaultObjectRegionArea)));
            var clientHelloMessage = new ClientHelloMessage()
            {
                Message    = string.Empty,
                ClientId   = CLIENTID,
                ClientPort = 9999,
                Version    = Shared.Constants.Version.PROTOCOL,
            };
            var clientAuthenticationResponse = new ClientAuthenticationResponse()
            {
                AuthenticationToken = TOKEN,
            };

            //execute - client hello
            testeeRef.Tell(new UdpTransferFrame(FrameType.ClientHello, clientHelloMessage.Serialize()));

            //verify
            clientSocketProbe.ExpectMsg <Udp.Send>(s =>
            {
                var msg = new UdpTransferFrame(s.Payload.ToArray());
                Assert.Equal(FrameType.ServerAuthenticationRequest, msg.Type);
            });

            //execute - client authentication response
            testeeRef.Tell(new UdpTransferFrame(FrameType.ClientAuthenticationResponse, clientAuthenticationResponse.Serialize()));

            //verify
            authenticationProbe.ExpectMsg <RequestAuthenticationCommand>(c =>
            {
                Assert.Equal(TOKEN, c.Token);
            });

            //execute - authentication actor response
            testeeRef.Tell(new AuthenticationSuccess());

            //verify
            clientSocketProbe.ExpectMsg <Udp.Send>(s =>
            {
                var msg = new UdpTransferFrame(s.Payload.ToArray());
                Assert.Equal(FrameType.ServerHello, msg.Type);
                var serverHello = new ServerHelloMessage(msg.MessageBuffer);
                Assert.Equal(EXPECTEDRESPONSE, serverHello.Message);
                Assert.Equal(clientHelloMessage.Version, serverHello.Version);
            });

            return(testeeRef);
        }
Exemplo n.º 4
0
        private void ProcessUdpLoginFrame(UdpTransferFrame frame)
        {
            switch (frame.Type)
            {
            case FrameType.ClientHello:
                var msgClientHello = new ClientHelloMessage(frame.MessageBuffer);
                this.state.ClientId      = msgClientHello.ClientId;
                this.state.ClientVersion = msgClientHello.Version;
                this.RequestAuthentication();
                break;

            case FrameType.ClientAuthenticationResponse:
                var msgClientAuthenticationResponse = new ClientAuthenticationResponse(frame.MessageBuffer);
                this.AuthenticateClient(msgClientAuthenticationResponse);
                break;

            default:
                this.log.Warning($"[Client:{this.state.ClientId} => Server] not authenticated - unexpected frame type '{frame.Type}'");
                break;
            }
        }