Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to go1.21.9 #27

Merged
merged 96 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
718e1a2
internal/godebug: export non-default-behavior counters in runtime/met…
rsc Nov 28, 2022
13f43d5
all: fix typos in go file comments
meyermarcel Jan 19, 2023
e100e8d
crypto/tls: improve client auth failure alerts
anitgandhi Nov 21, 2022
326ef1d
crypto/rand, internal/syscall/unix: add support for getrandom on NetB…
tklauser Jan 25, 2023
badb8f8
crypto/sha512: reduce add usage on PPC64
pmur Jan 4, 2023
8369e7a
all: give nested modules fully-qualified names
prattmic Jan 12, 2023
0b2a7dc
all: fix problematic comments
cuishuang Jan 29, 2023
a8807b3
crypto/rand: batch large random reads on js
johanbrandhorst Jan 31, 2023
1a6cc6e
crypto/rand: replace shift with constant
johanbrandhorst Feb 4, 2023
c9d60af
crypto/sha1: use math/bits.RotateLeft32
AlexanderYastrebov Oct 24, 2022
1d5a212
crypto/ecdh: explicitly reject mismatched curves in ECDH
rolandshoemaker Jan 31, 2023
6dd8db1
crypto/internal/edwards25519: reduce Point size by reordering fields
Jorropo Feb 13, 2023
72f8bb3
crypto/tls: replace all usages of BytesOrPanic
rolandshoemaker Dec 14, 2022
e27a5ff
crypto/internal/bigmod: flag amd64 assembly as noescape
FiloSottile Jan 8, 2023
4040ca4
crypto/internal/nistec: reduce P-256 scalar
FiloSottile Feb 13, 2023
a78ff97
crypto/x509: fix ParsePKCS8PrivateKey comment
rolandshoemaker Feb 28, 2023
8cbb128
crypto/x509: fix system root tests + darwin intermediate handling
rolandshoemaker Feb 28, 2023
e74c4b6
crypto/x509: fix broken tests
rolandshoemaker Mar 1, 2023
8f66022
crypto/x509: make TestIssue51759 builder only
rolandshoemaker Mar 1, 2023
00d18e9
all: move //go: function directives directly above functions
prattmic Mar 2, 2023
03bc703
crypto/ed25519: improve Ed25519ctx error for oversized contexts
tmthrgd Mar 6, 2023
e4f9e09
all: fix some problematic comments
cuishuang Mar 11, 2023
92e8a09
crypto/internal/nistec: refactor scalar multiplication
FiloSottile Feb 13, 2023
e8a791e
crypto/x509: surface ReasonCode in RevocationList API
aarongable Feb 15, 2023
fc5d9aa
crypto/rsa: deprecate multiprime RSA support
FiloSottile Dec 29, 2022
67c5966
crypto/elliptic: deprecate unsafe APIs
FiloSottile Dec 29, 2022
328390e
all: replace leading spaces with tabs in assembly
prattmic Mar 23, 2023
49d0e28
crypto/x509: remove letters from the end of basic constraints parsing…
mateusz834 Mar 23, 2023
20ce9eb
crypto/x509: remove unnecessary !Empty() check
mateusz834 Mar 23, 2023
e304bc4
all: add a few links in package godocs
mvdan Mar 23, 2023
ee2b710
crypto/sha256: add sha-ni implementation
tpaint May 26, 2022
6581377
crypto/subtle: don't cast to *uintptr when word size is 0
randall77 Mar 30, 2023
ad740cf
all: fix misuses of "a" vs "an"
cuishuang Mar 30, 2023
b1d56d5
crypto/x509: skip broken darwin root tests
prattmic Apr 10, 2023
7e7ae0a
crypto/internal/nistec: update generator for re-enabled s390x asm
ianlancetaylor Apr 11, 2023
a5b55fe
crypto: add wasip1 support
johanbrandhorst Mar 25, 2023
f2fc44b
crypto/tls: retry DialWithTimeout until the listener accepts a connec…
Apr 17, 2023
8923edd
std: fix various nilness findings
adonovan Apr 19, 2023
a55f408
crypto/x509: use the RFC 6125 terminology in the VerifyHostname docs
mateusz834 Apr 20, 2023
70a2712
cmd/internal/obj/ppc64: modify PCALIGN to ensure alignment
laboger Apr 17, 2023
60da880
crypto/tls: fix PSK binder calculation
tsaarni Apr 12, 2023
066b64e
crypto/sha256: add WriteString and WriteByte method
ianlancetaylor Apr 3, 2023
225bffe
crypto/sha1: add WriteString and WriteByte method
ianlancetaylor Apr 11, 2023
80669ce
crypto/sha512: add WriteString and WriteByte method
ianlancetaylor Apr 12, 2023
df0fc7f
crypto: use t.Parallel() to increase speed
cuishuang Apr 6, 2023
9304f00
Revert "crypto/sha512: add WriteString and WriteByte method"
ianlancetaylor May 3, 2023
122dd08
Revert "crypto/sha256: add WriteString and WriteByte method"
ianlancetaylor May 3, 2023
52a0cee
Revert "crypto/sha1: add WriteString and WriteByte method"
ianlancetaylor May 3, 2023
bbcd63f
crypto/rsa: use BoringCrypto for 4096 bit keys
FiloSottile Mar 8, 2023
e076e5d
crypto/ed25519,crypto/rsa: make Equal methods constant time
FiloSottile May 5, 2023
8f2e597
crypto/x509: fix certificate validation with FQDN on Windows
Gulio May 17, 2023
20f0721
crypto/rsa: make DecryptPKCS1v15SessionKey warning more dire
rolandshoemaker Feb 17, 2023
a79bcd3
crypto/x509: properly apply name constrains to roots and intermediates
rolandshoemaker Mar 21, 2023
2140ada
crypto/tls: remove unused nonAESGCMAEADCiphers variable
thaJeztah Nov 14, 2022
04f7828
crypto/tls: enforce 1.3 record version semantics
rolandshoemaker Apr 18, 2023
664320c
crypto/internal/bigmod: switch to saturated limbs
FiloSottile Feb 25, 2023
f9c5836
crypto/rsa,crypto/internal/bigmod: optimized short exponentiations
FiloSottile May 5, 2023
bc3ad94
crypto/tls: support QUIC as a transport
neild Oct 14, 2022
621de49
crypto/tls: reduce session ticket linkability
FiloSottile May 19, 2023
246e76f
crypto/tls: add SessionState and use it on the server side
FiloSottile May 20, 2023
35f08ed
crypto/tls: use SessionState on the client side
FiloSottile May 21, 2023
c5a88b8
crypto/tls: add ClientSessionState.ResumptionState and NewResumptionS…
FiloSottile May 21, 2023
ec82ae8
crypto/tls: add WrapSession and UnwrapSession
FiloSottile May 22, 2023
5dedb84
crypto/tls: add SessionState.Extra
FiloSottile May 22, 2023
e6eb4ce
crypto/tls: add QUIC 0-RTT APIs
FiloSottile May 22, 2023
ce5eae4
crypto/tls: implement Extended Master Secret
FiloSottile May 23, 2023
a2861c0
crypto/tls: add VersionName
FiloSottile May 24, 2023
ce82bd4
crypto/tls: don't reverify but check certificate expiration on resump…
FiloSottile May 24, 2023
13883fd
crypto/tls: advertise correct ciphers in TLS 1.3 only mode
enj Jan 13, 2023
abebf6e
crypto/internal/bigmod: don't panic on NewModulusFromBig(0)
rolandshoemaker May 24, 2023
e25cc81
crypto/tls: avoid referencing potentially unused symbols in init
neild May 26, 2023
86462cc
crypto/tls: fix cipher suite check when doing 0-RTT resumption
marten-seemann May 25, 2023
324c23f
all: fix function names in comments
cuishuang Jun 9, 2023
0353dcc
crypto/tls: make SessionState.Extra a slice of byte slices
FiloSottile Jun 7, 2023
94f9c47
Revert "crypto/internal/nistec: refactor scalar multiplication"
FiloSottile Jun 12, 2023
2176377
crypto/ecdsa: properly truncate P-521 hashes
FiloSottile Jun 12, 2023
8eacbd1
all: fix spelling errors
AlexanderYastrebov Jun 13, 2023
a38a1d0
crypto/x509: use synthetic root for platform testing
rolandshoemaker Apr 25, 2023
ec1e76d
crypto/x509: tolerate multiple matching chains in testVerify
rolandshoemaker Jun 21, 2023
4de860a
crypto: document non-determinism of GenerateKey
FiloSottile Jun 22, 2023
80abb38
crypto/x509: rename duplicated test
rolandshoemaker Jun 23, 2023
7c95775
[release-branch.go1.21] crypto/tls: restrict RSA keys in certificates…
rolandshoemaker Jun 7, 2023
53dbcf8
[release-branch.go1.21] crypto/tls: change SendSessionTicket to take …
neild Aug 1, 2023
0eb2af3
[release-branch.go1.21] crypto/tls: add GODEBUG to control max RSA ke…
rolandshoemaker Aug 9, 2023
121aac8
[release-branch.go1.21] crypto/tls: QUIC: fix panics when processing …
neild Aug 24, 2023
c05596d
[release-branch.go1.21] crypto/rand,runtime: switch RtlGenRandom for …
rolandshoemaker Oct 18, 2023
d2ca87e
[release-branch.go1.21] crypto/internal/boring: upgrade module to fip…
FiloSottile Dec 14, 2023
1af63ac
[release-branch.go1.21] crypto/tls: align FIPS-only mode with BoringS…
FiloSottile Dec 14, 2023
20c6214
[release-branch.go1.21] crypto/x509: properly gate test on macos version
rolandshoemaker Dec 12, 2023
0efad45
[release-branch.go1.21] Revert "crypto/internal/boring: upgrade modul…
FiloSottile Jan 26, 2024
abc351c
[release-branch.go1.21] crypto/x509: make sure pub key is non-nil bef…
rolandshoemaker Jan 18, 2024
50bbfe0
chore: upgrade to go1.21.9
bassosimone Apr 12, 2024
77c90c6
chore: merge with go1.21.9
bassosimone Apr 12, 2024
f557be0
fix: remove merge leftovers breaking the build
bassosimone Apr 12, 2024
e38b265
fix: make sure go test ./... passes
bassosimone Apr 12, 2024
1d387c4
chore: upgrade dependencies
bassosimone Apr 12, 2024
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ will continue to keep this fork up to date as long as it serves our goals.

