crypto/tls: implement TLS 1.3 KeyUpdate messages

Since TLS 1.3 delivers handshake messages (including KeyUpdate) after
the handshake, the want argument to readRecord had became almost
pointless: it only meant something when set to recordTypeChangeCipherSpec.
Replaced it with a bool to reflect that, and added two shorthands to
avoid anonymous bools in calls.

Took the occasion to simplify and formalize the invariants of readRecord.

The maxConsecutiveEmptyRecords loop became useless when readRecord
started retrying on any non-advancing record in CL 145297.

Replaced panics with errors, because failure is better than undefined
behavior, but contained failure is better than a DoS vulnerability. For
example, I suspect the panic at the top of readRecord was reachable from
handleRenegotiation, which calls readHandshake with handshakeComplete
false. Thankfully it was not a panic in 1.11, and it's allowed now.

Removed Client-TLSv13-RenegotiationRejected because OpenSSL isn't
actually willing to ask for renegotiation over TLS 1.3, the expected
error was due to NewSessionTicket messages, which didn't break the rest
of the tests because they stop too soon.

Updates #9671

Change-Id: I297a81bde5c8020a962a92891b70d6d70b90f5e3
Reviewed-on: https://go-review.googlesource.com/c/147418
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Filippo Valsorda 2018-11-03 18:29:09 -04:00
parent f513a10f59
commit e04a8ac694
7 changed files with 364 additions and 228 deletions

130
testdata/Client-TLSv13-KeyUpdate vendored Normal file
View file

