【问题标题】:How to avoid /dev/urandom when using keytool使用 keytool 时如何避免 /dev/urandom
【发布时间】:2014-06-12 01:28:31
【问题描述】:

我们在 Linux、Solaris 和 AIX 平台上使用 tomcat、weblogic、websphere、apache(基本上是 java)。对于加密,我们使用 SSL。要生成私钥/公钥对,我们使用 keytool。有关 java keytool 的文章建议我们避免使用 /dev/urandom 作为熵设备。鉴于 /dev/urandom 是默认设置,我们如何在不使用 /dev/urandom 的情况下创建私钥/公钥对?

【问题讨论】:

  • 这些文章的任何指针?

标签: ssl keytool


【解决方案1】:

感兴趣的文件位于您的 JRE lib/security 文件夹中,名为 java.security。在里面你会发现下面一行:

securerandom.source=file:/dev/urandom

文件中有描述其行为的 cmets。如果您需要,您可以将其切换为使用/dev/random(这更安全,但由于熵问题可能需要很长时间):

#
# Select the source of seed data for SecureRandom. By default an
# attempt is made to use the entropy gathering device specified by 
# the securerandom.source property. If an exception occurs when
# accessing the URL then the traditional system/thread activity 
# algorithm is used. 
#
# On Solaris and Linux systems, if file:/dev/urandom is specified and it
# exists, a special SecureRandom implementation is activated by default.
# This "NativePRNG" reads random bytes directly from /dev/urandom.
#
# On Windows systems, the URLs file:/dev/random and file:/dev/urandom
# enables use of the Microsoft CryptoAPI seed functionality.
#
securerandom.source=file:/dev/urandom
#
# The entropy gathering device is described as a URL and can also
# be specified with the system property "java.security.egd". For example,
#   -Djava.security.egd=file:/dev/urandom
# Specifying this system property will override the securerandom.source 
# setting.

你可以看到更多关于Java policy files here in the Oracle docs

这里还有一个关于overriding default Java security 的简短教程

【讨论】: