使用Firefox浏览器做JDK11 TLS1.3连接测试

本文介绍了如何使用Firefox浏览器进行JDK11的TLS1.3连接测试,详细解析了TLS1.3的握手和请求流程,包括ClientHello、ServerHello、Cipher Suites、Key Exchange等关键步骤,以及调试输出的格式和含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备

JDK11开始支持TLS1.3了:JEP 332
理解TLS连接,有时候是困难的,特别是不清楚实际上发送和接收的消息的时候。JSSE有一个内置的调试设施,设置系统属性javax.net.debug可以激活。想知道更多信息,参见Debugging Utilities
下面看一看TLS 1.3握手时的调试输出。
例子使用默认的JSSE X509KeyManager和X509TrustManager。
ClassFileServer.java:

import java.io.*;
import java.net.*;
import java.security.KeyStore;
import javax.net.*;
import javax.net.ssl.*;
import javax.security.cert.X509Certificate;

/* ClassFileServer.java -- 一个简单的文件服务器,
 * 支持HTTP GET请求,支持secure channel
 *
 * The ClassFileServer 实现了 a ClassServer,从文件系统读文件。
 */

public class ClassFileServer extends ClassServer {
   
   

    private String docroot;

    private static int DefaultServerPort = 2001;

    /**
     * 构造ClassFileServer.
     *
     * @param docroot 定位文件的路径
     */
    public ClassFileServer(ServerSocket ss, String docroot) throws IOException
    {
   
   
        super(ss);
        this.docroot = docroot;
    }

    /**
     * 返回的byte[]是文件的内容
     *
     * @return the bytes for the file
     * @exception FileNotFoundException,找不到文件时
     */
    public byte[] getBytes(String path)
        throws IOException
    {
   
   
        System.out.println("reading: " + path);
        File f = new File(docroot + File.separator + path);
        int length = (int)(f.length());
        if (length == 0) {
   
   
            throw new IOException("File length is zero: " + path);
        } else {
   
   
            FileInputStream fin = new FileInputStream(f);
            DataInputStream in = new DataInputStream(fin);

            byte[] bytecodes = new byte[length];
            in.readFully(bytecodes);
            return bytecodes;
        }
    }

    /**
     * Main方法
     * 两个命令行参数
     * port是服务器端口 
     * docroot是文件路径
     *
     * <code>   new ClassFileServer(port, docroot);
     * </code>
     */
    public static void main(String args[])
    {
   
   
        System.out.println(
            "USAGE: java ClassFileServer port docroot [TLS [true]]");
        System.out.println("");
        System.out.println(
            "If the third argument is TLS, it will start as\n" +
            "a TLS/SSL file server, otherwise, it will be\n" +
            "an ordinary file server. \n" +
            "If the fourth argument is true,it will require\n" +
            "client authentication as well.");

        int port = DefaultServerPort;
        String docroot = "";

        if (args.length >= 1) {
   
   
            port = Integer.parseInt(args[0]);
        }

        if (args.length >= 2) {
   
   
            docroot = args[1];
        }
        String type = "PlainSocket";
        if (args.length >= 3) {
   
   
            type = args[2];
        }
        try {
   
   
            ServerSocketFactory ssf =
                ClassFileServer.getServerSocketFactory(type);
            ServerSocket ss = ssf.createServerSocket(port);
            if (args.length >= 4 && args[3].equals("true")) {
   
   
                ((SSLServerSocket)ss).
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值