【问题标题】:Glassfish 4 + SSL client = Connection failure: socketType: SSL; hostname: 127.0.0.1Glassfish 4 + SSL 客户端 = 连接失败:socketType:SSL;主机名:127.0.0.1
【发布时间】:2014-05-28 17:30:09
【问题描述】:

我有一个 glassfish 服务器,我想通过 SSL 从独立的 swing 客户端连接到 EJB。没有 SSL,一切正常。

当我尝试使用此环境在客户端中创建 InitialContext 时:

hashtable.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
hashtable.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
hashtable.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
hashtable.put("org.omg.CORBA.ORBInitialHost", serverIp);
hashtable.put("org.omg.CORBA.ORBInitialPort", 3820);

此外,我使用以下 JVM 参数:

-Djavax.net.ssl.trustStorePassword=changeit \
-Djavax.net.ssl.trustStore=./myTrustStore\
-Dcom.sun.CSIV2.ssl.standalone.client.required=true\
-Dorg.omg.CORBA.ORBInitialPort=3820 \

我在cient方面得到以下信息:

javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=10.0.17.2, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.rmi.MarshalException: CORBA COMM_FAILURE 1330446337 No; nested exception is: 
    org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: SSL; hostname: 127.0.0.1; port: 3820  vmcid: OMG  minor code: 1  completed: No]
....
Caused by: java.rmi.MarshalException: CORBA COMM_FAILURE 1330446337 No; nested exception is: 
    org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: SSL; hostname: 127.0.0.1; port: 3820  vmcid: OMG  minor code: 1  completed: No
...
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: SSL; hostname: 127.0.0.1; port: 3820  vmcid: OMG  minor code: 1  completed: No
    at com.sun.proxy.$Proxy17.connectFailure(Unknown Source)
...
Caused by: java.lang.RuntimeException: java.io.IOException: Error opening SSL socket to host=home.home port=3820
...
Caused by: java.io.IOException: Error opening SSL socket to host=home.home port=3820
...
Caused by: java.net.ConnectException: Connection refused

home.home 是我的工作站。完整日志为here

请解释为什么它尝试打开到 localhost 而不是 serverIp 的连接。

编辑:这是我的 sun-ejb-jar.xml(服务器端)

<sun-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>OrganizationDirBean</ejb-name>
            <ior-security-config>
                <transport-config>
                    <integrity>required</integrity>
                    <confidentiality>required</confidentiality>
                    <establish-trust-in-target>supported</establish-trust-in-target>
                    <establish-trust-in-client>supported</establish-trust-in-client>
                </transport-config>
                <sas-context>
                    <caller-propagation>supported</caller-propagation>
                </sas-context>
            </ior-security-config>
        </ejb>
    </enterprise-beans>
</sun-ejb-jar>

编辑 2
我使用以下代码来创建初始上下文(env 在上面)。我在客户端使用 OSGI(在服务器端 EJB 应用程序包,EAB),这就是为什么我需要在这里使用类加载器:

   ClassLoader thatLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
        InitialContext ctx = new InitialContext(hashtable);
        Directory directory = (Directory) ctx.lookup("ejb/OrganizationDirBean");
        action=directory.read(action);
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        Thread.currentThread().setContextClassLoader(thatLoader);
    }

编辑 3
我自己从资源中构建了 glassfish(GF 4.0.1)。我现在拥有的。当客户端和服务器在同一台主机上时,一切似乎都正常。客户端获取 EJB,EJB 将信息写入日志。是的。我又查了一遍。所有数据包都通过接口 lo。在服务器端 3820 端口上。一切正常。

但是当他们现在在不同的主机上时,我也不例外。 Tcpdump 表明我们每分钟都在欣赏,而且这种情况无休止地继续下去(我还是离开了晚上):

    10.0.18.5.55618 > 10.0.17.2.3820: Flags [.], cksum 0xa8e4 (correct), seq 76855, ack 136375, win 499, options [nop,nop,TS val 669632607 ecr 224087792], length 0
08:44:46.148416 IP (tos 0x0, ttl 64, id 38301, offset 0, flags [DF], proto TCP (6), length 52)
    10.0.18.5.55618 > 10.0.17.2.3820: Flags [.], cksum 0xa7c1 (correct), seq 76855, ack 136668, win 497, options [nop,nop,TS val 669632607 ecr 224087792], length 0
08:45:48.965565 IP (tos 0x0, ttl 64, id 38302, offset 0, flags [DF], proto TCP (6), length 238)
    10.0.18.5.55618 > 10.0.17.2.3820: Flags [P.], cksum 0xdf9c (correct), seq 76855:77041, ack 136668, win 499, options [nop,nop,TS val 669695423 ecr 224087792], length 186
