MCPcopy Create free account
hub / github.com/pion/dtls / initializeCipherSuite

Function initializeCipherSuite

flight5handler.go:309–410  ·  view source on GitHub ↗

nolint:gocognit,cyclop

(
	state *State,
	cache *handshakeCache,
	cfg *handshakeConfig,
	handshakeKeyExchange *handshake.MessageServerKeyExchange,
	sendingPlainText []byte,
)

Source from the content-addressed store, hash-verified

307
308//nolint:gocognit,cyclop
309func initializeCipherSuite(
310 state *State,
311 cache *handshakeCache,
312 cfg *handshakeConfig,
313 handshakeKeyExchange *handshake.MessageServerKeyExchange,
314 sendingPlainText []byte,
315) (*alert.Alert, error) {
316 if state.cipherSuite.IsInitialized() {
317 return nil, nil //nolint
318 }
319
320 clientRandom := state.localRandom.MarshalFixed()
321 serverRandom := state.remoteRandom.MarshalFixed()
322
323 var err error
324
325 if state.extendedMasterSecret {
326 var sessionHash []byte
327 sessionHash, err = cache.sessionHash(state.cipherSuite.HashFunc(), cfg.initialEpoch, sendingPlainText)
328 if err != nil {
329 return &alert.Alert{Level: alert.Fatal, Description: alert.InternalError}, err
330 }
331
332 state.masterSecret, err = prf.ExtendedMasterSecret(state.preMasterSecret, sessionHash, state.cipherSuite.HashFunc())
333 if err != nil {
334 return &alert.Alert{Level: alert.Fatal, Description: alert.IllegalParameter}, err
335 }
336 } else {
337 state.masterSecret, err = prf.MasterSecret(
338 state.preMasterSecret,
339 clientRandom[:],
340 serverRandom[:],
341 state.cipherSuite.HashFunc(),
342 )
343 if err != nil {
344 return &alert.Alert{Level: alert.Fatal, Description: alert.InternalError}, err
345 }
346 }
347
348 if state.cipherSuite.AuthenticationType() == CipherSuiteAuthenticationTypeCertificate { //nolint:nestif
349 // Verify that the pair of hash algorithm and signiture is listed.
350 var validSignatureScheme bool
351 for _, ss := range cfg.localSignatureSchemes {
352 if ss.Hash == handshakeKeyExchange.HashAlgorithm && ss.Signature == handshakeKeyExchange.SignatureAlgorithm {
353 validSignatureScheme = true
354
355 break
356 }
357 }
358 if !validSignatureScheme {
359 return &alert.Alert{Level: alert.Fatal, Description: alert.InsufficientSecurity}, errNoAvailableSignatureSchemes
360 }
361
362 expectedMsg := valueKeyMessage(
363 clientRandom[:],
364 serverRandom[:],
365 handshakeKeyExchange.PublicKey,
366 handshakeKeyExchange.NamedCurve,

Callers 1

flight5GenerateFunction · 0.85

Calls 13

ExtendedMasterSecretFunction · 0.92
MasterSecretFunction · 0.92
valueKeyMessageFunction · 0.85
verifyKeySignatureFunction · 0.85
verifyServerCertFunction · 0.85
MarshalFixedMethod · 0.80
sessionHashMethod · 0.80
cloneMethod · 0.80
writeKeyLogMethod · 0.80
IsInitializedMethod · 0.65
HashFuncMethod · 0.65
AuthenticationTypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…