diff --git a/common.go b/common.go index 868c725e077..7d772a6544b 100644 --- a/common.go +++ b/common.go @@ -124,6 +124,7 @@ const ( extensionSupportedVersions uint16 = 43 extensionCookie uint16 = 44 extensionPSKModes uint16 = 45 + extensionPostHandshakeAuth uint16 = 49 extensionCertificateAuthorities uint16 = 47 extensionSignatureAlgorithmsCert uint16 = 50 extensionKeyShare uint16 = 51 diff --git a/dicttls/exttype_values.go b/dicttls/exttype_values.go index cb0ef403fcd..34f791a185d 100644 --- a/dicttls/exttype_values.go +++ b/dicttls/exttype_values.go @@ -138,6 +138,7 @@ var DictExtTypeValueIndexed = map[uint16]string{ 13172: "next_protocol_negotiation", 17513: "application_settings", 17613: "application_settings_new", + 65037: "encrypted_client_hello", 30031: "channel_id_old", 30032: "channel_id", } @@ -204,6 +205,7 @@ var DictExtTypeNameIndexed = map[string]uint16{ "dnssec_chain": 59, "renegotiation_info": 65281, + "encrypted_client_hello": 65037, // 0xfe0d "next_protocol_negotiation": 13172, "application_settings": 17513, "application_settings_new": 17613, diff --git a/dicttls/supported_groups.go b/dicttls/supported_groups.go index b728947ed93..25539e659b5 100644 --- a/dicttls/supported_groups.go +++ b/dicttls/supported_groups.go @@ -33,6 +33,7 @@ const ( SupportedGroups_brainpoolP384r1 uint16 = 27 SupportedGroups_brainpoolP512r1 uint16 = 28 SupportedGroups_x25519 uint16 = 29 + SupportedGroups_x25519mlkem768 uint16 = 4588 SupportedGroups_x448 uint16 = 30 SupportedGroups_brainpoolP256r1tls13 uint16 = 31 SupportedGroups_brainpoolP384r1tls13 uint16 = 32 @@ -136,6 +137,7 @@ var DictSupportedGroupsNameIndexed = map[string]uint16{ "brainpoolP384r1": 27, "brainpoolP512r1": 28, "x25519": 29, + "X25519MLKEM768": 4588, "x448": 30, "brainpoolP256r1tls13": 31, "brainpoolP384r1tls13": 32, @@ -153,7 +155,6 @@ var DictSupportedGroupsNameIndexed = map[string]uint16{ "ffdhe4096": 258, "ffdhe6144": 259, "ffdhe8192": 260, - "X25519MLKEM768": 4588, // 0x11ec — X25519 + ML-KEM-768 hybrid "arbitrary_explicit_prime_curves": 65281, "arbitrary_explicit_char2_curves": 65282, } diff --git a/u_clienthello_json.go b/u_clienthello_json.go index 94cec195090..a9a23ccd29f 100644 --- a/u_clienthello_json.go +++ b/u_clienthello_json.go @@ -103,9 +103,30 @@ func (e *TLSExtensionsJSONUnmarshaler) UnmarshalJSON(jsonStr []byte) error { continue } - if extID, ok := dicttls.DictExtTypeNameIndexed[accepter.extNameOnly.Name]; !ok { - return fmt.Errorf("%w: %s", ErrUnknownExtension, accepter.extNameOnly.Name) + if accepter.extNameOnly.Name == "encrypted_client_hello" { + // ECH: real ECH configs are transport-specific; imported specs use + // the BoringSSL GREASE form (what real Chrome sends when ECH is + // not negotiated). + exts = append(exts, &GREASEEncryptedClientHelloExtension{}) + continue + } + + var extID uint16 + if id, ok := dicttls.DictExtTypeNameIndexed[accepter.extNameOnly.Name]; ok { + extID = id + } else if len(accepter.extNameOnly.Name) > 4 && accepter.extNameOnly.Name[:4] == "ext_" { + // numeric fallback for proprietary extensions without a dictionary + // name (e.g. Chrome's 51764); imported as GenericExtension + var n int + if _, err := fmt.Sscanf(accepter.extNameOnly.Name, "ext_%d", &n); err != nil || n <= 0 || n > 65535 { + return fmt.Errorf("%w: %s", ErrUnknownExtension, accepter.extNameOnly.Name) + } + exts = append(exts, &GenericExtension{Id: uint16(n)}) + continue } else { + return fmt.Errorf("%w: %s", ErrUnknownExtension, accepter.extNameOnly.Name) + } + if true { // get extension type from ID var ext TLSExtension = ExtensionFromID(extID) if ext == nil { diff --git a/u_common.go b/u_common.go index 770507c6a1d..741174d8439 100644 --- a/u_common.go +++ b/u_common.go @@ -613,7 +613,7 @@ var ( HelloFirefox_120 = ClientHelloID{helloFirefox, "120", nil, nil} HelloFirefox_148 = ClientHelloID{helloFirefox, "148", nil, nil} - HelloChrome_Auto = HelloChrome_133 + HelloChrome_Auto = HelloChrome_152 HelloChrome_58 = ClientHelloID{helloChrome, "58", nil, nil} HelloChrome_62 = ClientHelloID{helloChrome, "62", nil, nil} HelloChrome_70 = ClientHelloID{helloChrome, "70", nil, nil} @@ -645,6 +645,7 @@ var ( HelloChrome_131 = ClientHelloID{helloChrome, "131", nil, nil} // Chrome w/ New ALPS codepoint HelloChrome_133 = ClientHelloID{helloChrome, "133", nil, nil} + HelloChrome_152 = ClientHelloID{helloChrome, "152", nil, nil} HelloIOS_Auto = HelloIOS_14 HelloIOS_11_1 = ClientHelloID{helloIOS, "111", nil, nil} // legacy "111" means 11.1 diff --git a/u_ech.go b/u_ech.go index 325cd41f98d..5e6d348335b 100644 --- a/u_ech.go +++ b/u_ech.go @@ -328,3 +328,10 @@ func BoringGREASEECH() *GREASEEncryptedClientHelloExtension { CandidatePayloadLens: []uint16{128, 160, 192, 224}, // +16: 144, 176, 208, 240 } } + +// UnmarshalJSON accepts any JSON body ({"name":"encrypted_client_hello"}). +// The GREASE form carries no importable parameters: the real payload is +// derived at handshake time from the ECH configs and HPKE keys. +func (e *GREASEEncryptedClientHelloExtension) UnmarshalJSON(_ []byte) error { + return nil +} diff --git a/u_parrots.go b/u_parrots.go index 425ab6ddda6..a63e793cef7 100644 --- a/u_parrots.go +++ b/u_parrots.go @@ -964,6 +964,79 @@ func utlsIdToSpec(id ClientHelloID) (ClientHelloSpec, error) { &UtlsGREASEExtension{}, }), }, nil + case HelloChrome_152: + return ClientHelloSpec{ + CipherSuites: []uint16{ + GREASE_PLACEHOLDER, + TLS_AES_128_GCM_SHA256, + TLS_AES_256_GCM_SHA384, + TLS_CHACHA20_POLY1305_SHA256, + TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, + TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, + TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + TLS_RSA_WITH_AES_128_GCM_SHA256, + TLS_RSA_WITH_AES_256_GCM_SHA384, + TLS_RSA_WITH_AES_128_CBC_SHA, + TLS_RSA_WITH_AES_256_CBC_SHA, + }, + CompressionMethods: []byte{ + 0x00, // compressionNone + }, + Extensions: ShuffleChromeTLSExtensions([]TLSExtension{ + &UtlsGREASEExtension{}, + &SNIExtension{}, + &ExtendedMasterSecretExtension{}, + &RenegotiationInfoExtension{Renegotiation: RenegotiateOnceAsClient}, + &SupportedCurvesExtension{[]CurveID{ + GREASE_PLACEHOLDER, + X25519MLKEM768, + X25519, + CurveP256, + CurveP384, + }}, + &SupportedPointsExtension{SupportedPoints: []byte{ + 0x00, // pointFormatUncompressed + }}, + &SessionTicketExtension{}, + &ALPNExtension{AlpnProtocols: []string{"h2", "http/1.1"}}, + &StatusRequestExtension{}, + &SignatureAlgorithmsExtension{SupportedSignatureAlgorithms: []SignatureScheme{ + ECDSAWithP256AndSHA256, + PSSWithSHA256, + PKCS1WithSHA256, + ECDSAWithP384AndSHA384, + PSSWithSHA384, + PKCS1WithSHA512, + PSSWithSHA512, + PKCS1WithSHA384, + }}, + &SCTExtension{}, + &KeyShareExtension{[]KeyShare{ + {Group: CurveID(GREASE_PLACEHOLDER), Data: []byte{0}}, + {Group: X25519MLKEM768}, + {Group: X25519}, + }}, + &PSKKeyExchangeModesExtension{[]uint8{ + PskModeDHE, + }}, + &SupportedVersionsExtension{[]uint16{ + GREASE_PLACEHOLDER, + VersionTLS13, + VersionTLS12, + }}, + &UtlsCompressCertExtension{[]CertCompressionAlgo{ + CertCompressionBrotli, + }}, + &ApplicationSettingsExtensionNew{SupportedProtocols: []string{"h2"}}, + BoringGREASEECH(), + &UtlsGREASEExtension{}, + }), + }, nil case HelloFirefox_55, HelloFirefox_56: return ClientHelloSpec{ TLSVersMax: VersionTLS12, diff --git a/u_tls_extensions.go b/u_tls_extensions.go index 77ee10ce684..6df3941a790 100644 --- a/u_tls_extensions.go +++ b/u_tls_extensions.go @@ -45,6 +45,11 @@ func ExtensionFromID(id uint16) TLSExtension { return &UtlsCompressCertExtension{} case fakeRecordSizeLimit: return &FakeRecordSizeLimitExtension{} + case fakeExtensionEncryptThenMAC: + return &FakeEtMExtension{} + case extensionPostHandshakeAuth: + // post_handshake_auth (49) is an empty extension in TLS 1.3 + return &FakeEtMExtension{ID: extensionPostHandshakeAuth} case fakeExtensionDelegatedCredentials: return &FakeDelegatedCredentialsExtension{} case extensionSessionTicket: @@ -302,9 +307,18 @@ func (e *SupportedCurvesExtension) UnmarshalJSON(data []byte) error { if group, ok := dicttls.DictSupportedGroupsNameIndexed[namedGroup]; ok { e.Curves = append(e.Curves, CurveID(group)) - } else { - return fmt.Errorf("unknown named group: %s", namedGroup) + continue + } + // numeric fallback "GREASE_4587" etc. — exact GREASE values captured + // from a real client that sit adjacent to real groups + if len(namedGroup) > 7 && namedGroup[:7] == "GREASE_" { + var n int + if _, err := fmt.Sscanf(namedGroup, "GREASE_%d", &n); err == nil && n > 0 && n <= 65535 { + e.Curves = append(e.Curves, CurveID(n)) + continue + } } + return fmt.Errorf("unknown named group: %s", namedGroup) } return nil } @@ -439,6 +453,14 @@ func (e *SignatureAlgorithmsExtension) UnmarshalJSON(data []byte) error { if scheme, ok := dicttls.DictSignatureSchemeNameIndexed[sigScheme]; ok { e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(scheme)) + } else if len(sigScheme) > 0 && sigScheme[0] >= '0' && sigScheme[0] <= '9' { + // numeric fallback for proprietary/GREASE-variant values emitted by + // capture tools (e.g. Chrome 152's 0x0904-0x0906) + var v uint64 + if _, err := fmt.Sscanf(sigScheme, "%d", &v); err != nil || v > 65535 { + return fmt.Errorf("invalid signature scheme %s", sigScheme) + } + e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(v)) } else { return fmt.Errorf("unknown signature scheme: %s", sigScheme) } @@ -569,6 +591,14 @@ func (e *SignatureAlgorithmsCertExtension) UnmarshalJSON(data []byte) error { if scheme, ok := dicttls.DictSignatureSchemeNameIndexed[sigScheme]; ok { e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(scheme)) + } else if len(sigScheme) > 0 && sigScheme[0] >= '0' && sigScheme[0] <= '9' { + // numeric fallback for proprietary/GREASE-variant values emitted by + // capture tools (e.g. Chrome 152's 0x0904-0x0906) + var v uint64 + if _, err := fmt.Sscanf(sigScheme, "%d", &v); err != nil || v > 65535 { + return fmt.Errorf("invalid signature scheme %s", sigScheme) + } + e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(v)) } else { return fmt.Errorf("unknown cert signature scheme: %s", sigScheme) } @@ -912,6 +942,14 @@ func (e *GenericExtension) UnmarshalJSON(b []byte) error { // lookup extension ID by name if id, ok := dicttls.DictExtTypeNameIndexed[genericExtension.Name]; ok { e.Id = id + } else if len(genericExtension.Name) > 4 && genericExtension.Name[:4] == "ext_" { + // numeric fallback emitted by capture tools for proprietary extensions + // that have no dictionary name (e.g. Chrome's 51764) + var id int + if _, err := fmt.Sscanf(genericExtension.Name, "ext_%d", &id); err != nil || id <= 0 || id > 65535 { + return fmt.Errorf("invalid numeric extension name %s", genericExtension.Name) + } + e.Id = uint16(id) } else { return fmt.Errorf("unknown extension name %s", genericExtension.Name) } @@ -1744,6 +1782,36 @@ func (e *FakeChannelIDExtension) UnmarshalJSON(_ []byte) error { return nil } +// FakeEtMExtension implements encrypt_then_mac (22) as an empty extension. +// Real Chrome sends it with an empty body; it has no uTLS-internal effect. +// EmptyExt is also reused for other empty-body extensions (post_handshake_auth). +type FakeEtMExtension struct { + ID uint16 // extension number to write; 0 = encrypt_then_mac (22) +} + +func (e *FakeEtMExtension) writeToUConn(uc *UConn) error { return nil } + +func (e *FakeEtMExtension) Len() int { return 4 } + +func (e *FakeEtMExtension) Read(b []byte) (int, error) { + if len(b) < e.Len() { + return 0, io.ErrShortBuffer + } + id := e.ID + if id == 0 { + id = fakeExtensionEncryptThenMAC + } + // https://tools.ietf.org/html/rfc7366 + b[0] = byte(id >> 8) + b[1] = byte(id & 0xff) + // The length is 0 + return e.Len(), io.EOF +} + +func (e *FakeEtMExtension) Write(_ []byte) (int, error) { return 0, nil } + +func (e *FakeEtMExtension) UnmarshalJSON(_ []byte) error { return nil } + // FakeRecordSizeLimitExtension implements record_size_limit (28) // but with no support. type FakeRecordSizeLimitExtension struct { @@ -1942,6 +2010,14 @@ func (e *FakeDelegatedCredentialsExtension) UnmarshalJSON(data []byte) error { if scheme, ok := dicttls.DictSignatureSchemeNameIndexed[sigScheme]; ok { e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(scheme)) + } else if len(sigScheme) > 0 && sigScheme[0] >= '0' && sigScheme[0] <= '9' { + // numeric fallback for proprietary/GREASE-variant values emitted by + // capture tools (e.g. Chrome 152's 0x0904-0x0906) + var v uint64 + if _, err := fmt.Sscanf(sigScheme, "%d", &v); err != nil || v > 65535 { + return fmt.Errorf("invalid signature scheme %s", sigScheme) + } + e.SupportedSignatureAlgorithms = append(e.SupportedSignatureAlgorithms, SignatureScheme(v)) } else { return fmt.Errorf("unknown delegated credentials signature scheme: %s", sigScheme) }