diff --git a/u_common.go b/u_common.go index ad4ced721f..2c0905e123 100644 --- a/u_common.go +++ b/u_common.go @@ -657,8 +657,9 @@ var ( HelloEdge_85 = ClientHelloID{helloEdge, "85", nil, nil} HelloEdge_106 = ClientHelloID{helloEdge, "106", nil, nil} - HelloSafari_Auto = HelloSafari_16_0 + HelloSafari_Auto = HelloSafari_26_3 HelloSafari_16_0 = ClientHelloID{helloSafari, "16.0", nil, nil} + HelloSafari_26_3 = ClientHelloID{helloSafari, "26.3", nil, nil} Hello360_Auto = Hello360_7_5 // Hello360_11_0 seems to be incompatible with this library Hello360_7_5 = ClientHelloID{hello360, "7.5", nil, nil} diff --git a/u_parrots.go b/u_parrots.go index 7fcf0d688d..a15674f91e 100644 --- a/u_parrots.go +++ b/u_parrots.go @@ -2106,6 +2106,116 @@ func utlsIdToSpec(id ClientHelloID) (ClientHelloSpec, error) { }, }, }, nil + case HelloSafari_26_3: + return ClientHelloSpec{ + TLSVersMin: VersionTLS12, + TLSVersMax: VersionTLS13, + CipherSuites: []uint16{ + GREASE_PLACEHOLDER, + TLS_AES_256_GCM_SHA384, + TLS_CHACHA20_POLY1305_SHA256, + TLS_AES_128_GCM_SHA256, + TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, + TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, + TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + TLS_RSA_WITH_AES_256_GCM_SHA384, + TLS_RSA_WITH_AES_128_GCM_SHA256, + TLS_RSA_WITH_AES_256_CBC_SHA, + TLS_RSA_WITH_AES_128_CBC_SHA, + FAKE_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + TLS_RSA_WITH_3DES_EDE_CBC_SHA, + }, + CompressionMethods: []uint8{ + 0x0, // no compression + }, + Extensions: []TLSExtension{ + &UtlsGREASEExtension{}, + &SNIExtension{}, + &ExtendedMasterSecretExtension{}, + &RenegotiationInfoExtension{ + Renegotiation: RenegotiateOnceAsClient, + }, + &SupportedCurvesExtension{ + Curves: []CurveID{ + GREASE_PLACEHOLDER, + X25519MLKEM768, + X25519, + CurveP256, + CurveP384, + CurveP521, + }, + }, + &SupportedPointsExtension{ + SupportedPoints: []uint8{ + 0x0, // uncompressed + }, + }, + &ALPNExtension{ + AlpnProtocols: []string{ + "h2", + "http/1.1", + }, + }, + &StatusRequestExtension{}, + &SignatureAlgorithmsExtension{ + SupportedSignatureAlgorithms: []SignatureScheme{ + ECDSAWithP256AndSHA256, + PSSWithSHA256, + PKCS1WithSHA256, + ECDSAWithP384AndSHA384, + PSSWithSHA384, + PSSWithSHA384, + PKCS1WithSHA384, + PSSWithSHA512, + PKCS1WithSHA512, + PKCS1WithSHA1, + }, + }, + &SCTExtension{}, + &KeyShareExtension{ + KeyShares: []KeyShare{ + { + Group: GREASE_PLACEHOLDER, + Data: []byte{ + 0, + }, + }, + { + Group: X25519MLKEM768, + }, + { + Group: X25519, + }, + }, + }, + &PSKKeyExchangeModesExtension{ + Modes: []uint8{ + PskModeDHE, + }, + }, + &SupportedVersionsExtension{ + Versions: []uint16{ + GREASE_PLACEHOLDER, + VersionTLS13, + VersionTLS12, + }, + }, + &UtlsCompressCertExtension{ + Algorithms: []CertCompressionAlgo{ + CertCompressionZlib, + }, + }, + &UtlsGREASEExtension{}, + }, + }, nil case Hello360_7_5: return ClientHelloSpec{ CipherSuites: []uint16{ diff --git a/u_safari_profile_test.go b/u_safari_profile_test.go new file mode 100644 index 0000000000..47aaeb6dc4 --- /dev/null +++ b/u_safari_profile_test.go @@ -0,0 +1,39 @@ +package tls + +import ( + "net" + "testing" +) + +func TestSafariKeyShares(t *testing.T) { + for _, tc := range []struct { + id ClientHelloID + wantHybrid bool + }{ + {HelloSafari_Auto, true}, + {HelloSafari_16_0, false}, + } { + conn := UClient(&net.TCPConn{}, &Config{ServerName: "example.com"}, tc.id) + if err := conn.BuildHandshakeState(); err != nil { + t.Fatal(err) + } + shares := conn.HandshakeState.Hello.KeyShares + var groups []CurveID + for _, share := range shares { + if !isGREASEUint16(uint16(share.Group)) { + groups = append(groups, share.Group) + } + } + if tc.wantHybrid { + if len(groups) < 2 || groups[0] != X25519MLKEM768 || groups[1] != X25519 { + t.Fatalf("%s: unexpected key shares %v", tc.id.Str(), groups) + } + } else { + for _, group := range groups { + if group == X25519MLKEM768 { + t.Fatalf("%s: legacy profile gained a hybrid key share", tc.id.Str()) + } + } + } + } +}