在局域网内实现https安全访问

准备原料

服务器 resin (当然也可以是tomcat,这里以resin为例)

安装jdk

域名 (随便写一个就行,因为是内网使用,不会被校验)

生成证书

  • 第一步:为服务器生成证书
​​keytool -genkey -alias resin -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/keys/resin.keystore -storepass 123456​​
  • 第二步:为客户端生成证书
​​keytool -genkey -alias client1 -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -storetype PKCS12 -keystore D:/keys/client1.p12 -storepass 123456​​
  • 第三步:让服务器信任客户端证书
​​keytool -export -alias client1 -keystore D:/keys/client1.p12 -storetype PKCS12 -keypass 123456 -file D:/keys/client1.cer​​
​​keytool -import -v -file D:/keys/client1.cer -keystore D:/keys/resin.keystore -storepass 123456​​
  • 第四步:让客户端信任服务器证书
​​keytool -list -v -keystore D:/keys/resin.keystore​​
​​keytool -keystore D:/keys/resin.keystore -export -alias resin -file D:/keys/server.cer​​

注意:当提示:您的名字与姓氏是什么? 请输入你准备的域名比如:​​www.aclululu.com​

 

在局域网内实现https安全访问_客户端

 

其他的按照提示输入就是了,最后会得到四个文件如下:

 

在局域网内实现https安全访问_服务器_02

生成客户端安装证书

  • 双击server.cer文件,按默认安装,直到安装成功
  • 打开IE浏览器,找到证书
  • 在局域网内实现https安全访问_服务器_03



  • 在局域网内实现https安全访问_服务器_04


  • 选择导出,导出的证书即可用于其他客户进行安装使用。这里命名为aclululu_client

配置服务器端resin

早期的版本,因为没有最新的,所以请见谅!
resin.conf文件具体需要修改的地方

  • 配置https证书
<http address="*" port="443">
​​
<jsse-ssl>
<key-store-type>jks</key-store-type>
<key-store-file>keys/resin.keystore</key-store-file>
<password>123456</password>
</jsse-ssl>
</http>
  • 配置更新
​​<session-config>
​​
<session-timeout>-1</session-timeout>
<enable-url-rewriting>false</enable-url-rewriting>
<reuse-session-id>false</reuse-session-id>
<cookie-secure >true</cookie-secure>
</session-config>
  • 配置httpOnly请求
​​<cookie-http-only>true</cookie-http-only>​​
  • 配置secure属性
​​<secure>true</secure>​​

客户机安装证书,修改host文件(注意客户机)

打开IE浏览器,导入证书

 

在局域网内实现https安全访问_安全访问_05

按照默认导入刚刚保存的aclululu_client证书。直到导入成功。

 

在局域网内实现https安全访问_安全访问_06

 

在局域网内实现https安全访问_客户端_07

修改host文件

假如服务器的ip为:172.16.1.123
方法一:
修改批处理文件:aclululu_host.bat

@echo off
color 0F
@attrib -r "%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo #Fssoft Start >>"%windir%\system32\drivers\etc\hosts"
@echo 172.16.1.123 ​​​www.aclululu.com​​​>>"%windir%\system32\drivers\etc\hosts"
@echo #Fssoft End >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@echo= >>"%windir%\system32\drivers\etc\hosts"
@attrib +r "%windir%\system32\drivers\etc\hosts"

然后双击执行bat即可

方法二:
直接去
C:\Windows\System32\drivers\etc下手动修改


 

在局域网内实现https安全访问_客户端_08

访问

https
就可以安全访问172.16.1.123这台主机上的网页了

龙腾一族至尊龙骑