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

Allow TLS cache wrapper user to specify hard-coded session key

aa
Amir Khan 1 год назад
Родитель
Сommit
31e41fdafa
2 измененных файлов с 11 добавлено и 19 удалено
  1. 7 13
      psiphon/common/tlsCache.go
  2. 4 6
      psiphon/dialParameters.go

+ 7 - 13
psiphon/common/tlsCache.go

@@ -20,8 +20,6 @@
 package common
 package common
 
 
 import (
 import (
-	"fmt"
-
 	tls "github.com/Psiphon-Labs/psiphon-tls"
 	tls "github.com/Psiphon-Labs/psiphon-tls"
 	utls "github.com/refraction-networking/utls"
 	utls "github.com/refraction-networking/utls"
 )
 )
@@ -32,7 +30,7 @@ import (
 type TLSClientSessionCacheWrapper struct {
 type TLSClientSessionCacheWrapper struct {
 	tls.ClientSessionCache
 	tls.ClientSessionCache
 
 
-	// sessinoKey specifies the value of the hard-coded TLS session cache key.
+	// sessionKey specifies the value of the hard-coded TLS session cache key.
 	sessionKey string
 	sessionKey string
 }
 }
 
 
@@ -40,12 +38,12 @@ type TLSClientSessionCacheWrapper struct {
 // derived from the ipAddress and dialPortNumber.
 // derived from the ipAddress and dialPortNumber.
 func WrapClientSessionCache(
 func WrapClientSessionCache(
 	cache tls.ClientSessionCache,
 	cache tls.ClientSessionCache,
-	ipAddress string,
-	dialPortNumber int) *TLSClientSessionCacheWrapper {
+	hardCodedSessionKey string,
+) *TLSClientSessionCacheWrapper {
 
 
 	return &TLSClientSessionCacheWrapper{
 	return &TLSClientSessionCacheWrapper{
 		ClientSessionCache: cache,
 		ClientSessionCache: cache,
-		sessionKey:         sessionKey(ipAddress, dialPortNumber),
+		sessionKey:         hardCodedSessionKey,
 	}
 	}
 }
 }
 
 
@@ -81,12 +79,12 @@ type UtlsClientSessionCacheWrapper struct {
 // derived from the ipAddress and dialPortNumber.
 // derived from the ipAddress and dialPortNumber.
 func WrapUtlsClientSessionCache(
 func WrapUtlsClientSessionCache(
 	cache utls.ClientSessionCache,
 	cache utls.ClientSessionCache,
-	ipAddress string,
-	dialPortNumber int) *UtlsClientSessionCacheWrapper {
+	hardCodedSessionKey string,
+) *UtlsClientSessionCacheWrapper {
 
 
 	return &UtlsClientSessionCacheWrapper{
 	return &UtlsClientSessionCacheWrapper{
 		ClientSessionCache: cache,
 		ClientSessionCache: cache,
-		sessionKey:         sessionKey(ipAddress, dialPortNumber),
+		sessionKey:         hardCodedSessionKey,
 	}
 	}
 }
 }
 
 
@@ -107,7 +105,3 @@ func (c *UtlsClientSessionCacheWrapper) IsSessionResumptionAvailable() bool {
 func (c *UtlsClientSessionCacheWrapper) RemoveCacheEntry() {
 func (c *UtlsClientSessionCacheWrapper) RemoveCacheEntry() {
 	c.ClientSessionCache.Put(c.sessionKey, nil)
 	c.ClientSessionCache.Put(c.sessionKey, nil)
 }
 }
-
-func sessionKey(ipAddress string, dialPortNumber int) string {
-	return fmt.Sprintf("%s:%d", ipAddress, dialPortNumber)
-}

+ 4 - 6
psiphon/dialParameters.go

@@ -690,10 +690,8 @@ func MakeDialParameters(
 		if err != nil {
 		if err != nil {
 			return nil, errors.Trace(err)
 			return nil, errors.Trace(err)
 		}
 		}
-		dialParams.tlsClientSessionCache = common.WrapUtlsClientSessionCache(
-			tlsClientSessionCache,
-			serverEntry.IpAddress,
-			dialPortNumber)
+		sessionKey := net.JoinHostPort(serverEntry.IpAddress, strconv.Itoa(dialPortNumber))
+		dialParams.tlsClientSessionCache = common.WrapUtlsClientSessionCache(tlsClientSessionCache, sessionKey)
 
 
 		if !isReplay {
 		if !isReplay {
 			// Remove the cache entry to make a fresh dial when !isReplay.
 			// Remove the cache entry to make a fresh dial when !isReplay.
@@ -833,10 +831,10 @@ func MakeDialParameters(
 		if err != nil {
 		if err != nil {
 			return nil, errors.Trace(err)
 			return nil, errors.Trace(err)
 		}
 		}
+		sessionKey := net.JoinHostPort(serverEntry.IpAddress, strconv.Itoa(dialPortNumber))
 		dialParams.QUICTLSClientSessionCache = common.WrapClientSessionCache(
 		dialParams.QUICTLSClientSessionCache = common.WrapClientSessionCache(
 			quicTLSClientSessionCache,
 			quicTLSClientSessionCache,
-			serverEntry.IpAddress,
-			dialPortNumber)
+			sessionKey)
 
 
 		if !isReplay {
 		if !isReplay {
 			// Remove the cache entry to make a fresh dial when !isReplay.
 			// Remove the cache entry to make a fresh dial when !isReplay.