private void PerformGreeting() { ByteBuilder builder = new ByteBuilder(); using (BinaryReader reader = new BinaryReader(this.stream, Encoding.UTF8)) { byte[] values = reader.ReadBytes(2); builder.Append(values); builder.Append(reader.ReadBytes(values[1])); } if (!ClientGreeting.Deserialize(builder.ToArray()).Methods.Contains <AuthMethod>(AuthMethod.None)) { this.Dispose(); throw new Socks5Exception("Client requires authentication."); } byte[] buffer2 = new ServerGreeting(AuthMethod.None).Serialize(); this.stream.Write(buffer2, 0, buffer2.Length); }
/// <summary> /// Performs the initial greeting. /// </summary> /// <exception cref="Socks5Exception">The client sent invalid data, or /// requires authentication.</exception> /// <exception cref="IOException">The stream could not be read, or the /// operation timed out.</exception> void PerformGreeting() { ByteBuilder b = new ByteBuilder(); using (var r = new BinaryReader(stream, Encoding.UTF8, true)) { byte[] bytes = r.ReadBytes(2); b.Append(bytes); // The number of method-bytes following is contained in the second byte. b.Append(r.ReadBytes(bytes[1])); } ClientGreeting greeting = ClientGreeting.Deserialize(b.ToArray()); // We only accept an authentication method of 'none'. if (!greeting.Methods.Contains(AuthMethod.None)) { Dispose(); throw new Socks5Exception("Client requires authentication."); } // Send back our greeting response. var response = new ServerGreeting(AuthMethod.None).Serialize(); stream.Write(response, 0, response.Length); }