internal override async Task <bool> HandleP03FinishHandshake(P03FinishHandshake p) { switch (p.ConnectionState) { case ConnectionState.CompatibilityMode: parent.ConnectionVersion = 1; // A VSL 1.1 Server sends this response. await parent.OnConnectionEstablished(); return(true); case ConnectionState.Redirect: parent.ExceptionHandler.CloseConnection("NotSupported", "This VSL version does not support redirects.", nameof(PacketHandlerClient)); return(false); case ConnectionState.NotCompatible: parent.ExceptionHandler.CloseConnection("ConnectionDenied", "The specified server denied the connection to this VSL/application version client.", nameof(PacketHandlerClient)); return(false); case ConnectionState.Compatible: parent.ConnectionVersion = p.VSLVersion; await parent.OnConnectionEstablished(); return(true); default: parent.ExceptionHandler.CloseConnection("InvalidConnectionState", $"The specified ConnectionState.{p.ConnectionState} is invalid", nameof(PacketHandlerClient)); return(false); } }
internal override Task <bool> HandleP03FinishHandshake(P03FinishHandshake p) { parent.ExceptionHandler.CloseConnection("InvalidPacket", "VSL servers can not handle P03FinishHandshake.", nameof(PacketHandlerServer), nameof(HandleP03FinishHandshake)); return(Task.FromResult(false)); }
internal override async Task <bool> HandleP01KeyExchange(P01KeyExchange p) { ushort?vslVersion = VersionManager.GetSharedVersion(parent.Settings.LatestVslVersion, parent.Settings.OldestVslVersion, p.LatestVSL, p.OldestVSL); ushort?productVersion = VersionManager.GetSharedVersion(latestProduct, oldestProduct, p.LatestProduct, p.OldestProduct); if (!vslVersion.HasValue || !productVersion.HasValue) { return(await parent.Manager.SendPacketAsync(CryptoAlgorithm.None, new P03FinishHandshake(ConnectionState.NotCompatible))); } parent.Manager.AesKey = p.AesKey; parent.ConnectionVersion = vslVersion.Value; P03FinishHandshake packet; if (vslVersion.Value < 2) { parent.Manager.SendIV = p.ServerIV; parent.Manager.ReceiveIV = p.ClientIV; parent.Manager.Ready4Aes = true; packet = new P03FinishHandshake(ConnectionState.CompatibilityMode); } else if (vslVersion.Value == 2) { parent.Manager.HmacKey = Util.ConcatBytes(p.ClientIV, p.ServerIV); parent.Manager.Ready4Aes = true; packet = new P03FinishHandshake(ConnectionState.Compatible, vslVersion.Value, productVersion.Value); } else { parent.Manager.SendIV = p.ServerIV; parent.Manager.ReceiveIV = p.ClientIV; parent.Manager.HmacKey = Util.ConcatBytes(p.ClientIV, p.ServerIV); parent.Manager.Ready4Aes = true; packet = new P03FinishHandshake(ConnectionState.Compatible, vslVersion.Value, productVersion.Value); } if (!await parent.Manager.SendPacketAsync(VersionManager.GetNetworkAlgorithm(vslVersion), packet)) { return(false); } await parent.OnConnectionEstablished(); return(true); }
internal abstract Task <bool> HandleP03FinishHandshake(P03FinishHandshake p);