简体   繁体   English

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

[英]SSL on service(on CentOS) does not work

I am running a HTTP server using Netty 4.0.11 with OpenJDK 1.7. 我正在使用Netty 4.0.11和OpenJDK 1.7运行HTTP服务器。 I am using CentOS 6.3. 我正在使用CentOS 6.3。

Everything works fine when I just use "java -jar myServer.jar" on the command. 当我仅在命令上使用“ java -jar myServer.jar”时,一切正常。 However, when I put the it on the service, I get an exception saying the channel can't be initialized. 但是,当我将其放在服务上时,出现了异常,指出无法初始化通道。

It's strange because, everything works fine on just command line. 这很奇怪,因为在命令行上一切正常。 But, on service, something seems to go wrong. 但是,在服务中,似乎出现了问题。

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)

And here's where the exception is called. 这就是调用异常的地方。

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());
    }
}

The exception log shows that my SSLEngine is where to problem is. 异常日志显示我的SSLEngine是问题所在。

I tested the server without SSL, it works!!! 我测试了没有SSL的服务器,它正常工作!!!

What's going on with SSL with service?? 带服务的SSL发生了什么事?

Solved by changing the directory of the keystore. 通过更改密钥库的目录来解决。

I used to store my keystore in the same directroy as the jar file. 我以前将密钥库存储在与jar文件相同的目录中。 So i used the path "keystore". 因此,我使用了路径“密钥库”。

Just change it to "/DirectoryOfTheKeystore/keystore". 只需将其更改为“ / DirectoryOfTheKeystore / keystore”。 It works!! 有用!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM