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

Method doHelloRetryRequest

handshake_server_tls13.go:396–454  ·  view source on GitHub ↗
(selectedGroup CurveID)

Source from the content-addressed store, hash-verified

394}
395
396func (hs *serverHandshakeStateTLS13) doHelloRetryRequest(selectedGroup CurveID) error {
397 c := hs.c
398
399 // The first ClientHello gets double-hashed into the transcript upon a
400 // HelloRetryRequest. See RFC 8446, Section 4.4.1.
401 hs.transcript.Write(hs.clientHello.marshal())
402 chHash := hs.transcript.Sum(nil)
403 hs.transcript.Reset()
404 hs.transcript.Write([]byte{typeMessageHash, 0, 0, uint8(len(chHash))})
405 hs.transcript.Write(chHash)
406
407 helloRetryRequest := &serverHelloMsg{
408 vers: hs.hello.vers,
409 random: helloRetryRequestRandom,
410 sessionId: hs.hello.sessionId,
411 cipherSuite: hs.hello.cipherSuite,
412 compressionMethod: hs.hello.compressionMethod,
413 supportedVersion: hs.hello.supportedVersion,
414 selectedGroup: selectedGroup,
415 }
416
417 hs.transcript.Write(helloRetryRequest.marshal())
418 if _, err := c.writeRecord(recordTypeHandshake, helloRetryRequest.marshal()); err != nil {
419 return err
420 }
421
422 if err := hs.sendDummyChangeCipherSpec(); err != nil {
423 return err
424 }
425
426 msg, err := c.readHandshake()
427 if err != nil {
428 return err
429 }
430
431 clientHello, ok := msg.(*clientHelloMsg)
432 if !ok {
433 c.sendAlert(alertUnexpectedMessage)
434 return unexpectedMessageError(clientHello, msg)
435 }
436
437 if len(clientHello.keyShares) != 1 || clientHello.keyShares[0].group != selectedGroup {
438 c.sendAlert(alertIllegalParameter)
439 return errors.New("tls: client sent invalid key share in second ClientHello")
440 }
441
442 if clientHello.earlyData {
443 c.sendAlert(alertIllegalParameter)
444 return errors.New("tls: client indicated early data in second ClientHello")
445 }
446
447 if illegalClientHelloChange(clientHello, hs.clientHello) {
448 c.sendAlert(alertIllegalParameter)
449 return errors.New("tls: client illegally modified second ClientHello")
450 }
451
452 hs.clientHello = clientHello
453 return nil

Callers 1

processClientHelloMethod · 0.95

Calls 11

marshalMethod · 0.95
unexpectedMessageErrorFunction · 0.85
illegalClientHelloChangeFunction · 0.85
ResetMethod · 0.80
writeRecordMethod · 0.80
readHandshakeMethod · 0.80
sendAlertMethod · 0.80
marshalMethod · 0.65
WriteMethod · 0.45
SumMethod · 0.45

Tested by

no test coverage detected