PS: keystore有自己的访问密码,这个保护层次要低一些,然后keystore里面存有自己的私钥,所以用户要破解的话,既要有keystore,又要有keystore的密码,p12是客户端keystore的一种形式,也需要密码去打开

第一步:为服务器生成证书
使用keytool为Tomcat生成证书,假定目标机器的域名是“localhost”,keystore文件存放在“E:\tomcat.keystore”,口令为“password”,使用如下命令生成

keytool -genkey -v -alias tomcat -keyalg RSA -keystore
tomcat.keystore -dname "CN=gavin-pc,OU=cn,o=cn,L=cn,ST=cn,C=cn"
-storepass changeit -keypass changeit

第二步:为客户端生成证书

下一步是为浏览器生成证书,以便让服务器来验证它。为了能将证书顺利导入至IE和Firefox,证书格式应该是PKCS12,因此,使用如下命令生成:

keytool -genkey -v -alias myKey -keyalg RSA -storetype PKCS12
-keystore my.p12 -dname "CN=MyKey,OU=cn,o=cn,L=cn,ST=cn,C=cn" -storepass
password1 -keypass

password2

第三步:让服务器信任客户端证书

由于是双向SSL认证,服务器必须要信任客户端证书,因此,必须把客户端证书添加为服务器的信任认证。由于不能直接将PKCS12格式的证书库导入,我们必须先把客户端证书导出

为一个单独的CER文件,使用如下命令:

keytool -export -alias myKey -keystore my.p12 -storetype PKCS12 -storepass password1 -rfc -file my.cer

通过以上命令,客户端证书就被我们导出到“C:\my.cer”文件了。下一步,是将该文件导入到服务器的证书库,添加为一个信任证书:

keytool -import -v -file my.cer -keystore tomcat.keystore -storepass changeit

最后:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

    maxThreads="150" scheme="https" secure="true"

    clientAuth="false" sslProtocol="TLS"

    keystoreFile="e:/tomcat.keystore" keystorePass="changeit"          -> comment: tomcat access keystore
    truststoreFile="e:/tomcat.keystore" truststorePass="changeit"     
-> comment: tomcat truststore
/>

验证:其中,clientAuth指定是否需要验证客户端证书,如果该设置为“false”,则为单向SSL验证,SSL配置可到此结束。如果clientAuth设置为“true”,表示强制双向SSL验证 
    <- comment: 单向认证是指服务器把证书发给客户端,客户端可以自由选择是否要验证,双向认证是指客户度也需要导入证书发给服务器去做验证

,必须验证客户端证书。如果clientAuth设置为“want”,则表示可以验证客户端证书,但如果客户端没有有效证书,也不强制验证。

true是 服务器不会颁发证书必须由客户端导入                                   -> comment: 证书导入使用

Here are example commands for generating your own Certificate Authority, and signing your own keys to distribute to end users. This tool may help as its graphical instead of command line: http://xca.sourceforge.net/

openssl req -newkey rsa:512 -nodes -out ca.csr -keyout ca.key

Fill in the questions. Use relevant data, but this information is only for you.

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:Texas
Locality Name (eg, city) []:Dallas
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CrushFTP
Organizational Unit Name (eg, section) []:Development
Common Name (eg, YOUR name) []:www.domain.com
Email Address []:ben@crushftp.com
A challenge password []:
An optional company name []:

Now we get our private key for signing.

openssl x509 -req -trustout -signkey ca.key -days 365 -req -in ca.csr -out ca.pem
echo "02" > ca.srl

And finally, we import the public key for our signing into our trust store so we can validate all signed keys user's submit. This files name "crush.keystore_trust" is specific. It must be in the same folder as the real keystore file for the server port, and must have the exact same name and password, except its name ends with "_trust". So in this case we expect to have a keystore named "crush.keystore".

keytool -import -alias crushftp_ca -keystore crush.keystore_trust -trustcacerts -file ca.pem -storepass password

Now from here on, we just generate new signed certs for your clients. The key part is to set their username to be "NOLOGIN_myuser" if you want to force them to still enter a user/pass. Otherwise if you set their common name to a valid username, they will be able to login without a user/pass.

openssl req -newkey rsa:512 -nodes -out myuser.req -keyout myuser.key

Fill in the information on this client's key you are building. Note that the Common Name must be the username of the client, or "NOLOGIN_" and anything else.

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:Texas
Locality Name (eg, city) []:Ft. Worth
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CrushFTP
Organizational Unit Name (eg, section) []:Development
Common Name (eg, YOUR name) []:myuser
Email Address []:ben@crushftp.com
A challenge password []:
An optional company name []:

Now we build the "myuser.p12" file that we need. This is what we will distribute to the end user for them to add to their browser to allow them access.

openssl x509 -CA ca.pem -CAkey ca.key -CAserial ca.srl -req -in myuser.req -out myuser.pem -days 365
openssl pkcs12 -export -clcerts -in myuser.pem -inkey myuser.key -out myuser.p12 -name "myuser_

