`
wx634200
  • 浏览: 5059 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Keytool cacert extraction

阅读更多

Sometimes you need to have a PEM format CA certificate available for trust verification in certain apps like postfix or apache. If

you have java installed, you most likely have a cacerts file that came with it. Mine is in

/usr/java/j2re1.4.2_07/lib/security/cacerts

Problem is, the cacerts file is a JKS keystore, stored in a format unreadable to non-java applications. So I will show how to use

keytool and openssl to extract and convert a single CA certificate (alias verisignserverca) to PEM format, which CAN usually be

read.

First, figure out which ca certificate you need. This is usually a matter of identifying the subject (also called DN or

distinguished name) of the issuers certificate. In my case the subject was unknown... all I had was a message in the postfix log

saying:

May 13 22:10:02 localhost postfix/smtp[22102]: setting up TLS connection to smtp.comcast.net
May 13 22:10:02 localhost postfix/smtp[22102]: verify error:num=19:self signed certificate in certificate chain
May 13 22:10:02 localhost postfix/smtp[22102]: Peer certificate could not be verified

Since the connection was clearly to smtp.comcast.net, I use openssl to get the issuer.

openssl s_client -connect smtp.comcast.net:25 -starttls smtp

The relevant output is in the Certificate chain section of the output. I see this;

0 s:/C=US/ST=New Jersey/L=Middletown/O=AT&T/OU=for Comcast/CN=smtp.comcast.net
  i:/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
1 s:/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
  i:/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority <-- Issuing Certificate Authority!!

I want to find the corresponding certificate in the cacerts keystore so as to get the alias used.

keytool -keystore /usr/java/j2re1.4.2_07/lib/security/cacerts -v -list

The password is normally blank so just press enter...or try "changeme". Look for the corresponding certificate. Hint: Alot of output

so redirect to a file or pipe to less.

Alias name: verisignserverca <-- This is what we need for extraction
Creation date: Jun 29, 1998
Entry type: trustedCertEntry

Owner: OU=Secure Server Certification Authority, O="RSA Data Security, Inc.", C=US
Issuer: OU=Secure Server Certification Authority, O="RSA Data Security, Inc.", C=US
Serial number: 2ad667e4e45fe5e576f3c98195eddc0
Valid from: Tue Nov 08 16:00:00 PST 1994 until: Thu Jan 07 15:59:59 PST 2010
Certificate fingerprints:
         MD5:  74:7B:82:03:43:F0:00:9E:6B:B3:EC:47:BF:85:A5:93
         SHA1: 44:63:C5:31:D7:CC:C1:00:67:94:61:2B:B6:56:D3:BF:82:57:84:6F

Once the alias has been identified we can do the extraction.

keytool -keystore /usr/java/j2re1.4.2_07/lib/security/cacerts -export -alias verisignserverca > /tmp/verisign.cacert

The result is a DER (binary) formatted certificate in /tmp/verisign.cacert. It can be viewed using:

openssl x509 -noout -text -in /tmp/verisign.cacert -inform der

You will want to convert it to another format - PEM - which is more widely used in applications such as apache and postfix.

openssl x509 -out /tmp/verisign-cacert.pem -outform pem -text -in /tmp/verisign.cacert -inform der

The resulting file can now be referenced from apache, postfix, etc as the CA certificate.
Important update! 2005-May-20

It appears there is a much easier way to do this, as usual the openssl toolkit is the solution. By running the following command,

the PEM format certificate chain will be displayed on STDOUT.

openssl s_client -connect smtp.comcast.net:25 -starttls smtp -showcerts

The last certificate in the chain is the CA (issuer) cert. This can be pasted into a text file and named according to the output of

the openssl hash command (see above).


Extracting a PEM certificate from .jks file in one command

This can be done by using the -rfc flag which will cause the key to be printed in a readable form. So the original command:

keytool -keystore /usr/java/j2re1.4.2_07/lib/security/cacerts -export -alias verisignserverca > /tmp/verisign.cacert

becomes

keytool -keystore /usr/java/j2re1.4.2_07/lib/security/cacerts -export -alias verisignserverca -rfc -file /tmp/verisign.cacert

Also notice that the -file option can be used instead of a redirect.

Finally, you can use the -storepass option to specify the password on the command line. While this is potentially a violation of

security the convenience usually outweighs the remote possibility of someone capturing the command line before it completes. The

final command would be:

keytool -keystore /usr/java/j2re1.4.2_07/lib/security/cacerts -export -alias verisignserverca -rfc -file /tmp/verisign.cacert -

storepass changeme

记录点东东~!
分享到:
评论

相关推荐

    keytool图形化工具

    `KeyToolGui` 是一个用于管理数字证书的图形化工具,它基于Java的命令行工具`keytool`进行扩展,为用户提供了一个更加友好的界面来执行各种与密钥和证书相关的操作。在Java开发和部署环境中,尤其是在涉及到SSL/TLS...

    密钥管理工具 Keytool-IUI

    证书是一种电子文档,用于证明公钥的所有权,通常由可信任的证书颁发机构(CA)签名。 2. **Keytool命令行工具**:Keytool是Java的标准工具,用于生成、存储、导出、导入和管理密钥对及证书。它可以创建Keystore,...

    Keytool与数字证书

    ### Keytool与数字证书 #### 一、Keytool简介及基本操作 **Keytool** 是 Java 开发工具包(JDK)中的一个实用程序,用于管理密钥库(key stores),其中包括私钥(private keys)及其对应的公钥证书(public key ...

    KeyTool_GUI

    3. **证书请求**:KeyTool可以创建证书请求(CSR,Certificate Signing Request),然后发送给证书颁发机构(CA)以获取签名的数字证书。 4. **信任锚点**:KeyTool也用于管理信任存储,其中包含了被系统信任的根...

    keytool-importkeypair.zip

    keytool-importkeypair 是生成keystore的必须文件,可以用此工具放于目录文件夹下载,和系统的 platform.pk8 platform.x509.pem 以及signapk.jar 生成签名文件,让软件编译的时候就有系统签名

    KeyTool1.6.zip

    KeyTool1.6,数字证书工具、服务器证书管理工具。用于数字证书私钥公钥管理。可新增私钥文件。,数字证书工具、

    keytool证书制作工具

    - 配置Tomcat服务器:在部署Web应用时,使用`keytool`生成自签名证书或导入CA签发的证书,以实现HTTPS连接。 - 安卓应用签名:开发者使用`keytool`为APK文件生成签名,确保应用的发布和更新安全。 6. **安全性...

    证书工具KeyTool1.6

    6. **信任管理**:KeyTool可以帮助管理信任的CA证书,这些证书被存放在“Truststore”中,用于验证远程服务器的证书。 7. **密钥别名**:在Keystore中,每个密钥对都有一个唯一的别名,通过别名可以方便地引用和...

    keytoolgui

    keytoolGUI可以帮助你管理信任的CA(证书颁发机构)证书,以及构建和验证证书链。 6. **自签名证书**:对于测试环境,可以自签证书,即用自己的私钥为自己的公钥签名。keytoolGUI提供了简便的步骤来完成这个过程。 ...

    java keytool使用例子

    Java Keytool是Java开发工具包(JDK)中自带的一个命令行工具,主要用于管理数字证书、密钥对以及信任库。这个工具对于开发者和系统管理员来说非常重要,因为它们在进行安全通信,尤其是HTTPS、SSL/TLS连接时起着...

    KeyTool

    - **数字证书**:数字证书是一个包含公钥、发行者信息、主体信息以及证书有效期等的文件,通常由证书颁发机构(CA)签署。它用于证明公钥持有者的身份。 - **PKI(公钥基础设施)**:是一套管理和验证公钥系统安全...

    KeyTool 工具生成X.509证书

    3. **签署证书**:将CSR提交给证书颁发机构(CA),他们将验证信息并返回签署的证书。 4. **导入证书**:收到签署的证书后,使用`keytool -importcert`将其导入到Keystore中。 5. **配置应用程序**:最后,配置你的...

    基于java的开发源码-密钥管理工具 Keytool-IUI.zip

    3. 证书操作:源码会涉及证书的导入、导出,以及处理自签名证书和从证书颁发机构(CA)获取的证书。 4. 证书链处理:在某些情况下,一个证书可能依赖于其他证书来建立信任链,源码需要能正确处理这种情况。 5. 密钥和...

    KeyTool.GUI.1.6 证书密钥查看生成工具

    - **数字证书**:证书是一种电子文档,包含公钥和发行者的身份信息,由受信任的第三方(称为证书颁发机构,CA)进行签名。它验证了公钥持有者的身份,确保通信方能信任该公钥。 - **密钥对**:由公钥和私钥组成,...

    keytool_gui

    4. **信任链管理**:使用 `keytool -trustcacerts` 和 `-import` 命令可以管理信任的证书颁发机构(CA)。 5. **验证证书**:`keytool -verify` 命令可以验证证书的有效性。 6. **密钥库操作**:包括修改密钥库...

    keytool查询apk证书指纹.zip

    `keytool`是Java开发工具包(JDK)中提供的一个命令行工具,用于管理和创建密钥对以及数字证书,包括查询APK的签名信息。本篇将详细讲解如何使用`keytool`来查询APK的证书指纹,包括MD5、SHA1和SHA256等安全摘要算法...

    keytool生成公私钥,默认jdk8 使用keytool生成bks或者jks时报错,缺少jar包

    keytool生成公私钥,默认jdk8 使用keytool生成bks或者jks时报错,缺少jar包 包含:bcprov-jdk15-143.jar,local_policy.jar,US_export_policy.jar

    keytool 加密证书制作

    标题中的“keytool 加密证书制作”指的是使用Java自带的工具——keytool,来创建和管理数字证书。这个过程涉及到网络安全、加密技术和PKI(Public Key Infrastructure,公钥基础设施)等概念。 首先,理解keytool的...

    Android签名工具(keytool)

    keytool -genkey -alias ChangeBackgroundWid get.keystore -keyalg RSA -validity 20000 -eystore ChangeBackgroundWidget.keystore 上面的命令中间不换行,按下“Enter”键,并根据提示填写相关信息,详细信息如下...

    keytool建立双向认证

    keytool -gencert -alias server-ca -validity 365 -keystore server-ca.keystore -file client.crt -in client.csr ``` - `-validity` 指定证书的有效期,单位为天。 4. **导入证书** - 将服务器的证书导入到...

Global site tag (gtag.js) - Google Analytics