linux下keytool生成证书_在Linux浏览器(或Linux命令行)中为Java证书信任库导出SSL证书...

本文围绕在Linux下使用ColdFusion 9消费Web服务时遇到的证书问题展开。介绍了在Chrome浏览器及Linux CLI中导出证书的方法,包括选择合适的导出级别和格式,还给出了使用keytool导入证书的命令,同时提供了不借助浏览器,通过openssl s_client获取证书的脚本。

Background:

I am having some trouble consuming a Web Service with ColdFusion 9 (peer not authenticated).

But my questions are more specific...

Question:

How do I export the cert (at the right level) in Chrome (or Linux CLI), and in which format?

Details

I have seen some instructions for exporting a cert from a browser, but they have been for IE (old versions, at that), and I would prefer to use Chrome, because I'm on Linux.

In order to get to the screen shot, below, I:

Click the lock icon next to the URL

"Connection" tab (shows "The identity of this website has been verified by Thawte SSL CA")

Click "Certificate Information Link"

"Details" tab

From there, I am able to export at one of four levels:

Builtin Object Token:Thawte Premium Server CA

thawte Primary Root CA

Thawte SSL CA

sb1.geolearning.com

Which one is appropriate?

Also, Adobe's documentation says "The certificate must be an X.509 certificate in Distinguished Encoding Rules (DER) format.", and Chrome's export dialog offers these options:

Base64-encoded ASCII, single certificate

Base64-encoded ASCII, certificate chain

DER-encoded binary, single certificate

PKCS #7, single certificate

PKCS #7, certificate chain

All Files

I assume "DER-encoded binary, single certificate" is appropriate?

解决方案

With a Browser

The following generated a certificate that I was able to import using keytool:

Level: sb1.geolearning.com

File Type: DER-encoded binary, single certificate

For posterity, here was the command used to import:

sudo keytool -import -keystore /opt/jrun4/jre/lib/security/cacerts -alias "sb1.geolearning.com (Thawte SSL CA)" -storepass changeit -noprompt -trustcacerts -file ~/Downloads/sb1.geolearning.com

Without a Browser

Here's what I'm doing these days (in a Vagrant provisioner). In this script, the keystore is hard-coded, because I'm only using it for Lucee, at the moment; however, the path the the keystore could easily be parameterized. Also, the runfile related code is just so Vagrant doesn't run the script more than once; those lines are superfluous if you're not using the code as a Vagrant provisioner.

The only thing that really differentiates this from the above solution is that this gets the cert via openssl s_client (and cleans it up with sed) instead doing so manually, via a browser.

#!/usr/bin/env bash

set -e

description="Add cert to Lucee's keystore."

while :

do

case $1 in

--provisioned-dir=*)

provisioned_dir=${1#*=} # Delete everything up till "="

shift

;;

--runfile-name=*)

runfile_name=${1#*=} # Delete everything up till "="

shift

;;

--site-host-name=*)

site_host_name=${1#*=} # Delete everything up till "="

shift

;;

-*)

echo "WARN: Unknown option (ignored): $1" >&2

shift

;;

*) # no more options. Stop while loop

break

;;

esac

done

runfile="${provisioned_dir}/${runfile_name}"

if [ -f "${runfile}" ]; then

echo "${description}: Already run."

exit 0

fi

echo "add cert to keystore"

echo -n | \

openssl s_client -connect ${site_host_name}:443 \

| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \

> /tmp/${site_host_name}.cert

/opt/lucee/jdk/jre/bin/keytool \

-import \

-keystore /opt/lucee/lib/lucee-server/context/security/cacerts \

-alias "${site_host_name} (self-signed)" \

-storepass changeit \

-file /tmp/${site_host_name}.cert \

-noprompt \

|| true

touch "${runfile}"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值