将 SSL 证书导入 Eclipse

发布于 2024-07-16 00:28:30 字数 38 浏览 8 评论 0原文

如何将java创建的SSL证书导入到Eclipse中的项目中?

How do you import an SSL certificate created by java into a project in Eclipse?

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

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

发布评论

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

评论(8

横笛休吹塞上声 2024-07-23 00:28:30

如果您的 Windows 证书存储中已有该证书(这在使用 MITM 证书的公司/公司部署中很常见),您还可以使用以下步骤(在 另一个带有更详细解释的 Stackoverflow 答案):

  1. 在 Eclipse 安装中找到 eclipse.ini 文件并打开它

  2. -vmargs 行下方,添加以下行,然后保存文件:

-Djavax.net.ssl.trustStore=NUL
-Djavax.net.ssl.trustStoreType=Windows-ROOT 
  1. 重新启动 eclipse。

In case you have the certificate already in your Windows' certificate store (this is common in corporate/company deployments with MITM certificates), you can also use the following steps (with help from another Stackoverflow answer with more detailed explaination):

  1. Locate the eclipse.ini file in your Eclipse installation and open it

  2. Below the line -vmargs, add the following lines, then save the file:

-Djavax.net.ssl.trustStore=NUL
-Djavax.net.ssl.trustStoreType=Windows-ROOT 
  1. Restart eclipse.
十六岁半 2024-07-23 00:28:30

您可能希望在 JRE 的 trustcacerts 中导入“假”SSL 证书,以避免证书无效的问题。 不是吗?

正如乔恩所说,您可以使用 keytool:

keytool
    -import
    -alias <provide_an_alias>
    -file <certificate_file>
    -keystore <your_path_to_jre>/lib/security/cacerts

在询问时使用“changeit”作为默认密码(感谢 Brian Clozel)。 确保在您的服务器或启动配置中使用此运行时。

Probably you want to import a "fake" SSL cert in JRE's trustcacerts for avoiding not-a-valid-certificate issues. Isn't it?

As Jon said, you can do the job with keytool:

keytool
    -import
    -alias <provide_an_alias>
    -file <certificate_file>
    -keystore <your_path_to_jre>/lib/security/cacerts

Use "changeit" as the default password when asked (thanks Brian Clozel). Ensure to use this runtime at your server or launch configuration.

想你的星星会说话 2024-07-23 00:28:30

有一个更好的工具可以完成这项工作。

KeyStore Explorer

当您运行时(在 Windows 中以管理员身份运行以便保存对系统的更改), sudo linux等)应用程序(它有win / mac / linux的安装程序)有一个内置功能可以编辑系统的cacerts文件:

文件->; 开放特价 -> 打开 CA 证书

打开CA证书

只要你已经有了证书文件,你可以进入:

工具->CA 导入可信证书

或者您需要从服务器下载证书; 转到:

检查-> 检查 SSL

检查菜单

Examine SSL

从那里输入主机名,然后单击“确定”。 它将弹出一个窗口,显示证书详细信息。 该窗口底部有一个“导入”按钮,可让您直接将其导入到 cacerts 中。

证书详细信息SSL 连接

确保保存并关闭 cacerts,然后重新启动 eclipse/应用程序以使设置生效。

There's a better tool for the job.

KeyStore Explorer

When you run (run as administrator in windows in order to save changes to system, sudo in linux, etc.) the application (it has installers for win/mac/linux) there's a built-in function to edit the system's cacerts file:

File -> Open Special -> Open CA Certificates

Open CA Certificates

EITHER you already have the certificate file and you can go to:

Tools -> Import Trusted Certificate

OR you need to download the certificate from the server; go to:

Examine -> Examine SSL

Examine menu

Examine SSL

From there type in the hostname and click ok. It will pop up a window showing the certificate details. At the bottom of that window there's an "Import" button that will allow you to directly import it into the cacerts.

Certificate Details for SSL Connection

Make sure you save and close cacerts, and restart your eclipse/application for the settings to take effect.

帅哥哥的热头脑 2024-07-23 00:28:30

Mac

  1. 打开 Keychain Access.app (快捷键:按 Command + 空格键并输入 Keychain)
  2. 搜索所需的证书文件(例如 example.cer)并右键单击 ➡️ 选择 导出... ➡️ 将其保存到某个位置,例如桌面
  3. 按照此答案中的说明将其导入到您的 Java 证书存储中。 重要的命令是:
cd $JAVA_HOME/lib/security
sudo cp cacerts cacerts.bak
sudo keytool -importcert -alias youralias -file ~/Desktop/example.cer -keystore cacerts

密钥库的默认密码是:changeit

  1. 假设 $JAVA_HOME/lib/security 指向系统中的 /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/lib/security,添加eclipse.ini 文件中包含以下几行:
-Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/lib/security/cacerts
-Djavax.net.ssl.trustStorePassword=changeit

注意: 如果您使用的是 STS,请按照 此答案 找到 .ini 文件。

  1. 重新启动 Eclipse。

