Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,12 @@ type Config struct {
// this behavior at their own discretion.
OmitEmptyPsk bool // [uTLS]

// AlwaysIncludePSK controls whether the PreSharedKey extension is always
// included in the ClientHello if there is a cached session, even if not specified
// in the selected ClientHelloSpec. If there are no cached sessions, OmitEmptyPsk
// controls whether the extension is omitted.
AlwaysIncludePSK bool // [uTLS]

// InsecureServerNameToVerify is used to verify the hostname on the returned
// certificates. It is intended to use with spoofed ServerName.
// If InsecureServerNameToVerify is "*", crypto/tls will do normal
Expand Down Expand Up @@ -999,6 +1005,7 @@ func (c *Config) Clone() *Config {
InsecureSkipTimeVerify: c.InsecureSkipTimeVerify,
InsecureServerNameToVerify: c.InsecureServerNameToVerify,
OmitEmptyPsk: c.OmitEmptyPsk,
AlwaysIncludePSK: c.AlwaysIncludePSK,
CipherSuites: c.CipherSuites,
PreferServerCipherSuites: c.PreferServerCipherSuites,
SessionTicketsDisabled: c.SessionTicketsDisabled,
Expand Down
2 changes: 1 addition & 1 deletion tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ func TestCloneNonFuncFields(t *testing.T) {
f.Set(reflect.ValueOf("b"))
case "ClientAuth":
f.Set(reflect.ValueOf(VerifyClientCertIfGiven))
case "InsecureSkipVerify", "InsecureSkipTimeVerify", "SessionTicketsDisabled", "DynamicRecordSizingDisabled", "PreferServerCipherSuites", "OmitEmptyPsk", "PreferSkipResumptionOnNilExtension":
case "InsecureSkipVerify", "InsecureSkipTimeVerify", "SessionTicketsDisabled", "DynamicRecordSizingDisabled", "PreferServerCipherSuites", "OmitEmptyPsk", "PreferSkipResumptionOnNilExtension", "AlwaysIncludePSK":
f.Set(reflect.ValueOf(true))
case "InsecureServerNameToVerify":
f.Set(reflect.ValueOf("c"))
Expand Down
17 changes: 17 additions & 0 deletions u_parrots.go
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,23 @@ func (uconn *UConn) ApplyPreset(p *ClientHelloSpec) error {
return err
}

// Add PSK extension if not specified in the spec.
if uconn.config.AlwaysIncludePSK {
supportsPSK := uconn.config.MaxVersion >= VersionTLS13
if supportsPSK {
hasPskExt := false
for _, ext := range p.Extensions {
if _, ok := ext.(PreSharedKeyExtension); ok {
hasPskExt = true
}
}
if !hasPskExt {
// pre_shared_key must be the last extension (RFC 8446, Section 4.2.11).
p.Extensions = append(p.Extensions, &UtlsPreSharedKeyExtension{})
}
}
}

privateHello, clientKeySharePrivate, ech, err := uconn.makeClientHelloForApplyPreset()
if err != nil {
return err
Expand Down