Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[milo-dev] ClientServerExample.java failed and fix bug ?

Hi Kevin,

I tried to run ClientServerExample.java and this stack trace was output below.

ClientServerExample.java)
-----
https://github.com/eclipse/milo/blob/master/opc-ua-stack/stack-examples/src/main/java/org/eclipse/milo/opcua/stack/examples/ClientServerExample.java

stack trace)
-----
org.eclipse.milo.opcua.stack.server.handlers.UaTcpServerAsymmetricHandler exceptionCaught - [remote=/127.0.0.1:53797] Exception caught; sent ErrorMessage{error=StatusCode{name=Bad_UnexpectedError,  
value=0x80010000, quality=bad}, reason=java.lang.IllegalArgumentException: securityPolicyUri length cannot be greater than 255 bytes}
io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: securityPolicyUri length cannot be greater than 255 bytes
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:326)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1320)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:905)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:563)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:504)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:418)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:390)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: securityPolicyUri length cannot be greater than 255 bytes
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
	at org.eclipse.milo.opcua.stack.core.channel.headers.AsymmetricSecurityHeader.<init>(AsymmetricSecurityHeader.java:44)
	at org.eclipse.milo.opcua.stack.core.channel.headers.AsymmetricSecurityHeader.decode(AsymmetricSecurityHeader.java:139)
	at org.eclipse.milo.opcua.stack.server.handlers.UaTcpServerAsymmetricHandler.onOpenSecureChannel(UaTcpServerAsymmetricHandler.java:134)
	at org.eclipse.milo.opcua.stack.server.handlers.UaTcpServerAsymmetricHandler.decode(UaTcpServerAsymmetricHandler.java:103)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
	... 15 more
-----

Therefore I modified decode() method in AsymmetricSecurityHeader.java and
run it successfully. I will send this patch to you.

Regards,

--Shigeru
--- AsymmetricSecurityHeader.java.orig	2016-06-23 07:38:21.000000000 +0900
+++ AsymmetricSecurityHeader.java	2016-06-30 14:33:24.008478166 +0900
@@ -121,20 +121,25 @@
     public static AsymmetricSecurityHeader decode(ByteBuf buffer) {
         /* SecurityPolicyUri */
         int securityPolicyUriLength = buffer.readInt();
-        String securityPolicyUri = new String(
-            buffer.readBytes(securityPolicyUriLength).array(),
-            Charset.forName("UTF-8")
-        );
+        byte[] bytes = new byte[securityPolicyUriLength];
+        buffer.readBytes(bytes);
+        String securityPolicyUri = new String(bytes, Charset.forName("UTF-8"));
 
         /* SenderCertificate */
         int senderCertificateLength = buffer.readInt();
-        byte[] senderCertificate = senderCertificateLength >= 0 ?
-            buffer.readBytes(senderCertificateLength).array() : null;
+        byte[] senderCertificate = null;
+        if (senderCertificateLength >= 0) {
+        	senderCertificate = new byte[senderCertificateLength];
+            buffer.readBytes(senderCertificate);
+        }
 
         /* ReceiverCertificateThumbprint */
         int thumbprintLength = buffer.readInt();
-        byte[] receiverCertificateThumbprint = thumbprintLength >= 0 ?
-            buffer.readBytes(thumbprintLength).array() : null;
+        byte[] receiverCertificateThumbprint = null;
+        if (thumbprintLength >= 0) {
+        	receiverCertificateThumbprint = new byte[thumbprintLength];
+            buffer.readBytes(receiverCertificateThumbprint);
+        }
 
         return new AsymmetricSecurityHeader(
             securityPolicyUri,

Back to the top