2026-02-05 15:34:59 +01:00
|
|
|
|
using RemoteFrameBuffer.Common;
|
2026-02-09 14:26:11 +01:00
|
|
|
|
using System.Text;
|
2026-02-05 15:34:59 +01:00
|
|
|
|
|
|
|
|
|
|
namespace RemoteFrameBuffer.Client
|
|
|
|
|
|
{
|
|
|
|
|
|
public class RemoteFrameBufferClientProtocol_3_3 : RemoteFrameBufferClientProtocol
|
|
|
|
|
|
{
|
|
|
|
|
|
public override RfbProtoVersion Version => new(3, 3);
|
|
|
|
|
|
|
|
|
|
|
|
public RemoteFrameBufferClientProtocol_3_3(Stream s) : base(s)
|
|
|
|
|
|
{
|
2026-02-09 14:26:11 +01:00
|
|
|
|
this.Phase = RfbClientProtocolPhase.Constructed;
|
2026-02-05 15:34:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-09 14:26:11 +01:00
|
|
|
|
public override void Handshake(CancellationToken token)
|
2026-02-05 15:34:59 +01:00
|
|
|
|
{
|
2026-02-09 14:26:11 +01:00
|
|
|
|
if (this.Phase != RfbClientProtocolPhase.Constructed)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException("In wrong phase when calling Handshake");
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Phase = RfbClientProtocolPhase.Handshake;
|
|
|
|
|
|
Byte[] buf;
|
|
|
|
|
|
// Request protocol version
|
|
|
|
|
|
this.vncStream.Write(Encoding.ASCII.GetBytes("RFB 003.003\n"));
|
|
|
|
|
|
// Read security type
|
|
|
|
|
|
buf = new Byte[4];
|
|
|
|
|
|
CancellationTokenSource readTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
|
|
|
|
|
CancellationTokenSource readTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, readTimeout.Token);
|
|
|
|
|
|
this.vncStream.ReadExactlyAsync(buf, 0, buf.Length, readTokenSource.Token).AsTask().Wait();
|
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
|
|
{
|
|
|
|
|
|
Array.Reverse(buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.SecurityType = (RemoteFramebufferSecurityType)BitConverter.ToUInt32(buf, 0);
|
|
|
|
|
|
Console.Error.WriteLine($"Server uses security type {this.SecurityType}");
|
|
|
|
|
|
switch (this.SecurityType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case RemoteFramebufferSecurityType.Invalid:
|
|
|
|
|
|
throw new Exception("Connection failed");
|
|
|
|
|
|
case RemoteFramebufferSecurityType.None:
|
|
|
|
|
|
break;// RFB 3.3 straight up jumps to initialization here
|
|
|
|
|
|
case RemoteFramebufferSecurityType.VncAuthentication:
|
|
|
|
|
|
throw new NotImplementedException("VNC Authentication is not implemented");
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotSupportedException("RFB version 3.3 doesn't support the security type returned by the server");
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Phase = RfbClientProtocolPhase.HandshakeDone;
|
2026-02-05 15:34:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|