分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

https

发布时间:2023-09-06 02:32责任编辑:顾先生关键词:http
  • 01.https介绍

访问安全网站CA结构校验是否安全

CA:授权机构,赛门铁克、交钱认证https网站

实现山寨百度,是https

  • 02.https服务器配置

如何把一个http编程https安全网站

tomcat文档:http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html

配置https的keystore

apache-tomcat-7.0.72\conf\server.xml

 

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"

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

            keystoreFile="conf/meituan.jks" keystorePass="123456"

           clientAuth="false" sslProtocol="TLS" />

  • 03.https客户端编程-信任管理器

  //通过信任管理器工厂生成管理器

    TrustManagerFactory tfm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

    //为了能够访问没有认证的https网站,

    // 需要设置信任管理器(相当于保安)

 

    //1.创建安全上下文对象:看api文档

    SSLContext context = SSLContext.getInstance("TLS");

    //2.管理信任管理器

    TrustManager[] tm  = tfm.getTrustManagers();

    context.init(null, tm, null);//逆向编程:先写对象,通过快捷键创建对应类型

 

    HttpsURLConnection conn = (HttpsURLConnection) new URL("https://10.0.2.2:8443/heima.json").openConnection();

    ins = conn.getInputStream();

    //使用信任管理器

    conn.setSSLSocketFactory(context.getSocketFactory());

  • 04.https客户端编程-导出证书

通过keystore导出证书

keytool -exportcert -alias meituan -file meituan.cer -keystore meituan.jks

  • 05.https客户端编程-使用证书

  TrustManagerFactory tfm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    ks.load(null);//清空默认证书信息

    InputStream certIn = getAssets().open("meituan.cer");

    Certificate cert = cf.generateCertificate(certIn);//证书对象

    certIn.close();

    ks.setCertificateEntry("meituan", cert);

    tfm.init(ks);//初始化信任管理器工厂

https

原文地址:https://www.cnblogs.com/nangongyibin/p/10354917.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved