[转] Tomcat 配置 SSL

时间:2022-11-13 09:57:08

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 请求 &amp&semi; Tomcat配置SSL支持https请求

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

  9. apache Tomcat配置SSL&lpar;https&rpar;步骤

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

  10. linux apache Tomcat配置SSL&lpar;https&rpar;步骤

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

随机推荐

  1. string、Empty和null三者的区别

    string.Empty和null三者的区别 本文转自  http://www.bitscn.com/pdb/dotnet/201003/181883.html 时间:2010-03-01 00:00 ...

  2. 微软分布式云计算框架Orleans&lpar;2&rpar;:容灾与集群&lpar;1&rpar;

    在上一篇:微软分布式云计算框架Orleans(1):Hello World,我们大概了解了Orleans如何运用,当然上一篇的例子可以说是简单且无效的,因为用了Orleans不可能只写一个Hello ...

  3. iphone6 帶回家”活動&excl;

    十一小長假即將來臨,周向榮還準備窩在家裏坐等“鋒菲戀”的後續結果嗎?雖然宅男無罪,但是請不要繼續在論壇裏高呼“李亞鵬娶了張柏芝”等口號,放下你“不吐槽會死星人”的特質,走出家門去領略一下祖國的大好山河 ...

  4. iframe自适应高度&lpar;兼容IE 火狐 谷歌&rpar;

    <div id="leamain"> <iframe src="#" marginheight="0" marginwid ...

  5. VMware-workstation-full-10&period;0&period;3-1895310 CN

    Name: VMware-workstation-full-10.0.3-1895310.exe发行日期: 2014-07-01内部版本号: 1895310文件大小: 491 MB文件类型: exe ...

  6. IIS URL重写找不到页面 (URLRewriter&period;dll伪静态)

    在网站上点右键 属性 进入主目录菜单 点击配置 找到.html扩展名 编辑 将 检查文件是否存在 的钩去掉! OK

  7. C&plus;&plus;重载输入流复习

    C++重载输入流 #include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point(int xx, ...

  8. 【python】升级pip后报错解决pkg&lowbar;resources&period;DistributionNotFound&colon; The &&num;39&semi;pip&equals;&equals;7&period;1&period;0&&num;39&semi; distribution was not found and is required by the application

    原本使用pip版本为7.1.0,后升级至9.0.1 之后使用pip list提示pkg_resources.DistributionNotFound: The 'pip==7.1.0' distrib ...

  9. day 32 子进程的开启 及其用法

    开启两种子进程的两种方式# # # 1 传统方式# from multiprocessing import Process# import time# def task(name):# print ( ...

  10. &lbrack;转&rsqb;OpenStack Keystone V3

    Keystone V3 Keystone 中主要涉及到如下几个概念:User.Tenant.Role.Token.下面对这几个概念进行简要说明. User:顾名思义就是使用服务的用户,可以是人.服务或 ...