## Intended usage

You MUST use this package with the exact Go version from which we extracted
You SHOULD use this package with the exact Go version from which we extracted
the source, which is documented in the [Update procedure](#update-procedure) section. The
standard library is composed of tightly integrated packages, hence
using this code with another Go version could cause subtle security issues.
Expand Down Expand Up @@ -93,7 +93,7 @@ to improve hardware capability detection on `android/arm64`.
(Adapted from ooni/oohttp instructions.)

- [ ] check whether hardware capability detection has been improved upstream
by reading [os_linux.go](https://github.com/golang/go/blob/go1.20.14/src/runtime/os_linux.go#L246)
by reading [os_linux.go](https://github.com/golang/go/blob/go1.21.9/src/runtime/os_linux.go#L250)
and update the link to `os_linux.go` based on the upstream version that
we're tracking with this fork

Expand Down Expand Up @@ -121,12 +121,19 @@ the following checks (we could also use `go list` as follows

3. `git grep 'aes"'`

4. `git grep 'alias"'`

5. `git grep 'boring"'`

- [ ] double check whether we need to add more checks to the list above (you
can get a list of packages using `tree -d`)

- [ ] ensure that `stdlibwrapper.go` correctly fills `tls.ConnectionState`
in the `ConnStdlib.ConnectionState` method

- [ ] use `./tools/compare.bash` to make sure the changes with respect
to upstream are reasonable

- [ ] `go build -v ./...` must succeed

- [ ] `go test -race ./...` must succeed
Expand Down
2 changes: 1 addition & 1 deletion UPSTREAM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go1.20.14
go1.21.9
2 changes: 1 addition & 1 deletion aes/asm_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ks128Loop:
BNE ks128Loop
CBZ R11, ksDone // If dec is nil we are done
SUB $176, R10
// Decryption keys are encryption keys with InverseMixColumns applied
// Decryption keys are encryption keys with InverseMixColumns applied
VLD1.P 64(R10), [V0.B16, V1.B16, V2.B16, V3.B16]
VMOV V0.B16, V7.B16
AESIMC V1.B16, V6.B16
Expand Down
2 changes: 1 addition & 1 deletion aes/gcm_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ initEncFinish:
AESE T0.B16, B0.B16
AESMC B0.B16, B0.B16
AESE T1.B16, B0.B16
VEOR T2.B16, B0.B16, B0.B16
VEOR T2.B16, B0.B16, B0.B16

VREV64 B0.B16, B0.B16

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module github.com/ooni/oocrypto

go 1.20

require golang.org/x/crypto v0.21.0
require golang.org/x/crypto v0.22.0

require golang.org/x/sys v0.18.0
require golang.org/x/sys v0.19.0
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2 changes: 1 addition & 1 deletion internal/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package alias implements memory alaising tests.
// Package alias implements memory aliasing tests.
// This code also exists as golang.org/x/crypto/internal/alias.
package alias

Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions tls/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ package tls

import "strconv"

// An AlertError is a TLS alert.
//
// When using a QUIC transport, QUICConn methods will return an error
// which wraps AlertError rather than sending a TLS alert.
type AlertError uint8

func (e AlertError) Error() string {
return alert(e).String()
}

type alert uint8

const (
Expand Down
6 changes: 3 additions & 3 deletions tls/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type cacheEntry struct {
// multiple Conns. Returned references should not be mutated by callers. Certificates
// are still safe to use after they are removed from the cache.
//
// Certificates are returned wrapped in a activeCert struct that should be held by
// Certificates are returned wrapped in an activeCert struct that should be held by
// the caller. When references to the activeCert are freed, the number of references
// to the certificate in the cache is decremented. Once the number of references
// reaches zero, the entry is evicted from the cache.
Expand All @@ -39,7 +39,7 @@ type certCache struct {
sync.Map
}

var clientCertCache = new(certCache)
var globalCertCache = new(certCache)

// activeCert is a handle to a certificate held in the cache. Once there are
// no alive activeCerts for a given certificate, the certificate is removed
Expand All @@ -49,7 +49,7 @@ type activeCert struct {
}

// active increments the number of references to the entry, wraps the
// certificate in the entry in a activeCert, and sets the finalizer.
// certificate in the entry in an activeCert, and sets the finalizer.
//
// Note that there is a race between active and the finalizer set on the
// returned activeCert, triggered if active is called after the ref count is
Expand Down
8 changes: 0 additions & 8 deletions tls/cipher_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,6 @@ var aesgcmCiphers = map[uint16]bool{
TLS_AES_256_GCM_SHA384: true,
}

var nonAESGCMAEADCiphers = map[uint16]bool{
// TLS 1.2
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: true,
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: true,
// TLS 1.3
TLS_CHACHA20_POLY1305_SHA256: true,
}

// aesgcmPreferred returns whether the first known cipher in the preference list
// is an AES-GCM cipher, implying the peer has hardware support for it.
func aesgcmPreferred(ciphers []uint16) bool {
Expand Down
121 changes: 79 additions & 42 deletions tls/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ const (
VersionSSL30 = 0x0300
)

// VersionName returns the name for the provided TLS version number
// (e.g. "TLS 1.3"), or a fallback representation of the value if the
// version is not implemented by this package.
func VersionName(version uint16) string {
switch version {
case VersionSSL30:
return "SSLv3"
case VersionTLS10:
return "TLS 1.0"
case VersionTLS11:
return "TLS 1.1"
case VersionTLS12:
return "TLS 1.2"
case VersionTLS13:
return "TLS 1.3"
default:
return fmt.Sprintf("0x%04X", version)
}
}

const (
maxPlaintext = 16384 // maximum plaintext payload length
maxCiphertext = 16384 + 2048 // maximum ciphertext payload length
Expand Down Expand Up @@ -90,6 +110,7 @@ const (
extensionSignatureAlgorithms uint16 = 13
extensionALPN uint16 = 16
extensionSCT uint16 = 18
extensionExtendedMasterSecret uint16 = 23
extensionSessionTicket uint16 = 35
extensionPreSharedKey uint16 = 41
extensionEarlyData uint16 = 42
Expand All @@ -99,6 +120,7 @@ const (
extensionCertificateAuthorities uint16 = 47
extensionSignatureAlgorithmsCert uint16 = 50
extensionKeyShare uint16 = 51
extensionQUICTransportParameters uint16 = 57
extensionRenegotiationInfo uint16 = 0xff01
)

Expand Down Expand Up @@ -270,12 +292,8 @@ type ConnectionState struct {
OCSPResponse []byte

// TLSUnique contains the "tls-unique" channel binding value (see RFC 5929,
// Section 3). This value will be nil for TLS 1.3 connections and for all
// resumed connections.
//
// Deprecated: there are conditions in which this value might not be unique
// to a connection. See the Security Considerations sections of RFC 5705 and
// RFC 7627, and https://mitls.org/pages/attacks/3SHAKE#channelbindings.
// Section 3). This value will be nil for TLS 1.3 connections and for
// resumed connections that don't support Extended Master Secret (RFC 7627).
TLSUnique []byte

// ekm is a closure exposed via ExportKeyingMaterial.
Expand All @@ -286,6 +304,10 @@ type ConnectionState struct {
// slice as defined in RFC 5705. If context is nil, it is not used as part of
// the seed. If the connection was set to allow renegotiation via
// Config.Renegotiation, this function will return an error.
//
// There are conditions in which the returned values might not be unique to a
// connection. See the Security Considerations sections of RFC 5705 and RFC 7627,
// and https://mitls.org/pages/attacks/3SHAKE#channelbindings.
func (cs *ConnectionState) ExportKeyingMaterial(label string, context []byte, length int) ([]byte, error) {
return cs.ekm(label, context, length)
}
Expand Down Expand Up @@ -329,25 +351,6 @@ func requiresClientCert(c ClientAuthType) bool {
}
}

// ClientSessionState contains the state needed by clients to resume TLS
// sessions.
type ClientSessionState struct {
sessionTicket []uint8 // Encrypted ticket used for session resumption with server
vers uint16 // TLS version negotiated for the session
cipherSuite uint16 // Ciphersuite negotiated for the session
masterSecret []byte // Full handshake MasterSecret, or TLS 1.3 resumption_master_secret
serverCertificates []*x509.Certificate // Certificate chain presented by the server
verifiedChains [][]*x509.Certificate // Certificate chains we built for verification
receivedAt time.Time // When the session ticket was received from the server
ocspResponse []byte // Stapled OCSP response presented by the server
scts [][]byte // SCTs presented by the server

// TLS 1.3 fields.
nonce []byte // Ticket nonce sent by the server, to derive PSK
useBy time.Time // Expiration of the ticket lifetime as set by the server
ageAdd uint32 // Random obfuscation factor for sending the ticket age
}

// ClientSessionCache is a cache of ClientSessionState objects that can be used
// by a client to resume a TLS session with a given server. ClientSessionCache
// implementations should expect to be called concurrently from different
Expand Down Expand Up @@ -601,10 +604,16 @@ type Config struct {
// non-nil error, the handshake is aborted and that error results.
//
// If normal verification fails then the handshake will abort before
// considering this callback. If normal verification is disabled by
// setting InsecureSkipVerify, or (for a server) when ClientAuth is
// RequestClientCert or RequireAnyClientCert, then this callback will
// be considered but the verifiedChains argument will always be nil.
// considering this callback. If normal verification is disabled (on the
// client when InsecureSkipVerify is set, or on a server when ClientAuth is
// RequestClientCert or RequireAnyClientCert), then this callback will be
// considered but the verifiedChains argument will always be nil. When
// ClientAuth is NoClientCert, this callback is not called on the server.
// rawCerts may be empty on the server if ClientAuth is RequestClientCert or
// VerifyClientCertIfGiven.
//
// This callback is not invoked on resumed connections, as certificates are
// not re-verified on resumption.
//
// verifiedChains and its contents should not be modified.
VerifyPeerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error
Expand All @@ -615,8 +624,9 @@ type Config struct {
// and that error results.
//
// If normal verification fails then the handshake will abort before
// considering this callback. This callback will run for all connections
// regardless of InsecureSkipVerify or ClientAuth settings.
// considering this callback. This callback will run for all connections,
// including resumptions, regardless of InsecureSkipVerify or ClientAuth
// settings.
VerifyConnection func(ConnectionState) error

// RootCAs defines the set of root certificate authorities
Expand Down Expand Up @@ -691,6 +701,35 @@ type Config struct {
// session resumption. It is only used by clients.
ClientSessionCache ClientSessionCache

// UnwrapSession is called on the server to turn a ticket/identity
// previously produced by [WrapSession] into a usable session.
//
// UnwrapSession will usually either decrypt a session state in the ticket
// (for example with [Config.EncryptTicket]), or use the ticket as a handle
// to recover a previously stored state. It must use [ParseSessionState] to
// deserialize the session state.
//
// If UnwrapSession returns an error, the connection is terminated. If it
// returns (nil, nil), the session is ignored. crypto/tls may still choose
// not to resume the returned session.
UnwrapSession func(identity []byte, cs ConnectionState) (*SessionState, error)

// WrapSession is called on the server to produce a session ticket/identity.
//
// WrapSession must serialize the session state with [SessionState.Bytes].
// It may then encrypt the serialized state (for example with
// [Config.DecryptTicket]) and use it as the ticket, or store the state and
// return a handle for it.
//
// If WrapSession returns an error, the connection is terminated.
//
// Warning: the return value will be exposed on the wire and to clients in
// plaintext. The application is in charge of encrypting and authenticating
// it (and rotating keys) or returning high-entropy identifiers. Failing to
// do so correctly can compromise current, previous, and future connections
// depending on the protocol version.
WrapSession func(ConnectionState, *SessionState) ([]byte, error)

// MinVersion contains the minimum TLS version that is acceptable.
//
// By default, TLS 1.2 is currently used as the minimum when acting as a
Expand Down Expand Up @@ -747,10 +786,6 @@ type Config struct {
}

const (
// ticketKeyNameLen is the number of bytes of identifier that is prepended to
// an encrypted session ticket in order to identify the key used to encrypt it.
ticketKeyNameLen = 16

// ticketKeyLifetime is how long a ticket key remains valid and can be used to
// resume a client connection.
ticketKeyLifetime = 7 * 24 * time.Hour // 7 days
Expand All @@ -762,9 +797,6 @@ const (

// ticketKey is the internal representation of a session ticket key.
type ticketKey struct {
// keyName is an opaque byte string that serves to identify the session
// ticket key. It's exposed as plaintext in every session ticket.
keyName [ticketKeyNameLen]byte
aesKey [16]byte
hmacKey [16]byte
// created is the time at which this ticket key was created. See Config.ticketKeys.
Expand All @@ -776,15 +808,18 @@ type ticketKey struct {
// bytes and this function expands that into sufficient name and key material.
func (c *Config) ticketKeyFromBytes(b [32]byte) (key ticketKey) {
hashed := sha512.Sum512(b[:])
copy(key.keyName[:], hashed[:ticketKeyNameLen])
copy(key.aesKey[:], hashed[ticketKeyNameLen:ticketKeyNameLen+16])
copy(key.hmacKey[:], hashed[ticketKeyNameLen+16:ticketKeyNameLen+32])
// The first 16 bytes of the hash used to be exposed on the wire as a ticket
// prefix. They MUST NOT be used as a secret. In the future, it would make
// sense to use a proper KDF here, like HKDF with a fixed salt.
const legacyTicketKeyNameLen = 16
copy(key.aesKey[:], hashed[legacyTicketKeyNameLen:])
copy(key.hmacKey[:], hashed[legacyTicketKeyNameLen+len(key.aesKey):])
key.created = c.time()
return key
}

// maxSessionTicketLifetime is the maximum allowed lifetime of a TLS 1.3 session
// ticket, and the lifetime we set for tickets we send.
// ticket, and the lifetime we set for all tickets we send.
const maxSessionTicketLifetime = 7 * 24 * time.Hour

// Clone returns a shallow clone of c or nil if c is nil. It is safe to clone a Config that is
Expand Down Expand Up @@ -816,6 +851,8 @@ func (c *Config) Clone() *Config {
SessionTicketsDisabled: c.SessionTicketsDisabled,
SessionTicketKey: c.SessionTicketKey,
ClientSessionCache: c.ClientSessionCache,
UnwrapSession: c.UnwrapSession,
WrapSession: c.WrapSession,
MinVersion: c.MinVersion,
MaxVersion: c.MaxVersion,
CurvePreferences: c.CurvePreferences,
Expand Down
Loading
Loading