Mac

  1. Open Keychain Access.app (Shortcut: press Command + Spacebar and type Keychain)
  2. Search the desired certificate file (e.g. example.cer) and right-click ➡️ Select Export... ➡️ Save it to some location e.g. Desktop.
  3. Follow the instructions in this answer to import it to your Java certificate store. The important commands are:
cd $JAVA_HOME/lib/security
sudo cp cacerts cacerts.bak
sudo keytool -importcert -alias youralias -file ~/Desktop/example.cer -keystore cacerts

The default password of the keystore is: changeit.

  1. Assuming, $JAVA_HOME/lib/security points to /Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/lib/security in your system, add the following lines in the eclipse.ini file:
-Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/adoptopenjdk-15.jdk/Contents/Home/lib/security/cacerts
-Djavax.net.ssl.trustStorePassword=changeit

Note: If you are using STS, follow this answer to locate the .ini file.

  1. Restart Eclipse.
悲念泪 2024-07-23 00:28:30

我们需要导入证书意味着我们需要使用:

keytool 
 -importcert 
 -file <certificate_location> 
 -keystore <jre_location\lib\security\cacerts> 
 -alias "<cert_name>"

它将要求输入密码。 输入密码 changeit

Type Password : changeit

最后它会询问是否需要添加 {yes/no} :

输入 yes。

注意:位置路径中不要留有空格

We need to import a certificate means we need to use :

keytool 
 -importcert 
 -file <certificate_location> 
 -keystore <jre_location\lib\security\cacerts> 
 -alias "<cert_name>"

It will ask for a password. Type the password as changeit

Type Password : changeit

finally it will ask need to add {yes/no} :

type yes.

Note: Don't give blank space in location path

终难遇 2024-07-23 00:28:30

如果您有默认 Java 设置并提供了 Java 类路径,那么您必须使用 Java Truststore 来获取 SSL 证书。

为此,您可以按照以下步骤将证书导入信任存储区:

  1. 导航到 Java 设置的 JRE\bin 文件夹
    理想情况下,路径应该是:

用户\Java\jre1.8.0_221\bin

  1. 您将能够在 bin 文件夹中找到 Keytool(将用于运行命令):

定位 Keytool 的路径

  1. 现在,一旦您位于此路径上,请在 CMD 提示符中打开该路径:

CMD 中的 Bin 文件夹

  1. 现在您将能够在以下路径中找到 Java 的默认信任存储:
    小路-

用户\Java\jre1.8.0_221\bin

Java 默认信任存储的路径

  1. 现在您可以运行以下命令来查看此信任存储的内容:

    keytool -list -v -keystore "C:\Program Files\Java\jre1.8.0_221\lib\security\cacerts"

注意:如果信任存储的路径中有空格,则需要在路径中使用双引号。 否则,您可以提供如下路径:

keytool -list -v -keystore C:\Temp\Java\jre1.8.0_221\lib\security\cacerts

现在只需向信任存储提供密码(默认密码是:changeit):
使用 Keytool 访问信任存储

  1. 您现在可以根据需要将任何证书添加到信任商店:

    JRE_HOME/bin/keytool -import -trustcacerts
    -alias certAlias -file certFile
    -keystore trustStoreFile

If you have default Java setup and have provided Java classpath, then you must be using Java Truststore for SSL certificates.

For this you can follow below steps to import certificates into Trust store:

  1. Navigate to the JRE\bin folder of your Java setup
    Ideally the path should be:

user\Java\jre1.8.0_221\bin

  1. You will be able to find Keytool in the bin folder(which will be used to run the commands):

Path to locate Keytool

  1. Now once you are on this path, open the path in your CMD prompt:

Bin folder in CMD

  1. Now you will be able to find default Trust store of Java at below path:
    Path-

user\Java\jre1.8.0_221\bin

Path to Java default Trust store

  1. Now you can run below command to see contents of this Trust store:

    keytool -list -v -keystore "C:\Program Files\Java\jre1.8.0_221\lib\security\cacerts"

Note: If your path to Trust store has spaces in it, then you need to use double quotes for the path. Else you can provide path like below:

keytool -list -v -keystore C:\Temp\Java\jre1.8.0_221\lib\security\cacerts

Now just provide password to Trust Store(Default password is: changeit):
Accessing Trust store using Keytool

  1. You can now as per your need add any certificate to the Trust store:

    JRE_HOME/bin/keytool -import -trustcacerts
    -alias certAlias -file certFile
    -keystore trustStoreFile

长梦不多时 2024-07-23 00:28:30

您可能应该创建证书并使用 keytool 将其导入默认密钥库。 我不确定您想对您的应用程序执行什么操作,但它应该能够使用该证书。

You should probably create the certificate and import it into the default keystore using keytool. I'm not sure what you're trying to do with your application, but it should then be able to use that certificate.

奈何桥上唱咆哮 2024-07-23 00:28:30
sudo  keytool -import  -file /Users/balaji-pt2176/Desktop/Apple\ Worldwide\ Developer\ Relations\ Certification\ Authority.cer  -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/security/cacerts

在苹果电脑中

sudo  keytool -import  -file /Users/balaji-pt2176/Desktop/Apple\ Worldwide\ Developer\ Relations\ Certification\ Authority.cer  -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/security/cacerts

in mac

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