Просмотр исходного кода

Use Psiphon-Labs/psiphon-tls@891a0d5d

Amir Khan 1 год назад
Родитель
Сommit
2ee3efacf6

+ 1 - 1
go.mod

@@ -11,7 +11,7 @@ require (
 	github.com/Psiphon-Labs/bolt v0.0.0-20200624191537-23cedaef7ad7
 	github.com/Psiphon-Labs/consistent v0.0.0-20240322131436-20aaa4e05737
 	github.com/Psiphon-Labs/goptlib v0.0.0-20200406165125-c0e32a7a3464
-	github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240424193802-52b2602ec60c
+	github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240716162946-891a0d5db073
 	github.com/Psiphon-Labs/quic-go v0.0.0-20240424181006-45545f5e1536
 	github.com/armon/go-proxyproto v0.0.0-20180202201750-5b7edb60ff5f
 	github.com/bifurcation/mint v0.0.0-20180306135233-198357931e61

+ 2 - 2
go.sum

@@ -17,8 +17,8 @@ github.com/Psiphon-Labs/consistent v0.0.0-20240322131436-20aaa4e05737 h1:QTMy7Uc
 github.com/Psiphon-Labs/consistent v0.0.0-20240322131436-20aaa4e05737/go.mod h1:Enj/Gszv2zCbuRbHbabmNvfO9EM+5kmaGj8CyjwNPlY=
 github.com/Psiphon-Labs/goptlib v0.0.0-20200406165125-c0e32a7a3464 h1:VmnMMMheFXwLV0noxYhbJbLmkV4iaVW3xNnj6xcCNHo=
 github.com/Psiphon-Labs/goptlib v0.0.0-20200406165125-c0e32a7a3464/go.mod h1:Pe5BqN2DdIdChorAXl6bDaQd/wghpCleJfid2NoSli0=
-github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240424193802-52b2602ec60c h1:+SEszyxW7yu+smufzSlAszj/WmOYJ054DJjb5jllulc=
-github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240424193802-52b2602ec60c/go.mod h1:AaKKoshr8RI1LZTheeNDtNuZ39qNVPWVK4uir2c2XIs=
+github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240716162946-891a0d5db073 h1:qOr7JasrUWOR7hIgNKeDqc/0qCNNeN9I1GO9AI2ZURk=
+github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240716162946-891a0d5db073/go.mod h1:AaKKoshr8RI1LZTheeNDtNuZ39qNVPWVK4uir2c2XIs=
 github.com/Psiphon-Labs/quic-go v0.0.0-20240424181006-45545f5e1536 h1:pM5ex1QufkHV8lDR6Tc1Crk1bW5lYZjrFIJGZNBWE9k=
 github.com/Psiphon-Labs/quic-go v0.0.0-20240424181006-45545f5e1536/go.mod h1:2MTiPsgoOqWs3Bo6Xr3ElMBX6zzfjd3YkDFpQJLwHdQ=
 github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=

+ 0 - 2
vendor/github.com/Psiphon-Labs/psiphon-tls/handshake_client.go

@@ -84,7 +84,6 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
 	}
 
 	// [Psiphon]
