MCPcopy Create free account
hub / github.com/XTLS/Go / initLegacySessionTicketKeyRLocked

Method initLegacySessionTicketKeyRLocked

common.go:826–852  ·  view source on GitHub ↗

initLegacySessionTicketKeyRLocked ensures the legacy SessionTicketKey field is randomized if empty, and that sessionTicketKeys is populated from it otherwise.

()

Source from the content-addressed store, hash-verified

824// initLegacySessionTicketKeyRLocked ensures the legacy SessionTicketKey field is
825// randomized if empty, and that sessionTicketKeys is populated from it otherwise.
826func (c *Config) initLegacySessionTicketKeyRLocked() {
827 // Don't write if SessionTicketKey is already defined as our deprecated string,
828 // or if it is defined by the user but sessionTicketKeys is already set.
829 if c.SessionTicketKey != [32]byte{} &&
830 (bytes.HasPrefix(c.SessionTicketKey[:], deprecatedSessionTicketKey) || len(c.sessionTicketKeys) > 0) {
831 return
832 }
833
834 // We need to write some data, so get an exclusive lock and re-check any conditions.
835 c.mutex.RUnlock()
836 defer c.mutex.RLock()
837 c.mutex.Lock()
838 defer c.mutex.Unlock()
839 if c.SessionTicketKey == [32]byte{} {
840 if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil {
841 panic(fmt.Sprintf("tls: unable to generate random session ticket key: %v", err))
842 }
843 // Write the deprecated prefix at the beginning so we know we created
844 // it. This key with the DEPRECATED prefix isn't used as an actual
845 // session ticket key, and is only randomized in case the application
846 // reuses it for some reason.
847 copy(c.SessionTicketKey[:], deprecatedSessionTicketKey)
848 } else if !bytes.HasPrefix(c.SessionTicketKey[:], deprecatedSessionTicketKey) && len(c.sessionTicketKeys) == 0 {
849 c.sessionTicketKeys = []ticketKey{c.ticketKeyFromBytes(c.SessionTicketKey)}
850 }
851
852}
853
854// ticketKeys returns the ticketKeys for this connection.
855// If configForClient has explicitly set keys, those will

Callers 1

ticketKeysMethod · 0.95

Calls 2

randMethod · 0.95
ticketKeyFromBytesMethod · 0.95

Tested by

no test coverage detected