nolint:gocognit,cyclop
( state *State, cache *handshakeCache, cfg *handshakeConfig, handshakeKeyExchange *handshake.MessageServerKeyExchange, sendingPlainText []byte, )
| 307 | |
| 308 | //nolint:gocognit,cyclop |
| 309 | func 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, |
no test coverage detected
searching dependent graphs…