[转] Tomcat 配置 SSL的更多相关文章

  1. 华为云服务器为Tomcat配置SSL

    近期由于开发小程序需要在云服务器上配置https访问协议,也遇到了一点小问题,把配置过程记录一下:SSL 证书申请下来之后会有 .jks .crt .pfx .pem为后缀的文件(如何申请SSL证书这 ...

  2. TOMCAT配置SSL认证为HTTPS协议服务

     1 . 问题概述 很多安全性要求较高的系统,都会使用安全套接字层(SSL)进行信息交换, Sun为了解决在Internet上的实现安全信息传输的解决方案.它实现了SSL和TSL(传输层安全)协议 ...

  3. 单点登录 SSO, 自动登录 , java 加密,ssl原理, Tomcat配置SSL

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 单点登录的英文简称为SSO(single sign on),单点登录功能使得用户只要登录 ...

  4. Tomcat配置SSL

    Tomcat配置SSL 查询网上资料配置如下: <Connector port="8443" protocol="HTTP/1.1" maxThreads ...

  5. 实战Tomcat配置SSL,使用openssl制作证书

    制作证书以及Tomcat配置 搭建openssl环境,下载openssl并设置环境变量方便命令行的使用: 修改openssl配置文件,设置dir目录,如设置dir=e:/temp/openssl_ca ...

  6. Mac下tomcat配置ssl

    最近在搞单点登录CAS,第一步就是需要给tomcat配置证书.但是,第一次配置就遇到了个问题排插了一下午.下面来存一份文档,以备以后遇到. 一.首先准备好环境 java环境:配置好环境变量,找到jdk ...

  7. Tomcat配置SSL后使用HTTP后跳转到HTTPS

    Tomcat配置好SSL后将HTTP请求自动转到HTTPS需要在TOMCAT/conf/web.xml的未尾加入以下配置: <login-config> <!-- Authoriza ...

  8. Springboot 配置 ssl 实现HTTPS 请求 & Tomcat配置SSL支持https请求

    SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TLS与 ...

  9. apache Tomcat配置SSL(https)步骤

    Tomcat配置https 1      生成Server端安全证书 要实现通信加密,首先要在本地准备一份符合X.509标准的Server端安全证书.如果有条件的话,可以向权威CA申请一份经过认证的安 ...

  10. linux apache Tomcat配置SSL(https)步骤

    https简介 它是由Netscape开发并内置于其浏览器中,用于对数据进行压缩和解压操作,并返回网络上传送回的结果.HTTPS实际上应用了Netscape的安全套接字层(SSL)作为HTTP应用层的 ...

随机推荐

  1. 分享七款视差滚动效果的jQuery 插件

    视差(Parallax)是指从不同的点看一个物体时形成的视觉差异,这个名词是源自希腊文的παράλλαξις (parallaxis),意思是”改变”.在网页设计中,视差滚动(Parallax Scr ...

  2. Uva10207 The Unreal Tournament

    题目链接戳这里 首先递归调用函数次数其实是可以预处理出来的,但是这里我们介绍一个更屌的做法. 设\(F(i,j)\)为求解\(P(i,j)\)所遍历的节点数目,则有\[F(0,j)=F(i,0)=0\ ...

  3. IAR ARM、IAR STM8、IAR MSP430共用一个IDE

    转自IAR ARM.IAR STM8.IAR MSP430共用一个IDE 试了安装好多个不同版本不同编译器的IAR,终于明白不同编译器的IAR共用IDE的条件,把几个不同编译器的IAR安装在一起,共用 ...

  4. [Mac]使用xcode命令行编译protobuf

    因为不想每次测试与画面显示无关的小功能时把cocos2dx包含进去,所以改用xcode的command line tool直接建立c++项目. 方法: 1.点击file-new-project,选择o ...

  5. 【CF】135 Div2 Choosing Capital for Treeland

    树形结构,挺有意思的题目.不难. /* 219D */ #include <iostream> #include <string> #include <map> # ...

  6. 编程实现改变win7主题

    一  : 解析问题 1. Windows 7 主题在:%windir%\Resources\Themes  : 2: 我们通过shell 命令  (这个是msdn中提到的) rundll32.exe ...

  7. 新Azure 服务仪表盘!

    通过仪表盘, 我们可以查看当前状态和历史记录: http://www.windowsazure.cn/support/service-dashboard/

  8. Android稳定性测试之Log分析

    做手机自动化测试已经快两年了,很久没写Blog了.今天抽空总结一下. 用自动化做稳定性测试,主要是为了发现系统或者应用出现FC/ ANR/ Reboot/ Freeze等问题. 先详细说下各种问题对应 ...

  9. Python生成器 yield

    迭代器与list相比较,就for in句型循环拿数据而言: 用list写很简洁,但如果list数据过大,会很消耗资源. 用iteration 迭代器写,则不会消耗那么多资源.他会随用随取,用一个拿一个 ...

  10. Windows Server AppFabric 安装文档

    安装指南 入门标题页 3 Windows Server AppFabric 安装和配置指南 3 版权 3 版权所有 3 简介 3 清单:规划安装 4 硬件要求 4 使计算机作好安装准备 5 本节内容 ...