服务上的SSL(在CentOS上)不起作用

时间:2013-11-07 07:57:13

标签: java linux ssl centos netty

我正在使用带有OpenJDK 1.7的Netty 4.0.11运行HTTP服务器。我使用的是CentOS 6.3。

当我在命令中使用“java -jar myServer.jar”时,一切正常。但是,当我把它放在服务上时,我得到一个例外,说无法初始化通道。

这很奇怪,因为一切都在命令行上运行正常。但是,在服务方面,似乎出现了问题。

Nov 07, 2013 4:26:00 PM io.netty.channel.ChannelInitializer channelRegistered
WARNING: Failed to initialize a channel. Closing: [id: 0x921deb84, /14.63.176.113:17319 => /172.27.125.139:1003]
java.lang.NullPointerException
    at server.BookkServerInitializer.initChannel(BookkServerInitializer.java:23)
    at server.BookkServerInitializer.initChannel(BookkServerInitializer.java:18)
    at io.netty.channel.ChannelInitializer.channelRegistered(ChannelInitializer.java:70)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRegistered(DefaultChannelHandlerContext.java:162)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRegistered(DefaultChannelHandlerContext.java:148)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRegistered(DefaultChannelPipeline.java:730)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:442)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$100(AbstractChannel.java:374)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:418)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Thread.java:724)

这就是调用异常的地方。

package server;

import handler.BookkServerHandler;
import handler.DeleteConnections;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.timeout.IdleStateHandler;
import util.ssl.ServerSslContext;

import javax.net.ssl.SSLEngine;


class BookkServerInitializer extends ChannelInitializer<SocketChannel> {
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        if (!System.getProperty("os.name").equals("Windows 7")) {
            SSLEngine engine = ServerSslContext.getInstance().serverContext().createSSLEngine();
            engine.setUseClientMode(false);
            pipeline.addLast("ssl", new SslHandler(engine));
        }

        pipeline.addFirst("connectionDeleter", new DeleteConnections());
        pipeline.addFirst("idleState", new IdleStateHandler(3, 3, 3));
        pipeline.addLast("codec", new HttpServerCodec());
        pipeline.addLast("inflater", new HttpContentDecompressor());
        pipeline.addLast("deflater", new HttpContentCompressor(9, 15, 9));
        pipeline.addLast("handler", new BookkServerHandler());
    }
}

异常日志显示我的SSLEngine是问题所在。

我测试了没有SSL的服务器,它可以工作!!!

SSL与服务有什么关系??

1 个答案:

答案 0 :(得分:0)

通过更改密钥库的目录来解决。

我曾经将我的密钥库存储在与jar文件相同的directroy中。所以我使用了路径“keystore”。

只需将其更改为“/ DirectoryOfTheKeystore / keystore”即可。它有效!!