Source file src/crypto/tls/ech_test.go

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package tls
     6  
     7  import (
     8  	"encoding/hex"
     9  	"testing"
    10  )
    11  
    12  func TestDecodeECHConfigLists(t *testing.T) {
    13  	for _, tc := range []struct {
    14  		list       string
    15  		numConfigs int
    16  	}{
    17  		{"0045fe0d0041590020002092a01233db2218518ccbbbbc24df20686af417b37388de6460e94011974777090004000100010012636c6f7564666c6172652d6563682e636f6d0000", 1},
    18  		{"0105badd00050504030201fe0d0066000010004104e62b69e2bf659f97be2f1e0d948a4cd5976bb7a91e0d46fbdda9a91e9ddcba5a01e7d697a80a18f9c3c4a31e56e27c8348db161a1cf51d7ef1942d4bcf7222c1000c000100010001000200010003400e7075626c69632e6578616d706c650000fe0d003d00002000207d661615730214aeee70533366f36a609ead65c0c208e62322346ab5bcd8de1c000411112222400e7075626c69632e6578616d706c650000fe0d004d000020002085bd6a03277c25427b52e269e0c77a8eb524ba1eb3d2f132662d4b0ac6cb7357000c000100010001000200010003400e7075626c69632e6578616d706c650008aaaa000474657374", 3},
    19  	} {
    20  		b, err := hex.DecodeString(tc.list)
    21  		if err != nil {
    22  			t.Fatal(err)
    23  		}
    24  		configs, err := parseECHConfigList(b)
    25  		if err != nil {
    26  			t.Fatal(err)
    27  		}
    28  		if len(configs) != tc.numConfigs {
    29  			t.Fatalf("unexpected number of configs parsed: got %d want %d", len(configs), tc.numConfigs)
    30  		}
    31  	}
    32  
    33  }
    34  
    35  func TestSkipBadConfigs(t *testing.T) {
    36  	b, err := hex.DecodeString("00c8badd00050504030201fe0d0029006666000401020304000c000100010001000200010003400e7075626c69632e6578616d706c650000fe0d003d000020002072e8a23b7aef67832bcc89d652e3870a60f88ca684ec65d6eace6b61f136064c000411112222400e7075626c69632e6578616d706c650000fe0d004d00002000200ce95810a81d8023f41e83679bc92701b2acd46c75869f95c72bc61c6b12297c000c000100010001000200010003400e7075626c69632e6578616d706c650008aaaa000474657374")
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	configs, err := parseECHConfigList(b)
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  	config := pickECHConfig(configs)
    45  	if config != nil {
    46  		t.Fatal("pickECHConfig picked an invalid config")
    47  	}
    48  }
    49  

View as plain text