zoukankan      html  css  js  c++  java
  • SSL证书

    1生成服务器端证书
    keytool -genkeypair -v -alias server -keyalg RSA -validity 3650 -keystore ./server.keystore  -storepass 123456 -keypass 123456 -dname "CN=*.yushangcc.com,OU=rm,O=rm,L=gz,ST=gd,C=cn"
    keytool -importkeystore -srckeystore ./server.keystore -destkeystore ./server.keystore -deststoretype pkcs12
    2导出服务器端证书
    keytool -exportcert -alias server  -keystore ./server.keystore  -file ./server.cer  -storepass 123456
    3将服务器端证书导入信任证书
    keytool -importcert -alias serverca  -keystore ./server_trust.keystore  -file ./server.cer  -storepass 123456

    4生成客户端证书
    keytool -genkeypair -v -alias client -dname "CN=*.yushangcc.com" -keyalg RSA -validity 3650 -keypass 123456 -keystore ./client.p12 -storepass 123456 -storetype PKCS12
    5导出客户端证书
    keytool -exportcert -alias client -file ./client.cer -keystore ./client.p12 -storepass 123456 -storetype PKCS12
    6导入客户端证书到服务器端信任证书库
    keytool -importcert -alias clientca  -keystore ./server_trust.keystore  -file ./client.cer  -storepass 123456

    7编辑conf/server.xml文件加入如下的配置:
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true"

                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="true" sslProtocol="TLS"
                   keystoreFile="${catalina.base}/server.keystore" keystorePass="123456"
                   truststoreFile ="${catalina.base}/server_trust.keystore" truststorePass="123456"/>
    • clientAuth为true表示开启SSL双向认证
    • keystoreFile指定服务器端的证书位置
    • truststoreFile指定服务器端信任证书库

    8 双击client.p12 导入客户端证书
    9 双击server.cer  导入服务器端证书到客户端
    openssl pkcs12 -in server.keystore
    https://www.yushangcc.com:8443/demo1/hello-servlet


    java 语言可使用pkcs12  client.p12即可访问;如果要其他语言访问需要转换成pem格式
    若服务端要求客户端认证,需要将pfx证书转换成pem格式
    openssl pkcs12 -clcerts -nokeys -in cert.pfx -out client.pem    #客户端个人证书的公钥
    openssl pkcs12 -nocerts -nodes -in cert.pfx -out key.pem #客户端个人证书的私钥
    也可以转换为公钥与私钥合二为一的文件
    openssl pkcs12 -in  cert.pfx -out all.pem -nodes                                   #客户端公钥与私钥,一起存在all.pem中
    执行curl命令
    1、使用client.pem+key.pem
    curl -k --cert client.pem --key key.pem https://www.yushangcc.com:8443/demo1/hello-servlet
    2、使用all.pem
    curl -k --cert all.pem  https://www.yushangcc.com:8443/demo1/hello-servlet
    使用-k,是不对服务器的证书进行检查,这样就不必关心服务器证书的导出问题了。
    3 ,服务端CA证书转换(必须要 -k)
    penssl x509 -inform der -in server.cer -out ca.pem
    curl --cacert ca.pem  --cert client.pem --key key.pem https://www.yushangcc.com:8443/demo1/hello-servlet



  • 相关阅读:
    前端使用 node-gyp 构建 Native Addon
    CHANGELOG 的实现
    深入 JavaScript 中的对象以及继承原理
    使用electron进行原生应用的打包(2)---主进程与渲染进程之间的通信
    使用electron进行原生应用的打包
    Babel编译
    HTML布局四剑客-Flex,Grid,Table,Float
    关于vtt 与 srt 字幕 的相互转换
    关于websocket
    关于jQuery中nth-child和nth-of-type的详解
  • 原文地址:https://www.cnblogs.com/adolfmc/p/14147818.html
Copyright © 2011-2022 走看看