]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/crypto/tls/common.go
crypto/tls: add WrapSession and UnwrapSession
[gostls13.git] / src / crypto / tls / common.go
index ccaf7d352fcdef77b6ed8f4065af0b5a4a25799c..8da3cc50cab2d1a66fcf93ca0dd204eaf30a3e2c 100644 (file)
@@ -673,6 +673,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
@@ -794,6 +823,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,