08:45:48.966448 IP (tos 0x0, ttl 64, id 3268, offset 0, flags [DF], proto TCP (6), length 89)
    10.0.17.2.3820 > 10.0.18.5.55618: Flags [P.], cksum 0x3752 (incorrect -> 0xe28f), seq 136668:136705, ack 77041, win 501, options [nop,nop,TS val 224150610 ecr 669695423], length 37
08:45:48.966520 IP (tos 0x0, ttl 64, id 3269, offset 0, flags [DF], proto TCP (6), length 345)
    10.0.17.2.3820 > 10.0.18.5.55618: Flags [P.], cksum 0x3852 (incorrect -> 0xbd0f), seq 136705:136998, ack 77041, win 501, options [nop,nop,TS val 224150610 ecr 669695423], length 293
08:45:48.966702 IP (tos 0x0, ttl 64, id 38303, offset 0, flags [DF], proto TCP (6), length 52)
    10.0.18.5.55618 > 10.0.17.2.3820: Flags [.], cksum 0xbc1b (correct), seq 77041, ack 136705, win 499, options [nop,nop,TS val 669695424 ecr 224150610], length 0
08:45:48.966962 IP (tos 0x0, ttl 64, id 38304, offset 0, flags [DF], proto TCP (6), length 52)
    10.0.18.5.55618 > 10.0.17.2.3820: Flags [.], cksum 0xbaf8 (correct), seq 77041, ack 136998, win 497, options [nop,nop,TS val 669695424 ecr 224150610], length 0

10.0.17.2 我的 GF 服务器在哪里。这是来自服务器的日志的结尾:

[2014-06-04T09:17:18.369+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=143 _ThreadName=Thread-8] [timeMillis: 1401859038369] [levelValue: 800] [[
  p: thread-pool-1; w: 2, WRITE: TLSv1 Application Data, length = 32]]
[2014-06-04T09:17:18.369+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=143 _ThreadName=Thread-8] [timeMillis: 1401859038369] [levelValue: 800] [[
  p: thread-pool-1; w: 2, WRITE: TLSv1 Application Data, length = 288]]
[2014-06-04T09:18:21.220+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=142 _ThreadName=Thread-8] [timeMillis: 1401859101220] [levelValue: 800] [[
  p: thread-pool-1; w: 1, READ: TLSv1 Application Data, length = 32]]
[2014-06-04T09:18:21.220+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=142 _ThreadName=Thread-8] [timeMillis: 1401859101220] [levelValue: 800] [[
  p: thread-pool-1; w: 1, READ: TLSv1 Application Data, length = 144]]
[2014-06-04T09:18:21.222+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=142 _ThreadName=Thread-8] [timeMillis: 1401859101222] [levelValue: 800] [[
  p: thread-pool-1; w: 1, WRITE: TLSv1 Application Data, length = 32]]
[2014-06-04T09:18:21.222+0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=142 _ThreadName=Thread-8] [timeMillis: 1401859101222] [levelValue: 800] [[
  p: thread-pool-1; w: 1, WRITE: TLSv1 Application Data, length = 288]]

我的意思是写、读、写、读等。 据我了解,如果它在同一主机上工作,则意味着客户端在某些时候连接到 127.0.0.1 3820。因此,有必要在设置中将其更改为真实服务器 ip。

【问题讨论】:

  • @Niemand 我读过这个问题。但它在那里尝试连接到正确的 IP。这里我不知道为什么客户端尝试连接到它的本地主机而不是服务器。
  • 你的 serverIp 变量中有什么?为什么是 hashtable 而不仅仅是 Properties 类?
  • 正如我很久以前测试的那样,我将ORBInitialPort 设置为默认的 IIOP 端口,例如3700 并在调用 EJB 期间将重定向到 SSL 端口。
  • @Charlee Chitsuk 我的意思是我在客户端 javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection 上获得的 3700 端口。为什么GF不重定向到3820?

标签: java jakarta-ee ssl glassfish


【解决方案1】:

我自己解决了这个问题。在 linux 机器上,需要在 /etc/hosts 文件中设置服务器 IP。因为 glassfish 使用函数

InetAddress.getLocalHost()

获取服务器IP。我没有在这个文件中设置服务器 IP。这就是为什么在 ssl 协商期间,当建立新连接时 glassfish 会尝试打开到 127.0.0.1 而不是真实服务器 IP 的连接。

【讨论】:

    猜你喜欢
    • 2014-06-07
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多