gpt4 book ai didi

java - 从进程列表中隐藏 keystore 密码

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:40 25 4
gpt4 key购买 nike

我有一个 Linux 服务器和一个 Java 应用程序。我正在使用 Java 1.7 来运行这个应用程序。我想启用 JMX 以进行监控。 JMX 连接应由 SSL 保护。到目前为止很容易。

我的问题:如何以安全的方式告诉 jvm keystore 密码?到目前为止,只有当我通过命令行参数“-Djavax.net.ssl.keyStorePassword=mypwd”传递密码时,ssl 连接才有效。似乎必须在初始化 jvm 时设置密码。

如果我在控制台上查看进程列表 (ps -ef),我可以看到我的 java 进程 - 但包含所有命令行参数。所以我的 keystore 密码以明文形式列出给每个可以列出 Activity 进程的人(例如通过 snmp 代理)。如何从进程列表中隐藏密码?

我尝试使用配置文件 (com.sun.management.config.file)。它适用于所有 jmx 特定参数。但是我的密码被忽略了。

在命令行参数中以纯文本形式提供密码真的是唯一的方法吗?

是的——我知道 Java 1.7 已停止服务。如果 Java 1.8 确实解决了这个问题,我会立即更改。

感谢您的帮助!

最佳答案

如果您在 System.setProperty("javax.net.ssl.keyStorePassword", "mypwd") 您使用程序中的任何 SSL 功能之前这样做应该管用。这意味着您应该尽可能在调用 main 之后尽早设置它。如果愿意,您可以在之前加载自己的属性文件(只能由运行 JVM 的用户读取),其中可以存储密码。


更新

管理所需的系统属性也可以在配置文件中设置。来自 Monitoring and Management Using JMX Technology :

You can set out-of-the-box monitoring and management properties in a configuration file or on the command line. Properties specified on the command line override properties in a configuration file. The default location for the configuration file is JRE_HOME/lib/management/management.properties. The Java VM reads this file if either of the command-line properties com.sun.management.jmxremote or com.sun.management.jmxremote.port are set.

本文档适用于 Java 1.8,但我想这同样适用于 Java 1.7。如果不是,我猜你必须按照你的建议进行切换。

关于java - 从进程列表中隐藏 keystore 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32011428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com