checkForResumption reports whether we should perform resumption on this connection.
()
| 388 | |
| 389 | // checkForResumption reports whether we should perform resumption on this connection. |
| 390 | func (hs *serverHandshakeState) checkForResumption() bool { |
| 391 | c := hs.c |
| 392 | |
| 393 | if c.config.SessionTicketsDisabled { |
| 394 | return false |
| 395 | } |
| 396 | |
| 397 | plaintext, usedOldKey := c.decryptTicket(hs.clientHello.sessionTicket) |
| 398 | if plaintext == nil { |
| 399 | return false |
| 400 | } |
| 401 | hs.sessionState = &sessionState{usedOldKey: usedOldKey} |
| 402 | ok := hs.sessionState.unmarshal(plaintext) |
| 403 | if !ok { |
| 404 | return false |
| 405 | } |
| 406 | |
| 407 | createdAt := time.Unix(int64(hs.sessionState.createdAt), 0) |
| 408 | if c.config.time().Sub(createdAt) > maxSessionTicketLifetime { |
| 409 | return false |
| 410 | } |
| 411 | |
| 412 | // Never resume a session for a different TLS version. |
| 413 | if c.vers != hs.sessionState.vers { |
| 414 | return false |
| 415 | } |
| 416 | |
| 417 | cipherSuiteOk := false |
| 418 | // Check that the client is still offering the ciphersuite in the session. |
| 419 | for _, id := range hs.clientHello.cipherSuites { |
| 420 | if id == hs.sessionState.cipherSuite { |
| 421 | cipherSuiteOk = true |
| 422 | break |
| 423 | } |
| 424 | } |
| 425 | if !cipherSuiteOk { |
| 426 | return false |
| 427 | } |
| 428 | |
| 429 | // Check that we also support the ciphersuite from the session. |
| 430 | hs.suite = selectCipherSuite([]uint16{hs.sessionState.cipherSuite}, |
| 431 | c.config.cipherSuites(), hs.cipherSuiteOk) |
| 432 | if hs.suite == nil { |
| 433 | return false |
| 434 | } |
| 435 | |
| 436 | sessionHasClientCerts := len(hs.sessionState.certificates) != 0 |
| 437 | needClientCerts := requiresClientCert(c.config.ClientAuth) |
| 438 | if needClientCerts && !sessionHasClientCerts { |
| 439 | return false |
| 440 | } |
| 441 | if sessionHasClientCerts && c.config.ClientAuth == NoClientCert { |
| 442 | return false |
| 443 | } |
| 444 | |
| 445 | return true |
| 446 | } |
| 447 |
no test coverage detected