client-state-machine.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. package mint
  2. import (
  3. "bytes"
  4. "crypto"
  5. "crypto/x509"
  6. "hash"
  7. "time"
  8. )
  9. // Client State Machine
  10. //
  11. // START <----+
  12. // Send ClientHello | | Recv HelloRetryRequest
  13. // / v |
  14. // | WAIT_SH ---+
  15. // Can | | Recv ServerHello
  16. // send | V
  17. // early | WAIT_EE
  18. // data | | Recv EncryptedExtensions
  19. // | +--------+--------+
  20. // | Using | | Using certificate
  21. // | PSK | v
  22. // | | WAIT_CERT_CR
  23. // | | Recv | | Recv CertificateRequest
  24. // | | Certificate | v
  25. // | | | WAIT_CERT
  26. // | | | | Recv Certificate
  27. // | | v v
  28. // | | WAIT_CV
  29. // | | | Recv CertificateVerify
  30. // | +> WAIT_FINISHED <+
  31. // | | Recv Finished
  32. // \ |
  33. // | [Send EndOfEarlyData]
  34. // | [Send Certificate [+ CertificateVerify]]
  35. // | Send Finished
  36. // Can send v
  37. // app data --> CONNECTED
  38. // after
  39. // here
  40. //
  41. // State Instructions
  42. // START Send(CH); [RekeyOut; SendEarlyData]
  43. // WAIT_SH Send(CH) || RekeyIn
  44. // WAIT_EE {}
  45. // WAIT_CERT_CR {}
  46. // WAIT_CERT {}
  47. // WAIT_CV {}
  48. // WAIT_FINISHED RekeyIn; [Send(EOED);] RekeyOut; [SendCert; SendCV;] SendFin; RekeyOut;
  49. // CONNECTED StoreTicket || (RekeyIn; [RekeyOut])
  50. type clientStateStart struct {
  51. Config *Config
  52. Opts ConnectionOptions
  53. Params ConnectionParameters
  54. cookie []byte
  55. firstClientHello *HandshakeMessage
  56. helloRetryRequest *HandshakeMessage
  57. hsCtx *HandshakeContext
  58. }
  59. var _ HandshakeState = &clientStateStart{}
  60. func (state clientStateStart) State() State {
  61. return StateClientStart
  62. }
  63. func (state clientStateStart) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  64. // key_shares
  65. offeredDH := map[NamedGroup][]byte{}
  66. ks := KeyShareExtension{
  67. HandshakeType: HandshakeTypeClientHello,
  68. Shares: make([]KeyShareEntry, len(state.Config.Groups)),
  69. }
  70. for i, group := range state.Config.Groups {
  71. pub, priv, err := newKeyShare(group)
  72. if err != nil {
  73. logf(logTypeHandshake, "[ClientStateStart] Error generating key share [%v]", err)
  74. return nil, nil, AlertInternalError
  75. }
  76. ks.Shares[i].Group = group
  77. ks.Shares[i].KeyExchange = pub
  78. offeredDH[group] = priv
  79. }
  80. logf(logTypeHandshake, "opts: %+v", state.Opts)
  81. // supported_versions, supported_groups, signature_algorithms, server_name
  82. sv := SupportedVersionsExtension{HandshakeType: HandshakeTypeClientHello, Versions: []uint16{supportedVersion}}
  83. sni := ServerNameExtension(state.Opts.ServerName)
  84. sg := SupportedGroupsExtension{Groups: state.Config.Groups}
  85. sa := SignatureAlgorithmsExtension{Algorithms: state.Config.SignatureSchemes}
  86. state.Params.ServerName = state.Opts.ServerName
  87. // Application Layer Protocol Negotiation
  88. var alpn *ALPNExtension
  89. if (state.Opts.NextProtos != nil) && (len(state.Opts.NextProtos) > 0) {
  90. alpn = &ALPNExtension{Protocols: state.Opts.NextProtos}
  91. }
  92. // Construct base ClientHello
  93. ch := &ClientHelloBody{
  94. LegacyVersion: wireVersion(state.hsCtx.hIn),
  95. CipherSuites: state.Config.CipherSuites,
  96. }
  97. _, err := prng.Read(ch.Random[:])
  98. if err != nil {
  99. logf(logTypeHandshake, "[ClientStateStart] Error creating ClientHello random [%v]", err)
  100. return nil, nil, AlertInternalError
  101. }
  102. for _, ext := range []ExtensionBody{&sv, &sni, &ks, &sg, &sa} {
  103. err := ch.Extensions.Add(ext)
  104. if err != nil {
  105. logf(logTypeHandshake, "[ClientStateStart] Error adding extension type=[%v] [%v]", ext.Type(), err)
  106. return nil, nil, AlertInternalError
  107. }
  108. }
  109. // XXX: These optional extensions can't be folded into the above because Go
  110. // interface-typed values are never reported as nil
  111. if alpn != nil {
  112. err := ch.Extensions.Add(alpn)
  113. if err != nil {
  114. logf(logTypeHandshake, "[ClientStateStart] Error adding ALPN extension [%v]", err)
  115. return nil, nil, AlertInternalError
  116. }
  117. }
  118. if state.cookie != nil {
  119. err := ch.Extensions.Add(&CookieExtension{Cookie: state.cookie})
  120. if err != nil {
  121. logf(logTypeHandshake, "[ClientStateStart] Error adding ALPN extension [%v]", err)
  122. return nil, nil, AlertInternalError
  123. }
  124. }
  125. // Run the external extension handler.
  126. if state.Config.ExtensionHandler != nil {
  127. err := state.Config.ExtensionHandler.Send(HandshakeTypeClientHello, &ch.Extensions)
  128. if err != nil {
  129. logf(logTypeHandshake, "[ClientStateStart] Error running external extension sender [%v]", err)
  130. return nil, nil, AlertInternalError
  131. }
  132. }
  133. // Handle PSK and EarlyData just before transmitting, so that we can
  134. // calculate the PSK binder value
  135. var psk *PreSharedKeyExtension
  136. var ed *EarlyDataExtension
  137. var offeredPSK PreSharedKey
  138. var earlyHash crypto.Hash
  139. var earlySecret []byte
  140. var clientEarlyTrafficKeys keySet
  141. var clientHello *HandshakeMessage
  142. if key, ok := state.Config.PSKs.Get(state.Opts.ServerName); ok {
  143. offeredPSK = key
  144. // Narrow ciphersuites to ones that match PSK hash
  145. params, ok := cipherSuiteMap[key.CipherSuite]
  146. if !ok {
  147. logf(logTypeHandshake, "[ClientStateStart] PSK for unknown ciphersuite")
  148. return nil, nil, AlertInternalError
  149. }
  150. compatibleSuites := []CipherSuite{}
  151. for _, suite := range ch.CipherSuites {
  152. if cipherSuiteMap[suite].Hash == params.Hash {
  153. compatibleSuites = append(compatibleSuites, suite)
  154. }
  155. }
  156. ch.CipherSuites = compatibleSuites
  157. // TODO(ekr@rtfm.com): Check that the ticket can be used for early
  158. // data.
  159. // Signal early data if we're going to do it
  160. if state.Config.AllowEarlyData && state.helloRetryRequest == nil {
  161. state.Params.ClientSendingEarlyData = true
  162. ed = &EarlyDataExtension{}
  163. err = ch.Extensions.Add(ed)
  164. if err != nil {
  165. logf(logTypeHandshake, "Error adding early data extension: %v", err)
  166. return nil, nil, AlertInternalError
  167. }
  168. }
  169. // Signal supported PSK key exchange modes
  170. if len(state.Config.PSKModes) == 0 {
  171. logf(logTypeHandshake, "PSK selected, but no PSKModes")
  172. return nil, nil, AlertInternalError
  173. }
  174. kem := &PSKKeyExchangeModesExtension{KEModes: state.Config.PSKModes}
  175. err = ch.Extensions.Add(kem)
  176. if err != nil {
  177. logf(logTypeHandshake, "Error adding PSKKeyExchangeModes extension: %v", err)
  178. return nil, nil, AlertInternalError
  179. }
  180. // Add the shim PSK extension to the ClientHello
  181. logf(logTypeHandshake, "Adding PSK extension with id = %x", key.Identity)
  182. psk = &PreSharedKeyExtension{
  183. HandshakeType: HandshakeTypeClientHello,
  184. Identities: []PSKIdentity{
  185. {
  186. Identity: key.Identity,
  187. ObfuscatedTicketAge: uint32(time.Since(key.ReceivedAt)/time.Millisecond) + key.TicketAgeAdd,
  188. },
  189. },
  190. Binders: []PSKBinderEntry{
  191. // Note: Stub to get the length fields right
  192. {Binder: bytes.Repeat([]byte{0x00}, params.Hash.Size())},
  193. },
  194. }
  195. ch.Extensions.Add(psk)
  196. // Compute the binder key
  197. h0 := params.Hash.New().Sum(nil)
  198. zero := bytes.Repeat([]byte{0}, params.Hash.Size())
  199. earlyHash = params.Hash
  200. earlySecret = HkdfExtract(params.Hash, zero, key.Key)
  201. logf(logTypeCrypto, "early secret: [%d] %x", len(earlySecret), earlySecret)
  202. binderLabel := labelExternalBinder
  203. if key.IsResumption {
  204. binderLabel = labelResumptionBinder
  205. }
  206. binderKey := deriveSecret(params, earlySecret, binderLabel, h0)
  207. logf(logTypeCrypto, "binder key: [%d] %x", len(binderKey), binderKey)
  208. // Compute the binder value
  209. trunc, err := ch.Truncated()
  210. if err != nil {
  211. logf(logTypeHandshake, "[ClientStateStart] Error marshaling truncated ClientHello [%v]", err)
  212. return nil, nil, AlertInternalError
  213. }
  214. truncHash := params.Hash.New()
  215. truncHash.Write(trunc)
  216. binder := computeFinishedData(params, binderKey, truncHash.Sum(nil))
  217. // Replace the PSK extension
  218. psk.Binders[0].Binder = binder
  219. ch.Extensions.Add(psk)
  220. // If we got here, the earlier marshal succeeded (in ch.Truncated()), so
  221. // this one should too.
  222. clientHello, _ = state.hsCtx.hOut.HandshakeMessageFromBody(ch)
  223. // Compute early traffic keys
  224. h := params.Hash.New()
  225. h.Write(clientHello.Marshal())
  226. chHash := h.Sum(nil)
  227. earlyTrafficSecret := deriveSecret(params, earlySecret, labelEarlyTrafficSecret, chHash)
  228. logf(logTypeCrypto, "early traffic secret: [%d] %x", len(earlyTrafficSecret), earlyTrafficSecret)
  229. clientEarlyTrafficKeys = makeTrafficKeys(params, earlyTrafficSecret)
  230. } else {
  231. clientHello, err = state.hsCtx.hOut.HandshakeMessageFromBody(ch)
  232. if err != nil {
  233. logf(logTypeHandshake, "[ClientStateStart] Error marshaling ClientHello [%v]", err)
  234. return nil, nil, AlertInternalError
  235. }
  236. }
  237. logf(logTypeHandshake, "[ClientStateStart] -> [ClientStateWaitSH]")
  238. state.hsCtx.SetVersion(tls12Version) // Everything after this should be 1.2.
  239. nextState := clientStateWaitSH{
  240. Config: state.Config,
  241. Opts: state.Opts,
  242. Params: state.Params,
  243. hsCtx: state.hsCtx,
  244. OfferedDH: offeredDH,
  245. OfferedPSK: offeredPSK,
  246. earlySecret: earlySecret,
  247. earlyHash: earlyHash,
  248. firstClientHello: state.firstClientHello,
  249. helloRetryRequest: state.helloRetryRequest,
  250. clientHello: clientHello,
  251. }
  252. toSend := []HandshakeAction{
  253. QueueHandshakeMessage{clientHello},
  254. SendQueuedHandshake{},
  255. }
  256. if state.Params.ClientSendingEarlyData {
  257. toSend = append(toSend, []HandshakeAction{
  258. RekeyOut{epoch: EpochEarlyData, KeySet: clientEarlyTrafficKeys},
  259. }...)
  260. }
  261. return nextState, toSend, AlertNoAlert
  262. }
  263. type clientStateWaitSH struct {
  264. Config *Config
  265. Opts ConnectionOptions
  266. Params ConnectionParameters
  267. hsCtx *HandshakeContext
  268. OfferedDH map[NamedGroup][]byte
  269. OfferedPSK PreSharedKey
  270. PSK []byte
  271. earlySecret []byte
  272. earlyHash crypto.Hash
  273. firstClientHello *HandshakeMessage
  274. helloRetryRequest *HandshakeMessage
  275. clientHello *HandshakeMessage
  276. }
  277. var _ HandshakeState = &clientStateWaitSH{}
  278. func (state clientStateWaitSH) State() State {
  279. return StateClientWaitSH
  280. }
  281. func (state clientStateWaitSH) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  282. hm, alert := hr.ReadMessage()
  283. if alert != AlertNoAlert {
  284. return nil, nil, alert
  285. }
  286. if hm == nil || hm.msgType != HandshakeTypeServerHello {
  287. logf(logTypeHandshake, "[ClientStateWaitSH] Unexpected message")
  288. return nil, nil, AlertUnexpectedMessage
  289. }
  290. sh := &ServerHelloBody{}
  291. if _, err := sh.Unmarshal(hm.body); err != nil {
  292. logf(logTypeHandshake, "[ClientStateWaitSH] unexpected message")
  293. return nil, nil, AlertUnexpectedMessage
  294. }
  295. // Common SH/HRR processing first.
  296. // 1. Check that sh.version is TLS 1.2
  297. if sh.Version != tls12Version {
  298. logf(logTypeHandshake, "[ClientStateWaitSH] illegal legacy version [%v]", sh.Version)
  299. return nil, nil, AlertIllegalParameter
  300. }
  301. // 2. Check that it responded with a valid version.
  302. supportedVersions := SupportedVersionsExtension{HandshakeType: HandshakeTypeServerHello}
  303. foundSupportedVersions, err := sh.Extensions.Find(&supportedVersions)
  304. if err != nil {
  305. logf(logTypeHandshake, "[ClientStateWaitSH] invalid supported_versions extension [%v]", err)
  306. return nil, nil, AlertDecodeError
  307. }
  308. if !foundSupportedVersions {
  309. logf(logTypeHandshake, "[ClientStateWaitSH] no supported_versions extension")
  310. return nil, nil, AlertMissingExtension
  311. }
  312. if supportedVersions.Versions[0] != supportedVersion {
  313. logf(logTypeHandshake, "[ClientStateWaitSH] unsupported version [%x]", supportedVersions.Versions[0])
  314. return nil, nil, AlertProtocolVersion
  315. }
  316. // 3. Check that the server provided a supported ciphersuite
  317. supportedCipherSuite := false
  318. for _, suite := range state.Config.CipherSuites {
  319. supportedCipherSuite = supportedCipherSuite || (suite == sh.CipherSuite)
  320. }
  321. if !supportedCipherSuite {
  322. logf(logTypeHandshake, "[ClientStateWaitSH] Unsupported ciphersuite [%04x]", sh.CipherSuite)
  323. return nil, nil, AlertHandshakeFailure
  324. }
  325. // Now check for the sentinel.
  326. if sh.Random == hrrRandomSentinel {
  327. // This is actually HRR.
  328. hrr := sh
  329. // Narrow the supported ciphersuites to the server-provided one
  330. state.Config.CipherSuites = []CipherSuite{hrr.CipherSuite}
  331. // Handle external extensions.
  332. if state.Config.ExtensionHandler != nil {
  333. err := state.Config.ExtensionHandler.Receive(HandshakeTypeHelloRetryRequest, &hrr.Extensions)
  334. if err != nil {
  335. logf(logTypeHandshake, "[ClientWaitSH] Error running external extension handler [%v]", err)
  336. return nil, nil, AlertInternalError
  337. }
  338. }
  339. // The only thing we know how to respond to in an HRR is the Cookie
  340. // extension, so if there is either no Cookie extension or anything other
  341. // than a Cookie extension and SupportedVersions we have to fail.
  342. serverCookie := new(CookieExtension)
  343. foundCookie, err := hrr.Extensions.Find(serverCookie)
  344. if err != nil {
  345. logf(logTypeHandshake, "[ClientStateWaitSH] Invalid server cookie extension [%v]", err)
  346. return nil, nil, AlertDecodeError
  347. }
  348. if !foundCookie || len(hrr.Extensions) != 2 {
  349. logf(logTypeHandshake, "[ClientStateWaitSH] No Cookie or extra extensions [%v] [%d]", foundCookie, len(hrr.Extensions))
  350. return nil, nil, AlertIllegalParameter
  351. }
  352. // Hash the body into a pseudo-message
  353. // XXX: Ignoring some errors here
  354. params := cipherSuiteMap[hrr.CipherSuite]
  355. h := params.Hash.New()
  356. h.Write(state.clientHello.Marshal())
  357. firstClientHello := &HandshakeMessage{
  358. msgType: HandshakeTypeMessageHash,
  359. body: h.Sum(nil),
  360. }
  361. state.hsCtx.receivedEndOfFlight()
  362. // TODO(ekr@rtfm.com): Need to rekey with cleartext if we are on 0-RTT
  363. // mode. In DTLS, we also need to bump the sequence number.
  364. // This is a pre-existing defect in Mint. Issue #175.
  365. logf(logTypeHandshake, "[ClientStateWaitSH] -> [ClientStateStart]")
  366. return clientStateStart{
  367. Config: state.Config,
  368. Opts: state.Opts,
  369. hsCtx: state.hsCtx,
  370. cookie: serverCookie.Cookie,
  371. firstClientHello: firstClientHello,
  372. helloRetryRequest: hm,
  373. }, []HandshakeAction{ResetOut{1}}, AlertNoAlert
  374. }
  375. // This is SH.
  376. // Handle external extensions.
  377. if state.Config.ExtensionHandler != nil {
  378. err := state.Config.ExtensionHandler.Receive(HandshakeTypeServerHello, &sh.Extensions)
  379. if err != nil {
  380. logf(logTypeHandshake, "[ClientWaitSH] Error running external extension handler [%v]", err)
  381. return nil, nil, AlertInternalError
  382. }
  383. }
  384. // Do PSK or key agreement depending on extensions
  385. serverPSK := PreSharedKeyExtension{HandshakeType: HandshakeTypeServerHello}
  386. serverKeyShare := KeyShareExtension{HandshakeType: HandshakeTypeServerHello}
  387. foundExts, err := sh.Extensions.Parse(
  388. []ExtensionBody{
  389. &serverPSK,
  390. &serverKeyShare,
  391. })
  392. if err != nil {
  393. logf(logTypeHandshake, "[ClientWaitSH] Error processing extensions [%v]", err)
  394. return nil, nil, AlertDecodeError
  395. }
  396. if foundExts[ExtensionTypePreSharedKey] && (serverPSK.SelectedIdentity == 0) {
  397. state.Params.UsingPSK = true
  398. }
  399. var dhSecret []byte
  400. if foundExts[ExtensionTypeKeyShare] {
  401. sks := serverKeyShare.Shares[0]
  402. priv, ok := state.OfferedDH[sks.Group]
  403. if !ok {
  404. logf(logTypeHandshake, "[ClientStateWaitSH] Key share for unknown group")
  405. return nil, nil, AlertIllegalParameter
  406. }
  407. state.Params.UsingDH = true
  408. dhSecret, _ = keyAgreement(sks.Group, sks.KeyExchange, priv)
  409. }
  410. suite := sh.CipherSuite
  411. state.Params.CipherSuite = suite
  412. params, ok := cipherSuiteMap[suite]
  413. if !ok {
  414. logf(logTypeCrypto, "Unsupported ciphersuite [%04x]", suite)
  415. return nil, nil, AlertHandshakeFailure
  416. }
  417. // Start up the handshake hash
  418. handshakeHash := params.Hash.New()
  419. handshakeHash.Write(state.firstClientHello.Marshal())
  420. handshakeHash.Write(state.helloRetryRequest.Marshal())
  421. handshakeHash.Write(state.clientHello.Marshal())
  422. handshakeHash.Write(hm.Marshal())
  423. // Compute handshake secrets
  424. zero := bytes.Repeat([]byte{0}, params.Hash.Size())
  425. var earlySecret []byte
  426. if state.Params.UsingPSK {
  427. if params.Hash != state.earlyHash {
  428. logf(logTypeCrypto, "Change of hash between early and normal init early=[%02x] suite=[%04x] hash=[%02x]",
  429. state.earlyHash, suite, params.Hash)
  430. }
  431. earlySecret = state.earlySecret
  432. } else {
  433. earlySecret = HkdfExtract(params.Hash, zero, zero)
  434. }
  435. if dhSecret == nil {
  436. dhSecret = zero
  437. }
  438. h0 := params.Hash.New().Sum(nil)
  439. h2 := handshakeHash.Sum(nil)
  440. preHandshakeSecret := deriveSecret(params, earlySecret, labelDerived, h0)
  441. handshakeSecret := HkdfExtract(params.Hash, preHandshakeSecret, dhSecret)
  442. clientHandshakeTrafficSecret := deriveSecret(params, handshakeSecret, labelClientHandshakeTrafficSecret, h2)
  443. serverHandshakeTrafficSecret := deriveSecret(params, handshakeSecret, labelServerHandshakeTrafficSecret, h2)
  444. preMasterSecret := deriveSecret(params, handshakeSecret, labelDerived, h0)
  445. masterSecret := HkdfExtract(params.Hash, preMasterSecret, zero)
  446. logf(logTypeCrypto, "early secret: [%d] %x", len(earlySecret), earlySecret)
  447. logf(logTypeCrypto, "handshake secret: [%d] %x", len(handshakeSecret), handshakeSecret)
  448. logf(logTypeCrypto, "client handshake traffic secret: [%d] %x", len(clientHandshakeTrafficSecret), clientHandshakeTrafficSecret)
  449. logf(logTypeCrypto, "server handshake traffic secret: [%d] %x", len(serverHandshakeTrafficSecret), serverHandshakeTrafficSecret)
  450. logf(logTypeCrypto, "master secret: [%d] %x", len(masterSecret), masterSecret)
  451. serverHandshakeKeys := makeTrafficKeys(params, serverHandshakeTrafficSecret)
  452. logf(logTypeHandshake, "[ClientStateWaitSH] -> [ClientStateWaitEE]")
  453. nextState := clientStateWaitEE{
  454. Config: state.Config,
  455. Params: state.Params,
  456. hsCtx: state.hsCtx,
  457. cryptoParams: params,
  458. handshakeHash: handshakeHash,
  459. masterSecret: masterSecret,
  460. clientHandshakeTrafficSecret: clientHandshakeTrafficSecret,
  461. serverHandshakeTrafficSecret: serverHandshakeTrafficSecret,
  462. }
  463. toSend := []HandshakeAction{
  464. RekeyIn{epoch: EpochHandshakeData, KeySet: serverHandshakeKeys},
  465. }
  466. // We're definitely not going to have to send anything with
  467. // early data.
  468. if !state.Params.ClientSendingEarlyData {
  469. toSend = append(toSend, RekeyOut{epoch: EpochHandshakeData,
  470. KeySet: makeTrafficKeys(params, clientHandshakeTrafficSecret)})
  471. }
  472. return nextState, toSend, AlertNoAlert
  473. }
  474. type clientStateWaitEE struct {
  475. Config *Config
  476. Params ConnectionParameters
  477. hsCtx *HandshakeContext
  478. cryptoParams CipherSuiteParams
  479. handshakeHash hash.Hash
  480. masterSecret []byte
  481. clientHandshakeTrafficSecret []byte
  482. serverHandshakeTrafficSecret []byte
  483. }
  484. var _ HandshakeState = &clientStateWaitEE{}
  485. func (state clientStateWaitEE) State() State {
  486. return StateClientWaitEE
  487. }
  488. func (state clientStateWaitEE) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  489. hm, alert := hr.ReadMessage()
  490. if alert != AlertNoAlert {
  491. return nil, nil, alert
  492. }
  493. if hm == nil || hm.msgType != HandshakeTypeEncryptedExtensions {
  494. logf(logTypeHandshake, "[ClientStateWaitEE] Unexpected message")
  495. return nil, nil, AlertUnexpectedMessage
  496. }
  497. ee := EncryptedExtensionsBody{}
  498. if err := safeUnmarshal(&ee, hm.body); err != nil {
  499. logf(logTypeHandshake, "[ClientStateWaitEE] Error decoding message: %v", err)
  500. return nil, nil, AlertDecodeError
  501. }
  502. // Handle external extensions.
  503. if state.Config.ExtensionHandler != nil {
  504. err := state.Config.ExtensionHandler.Receive(HandshakeTypeEncryptedExtensions, &ee.Extensions)
  505. if err != nil {
  506. logf(logTypeHandshake, "[ClientWaitStateEE] Error running external extension handler [%v]", err)
  507. return nil, nil, AlertInternalError
  508. }
  509. }
  510. serverALPN := &ALPNExtension{}
  511. serverEarlyData := &EarlyDataExtension{}
  512. foundExts, err := ee.Extensions.Parse(
  513. []ExtensionBody{
  514. serverALPN,
  515. serverEarlyData,
  516. })
  517. if err != nil {
  518. logf(logTypeHandshake, "[ClientStateWaitEE] Error decoding extensions: %v", err)
  519. return nil, nil, AlertDecodeError
  520. }
  521. state.Params.UsingEarlyData = foundExts[ExtensionTypeEarlyData]
  522. if foundExts[ExtensionTypeALPN] && len(serverALPN.Protocols) > 0 {
  523. state.Params.NextProto = serverALPN.Protocols[0]
  524. }
  525. state.handshakeHash.Write(hm.Marshal())
  526. toSend := []HandshakeAction{}
  527. if state.Params.ClientSendingEarlyData && !state.Params.UsingEarlyData {
  528. // We didn't get 0-RTT, so rekey to handshake.
  529. toSend = append(toSend, RekeyOut{epoch: EpochHandshakeData,
  530. KeySet: makeTrafficKeys(state.cryptoParams, state.clientHandshakeTrafficSecret)})
  531. }
  532. if state.Params.UsingPSK {
  533. logf(logTypeHandshake, "[ClientStateWaitEE] -> [ClientStateWaitFinished]")
  534. nextState := clientStateWaitFinished{
  535. Params: state.Params,
  536. hsCtx: state.hsCtx,
  537. cryptoParams: state.cryptoParams,
  538. handshakeHash: state.handshakeHash,
  539. certificates: state.Config.Certificates,
  540. masterSecret: state.masterSecret,
  541. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  542. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  543. }
  544. return nextState, toSend, AlertNoAlert
  545. }
  546. logf(logTypeHandshake, "[ClientStateWaitEE] -> [ClientStateWaitCertCR]")
  547. nextState := clientStateWaitCertCR{
  548. Config: state.Config,
  549. Params: state.Params,
  550. hsCtx: state.hsCtx,
  551. cryptoParams: state.cryptoParams,
  552. handshakeHash: state.handshakeHash,
  553. masterSecret: state.masterSecret,
  554. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  555. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  556. }
  557. return nextState, toSend, AlertNoAlert
  558. }
  559. type clientStateWaitCertCR struct {
  560. Config *Config
  561. Params ConnectionParameters
  562. hsCtx *HandshakeContext
  563. cryptoParams CipherSuiteParams
  564. handshakeHash hash.Hash
  565. masterSecret []byte
  566. clientHandshakeTrafficSecret []byte
  567. serverHandshakeTrafficSecret []byte
  568. }
  569. var _ HandshakeState = &clientStateWaitCertCR{}
  570. func (state clientStateWaitCertCR) State() State {
  571. return StateClientWaitCertCR
  572. }
  573. func (state clientStateWaitCertCR) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  574. hm, alert := hr.ReadMessage()
  575. if alert != AlertNoAlert {
  576. return nil, nil, alert
  577. }
  578. if hm == nil {
  579. logf(logTypeHandshake, "[ClientStateWaitCertCR] Unexpected message")
  580. return nil, nil, AlertUnexpectedMessage
  581. }
  582. bodyGeneric, err := hm.ToBody()
  583. if err != nil {
  584. logf(logTypeHandshake, "[ClientStateWaitCertCR] Error decoding message: %v", err)
  585. return nil, nil, AlertDecodeError
  586. }
  587. state.handshakeHash.Write(hm.Marshal())
  588. switch body := bodyGeneric.(type) {
  589. case *CertificateBody:
  590. logf(logTypeHandshake, "[ClientStateWaitCertCR] -> [ClientStateWaitCV]")
  591. nextState := clientStateWaitCV{
  592. Config: state.Config,
  593. Params: state.Params,
  594. hsCtx: state.hsCtx,
  595. cryptoParams: state.cryptoParams,
  596. handshakeHash: state.handshakeHash,
  597. serverCertificate: body,
  598. masterSecret: state.masterSecret,
  599. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  600. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  601. }
  602. return nextState, nil, AlertNoAlert
  603. case *CertificateRequestBody:
  604. // A certificate request in the handshake should have a zero-length context
  605. if len(body.CertificateRequestContext) > 0 {
  606. logf(logTypeHandshake, "[ClientStateWaitCertCR] Certificate request with non-empty context: %v", err)
  607. return nil, nil, AlertIllegalParameter
  608. }
  609. state.Params.UsingClientAuth = true
  610. logf(logTypeHandshake, "[ClientStateWaitCertCR] -> [ClientStateWaitCert]")
  611. nextState := clientStateWaitCert{
  612. Config: state.Config,
  613. Params: state.Params,
  614. hsCtx: state.hsCtx,
  615. cryptoParams: state.cryptoParams,
  616. handshakeHash: state.handshakeHash,
  617. serverCertificateRequest: body,
  618. masterSecret: state.masterSecret,
  619. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  620. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  621. }
  622. return nextState, nil, AlertNoAlert
  623. }
  624. return nil, nil, AlertUnexpectedMessage
  625. }
  626. type clientStateWaitCert struct {
  627. Config *Config
  628. Params ConnectionParameters
  629. hsCtx *HandshakeContext
  630. cryptoParams CipherSuiteParams
  631. handshakeHash hash.Hash
  632. serverCertificateRequest *CertificateRequestBody
  633. masterSecret []byte
  634. clientHandshakeTrafficSecret []byte
  635. serverHandshakeTrafficSecret []byte
  636. }
  637. var _ HandshakeState = &clientStateWaitCert{}
  638. func (state clientStateWaitCert) State() State {
  639. return StateClientWaitCert
  640. }
  641. func (state clientStateWaitCert) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  642. hm, alert := hr.ReadMessage()
  643. if alert != AlertNoAlert {
  644. return nil, nil, alert
  645. }
  646. if hm == nil || hm.msgType != HandshakeTypeCertificate {
  647. logf(logTypeHandshake, "[ClientStateWaitCert] Unexpected message")
  648. return nil, nil, AlertUnexpectedMessage
  649. }
  650. cert := &CertificateBody{}
  651. if err := safeUnmarshal(cert, hm.body); err != nil {
  652. logf(logTypeHandshake, "[ClientStateWaitCert] Error decoding message: %v", err)
  653. return nil, nil, AlertDecodeError
  654. }
  655. state.handshakeHash.Write(hm.Marshal())
  656. logf(logTypeHandshake, "[ClientStateWaitCert] -> [ClientStateWaitCV]")
  657. nextState := clientStateWaitCV{
  658. Config: state.Config,
  659. Params: state.Params,
  660. hsCtx: state.hsCtx,
  661. cryptoParams: state.cryptoParams,
  662. handshakeHash: state.handshakeHash,
  663. serverCertificate: cert,
  664. serverCertificateRequest: state.serverCertificateRequest,
  665. masterSecret: state.masterSecret,
  666. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  667. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  668. }
  669. return nextState, nil, AlertNoAlert
  670. }
  671. type clientStateWaitCV struct {
  672. Config *Config
  673. Params ConnectionParameters
  674. hsCtx *HandshakeContext
  675. cryptoParams CipherSuiteParams
  676. handshakeHash hash.Hash
  677. serverCertificate *CertificateBody
  678. serverCertificateRequest *CertificateRequestBody
  679. masterSecret []byte
  680. clientHandshakeTrafficSecret []byte
  681. serverHandshakeTrafficSecret []byte
  682. }
  683. var _ HandshakeState = &clientStateWaitCV{}
  684. func (state clientStateWaitCV) State() State {
  685. return StateClientWaitCV
  686. }
  687. func (state clientStateWaitCV) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  688. hm, alert := hr.ReadMessage()
  689. if alert != AlertNoAlert {
  690. return nil, nil, alert
  691. }
  692. if hm == nil || hm.msgType != HandshakeTypeCertificateVerify {
  693. logf(logTypeHandshake, "[ClientStateWaitCV] Unexpected message")
  694. return nil, nil, AlertUnexpectedMessage
  695. }
  696. certVerify := CertificateVerifyBody{}
  697. if err := safeUnmarshal(&certVerify, hm.body); err != nil {
  698. logf(logTypeHandshake, "[ClientStateWaitCV] Error decoding message: %v", err)
  699. return nil, nil, AlertDecodeError
  700. }
  701. hcv := state.handshakeHash.Sum(nil)
  702. logf(logTypeHandshake, "Handshake Hash to be verified: [%d] %x", len(hcv), hcv)
  703. serverPublicKey := state.serverCertificate.CertificateList[0].CertData.PublicKey
  704. if err := certVerify.Verify(serverPublicKey, hcv); err != nil {
  705. logf(logTypeHandshake, "[ClientStateWaitCV] Server signature failed to verify")
  706. return nil, nil, AlertHandshakeFailure
  707. }
  708. certs := make([]*x509.Certificate, len(state.serverCertificate.CertificateList))
  709. rawCerts := make([][]byte, len(state.serverCertificate.CertificateList))
  710. for i, certEntry := range state.serverCertificate.CertificateList {
  711. certs[i] = certEntry.CertData
  712. rawCerts[i] = certEntry.CertData.Raw
  713. }
  714. var verifiedChains [][]*x509.Certificate
  715. if !state.Config.InsecureSkipVerify {
  716. opts := x509.VerifyOptions{
  717. Roots: state.Config.RootCAs,
  718. CurrentTime: state.Config.time(),
  719. DNSName: state.Config.ServerName,
  720. Intermediates: x509.NewCertPool(),
  721. }
  722. for i, cert := range certs {
  723. if i == 0 {
  724. continue
  725. }
  726. opts.Intermediates.AddCert(cert)
  727. }
  728. var err error
  729. verifiedChains, err = certs[0].Verify(opts)
  730. if err != nil {
  731. logf(logTypeHandshake, "[ClientStateWaitCV] Certificate verification failed: %s", err)
  732. return nil, nil, AlertBadCertificate
  733. }
  734. }
  735. if state.Config.VerifyPeerCertificate != nil {
  736. if err := state.Config.VerifyPeerCertificate(rawCerts, verifiedChains); err != nil {
  737. logf(logTypeHandshake, "[ClientStateWaitCV] Application rejected server certificate: %s", err)
  738. return nil, nil, AlertBadCertificate
  739. }
  740. }
  741. state.handshakeHash.Write(hm.Marshal())
  742. logf(logTypeHandshake, "[ClientStateWaitCV] -> [ClientStateWaitFinished]")
  743. nextState := clientStateWaitFinished{
  744. Params: state.Params,
  745. hsCtx: state.hsCtx,
  746. cryptoParams: state.cryptoParams,
  747. handshakeHash: state.handshakeHash,
  748. certificates: state.Config.Certificates,
  749. serverCertificateRequest: state.serverCertificateRequest,
  750. masterSecret: state.masterSecret,
  751. clientHandshakeTrafficSecret: state.clientHandshakeTrafficSecret,
  752. serverHandshakeTrafficSecret: state.serverHandshakeTrafficSecret,
  753. peerCertificates: certs,
  754. verifiedChains: verifiedChains,
  755. }
  756. return nextState, nil, AlertNoAlert
  757. }
  758. type clientStateWaitFinished struct {
  759. Params ConnectionParameters
  760. hsCtx *HandshakeContext
  761. cryptoParams CipherSuiteParams
  762. handshakeHash hash.Hash
  763. certificates []*Certificate
  764. serverCertificateRequest *CertificateRequestBody
  765. peerCertificates []*x509.Certificate
  766. verifiedChains [][]*x509.Certificate
  767. masterSecret []byte
  768. clientHandshakeTrafficSecret []byte
  769. serverHandshakeTrafficSecret []byte
  770. }
  771. var _ HandshakeState = &clientStateWaitFinished{}
  772. func (state clientStateWaitFinished) State() State {
  773. return StateClientWaitFinished
  774. }
  775. func (state clientStateWaitFinished) Next(hr handshakeMessageReader) (HandshakeState, []HandshakeAction, Alert) {
  776. hm, alert := hr.ReadMessage()
  777. if alert != AlertNoAlert {
  778. return nil, nil, alert
  779. }
  780. if hm == nil || hm.msgType != HandshakeTypeFinished {
  781. logf(logTypeHandshake, "[ClientStateWaitFinished] Unexpected message")
  782. return nil, nil, AlertUnexpectedMessage
  783. }
  784. // Verify server's Finished
  785. h3 := state.handshakeHash.Sum(nil)
  786. logf(logTypeCrypto, "handshake hash 3 [%d] %x", len(h3), h3)
  787. logf(logTypeCrypto, "handshake hash for server Finished: [%d] %x", len(h3), h3)
  788. serverFinishedData := computeFinishedData(state.cryptoParams, state.serverHandshakeTrafficSecret, h3)
  789. logf(logTypeCrypto, "server finished data: [%d] %x", len(serverFinishedData), serverFinishedData)
  790. fin := &FinishedBody{VerifyDataLen: len(serverFinishedData)}
  791. if err := safeUnmarshal(fin, hm.body); err != nil {
  792. logf(logTypeHandshake, "[ClientStateWaitFinished] Error decoding message: %v", err)
  793. return nil, nil, AlertDecodeError
  794. }
  795. if !bytes.Equal(fin.VerifyData, serverFinishedData) {
  796. logf(logTypeHandshake, "[ClientStateWaitFinished] Server's Finished failed to verify [%x] != [%x]",
  797. fin.VerifyData, serverFinishedData)
  798. return nil, nil, AlertHandshakeFailure
  799. }
  800. // Update the handshake hash with the Finished
  801. state.handshakeHash.Write(hm.Marshal())
  802. logf(logTypeCrypto, "input to handshake hash [%d]: %x", len(hm.Marshal()), hm.Marshal())
  803. h4 := state.handshakeHash.Sum(nil)
  804. logf(logTypeCrypto, "handshake hash 4 [%d]: %x", len(h4), h4)
  805. // Compute traffic secrets and keys
  806. clientTrafficSecret := deriveSecret(state.cryptoParams, state.masterSecret, labelClientApplicationTrafficSecret, h4)
  807. serverTrafficSecret := deriveSecret(state.cryptoParams, state.masterSecret, labelServerApplicationTrafficSecret, h4)
  808. logf(logTypeCrypto, "client traffic secret: [%d] %x", len(clientTrafficSecret), clientTrafficSecret)
  809. logf(logTypeCrypto, "server traffic secret: [%d] %x", len(serverTrafficSecret), serverTrafficSecret)
  810. clientTrafficKeys := makeTrafficKeys(state.cryptoParams, clientTrafficSecret)
  811. serverTrafficKeys := makeTrafficKeys(state.cryptoParams, serverTrafficSecret)
  812. exporterSecret := deriveSecret(state.cryptoParams, state.masterSecret, labelExporterSecret, h4)
  813. logf(logTypeCrypto, "client exporter secret: [%d] %x", len(exporterSecret), exporterSecret)
  814. // Assemble client's second flight
  815. toSend := []HandshakeAction{}
  816. if state.Params.UsingEarlyData {
  817. logf(logTypeHandshake, "Sending end of early data")
  818. // Note: We only send EOED if the server is actually going to use the early
  819. // data. Otherwise, it will never see it, and the transcripts will
  820. // mismatch.
  821. // EOED marshal is infallible
  822. eoedm, _ := state.hsCtx.hOut.HandshakeMessageFromBody(&EndOfEarlyDataBody{})
  823. toSend = append(toSend, QueueHandshakeMessage{eoedm})
  824. state.handshakeHash.Write(eoedm.Marshal())
  825. logf(logTypeCrypto, "input to handshake hash [%d]: %x", len(eoedm.Marshal()), eoedm.Marshal())
  826. // And then rekey to handshake
  827. toSend = append(toSend, RekeyOut{epoch: EpochHandshakeData,
  828. KeySet: makeTrafficKeys(state.cryptoParams, state.clientHandshakeTrafficSecret)})
  829. }
  830. if state.Params.UsingClientAuth {
  831. // Extract constraints from certicateRequest
  832. schemes := SignatureAlgorithmsExtension{}
  833. gotSchemes, err := state.serverCertificateRequest.Extensions.Find(&schemes)
  834. if err != nil {
  835. logf(logTypeHandshake, "[ClientStateWaitFinished] WARNING invalid signature_schemes extension [%v]", err)
  836. return nil, nil, AlertDecodeError
  837. }
  838. if !gotSchemes {
  839. logf(logTypeHandshake, "[ClientStateWaitFinished] WARNING no appropriate certificate found")
  840. return nil, nil, AlertIllegalParameter
  841. }
  842. // Select a certificate
  843. cert, certScheme, err := CertificateSelection(nil, schemes.Algorithms, state.certificates)
  844. if err != nil {
  845. // XXX: Signal this to the application layer?
  846. logf(logTypeHandshake, "[ClientStateWaitFinished] WARNING no appropriate certificate found [%v]", err)
  847. certificate := &CertificateBody{}
  848. certm, err := state.hsCtx.hOut.HandshakeMessageFromBody(certificate)
  849. if err != nil {
  850. logf(logTypeHandshake, "[ClientStateWaitFinished] Error marshaling Certificate [%v]", err)
  851. return nil, nil, AlertInternalError
  852. }
  853. toSend = append(toSend, QueueHandshakeMessage{certm})
  854. state.handshakeHash.Write(certm.Marshal())
  855. } else {
  856. // Create and send Certificate, CertificateVerify
  857. certificate := &CertificateBody{
  858. CertificateList: make([]CertificateEntry, len(cert.Chain)),
  859. }
  860. for i, entry := range cert.Chain {
  861. certificate.CertificateList[i] = CertificateEntry{CertData: entry}
  862. }
  863. certm, err := state.hsCtx.hOut.HandshakeMessageFromBody(certificate)
  864. if err != nil {
  865. logf(logTypeHandshake, "[ClientStateWaitFinished] Error marshaling Certificate [%v]", err)
  866. return nil, nil, AlertInternalError
  867. }
  868. toSend = append(toSend, QueueHandshakeMessage{certm})
  869. state.handshakeHash.Write(certm.Marshal())
  870. hcv := state.handshakeHash.Sum(nil)
  871. logf(logTypeHandshake, "Handshake Hash to be verified: [%d] %x", len(hcv), hcv)
  872. certificateVerify := &CertificateVerifyBody{Algorithm: certScheme}
  873. logf(logTypeHandshake, "Creating CertVerify: %04x %v", certScheme, state.cryptoParams.Hash)
  874. err = certificateVerify.Sign(cert.PrivateKey, hcv)
  875. if err != nil {
  876. logf(logTypeHandshake, "[ClientStateWaitFinished] Error signing CertificateVerify [%v]", err)
  877. return nil, nil, AlertInternalError
  878. }
  879. certvm, err := state.hsCtx.hOut.HandshakeMessageFromBody(certificateVerify)
  880. if err != nil {
  881. logf(logTypeHandshake, "[ClientStateWaitFinished] Error marshaling CertificateVerify [%v]", err)
  882. return nil, nil, AlertInternalError
  883. }
  884. toSend = append(toSend, QueueHandshakeMessage{certvm})
  885. state.handshakeHash.Write(certvm.Marshal())
  886. }
  887. }
  888. // Compute the client's Finished message
  889. h5 := state.handshakeHash.Sum(nil)
  890. logf(logTypeCrypto, "handshake hash for client Finished: [%d] %x", len(h5), h5)
  891. clientFinishedData := computeFinishedData(state.cryptoParams, state.clientHandshakeTrafficSecret, h5)
  892. logf(logTypeCrypto, "client Finished data: [%d] %x", len(clientFinishedData), clientFinishedData)
  893. fin = &FinishedBody{
  894. VerifyDataLen: len(clientFinishedData),
  895. VerifyData: clientFinishedData,
  896. }
  897. finm, err := state.hsCtx.hOut.HandshakeMessageFromBody(fin)
  898. if err != nil {
  899. logf(logTypeHandshake, "[ClientStateWaitFinished] Error marshaling client Finished [%v]", err)
  900. return nil, nil, AlertInternalError
  901. }
  902. // Compute the resumption secret
  903. state.handshakeHash.Write(finm.Marshal())
  904. h6 := state.handshakeHash.Sum(nil)
  905. resumptionSecret := deriveSecret(state.cryptoParams, state.masterSecret, labelResumptionSecret, h6)
  906. logf(logTypeCrypto, "resumption secret: [%d] %x", len(resumptionSecret), resumptionSecret)
  907. toSend = append(toSend, []HandshakeAction{
  908. QueueHandshakeMessage{finm},
  909. SendQueuedHandshake{},
  910. RekeyIn{epoch: EpochApplicationData, KeySet: serverTrafficKeys},
  911. RekeyOut{epoch: EpochApplicationData, KeySet: clientTrafficKeys},
  912. }...)
  913. state.hsCtx.receivedEndOfFlight()
  914. logf(logTypeHandshake, "[ClientStateWaitFinished] -> [StateConnected]")
  915. nextState := stateConnected{
  916. Params: state.Params,
  917. hsCtx: state.hsCtx,
  918. isClient: true,
  919. cryptoParams: state.cryptoParams,
  920. resumptionSecret: resumptionSecret,
  921. clientTrafficSecret: clientTrafficSecret,
  922. serverTrafficSecret: serverTrafficSecret,
  923. exporterSecret: exporterSecret,
  924. peerCertificates: state.peerCertificates,
  925. verifiedChains: state.verifiedChains,
  926. }
  927. return nextState, toSend, AlertNoAlert
  928. }