public override void Start() { base.Start(); TimeUntilRelease = ConnectedTime.AddSeconds(Network.SecondsToAuthenticateBeforeDisconnect); AuthenticationThread = new Thread(new ThreadStart(CheckAuthentication)); AuthenticationThread.Start(); }
public override void Start() { base.Start(); SessionID = Index.ToString("000") + " - " + IP + " - " + ConnectedTime.ToString("yyyy/MM/dd hh:mm:ss"); }
private async Task HandlePacket(BbTcpPacket packet) { if (packet is BbTcpPacket_Hello_Ans && m_bRequestedHello) { m_bRequestedHello = false; BbTcpPacket_Hello_Ans hello_ans = (BbTcpPacket_Hello_Ans)packet; ServerName = hello_ans.Desc; ServerGUID = hello_ans.ServerGUID; ServerMinProtocolVersion = hello_ans.MinSupportedVersion; m_bRequiresPassword = hello_ans.RequiresPassword; UsedProtocolVersion = (byte)Math.Min(hello_ans.MaxSupportedVersion, BBProtocol.CURRENT_PROTOCOL_VERSION); if (UsedProtocolVersion < hello_ans.MinSupportedVersion || UsedProtocolVersion < BBProtocol.MIN_PROTOCOL_VERSION) { ProtocolIncompatible = true; Log.w(TAG, "Server supported protocol versions incompatible - " + ServerName); Disconnect(false, true); } SupportsScreenCapture = hello_ans.SupportsScreenCapture; IsProVersion = hello_ans.IsProVersion; Log.d(TAG, "Received Hello Answer from " + ServerName + " Protocol Version: " + UsedProtocolVersion + " Needs Password: "******"Got Pong"); } else if (packet is BbTcpPacket_EncryptionACK crypt) { await ContinueEncryptionNegotiation(crypt); } else if (packet is BbTcpPacket_Encryption_AuthAns auth) { if (m_abyTestedSharedSecret != null) { if (auth.ErrorCode == 0) { Log.d(TAG, "DH+Auth negotiated encryption key for session is: " + BitConverter.ToString(m_abyTestedSharedSecret)); m_sendStreamCipher.Init(m_abyTestedSharedSecret); m_recvStreamCipher.Init(m_abyTestedSharedSecret); m_bAuthentificated = true; m_abyTestedSharedSecret = null; m_dhKeyExchange = null; m_requestedEncryptionMethod = EEncryptionMethod.NONE; Log.d(TAG, "Password accepted, DH+Auth Encryption negotiation finished, transmissions will now be encrypted with " + m_sendStreamCipher.Algorithm); Attach(); } else { Log.w(TAG, "Challenge failed - Password rejected. Trying again."); m_abyTestedSharedSecret = null; await Authenticate(true); } } else { Log.e(TAG, "Unexpected/Unrequested Encryption_AuthAns packet"); Disconnect(false, false); } } else if (packet is BbTcpPacket_Attach_Ans attach_ans && m_bRequestedAttach) { m_bRequestedAttach = false; if (attach_ans.AttachResult == EAttachResult.ACCEPTED) { Attached = true; WasAttached = true; ConnectedTime.Start(); Connecting = false; ConnectionChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EState.CONNECTED, SessionID)); Log.d(TAG, "Attached to " + ServerName); } else { Log.d(TAG, "Cannot Attach to " + ServerName + " Error: " + attach_ans.AttachResult); Disconnect(false, false); } }