RMI 导出对象中的客户端套接字工厂?
如果您想为 RMI 使用自定义套接字(例如使用 SSL),请在 UnicastRemoteObject.exportObject(4) 您需要指定客户端套接字工厂和服务器套接字工厂。但对象的导出是在服务器端完成的。为什么需要客户端套接字工厂?
除非...它被序列化并由想要获取与该对象的连接的客户端使用?我发现这不太可能(尽管这可能是答案); (SSL) 对我来说,套接字工厂听起来不像可序列化对象的经典示例,其中密钥库是本地的,等等。
If you want to use custom sockets for RMI (e.g. using SSL), in UnicastRemoteObject.exportObject(4) you need to specify a client socket factory as well as a server socket factory. But the exporting of objects is done on the server side. Why is the client socket factory necessary?
Unless...it's serialized and used by client wanting to acquire a connection to that object? I find that unlikely (though it may be the answer); (SSL) Socket factories don't sound like classic examples of serializable objects to me, with keystores being local, and things like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,就像您在问题中所说的那样:
RMIClientSocketFactory 必须是可序列化的,并且与
exportObject 一起使用时将序列化到客户端另一端
code> 或 UnicastRemoteObject 的构造函数。
这意味着它不能包含对不可序列化对象的(非瞬态)引用,而只能包含动态创建套接字所需的信息。
(我最近发布了RMISocketFactory的示例,我需要请注意可序列化。)
编辑(在 EJP 的评论之后):
当然,这仅适用于如果您需要使用根本就是一个客户端套接字工厂。在许多情况下,您只需使用其他
exportObject
方法(或其他构造函数),然后在服务器端使用默认服务器套接字工厂,在客户端使用默认客户端套接字工厂,而无需序列化任何东西。是的,将服务器的信任存储序列化到客户端是没有意义的 - 如果客户端必须信任注册表或接受证书的其他远程对象,那么我们就有了中间人攻击的意义。因此 SslRMIClientSocketFactory虽然可序列化,但不会序列化服务器的 SSL 上下文,而只是使用客户端 VM 的 SSL 设置。
Yes, just like you said already in the question:
An RMIClientSocketFactory must be serializable, and will be serialized to the client other side, when used with
exportObject
or UnicastRemoteObject's constructor.This means that it must not contain (non-transient) references to objects which are non-serializable, only the necessary information to create a socket on the fly.
(I recently posted an example for a RMISocketFactory, where I needed to take care to be serializable.)
Edit (after the comment from EJP):
Of course, this only applies if you need to use a client socket factory at all. In many circumstances, you simply can use the other
exportObject
methods (or other constructors), which then use the default server socket factory on the server side, and the default client socket factory at the client side, without serializing anything.And yes, there is no point of serializing the server's trust store to the client - if the client has to trust the registry or other remote objects for which certificates to accept, we have the point for a man-in-the-middle attack. Thus SslRMIClientSocketFactory, while being Serializable, does not serialize the server's SSL context, but simply uses the client VM's SSL settings.
仅当您使用 exportObject() 的重载时,即使如此您也可以提供 null。还有另一种重载,您只需指定端口号。
事实并非如此。
正确的。
事实并非如此。
Only if you use that overload of exportObject(), and even then you can supply a null. There is another overload where you only have to specify the port number.
It isn't.
Correct.
It isn't.