@ -0,0 +1,130 @@
>>> Flow 1 (client to server)
00000000 16 03 01 00 f8 01 00 00 f4 03 03 00 00 00 00 00 |................|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 |........... ....|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 32 cc a8 |.............2..|
00000050 cc a9 c0 2f c0 2b c0 30 c0 2c c0 27 c0 13 c0 23 |.../.+.0.,.'...#|
00000060 c0 09 c0 14 c0 0a 00 9c 00 9d 00 3c 00 2f 00 35 |...........<./.5|
00000070 c0 12 00 0a 00 05 c0 11 c0 07 13 01 13 03 13 02 |................|
00000080 01 00 00 79 00 05 00 05 01 00 00 00 00 00 0a 00 |...y............|
00000090 0a 00 08 00 1d 00 17 00 18 00 19 00 0b 00 02 01 |................|
000000a0 00 00 0d 00 18 00 16 08 04 08 05 08 06 04 01 04 |................|
000000b0 03 05 01 05 03 06 01 06 03 02 01 02 03 ff 01 00 |................|
000000c0 01 00 00 12 00 00 00 2b 00 09 08 03 04 03 03 03 |.......+........|
000000d0 02 03 01 00 33 00 26 00 24 00 1d 00 20 2f e5 7d |....3.&.$... /.}|
000000e0 a3 47 cd 62 43 15 28 da ac 5f bb 29 07 30 ff f6 |.G.bC.(.._.).0..|
000000f0 84 af c4 cf c2 ed 90 99 5f 58 cb 3b 74 |........_X.;t|
>>> Flow 2 (server to client)
00000000 16 03 03 00 7a 02 00 00 76 03 03 91 02 b1 d0 21 |....z...v......!|
00000010 d1 5d ff 00 e2 ab f3 af 0d 22 45 1a a0 7d f1 c7 |.]......."E..}..|
00000020 73 fd 01 af f5 6e b4 d8 51 a7 26 20 00 00 00 00 |s....n..Q.& ....|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000040 00 00 00 00 00 00 00 00 00 00 00 00 13 01 00 00 |................|
00000050 2e 00 2b 00 02 03 04 00 33 00 24 00 1d 00 20 d4 |..+.....3.$... .|
00000060 6c db da 9b 60 3b 55 58 d2 7b 00 7c 85 8f 97 92 |l...`;UX.{.|....|
00000070 b6 02 a7 9f c2 fc cd 7f e4 45 37 ff f0 85 51 14 |.........E7...Q.|
00000080 03 03 00 01 01 17 03 03 00 17 c0 42 45 55 77 7d |...........BEUw}|
00000090 3c 65 5a 6a 1f d2 57 ff 9b b6 fe bf 2f 50 04 c9 |<eZj..W...../P..|
000000a0 5d 17 03 03 02 6d 8f f3 b8 02 b6 22 f2 de 83 41 |]....m....."...A|
000000b0 82 89 17 99 bf 18 bc 07 1b 75 02 3f ff 6b 54 dd |.........u.?.kT.|
000000c0 67 e6 81 2d 0b 10 5e b5 f5 e8 13 fd 4f 6a 49 2a |g..-..^.....OjI*|
000000d0 af 8e b0 2f 04 fe db 56 e5 71 f1 66 38 b4 62 82 |.../...V.q.f8.b.|
000000e0 5b dd 8f c4 ef f7 e9 bb 35 47 4e 3d a6 a7 0b f5 |[.......5GN=....|
000000f0 b3 4a 5a b7 92 6d 65 26 b6 94 88 f8 a4 9b 7e 33 |.JZ..me&......~3|
00000100 36 47 11 a2 53 44 f7 8e f6 b0 a7 b6 ba e1 0a ad |6G..SD..........|
00000110 00 7d eb 57 3b 18 54 cc 10 59 42 87 2a d0 99 27 |.}.W;.T..YB.*..'|
00000120 e4 25 6d 97 0f 6b d2 ec 3d 17 51 99 9d 6f af 57 |.%m..k..=.Q..o.W|
00000130 1e fc f2 32 2a bb 6e 05 cd eb 99 af 8e 6b 79 a8 |...2*.n......ky.|
00000140 23 60 e4 3f 1a 1c 2a 33 82 b1 bd 7d 7f 39 75 18 |#`.?..*3...}.9u.|
00000150 a6 94 91 6b 89 5c 9b c9 94 cc 09 65 8a 72 df 22 |...k.\.....e.r."|
00000160 6d ac 89 7b 59 0e 89 04 09 f7 15 7d 07 7b 26 49 |m..{Y......}.{&I|
00000170 da 66 1b b2 5b 0d aa 71 40 01 a2 53 ef da 55 ea |.f..[..q@..S..U.|
00000180 f0 22 33 e2 ff db 10 a5 67 3a ee f4 57 08 75 ea |."3.....g:..W.u.|
00000190 d1 c2 8c 7e 9b ab ca f8 38 86 92 5f 10 11 57 c9 |...~....8.._..W.|
000001a0 e5 ba 3c d2 82 61 0c aa 3f 2a e8 9e 1b 9a c0 55 |..<..a..?*.....U|
000001b0 74 1c b3 12 a3 26 a1 2e a8 b0 09 cf f8 92 4b aa |t....&........K.|
000001c0 b8 ec ff c0 f0 be 38 5e 68 39 58 47 1f ad b3 ba |......8^h9XG....|
000001d0 99 bd 21 da 63 50 73 37 8f 5b 92 3a 0e d9 d3 7a |..!.cPs7.[.:...z|
000001e0 26 df 07 6c 0b f0 f8 73 23 c9 9f b9 d0 79 aa b0 |&..l...s#....y..|
000001f0 17 cb 85 f6 47 55 c2 31 aa b0 77 54 b7 a1 dc 12 |....GU.1..wT....|
00000200 d6 d3 aa 5b 9c c6 ad 7b b5 34 77 a9 35 7f 7b 25 |...[...{.4w.5.{%|
00000210 b0 5f d2 c5 8d 41 3c eb 4b 4a 94 a0 07 25 d4 31 |._...A<.KJ...%.1|
00000220 80 93 13 a8 0c ae 7a 56 b2 52 de e6 30 66 ec 3e |......zV.R..0f.>|
00000230 6c 69 fd b2 4a f8 85 54 99 25 35 f7 66 50 fe 3f |li..J..T.%5.fP.?|
00000240 3f a3 2e b6 a1 f3 df d0 0b 2c 81 04 37 83 bd fe |?........,..7...|
00000250 15 69 2a 28 93 25 7e be a7 a2 54 14 ce ad 8c 93 |.i*(.%~...T.....|
00000260 5d 4b e8 bf 07 27 c3 ec 91 2f 55 39 4f 70 1d 17 |]K...'.../U9Op..|
00000270 3a f9 a5 71 0f 41 a6 17 fc 71 b6 50 43 aa 14 b6 |:..q.A...q.PC...|
00000280 38 ab af 0b 30 92 77 4d 02 97 fc fb 0d a9 50 96 |8...0.wM......P.|
00000290 68 30 49 6f 80 0e d3 99 27 a9 50 37 42 51 04 e1 |h0Io....'.P7BQ..|
000002a0 e8 88 93 1b 0a bf 86 14 c3 d9 b3 49 1a ce 2d 65 |...........I..-e|
000002b0 72 47 2a 3c b1 fd a3 4a fb a1 e8 c1 69 24 3a 51 |rG*<...J....i$:Q|
000002c0 17 1d 7b e7 33 77 21 94 67 5e f0 e7 93 5c 84 97 |..{.3w!.g^...\..|
000002d0 25 00 cd b2 d9 a1 40 06 6b f8 df a3 4b 7e 48 4c |%.....@.k...K~HL|
000002e0 14 30 93 17 cd 6b 8e e7 56 a0 34 1f d9 ba 14 16 |.0...k..V.4.....|
000002f0 cf 2c 1e c5 35 84 31 6f e8 81 f5 7c b2 11 5c 9d |.,..5.1o...|..\.|
00000300 5d 05 1c 12 41 74 ad 20 74 0c 0c 72 5e f2 43 1c |]...At. t..r^.C.|
00000310 91 1a 4d 17 03 03 00 99 d6 a2 b9 7b 55 6b d2 13 |..M........{Uk..|
00000320 9d 89 e6 7b d4 b2 e9 1c f6 7d 91 0a 87 00 ba 03 |...{.....}......|
00000330 c3 ae 47 e9 79 1b 75 e8 8b fe a8 15 4d 33 93 a5 |..G.y.u.....M3..|
00000340 df e7 d0 40 de 7c f2 63 2d 46 7a 1d e8 2d c6 dd |...@.|.c-Fz..-..|
00000350 56 ec cc 49 87 05 ad 2a c3 e4 89 2c c6 7c 2a 6a |V..I...*...,.|*j|
00000360 60 68 40 49 73 2b 29 55 9a 7b c4 e4 c6 24 5e 41 |`h@Is+)U.{...$^A|
00000370 16 c7 c2 46 e1 cf 10 cc 1d 3d b4 96 b3 ba c4 17 |...F.....=......|
00000380 1e dd e2 71 fc 80 45 f9 43 a1 16 4d e7 b4 ac a6 |...q..E.C..M....|
00000390 d3 26 a6 c2 23 06 6e 1c 4f 7e 1e a3 f1 57 e1 0c |.&..#.n.O~...W..|
000003a0 50 a6 5f 23 f4 a9 f8 b4 56 e9 d0 8c f6 fb ac 33 |P._#....V......3|
000003b0 b8 17 03 03 00 35 55 f6 25 b8 52 df c4 e2 2f b0 |.....5U.%.R.../.|
000003c0 ac 41 c3 ed 49 8d 73 cf f4 48 c2 4f 33 8c 56 df |.A..I.s..H.O3.V.|
000003d0 11 03 9e 7f de 78 d7 03 c3 f4 de e5 69 8e e4 9a |.....x......i...|
000003e0 c0 47 3b c9 99 3e 35 c9 66 b9 5a |.G;..>5.f.Z|
>>> Flow 3 (client to server)
00000000 17 03 03 00 35 03 e0 6c 82 55 1c 8a cb 82 4e 3d |....5..l.U....N=|
00000010 4a 5c 4f 94 3b 9c 23 fe 9d 5f 66 22 6a 83 31 98 |J\O.;.#.._f"j.1.|
00000020 e9 5b 0c 17 54 86 11 5f 85 2c 8c a8 fa 80 a0 d5 |.[..T.._.,......|
00000030 5f c5 02 30 0a 93 1f 42 b1 a9 17 03 03 00 17 3f |_..0...B.......?|
00000040 82 d9 94 f8 84 d1 9f 87 67 c2 37 b5 17 09 0a 99 |........g.7.....|
00000050 81 6d 0b 70 0b 6e |.m.p.n|
>>> Flow 4 (server to client)
00000000 17 03 03 00 da 94 6d 10 ed 89 9a e2 a8 d4 87 52 |......m........R|
00000010 7e ff c2 55 79 a7 9d a6 41 6d 1c d0 b5 75 10 95 |~..Uy...Am...u..|
00000020 8f 02 f4 49 b8 ad e7 29 77 d3 ed ab ee 4d db 6c |...I...)w....M.l|
00000030 fa 1b 42 d2 fe f7 d3 a2 a5 ed d5 0a d9 33 13 00 |..B..........3..|
00000040 6b 7b a0 79 08 c6 80 8c 74 c4 15 18 50 a4 b3 93 |k{.y....t...P...|
00000050 73 89 85 eb e6 d2 3d 64 db aa ec 68 22 64 22 ae |s.....=d...h"d".|
00000060 35 a5 7f 01 5b de eb ba f9 0e 5b 89 30 a8 5e 47 |5...[.....[.0.^G|
00000070 39 06 cb 4a bb ce 2c e5 87 36 3f b7 4f 02 6d 32 |9..J..,..6?.O.m2|
00000080 38 86 15 b2 17 60 af 95 8a 6c f1 29 ac e6 da 05 |8....`...l.)....|
00000090 78 42 e0 5f 7c a7 1e 3b 1c 85 5f 2d 2f 8f de c2 |xB._|..;.._-/...|
000000a0 a4 fb 53 ed 74 06 76 08 ef af 8b 59 f2 5e d2 2f |..S.t.v....Y.^./|
000000b0 a0 09 81 cb 41 e4 7d 11 6e 64 49 ff dc bf ac f3 |....A.}.ndI.....|
000000c0 13 d8 d5 a2 69 60 ef cd 82 7a 72 78 c3 58 5b 73 |....i`...zrx.X[s|
000000d0 7b 77 7a 4d cd 66 a0 fb ab 46 37 6d 4f 4e 57 17 |{wzM.f...F7mONW.|
000000e0 03 03 00 da d8 64 ed 87 a6 ac ae d1 16 25 ee 7a |.....d.......%.z|
000000f0 e1 2d 0a 61 1b db 33 c9 72 92 75 04 1f af 6b fb |.-.a..3.r.u...k.|
00000100 73 e6 55 fe 3c cb c8 93 0b 15 ae d1 dc 39 f2 a9 |s.U.<........9..|
00000110 52 29 69 0f cd 3a 9d c6 8a c6 e0 57 c0 29 19 dc |R)i..:.....W.)..|
00000120 26 4d ec b8 49 d3 11 6f 83 c3 a3 71 bb 70 ca 07 |&M..I..o...q.p..|
00000130 bf 7a 94 15 58 6f a0 f8 b4 23 70 e7 c4 1a 3d 03 |.z..Xo...#p...=.|
00000140 c9 55 da 35 47 8c 08 79 09 f6 0e 67 b0 ea 35 ed |.U.5G..y...g..5.|
00000150 37 72 02 92 41 ef 6f 05 db 04 e2 17 35 22 2c c9 |7r..A.o.....5",.|
00000160 98 4b 86 a9 b3 bf 4a 21 9f 01 b1 9b b2 6e 08 d4 |.K....J!.....n..|
00000170 04 9d 60 1d af 79 b5 cd c1 5d c3 26 92 60 c7 7b |..`..y...].&.`.{|
00000180 b2 6f 11 21 58 7d 28 75 92 f3 7c 43 d2 60 0c 8b |.o.!X}(u..|C.`..|
00000190 51 a0 ec a7 b9 1e bb 31 52 ca 48 7e 77 fe 24 d7 |Q......1R.H~w.$.|
000001a0 a5 f6 51 ab 7a 1d ad dd e3 6e 9c 6a a3 46 f5 5d |..Q.z....n.j.F.]|
000001b0 22 33 c7 86 c9 08 d1 1c 07 b7 93 ac f3 93 17 03 |"3..............|
000001c0 03 00 16 51 14 60 dd e3 6f 3d ae 8e b0 da 29 b3 |...Q.`..o=....).|
000001d0 ef 24 61 5b 10 52 da ba b0 |.$a[.R...|
>>> Flow 5 (client to server)
00000000 17 03 03 00 16 28 82 46 cd 7d f4 b8 ad 95 3d 87 |.....(.F.}....=.|
00000010 6f 95 c2 b5 84 1e 5b fc f9 9b 15 |o.....[....|
>>> Flow 6 (server to client)
00000000 17 03 03 00 1a 3b 79 64 b2 54 a9 0f e7 76 a3 47 |.....;yd.T...v.G|
00000010 bc c1 e2 e0 0d 3d c3 60 43 d2 29 cb e4 89 de |.....=.`C.)....|
>>> Flow 7 (client to server)
00000000 17 03 03 00 1d fc 2f 64 89 dc 2d 83 18 7e 48 20 |....../d..-..~H |
00000010 33 32 5c bf 2c a6 c6 4d 26 f6 75 cd 9d ce 20 1e |32\.,..M&.u... .|
00000020 d9 b8 17 03 03 00 13 6b c6 68 a6 50 07 18 2b f3 |.......k.h.P..+.|
00000030 73 29 e5 f4 0d f1 ce c9 c0 39 |s).......9|