crypto/tls: implement TLS 1.3 client handshake (base)

Implement a basic TLS 1.3 client handshake, only enabled if explicitly
requested with MaxVersion.

This CL intentionally leaves for future CLs:
  - PSK modes and resumption
  - client authentication
  - post-handshake messages
  - downgrade protection
  - KeyLogWriter support

Updates #9671

Change-Id: Ieb6130fb6f25aea4f0d39e3a2448dfc942e1de7a
Reviewed-on: https://go-review.googlesource.com/c/146559
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-01 01:01:09 -04:00
parent ed74f7823e
commit 2c3ff7ba06
25 changed files with 2074 additions and 362 deletions

118
testdata/Client-TLSv13-HelloRetryRequest vendored Normal file
View file

@ -0,0 +1,118 @@
>>> Flow 1 (client to server)
00000000 16 03 01 00 f4 01 00 00 f0 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 75 00 05 00 05 01 00 00 00 00 00 0a 00 |...u............|
00000090 06 00 04 00 1d 00 17 00 0b 00 02 01 00 00 0d 00 |................|
000000a0 18 00 16 08 04 08 05 08 06 04 01 04 03 05 01 05 |................|
000000b0 03 06 01 06 03 02 01 02 03 ff 01 00 01 00 00 12 |................|
000000c0 00 00 00 2b 00 09 08 03 04 03 03 03 02 03 01 00 |...+............|
000000d0 33 00 26 00 24 00 1d 00 20 2f e5 7d a3 47 cd 62 |3.&.$... /.}.G.b|
000000e0 43 15 28 da ac 5f bb 29 07 30 ff f6 84 af c4 cf |C.(.._.).0......|
000000f0 c2 ed 90 99 5f 58 cb 3b 74 |...._X.;t|
>>> Flow 2 (server to client)
00000000 16 03 03 00 58 02 00 00 54 03 03 cf 21 ad 74 e5 |....X...T...!.t.|
00000010 9a 61 11 be 1d 8c 02 1e 65 b8 91 c2 a2 11 16 7a |.a......e......z|
00000020 bb 8c 5e 07 9e 09 e2 c8 a8 33 9c 20 00 00 00 00 |..^......3. ....|
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 0c 00 2b 00 02 03 04 00 33 00 02 00 17 14 03 03 |..+.....3.......|
00000060 00 01 01 |...|
>>> Flow 3 (client to server)
00000000 16 03 03 01 15 01 00 01 11 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 96 00 05 00 05 01 00 00 00 00 00 0a 00 |................|
00000090 06 00 04 00 1d 00 17 00 0b 00 02 01 00 00 0d 00 |................|
000000a0 18 00 16 08 04 08 05 08 06 04 01 04 03 05 01 05 |................|
000000b0 03 06 01 06 03 02 01 02 03 ff 01 00 01 00 00 12 |................|
000000c0 00 00 00 2b 00 09 08 03 04 03 03 03 02 03 01 00 |...+............|
000000d0 33 00 47 00 45 00 17 00 41 04 1e 18 37 ef 0d 19 |3.G.E...A...7...|
000000e0 51 88 35 75 71 b5 e5 54 5b 12 2e 8f 09 67 fd a7 |Q.5uq..T[....g..|
000000f0 24 20 3e b2 56 1c ce 97 28 5e f8 2b 2d 4f 9e f1 |$ >.V...(^.+-O..|
00000100 07 9f 6c 4b 5b 83 56 e2 32 42 e9 58 b6 d7 49 a6 |..lK[.V.2B.X..I.|
00000110 b5 68 1a 41 03 56 6b dc 5a 89 |.h.A.Vk.Z.|
>>> Flow 4 (server to client)
00000000 16 03 03 00 9b 02 00 00 97 03 03 7b 87 0f 37 7b |...........{..7{|
00000010 8a c3 85 98 1c 19 61 a4 bd 12 06 b5 72 58 09 24 |......a.....rX.$|
00000020 c7 ab c0 12 f7 b7 b5 69 c2 05 46 20 00 00 00 00 |.......i..F ....|
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 4f 00 2b 00 02 03 04 00 33 00 45 00 17 00 41 04 |O.+.....3.E...A.|
00000060 95 47 67 c9 ae 36 1b 3f b7 b7 21 15 ab 11 9f de |.Gg..6.?..!.....|
00000070 4d 06 76 61 be 86 9e 79 c9 e9 9d 62 95 8e b7 f9 |M.va...y...b....|
00000080 c7 e1 9f 79 08 f0 98 76 54 22 90 c1 fa 15 56 99 |...y...vT"....V.|
00000090 21 64 93 92 78 9a 52 3c 4e e7 b1 39 be 25 88 af |!d..x.R<N..9.%..|
000000a0 17 03 03 00 17 bb 8b df b4 49 c6 1a 38 40 74 97 |.........I..8@t.|
000000b0 4a c1 5f 9c 34 a4 b3 19 5c 90 e3 6a 17 03 03 02 |J._.4...\..j....|
000000c0 6d 2a 17 d7 28 77 3c 60 4f 8b 1a 55 2b a4 16 fd |m*..(w<`O..U+...|
000000d0 ce 37 a1 48 4a 39 ac a9 b1 a6 d2 b2 9c 59 12 a3 |.7.HJ9.......Y..|
000000e0 31 f3 92 d1 13 bc c4 43 f9 28 1b 97 63 9d ce df |1......C.(..c...|
000000f0 aa 71 b4 c8 16 03 53 09 8a b1 f2 ff 08 15 b0 c7 |.q....S.........|
00000100 2a d2 13 23 ba 26 4e f1 df 78 4f d4 ff 93 11 7f |*..#.&N..xO.....|
00000110 04 47 08 fd b7 9c 5d 8e 5e 95 d0 85 a7 cc 01 09 |.G....].^.......|
00000120 9a 8e fb 8d ab 39 e8 60 8d 58 6c 66 9d 2b a4 76 |.....9.`.Xlf.+.v|
00000130 58 9f d5 57 ad a8 65 82 c8 d1 12 1b c5 25 47 fe |X..W..e......%G.|
00000140 4e f5 46 54 fc 43 5a a4 a6 b8 ae 24 cc 6a dd ab |N.FT.CZ....$.j..|
00000150 3e 17 6d d2 d4 b6 51 41 6c 9e 86 e8 c6 e9 b4 74 |>.m...QAl......t|
00000160 ac 8c 12 df ba c6 bb e9 90 1c e9 ed e1 9c 28 d4 |..............(.|
00000170 50 89 88 09 06 61 2e 27 c6 60 26 86 91 f2 37 a2 |P....a.'.`&...7.|
00000180 83 67 ac c4 3f e7 6d 9c 30 de 74 a0 2e b9 0e 6b |.g..?.m.0.t....k|
00000190 de 4a 73 4d 67 9a ee 45 c7 5e bc d1 bb bb 01 67 |.JsMg..E.^.....g|
000001a0 cd b2 e6 c6 fa 3c e1 59 d9 e0 c9 85 5d 76 8d c8 |.....<.Y....]v..|
000001b0 ed 83 cd eb 88 51 d6 05 9f 0c 45 81 66 07 7c 2d |.....Q....E.f.|-|
000001c0 dd 6f 35 fd 76 d0 03 00 46 d9 f7 87 fe e4 8f bc |.o5.v...F.......|
000001d0 1b 69 6a 97 38 82 46 5e fe f6 a6 8a 0c 1a 6d 7f |.ij.8.F^......m.|
000001e0 4d b2 1b dd df 5c f3 43 21 cd 26 47 09 32 3a cc |M....\.C!.&G.2:.|
000001f0 b6 30 5a 1d 27 7a ad 6d da 2d 51 dc 67 84 09 8f |.0Z.'z.m.-Q.g...|
00000200 8f 86 2d 6f af 04 15 ce 90 53 4d 0d 32 a5 c4 c3 |..-o.....SM.2...|
00000210 41 94 0b 08 33 b9 2c 23 d3 d5 c2 42 f1 e4 d6 cf |A...3.,#...B....|
00000220 b2 cd 45 8e dd 9f 52 cb e5 dd ec aa 40 55 fd 94 |..E...R.....@U..|
00000230 99 cc 97 88 6d b0 71 80 4d 31 34 5e 92 a0 7d 1d |....m.q.M14^..}.|
00000240 1e fe 6e d6 47 81 f1 db a5 00 37 32 f2 98 87 f8 |..n.G.....72....|
00000250 83 48 31 c1 5f 28 7a 59 de fd 5a 56 b0 e4 39 78 |.H1._(zY..ZV..9x|
00000260 38 d4 68 b3 ef 16 a1 3e 41 ee 57 94 2e fb 16 4c |8.h....>A.W....L|
00000270 fd 02 3a c1 57 c6 4b 3b 2b 63 79 67 e1 cf 07 21 |..:.W.K;+cyg...!|
00000280 27 c7 9e 4a b0 bf e1 c2 4a 6e 9a 82 2a 8c 05 8d |'..J....Jn..*...|
00000290 93 48 0d 1c 15 60 66 d0 da b3 2f dc 90 fd 9e 6b |.H...`f.../....k|
000002a0 c2 62 ee a4 25 c5 52 e3 44 00 b8 6c 2d 6b 16 d7 |.b..%.R.D..l-k..|
000002b0 bc a4 2b b9 71 b7 b0 fc a4 e7 78 a3 39 1e 54 6f |..+.q.....x.9.To|
000002c0 7f c5 4c 20 4d b5 84 db 00 1d d0 ad 7a b8 13 e6 |..L M.......z...|
000002d0 06 f1 c2 f9 06 b5 c1 23 50 b1 0d f9 38 4d 80 65 |.......#P...8M.e|
000002e0 e1 56 7c 04 3f d8 07 b7 46 5a ff 29 f3 d4 43 fa |.V|.?...FZ.)..C.|
000002f0 be 32 47 76 58 7a c4 50 76 b7 65 5f 56 83 f9 06 |.2GvXz.Pv.e_V...|
00000300 44 30 65 0a 4b b1 e9 5c 80 4e 3c 1b 67 6f e1 53 |D0e.K..\.N<.go.S|
00000310 09 a8 3b 0f a6 85 f7 2f 51 08 48 94 9b 5a 0f b6 |..;..../Q.H..Z..|
00000320 b8 24 52 e0 c2 67 55 1d bc e1 e3 1b 15 8e 17 03 |.$R..gU.........|
00000330 03 00 99 58 f7 33 99 2c 8c 8c 18 78 60 49 6d 44 |...X.3.,...x`ImD|
00000340 f7 b4 25 5f 29 2b 37 7d ff 40 07 42 dd b3 9b a1 |..%_)+7}.@.B....|
00000350 10 a5 d6 d0 de 6d ca a0 df 41 82 0b e6 8a 35 8c |.....m...A....5.|
00000360 b7 52 aa 1c 8c f4 c2 31 2c 92 0b be 99 70 b0 84 |.R.....1,....p..|
00000370 c1 f4 9f d4 ff c7 ab e0 64 9e 17 34 aa 58 2d 32 |........d..4.X-2|
00000380 6d 74 90 ec f1 87 11 8f 9c 86 e2 26 2a 51 3e d4 |mt.........&*Q>.|
00000390 4b e4 01 13 13 6b cf 96 c6 ba 8e cf 8a 2b 5a 72 |K....k.......+Zr|
000003a0 df d7 43 47 ef 33 10 53 22 5c ab 8b b3 b4 6d 3c |..CG.3.S"\....m<|
000003b0 a6 31 58 f2 d7 bc 1c 46 48 4f 34 a1 62 5c ed 33 |.1X....FHO4.b\.3|
000003c0 01 3f ae 63 15 d5 94 96 b6 a1 d5 00 17 03 03 00 |.?.c............|
000003d0 35 34 66 3e 16 07 f3 ea c0 61 a6 30 c7 6f e9 1d |54f>.....a.0.o..|
000003e0 8b 6d 66 11 3c eb 27 88 9e 1a 94 86 85 0e da a0 |.mf.<.'.........|
000003f0 d7 1e 9e 2c d8 55 3e 53 b7 0f bc 96 be 82 00 34 |...,.U>S.......4|
00000400 a1 b3 3e c6 d3 bf |..>...|
>>> Flow 5 (client to server)
00000000 17 03 03 00 35 df 1b 3b a9 e7 cd 63 2c a6 09 65 |....5..;...c,..e|
00000010 66 df 94 09 d1 c4 ce 44 22 8b b5 48 2e 23 62 3a |f......D"..H.#b:|
00000020 9f e3 b2 58 a7 b2 e3 2a 27 a9 4d 34 41 0c 31 41 |...X...*'.M4A.1A|
00000030 92 b7 48 02 d2 51 d6 97 3e 70 17 03 03 00 17 f1 |..H..Q..>p......|
00000040 b7 28 75 42 2a 8b 20 2a 97 ed 47 ac a0 ee fd 38 |.(uB*. *..G....8|
00000050 cb 00 e3 b2 b1 87 17 03 03 00 13 bc 5a f3 ee 64 |............Z..d|
00000060 4d a5 1a 64 35 f2 f6 82 e3 e4 7d 82 08 c4 |M..d5.....}...|