-	// TODO! is extraConfig check necessary/
 	if c.config != nil {
 		hello.PRNG = c.config.ClientHelloPRNG
 		if c.config.GetClientHelloRandom != nil {
@@ -124,7 +123,6 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
 	}
 
 	// [Psiphon]
-	// TODO! is config != nil check necessary?
 	var err error
 	if c.config == nil || c.config.GetClientHelloRandom == nil {
 

+ 53 - 14
vendor/github.com/Psiphon-Labs/psiphon-tls/ticket.go

@@ -12,6 +12,7 @@ import (
 	"crypto/sha256"
 	"crypto/subtle"
 	"crypto/x509"
+	"encoding/binary"
 	"errors"
 	"io"
 	"math/big"
@@ -459,16 +460,22 @@ type ObfuscatedClientSessionState struct {
 	SessionTicket      []uint8
 	Vers               uint16
 	CipherSuite        uint16
+	CreatedAt          uint64 // seconds since UNIX epoch
 	MasterSecret       []byte
 	ServerCertificates []*x509.Certificate
 	VerifiedChains     [][]*x509.Certificate
-	UseEMS             bool
+	ExtMasterSecret    bool
+
+	// Client-side TLS 1.3-only fields.
+	UseBy  uint64 // seconds since UNIX epoch
+	AgeAdd uint32
 }
 
-var obfuscatedSessionTicketCipherSuite = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+var obfuscatedSessionTicketCipherSuite_TLS12 = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+var obfuscatedSessionTicketCipherSuite_TLS13 = TLS_AES_128_GCM_SHA256
 
 // [Psiphon]
-// NewObfuscatedClientSessionState produces obfuscated session tickets.
+// NewObfuscatedClientSessionState produces obfuscated session tickets or PSK.
 //
 // # Obfuscated Session Tickets
 //
@@ -501,28 +508,47 @@ var obfuscatedSessionTicketCipherSuite = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
 //   - Since the client creates the session ticket, it selects parameters that were not
 //     negotiated with the server, such as the cipher suite. It's implicitly assumed that
 //     the server can support the selected parameters.
-//   - Obfuscated session tickets are not supported for TLS 1.3 _clients_, which use a
-//     distinct scheme. Obfuscated session ticket support in this package is intended to
-//     support TLS 1.2 clients.
-func NewObfuscatedClientSessionState(sharedSecret [32]byte) (*ObfuscatedClientSessionState, error) {
+func NewObfuscatedClientSessionState(
+	sharedSecret [32]byte, isTLS13 bool, extMasterSecret bool) (*ObfuscatedClientSessionState, error) {
 
 	// Create a session ticket that wasn't actually issued by the server.
 	vers := uint16(VersionTLS12)
-	cipherSuite := obfuscatedSessionTicketCipherSuite
+	cipherSuite := obfuscatedSessionTicketCipherSuite_TLS12
+	if isTLS13 {
+		vers = VersionTLS13
+		cipherSuite = obfuscatedSessionTicketCipherSuite_TLS13
+	}
+
 	masterSecret := make([]byte, masterSecretLength)
 	_, err := rand.Read(masterSecret)
 	if err != nil {
 		return nil, err
 	}
 
+	config := &Config{}
+
+	ageAdd := make([]byte, 4)
+	_, err = config.rand().Read(ageAdd)
+	if err != nil {
+		return nil, err
+	}
+
+	lifetime := maxSessionTicketLifetime
+
 	serverState := &SessionState{
 		version:          vers,
+		isClient:         false,
 		cipherSuite:      cipherSuite,
+		createdAt:        uint64(config.time().Unix()),
 		secret:           masterSecret,
 		peerCertificates: nil,
+		extMasterSecret:  extMasterSecret,
+
+		// TLS 1.3 fields
+		useBy:  uint64(config.time().Add(lifetime).Unix()),
+		ageAdd: binary.LittleEndian.Uint32(ageAdd),
 	}
 
-	config := &Config{}
 	sessionTicketKeys := []ticketKey{config.ticketKeyFromBytes(sharedSecret)}
 
 	ssBytes, err := serverState.Bytes()
@@ -538,10 +564,14 @@ func NewObfuscatedClientSessionState(sharedSecret [32]byte) (*ObfuscatedClientSe
 	// ClientSessionState objects for use in ClientSessionCaches. The client will
 	// use this cache to pretend it got that session ticket from the server.
 	clientState := &ObfuscatedClientSessionState{
-		SessionTicket: sessionTicket,
-		Vers:          vers,
-		CipherSuite:   cipherSuite,
-		MasterSecret:  masterSecret,
+		SessionTicket:   sessionTicket,
+		Vers:            vers,
+		CipherSuite:     cipherSuite,
+		MasterSecret:    masterSecret,
+		ExtMasterSecret: extMasterSecret,
+		UseBy:           serverState.useBy,
+		AgeAdd:          serverState.ageAdd,
+		CreatedAt:       serverState.createdAt,
 	}
 
 	return clientState, nil
@@ -549,7 +579,16 @@ func NewObfuscatedClientSessionState(sharedSecret [32]byte) (*ObfuscatedClientSe
 
 func ContainsObfuscatedSessionTicketCipherSuite(cipherSuites []uint16) bool {
 	for _, cipherSuite := range cipherSuites {
-		if cipherSuite == obfuscatedSessionTicketCipherSuite {
+		if cipherSuite == obfuscatedSessionTicketCipherSuite_TLS12 {
+			return true
+		}
+	}
+	return false
+}
+
+func ContainsObfuscatedPSKCipherSuite(cipherSuites []uint16) bool {
+	for _, cipherSuite := range cipherSuites {
+		if cipherSuite == obfuscatedSessionTicketCipherSuite_TLS13 {
 			return true
 		}
 	}

+ 1 - 1
vendor/modules.txt

@@ -23,7 +23,7 @@ github.com/Psiphon-Labs/consistent
 # github.com/Psiphon-Labs/goptlib v0.0.0-20200406165125-c0e32a7a3464
 ## explicit
 github.com/Psiphon-Labs/goptlib
-# github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240424193802-52b2602ec60c
+# github.com/Psiphon-Labs/psiphon-tls v0.0.0-20240716162946-891a0d5db073
 ## explicit; go 1.21
 github.com/Psiphon-Labs/psiphon-tls
 # github.com/Psiphon-Labs/quic-go v0.0.0-20240424181006-45545f5e1536