zoukankan      html  css  js  c++  java
  • Https socket 代理

    https直接与服务器通过ssLsocket连接可行

    import java.io.InputStream;
    import java.io.OutputStream;
    import java.security.SecureRandom;

    import javax.net.ssl.SSLContext;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.X509TrustManager;


    public class Ssl {

        
        public static void sslSocket2() throws Exception {    
            SSLContext context = SSLContext.getInstance("SSL");    
                       // 初始化    
            TrustManager[] tm = { new  X509TrustManager() {
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
                public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                }
                public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                }
            } };
            
            context.init(null, tm, new SecureRandom());    
            SSLSocketFactory factory = context.getSocketFactory();    
            SSLSocket s = (SSLSocket) factory.createSocket("mail.163.com", 443);    
            System.out.println(s.getEnabledProtocols());
            System.out.println(s.getEnableSessionCreation());
            System.out.println(s.getUseClientMode());
    //        System.out.println(s.getHandshakeSession().toString());
            System.out.println(s.getInetAddress());
            System.out.println(s.getSession().toString());
            System.out.println("ok");    
           // s.startHandshake();
            OutputStream output = s.getOutputStream();    
            InputStream input = s.getInputStream();    
            
            output.write(("POST https://mail.163.com/entry/cgi/ntesdoor?df=mail163_letter&from=web&funcid=loginone&iframe=1&language=-1&passtype=1&product=mail163&net=t&style=-1&race=1139_1154_1123_bj&uid=xj-07@163.com HTTP/1.1"
            +" Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*"
                    +" User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)"
            +" Content-Type: application/x-www-form-urlencoded"
                    +" Accept-Encoding: gzip, deflate"+" Host: mail.163.com"
            +" Content-Length: 106"+" Connection: Keep-Alive"
                    +" Cache-Control: no-cache"+" Referer: http://mail.163.com/"
            +" Accept-Language: zh-CN"+" "
                +" savelogin=0&url2=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferror163.htm&username=xj-07&password=123456").getBytes());    
            System.out.println("sent: alert");    
            output.flush();    
            
            byte[] buf = new byte[1024];    
            int len = input.read(buf);    
            System.out.println("received:" + new String(buf, 0, len));    
        }  
        public static void main(String[] args) throws Exception {
            
            sslSocket2();
        }
        
    }

    同样方式将

    SSLSocket s = (SSLSocket) factory.createSocket("mail.163.com", 443);   

    改为代理就不好使了

    SSLSocket s = (SSLSocket) factory.createSocket("127.0.0.1", 8080);   

    客户端与代理服务器之间的ssl握手出现了问题,还带进一步分析

  • 相关阅读:
    16、springboot——错误处理原理+定制错误页面(1)
    15、springboot——CRUD-跳转到修改员工页面+员工修改和删除实现 ⑥
    14、springboot——CRUD-跳转到添加员工页面+员工添加实现⑤
    13、springboot——CRUD-thymeleaf公共页面元素抽取④
    12、springboot——CRUD登录和拦截③
    11、springboot——CRUD国际化②
    10、springboot——CRUD导入静态资源以及设置默认访问首页①
    9、springmvc的自动配置
    8、模板引擎thymeleaf(百里香叶)
    7、对静态资源映射的规则
  • 原文地址:https://www.cnblogs.com/hua198/p/5223945.html
Copyright © 2011-2022 走看看