如何找出我的 JVM 使用的密钥库?

发布于 2024-12-29 02:45:26 字数 257 浏览 3 评论 0原文

我需要将证书导入到我的 JVM 密钥库中。我正在使用以下内容:

keytool -import -alias daldap -file somecert.cer

所以我可能需要将我的呼叫更改为类似以下内容:

keytool -import -alias daldap -file somecert.cer -keystore cacerts –storepass changeit

I need to import a certificate into my JVM keystore. I am using the following:

keytool -import -alias daldap -file somecert.cer

so I would need to probably change my call into something like:

keytool -import -alias daldap -file somecert.cer -keystore cacerts –storepass changeit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

风蛊 2025-01-05 02:45:26

您的密钥库将位于您的 JAVA_HOME--->;库--->安全--> cacerts。您需要检查 JAVA_HOME 的配置位置,可能是这些位置之一,

  1. 计算机--->高级 -->环境变量---> JAVA_HOME

  2. 您的服务器启动批处理文件。

在导入命令 -keystore cacerts 中(此处给出上述 JRE 的完整路径,而不仅仅是说 cacerts)。

Your keystore will be in your JAVA_HOME---> lib---> security--> cacerts. You need to check where your JAVA_HOME is configured, possibly one of these places,

  1. Computer--->Advanced --> Environment variables---> JAVA_HOME

  2. Your server startup batch files.

In your import command -keystore cacerts (give full path to the above JRE here instead of just saying cacerts).

愛放△進行李 2025-01-05 02:45:26

密钥库位置

每个 keytool 命令都有一个 -keystore 选项,用于指定 keytool 管理的密钥库的持久密钥库文件的名称和位置。默认情况下,密钥库存储在用户主目录中名为 .keystore 的文件中,该文件由“user.home”系统属性确定。给定用户名 uName,“user.home”属性值默认为

C:\Users\uName on Windows 7 systems
C:\Winnt\Profiles\uName on multi-user Windows NT systems
C:\Windows\Profiles\uName on multi-user Windows 95 systems
C:\Windows on single-user Windows 95 systems

因此,如果用户名为“cathy”,“user.home”默认为

C:\Users\cathy on Windows 7 systems
C:\Winnt\Profiles\cathy on multi-user Windows NT systems
C:\Windows\Profiles\cathy on multi-user Windows 95 systems

https://docs.oracle.com/en/java/javase/17/docs/specs/man/keytool.html#importing-a-certificate-for-the-ca

Keystore Location

Each keytool command has a -keystore option for specifying the name and location of the persistent keystore file for the keystore managed by keytool. The keystore is by default stored in a file named .keystore in the user's home directory, as determined by the "user.home" system property. Given user name uName, the "user.home" property value defaults to

C:\Users\uName on Windows 7 systems
C:\Winnt\Profiles\uName on multi-user Windows NT systems
C:\Windows\Profiles\uName on multi-user Windows 95 systems
C:\Windows on single-user Windows 95 systems

Thus, if the user name is "cathy", "user.home" defaults to

C:\Users\cathy on Windows 7 systems
C:\Winnt\Profiles\cathy on multi-user Windows NT systems
C:\Windows\Profiles\cathy on multi-user Windows 95 systems

https://docs.oracle.com/en/java/javase/17/docs/specs/man/keytool.html#importing-a-certificate-for-the-ca

诗笺 2025-01-05 02:45:26

Mac OS X 10.12 和 Java 1.8:

$JAVA_HOME/jre/lib/security

cd $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

从那里开始:

./jre/lib/security

我在那里有一个 cacerts 密钥库。

要将其指定为 VM 选项:

-Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/security/cacerts -Djavax.net.ssl.trustStorePassword=changeit

我并不是说这是正确的方法(为什么 java 不知道在 JAVA_HOME 中查找?),但这是我必须做的才能使其正常工作。

Mac OS X 10.12 with Java 1.8:

$JAVA_HOME/jre/lib/security

cd $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

From there it's in:

./jre/lib/security

I have a cacerts keystore in there.

To specify this as a VM option:

-Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/security/cacerts -Djavax.net.ssl.trustStorePassword=changeit

I'm not saying this is the correct way (Why doesn't java know to look within JAVA_HOME?), but this is what I had to do to get it working.

晨曦慕雪 2025-01-05 02:45:26

您可以在“Home”目录中找到它:

在 Windows 7 上:

C:\Users\<YOUR_ACCOUNT>\.keystore

在 Linux (Ubuntu) 上:

/home/<YOUR_ACCOUNT>/.keystore

You can find it in your "Home" directory:

On Windows 7:

C:\Users\<YOUR_ACCOUNT>\.keystore

On Linux (Ubuntu):

/home/<YOUR_ACCOUNT>/.keystore
一抹淡然 2025-01-05 02:45:26

这对我有用:

#! /bin/bash

CACERTS=$(readlink -e $(dirname $(readlink -e $(which keytool)))/../lib/security/cacerts)

if keytool -list -keystore $CACERTS -storepass changeit > /dev/null ; then
    echo $CACERTS
else
    echo 'Can not find cacerts file.' >&2
    exit 1
fi

仅适用于 Linux。我的 Solaris 没有阅读链接。最后我使用了这个 Perl 脚本:

#! /usr/bin/env perl
use strict;
use warnings;
use Cwd qw(realpath);
$_ = realpath((grep {-x && -f} map {"$_/keytool"} split(':', $ENV{PATH}))[0]);
die "Can not find keytool" unless defined $_;
my $keytool = $_;
print "Using '$keytool'.\n";
s/keytool$//;
$_ = realpath($_ . '../lib/security/cacerts');
die "Can not find cacerts" unless -f $_;
my $cacerts = $_;
print "Importing into '$cacerts'.\n";
`$keytool -list -keystore "$cacerts" -storepass changeit`;
die "Can not read key container" unless $? == 0;
exit if $ARGV[0] eq '-d';
foreach (@ARGV) {
    my $cert = $_;
    s/\.[^.]+$//;
    my $alias = $_;
    print "Importing '$cert' as '$alias'.\n";
    `keytool -importcert -file "$cert" -alias "$alias" -keystore "$cacerts" -storepass changeit`;
    warn "Can not import certificate: $?" unless $? == 0;
}

This works for me:

#! /bin/bash

CACERTS=$(readlink -e $(dirname $(readlink -e $(which keytool)))/../lib/security/cacerts)

if keytool -list -keystore $CACERTS -storepass changeit > /dev/null ; then
    echo $CACERTS
else
    echo 'Can not find cacerts file.' >&2
    exit 1
fi

Only for Linux. My Solaris has no readlink. In the end I used this Perl-Script:

#! /usr/bin/env perl
use strict;
use warnings;
use Cwd qw(realpath);
$_ = realpath((grep {-x && -f} map {"$_/keytool"} split(':', $ENV{PATH}))[0]);
die "Can not find keytool" unless defined $_;
my $keytool = $_;
print "Using '$keytool'.\n";
s/keytool$//;
$_ = realpath($_ . '../lib/security/cacerts');
die "Can not find cacerts" unless -f $_;
my $cacerts = $_;
print "Importing into '$cacerts'.\n";
`$keytool -list -keystore "$cacerts" -storepass changeit`;
die "Can not read key container" unless $? == 0;
exit if $ARGV[0] eq '-d';
foreach (@ARGV) {
    my $cert = $_;
    s/\.[^.]+$//;
    my $alias = $_;
    print "Importing '$cert' as '$alias'.\n";
    `keytool -importcert -file "$cert" -alias "$alias" -keystore "$cacerts" -storepass changeit`;
    warn "Can not import certificate: $?" unless $? == 0;
}
高跟鞋的旋律 2025-01-05 02:45:26

在 Debian 上,使用 openjdk 版本“1.8.0_212”,我在这里找到了 cacerts:

 /etc/ssl/certs/java/cacerts

如果有一个标准命令可以打印出此路径,那么当然会很方便。

On Debian, using openjdk version "1.8.0_212", I found cacerts here:

 /etc/ssl/certs/java/cacerts

Sure would be handy if there was a standard command that would print out this path.

So尛奶瓶 2025-01-05 02:45:26

正如 DimtryB 提到的,默认情况下密钥库位于用户目录下。但是,如果您尝试更新 cacerts 文件,以便 JVM 可以选择密钥,那么您必须更新 jre/lib 下的 cacerts 文件/安全。您还可以通过执行命令keytool -list -keystore cacerts来查看密钥,以查看您的证书是否已添加。

As DimtryB mentioned, by default the keystore is under the user directory. But if you are trying to update the cacerts file, so that the JVM can pick the keys, then you will have to update the cacerts file under jre/lib/security. You can also view the keys by executing the command keytool -list -keystore cacerts to see if your certificate is added.

若言繁花未落 2025-01-05 02:45:26

对于我使用官方 OpenJDK 12 Docker 映像来说,Java 密钥库的位置是:

/usr/java/openjdk-12/lib/security/cacerts

For me using the official OpenJDK 12 Docker image, the location of the Java keystore was:

/usr/java/openjdk-12/lib/security/cacerts
夏见 2025-01-05 02:45:26

我在 Ubuntu 20.04 上使用以下命令找到了 JVM 密钥库:

echo $JAVA_HOME/lib/security/cacerts

输出:

/usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts

此目录是指向以下内容的符号链接:

/etc/ssl/certs/java/cacerts

I found the JVM keystore using the following command on Ubuntu 20.04:

echo $JAVA_HOME/lib/security/cacerts

Output:

/usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts

This directory is a symbolic link to:

/etc/ssl/certs/java/cacerts
最舍不得你 2025-01-05 02:45:26

我们在从 jre 目录运行的 Tomcat 上遇到了此问题,该目录在自动 jre 更新后(几乎完全)被删除,因此运行的 jre 无法再找到 jre.../lib/security/cacerts,因为它不再存在。

重新启动 Tomcat(将配置更改为从不同的 jre 位置运行后)修复了该问题。

We encountered this issue on a Tomcat running from a jre directory that was (almost fully) removed after an automatic jre update, so that the running jre could no longer find jre.../lib/security/cacerts because it no longer existed.

Restarting Tomcat (after changing the configuration to run from the different jre location) fixed the problem.

起风了 2025-01-05 02:45:26

除了上面的所有答案之外:

如果更新 JRE 目录中的 cacerts 文件没有帮助,请尝试在 JDK 中更新它。

C:\Program Files\Java\jdk1.8.0_192\jre\lib\security

In addition to all answers above:

If updating the cacerts file in JRE directory doesn't help, try to update it in JDK.

C:\Program Files\Java\jdk1.8.0_192\jre\lib\security

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文