Skip to content

Commit

Permalink
add listening mode
Browse files Browse the repository at this point in the history
fix RFB 3.3 handshake issues
minor layout changes
  • Loading branch information
comtel2000 committed Aug 12, 2015
1 parent e6a6744 commit df871a5
Show file tree
Hide file tree
Showing 106 changed files with 1,016 additions and 1,013 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Server/Client clipboard transfer
- Zoom, Full screen (0.0.2)
- Touch gesture support
- VNC listening mode (0.0.3)

## Roadmap
- TRLE, ZRLE, Tight, Turbo, etc. encodings
Expand Down
2 changes: 1 addition & 1 deletion jfxvnc-net/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.0.28.Final</version>
<version>4.0.30.Final</version>
</dependency>
</dependencies>
</project>
22 changes: 11 additions & 11 deletions jfxvnc-net/src/main/java/org/jfxvnc/net/SampleVncClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package org.jfxvnc.net;

import org.jfxvnc.net.rfb.codec.ProtocolHandler;
import org.jfxvnc.net.rfb.codec.ProtocolState;
import org.jfxvnc.net.rfb.codec.decoder.ServerDecoderEvent;
import org.jfxvnc.net.rfb.codec.encoder.InputEventListener;
import org.jfxvnc.net.rfb.codec.security.SecurityType;
import org.jfxvnc.net.rfb.render.DefaultProtocolConfiguration;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderCallback;
import org.jfxvnc.net.rfb.render.RenderProtocol;
import org.jfxvnc.net.rfb.render.rect.ImageRect;

/*
* #%L
* RFB protocol
Expand Down Expand Up @@ -29,17 +40,6 @@
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

import org.jfxvnc.net.rfb.codec.ProtocolHandler;
import org.jfxvnc.net.rfb.codec.ProtocolState;
import org.jfxvnc.net.rfb.codec.decoder.ServerDecoderEvent;
import org.jfxvnc.net.rfb.codec.encoder.InputEventListener;
import org.jfxvnc.net.rfb.codec.security.SecurityType;
import org.jfxvnc.net.rfb.render.DefaultProtocolConfiguration;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderCallback;
import org.jfxvnc.net.rfb.render.RenderProtocol;
import org.jfxvnc.net.rfb.render.rect.ImageRect;

public class SampleVncClient {

public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* #L%
*/


public interface ClientEventType {

int SET_PIXEL_FORMAT = 0;
Expand Down
33 changes: 10 additions & 23 deletions jfxvnc-net/src/main/java/org/jfxvnc/net/rfb/codec/Encoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* #L%
*/


/**
* Encoding types
*
Expand Down Expand Up @@ -59,27 +58,15 @@
*
*/
public enum Encoding {

UNKNOWN(Integer.MIN_VALUE),
RAW(0),
COPY_RECT(1),
RRE(2),
HEXTILE(3),

CO_RRE(4),
ZLIB(6),
TIGHT(7),
ZLIB_HEX(8),
TRLE(15),
ZRLE(16),

H_ZYWRLE(17),
AW_XZ(18),
AW_XZYW(19),

DESKTOP_SIZE(-223),
CURSOR(-239);

UNKNOWN(Integer.MIN_VALUE), RAW(0), COPY_RECT(1), RRE(2), HEXTILE(3),

CO_RRE(4), ZLIB(6), TIGHT(7), ZLIB_HEX(8), TRLE(15), ZRLE(16),

H_ZYWRLE(17), AW_XZ(18), AW_XZYW(19),

DESKTOP_SIZE(-223), CURSOR(-239);

private final int type;

private Encoding(int type) {
Expand All @@ -94,8 +81,8 @@ public static Encoding valueOf(int type) {
}
return UNKNOWN;
}
public int getType(){

public int getType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package org.jfxvnc.net.rfb.codec;

import java.util.EnumMap;
import java.util.List;

import org.jfxvnc.net.rfb.codec.decoder.BellDecoder;
import org.jfxvnc.net.rfb.codec.decoder.ColourMapEntriesDecoder;
import org.jfxvnc.net.rfb.codec.decoder.FrameDecoder;
import org.jfxvnc.net.rfb.codec.decoder.FramebufferUpdateRectDecoder;
import org.jfxvnc.net.rfb.codec.decoder.ServerCutTextDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
* #%L
* RFB protocol
Expand All @@ -24,17 +35,6 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.EnumMap;
import java.util.List;

import org.jfxvnc.net.rfb.codec.decoder.BellDecoder;
import org.jfxvnc.net.rfb.codec.decoder.ColourMapEntriesDecoder;
import org.jfxvnc.net.rfb.codec.decoder.FrameDecoder;
import org.jfxvnc.net.rfb.codec.decoder.FramebufferUpdateRectDecoder;
import org.jfxvnc.net.rfb.codec.decoder.ServerCutTextDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FrameDecoderHandler extends ByteToMessageDecoder {
private static Logger logger = LoggerFactory.getLogger(FrameDecoderHandler.class);

Expand Down Expand Up @@ -66,10 +66,10 @@ public boolean isPixelFormatSupported() {

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable()){
if (!in.isReadable()) {
return;
}

FrameDecoder decoder;
switch (state) {
case NEXT:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jfxvnc.net.rfb.codec;


/*
* #%L
* RFB protocol
Expand All @@ -21,7 +20,6 @@
* #L%
*/


public class PixelFormat {

/**
Expand All @@ -41,7 +39,7 @@ public class PixelFormat {
RGB_888.setGreenShift(8);
RGB_888.setBlueShift(0);
}

private int bitPerPixel;
private int depth;
private boolean bigEndian;
Expand Down Expand Up @@ -141,8 +139,8 @@ public int getBytePerPixel() {

@Override
public String toString() {
return "PixelFormat [bitPerPixel=" + bitPerPixel + ", depth=" + depth + ", bigEndian=" + bigEndian + ", trueColor=" + trueColor + ", redMax=" + redMax
+ ", greenMax=" + greenMax + ", blueMax=" + blueMax + ", redShift=" + redShift + ", greenShift=" + greenShift + ", blueShift=" + blueShift + "]";
return "PixelFormat [bitPerPixel=" + bitPerPixel + ", depth=" + depth + ", bigEndian=" + bigEndian + ", trueColor=" + trueColor + ", redMax=" + redMax + ", greenMax="
+ greenMax + ", blueMax=" + blueMax + ", redShift=" + redShift + ", greenShift=" + greenShift + ", blueShift=" + blueShift + "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package org.jfxvnc.net.rfb.codec;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.jfxvnc.net.rfb.codec.decoder.ServerDecoderEvent;
import org.jfxvnc.net.rfb.codec.encoder.ClientCutTextEncoder;
import org.jfxvnc.net.rfb.codec.encoder.KeyButtonEventEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PixelFormatEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PointerEventEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PreferedEncoding;
import org.jfxvnc.net.rfb.codec.encoder.PreferedEncodingEncoder;
import org.jfxvnc.net.rfb.codec.handshaker.event.ServerInitEvent;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.jfxvnc.net.rfb.render.ConnectInfoEvent;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderProtocol;
import org.jfxvnc.net.rfb.render.rect.ImageRect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
* #%L
* RFB protocol
Expand All @@ -25,28 +45,9 @@
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.jfxvnc.net.rfb.codec.decoder.ServerDecoderEvent;
import org.jfxvnc.net.rfb.codec.encoder.ClientCutTextEncoder;
import org.jfxvnc.net.rfb.codec.encoder.KeyButtonEventEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PixelFormatEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PointerEventEncoder;
import org.jfxvnc.net.rfb.codec.encoder.PreferedEncoding;
import org.jfxvnc.net.rfb.codec.encoder.PreferedEncodingEncoder;
import org.jfxvnc.net.rfb.codec.handshaker.event.ServerInitEvent;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.jfxvnc.net.rfb.render.ConnectInfoEvent;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderProtocol;
import org.jfxvnc.net.rfb.render.rect.ImageRect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProtocolHandler extends MessageToMessageDecoder<Object> {

private static Logger logger = LoggerFactory.getLogger(ProtocolHandler.class);
Expand All @@ -72,7 +73,7 @@ public ProtocolHandler(RenderProtocol render, ProtocolConfiguration config) {
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
if (config.sslProperty().get()) {
if (sslContext == null) {
sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
}
ctx.pipeline().addFirst("ssl-handler", sslContext.newHandler(ctx.channel().alloc()));
}
Expand Down Expand Up @@ -100,7 +101,7 @@ protected void decode(final ChannelHandlerContext ctx, Object msg, List<Object>
// serverInit.getFrameBufferWidth(),
// serverInit.getFrameBufferHeight());

});
});
return;
}
if (msg instanceof ServerDecoderEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package org.jfxvnc.net.rfb.codec;

import java.util.Arrays;

import org.jfxvnc.net.rfb.codec.decoder.ProtocolVersionDecoder;
import org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshaker;
import org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshakerFactory;
import org.jfxvnc.net.rfb.codec.handshaker.event.SecurityResultEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.SecurityTypesEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.ServerInitEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.SharedEvent;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshaker;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshakerFactory;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityMessage;
import org.jfxvnc.net.rfb.codec.security.SecurityType;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.Unpooled;

/*
* #%L
* RFB protocol
Expand All @@ -24,24 +44,6 @@
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;

import java.util.Arrays;

import org.jfxvnc.net.rfb.codec.decoder.ProtocolVersionDecoder;
import org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshaker;
import org.jfxvnc.net.rfb.codec.handshaker.RfbClientHandshakerFactory;
import org.jfxvnc.net.rfb.codec.handshaker.event.SecurityResultEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.SecurityTypesEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.ServerInitEvent;
import org.jfxvnc.net.rfb.codec.handshaker.event.SharedEvent;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshaker;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityHandshakerFactory;
import org.jfxvnc.net.rfb.codec.security.RfbSecurityMessage;
import org.jfxvnc.net.rfb.codec.security.SecurityType;
import org.jfxvnc.net.rfb.exception.ProtocolException;
import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {

private static Logger logger = LoggerFactory.getLogger(ProtocolHandshakeHandler.class);
Expand Down Expand Up @@ -127,13 +129,14 @@ private void handleSecurityTypes(final ChannelHandlerContext ctx, SecurityTypesE
SecurityType userSecType = config.securityProperty().get();
boolean isSupported = Arrays.stream(supportTypes).anyMatch(i -> i == userSecType);
if (!isSupported) {
ctx.fireExceptionCaught(new ProtocolException(String.format("Authentication: '%s' is not supported. The server supports only (%s)",
userSecType, Arrays.toString(supportTypes))));
ctx.fireExceptionCaught(
new ProtocolException(String.format("Authentication: '%s' is not supported. The server supports only (%s)", userSecType, Arrays.toString(supportTypes))));
return;
}

if (userSecType == SecurityType.NONE) {
logger.info("no security available");
logger.info("none security type available");
ctx.writeAndFlush(Unpooled.buffer(1).writeByte(userSecType.getType()));
ctx.pipeline().fireUserEventTriggered(ProtocolState.SECURITY_COMPLETE);
return;
}
Expand All @@ -145,13 +148,12 @@ private void handleSecurityTypes(final ChannelHandlerContext ctx, SecurityTypesE
ctx.fireExceptionCaught(new ProtocolException(String.format("Authentication: '%s' is not supported yet", userSecType)));
return;
}
secHandshaker.handshake(ctx.channel()).addListener((future) -> {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
} else {
secHandshaker.handshake(ctx.channel(), msg.isResponse()).addListener((future) -> {
if (future.isSuccess()) {
ctx.pipeline().fireUserEventTriggered(ProtocolState.SECURITY_STARTED);
} else {
ctx.fireExceptionCaught(future.cause());
}

});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jfxvnc.net.rfb.codec;

import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderProtocol;

/*
* #%L
* jfxvnc-net
Expand All @@ -20,14 +23,10 @@
* #L%
*/


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

import org.jfxvnc.net.rfb.render.ProtocolConfiguration;
import org.jfxvnc.net.rfb.render.RenderProtocol;

public class ProtocolInitializer extends ChannelInitializer<SocketChannel> {
private RenderProtocol render;
private ProtocolConfiguration config;
Expand All @@ -41,7 +40,8 @@ public ProtocolInitializer(RenderProtocol render, ProtocolConfiguration config)
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();

// pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
pipeline.addLast(new ProtocolHandler(render, config));

}
}
Loading

0 comments on commit df871a5

Please sign in to comment.