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

View file

@ -0,0 +1,89 @@
>>> 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 a6 29 2f 1c 88 |....z...v...)/..|
00000010 12 96 7a 88 1c dc f7 ca dc 1e 6e e2 a7 09 65 01 |..z.......n...e.|
00000020 28 3a c1 58 01 6a ed 8d 18 fe b7 20 00 00 00 00 |(:.X.j..... ....|
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 ab |..+.....3.$... .|
00000060 5a f1 b4 52 1d 1c 87 fb b3 9e f2 f9 ee d1 f1 ff |Z..R............|
00000070 66 3e 01 70 41 6f 01 45 4a d0 3a 98 d3 e4 50 14 |f>.pAo.EJ.:...P.|
00000080 03 03 00 01 01 17 03 03 00 17 38 75 a9 bf e3 61 |..........8u...a|
00000090 2f 8a 58 1d 28 6b b5 25 83 c9 d8 86 31 38 ee 6d |/.X.(k.%....18.m|
000000a0 c1 17 03 03 02 6d cb 78 87 73 70 3d c4 e4 de d9 |.....m.x.sp=....|
000000b0 2d 22 f0 cf 35 9e c1 0a ac 97 88 75 20 8f 63 b1 |-"..5......u .c.|
000000c0 2f c0 c9 4d 86 7f d6 6b 3a 2e b6 c1 e3 d4 73 f4 |/..M...k:.....s.|
000000d0 f7 2b 4f 86 6f f0 fd ed 2a dd 17 98 5e e6 32 e9 |.+O.o...*...^.2.|
000000e0 48 5e 48 36 e0 f8 d3 a4 93 54 7b 17 c5 46 ea d5 |H^H6.....T{..F..|
000000f0 6b 0f 5b bd 1d 3c 15 b1 c2 3f 2f 91 e5 d3 dd 75 |k.[..<...?/....u|
00000100 c5 c7 73 f7 ce a2 6e e1 bc 10 2a b7 0f 5e 7d cc |..s...n...*..^}.|
00000110 3e 22 3c 71 37 3f ba f0 44 3b 55 c8 5c a7 19 f2 |>"<q7?..D;U.\...|
00000120 41 e9 55 82 3c ea 9b d3 d8 04 28 35 e4 6b bf 6c |A.U.<.....(5.k.l|
00000130 26 12 f0 e1 9f 5d b5 f3 71 68 b7 3f 8c 6f 43 f4 |&....]..qh.?.oC.|
00000140 e9 f2 e4 aa ca 47 ba 65 d4 f4 82 c3 4b 9a 06 05 |.....G.e....K...|
00000150 65 28 74 85 f1 52 ac 37 da 1e 63 84 3e 9a c2 a2 |e(t..R.7..c.>...|
00000160 28 a4 ac 75 1b 3b 7f 85 cb 2c 9c 64 09 38 75 59 |(..u.;...,.d.8uY|
00000170 33 0e 7f fe 93 0f 8a 67 5f 5e 86 c4 74 40 7f 0b |3......g_^..t@..|
00000180 f8 82 03 9c 8d 37 39 12 a9 20 cb 31 c5 40 f6 23 |.....79.. .1.@.#|
00000190 78 71 20 e3 8a a8 81 ab 6c 98 43 67 f8 2b a9 6f |xq .....l.Cg.+.o|
000001a0 41 2a 80 7f 1c 11 6d ae ea cf d9 6a 3c 11 74 72 |A*....m....j<.tr|
000001b0 86 e4 ab ee 1a f2 58 ce e2 8f d6 4e 06 57 e9 33 |......X....N.W.3|
000001c0 e9 ef 5a af 19 5c eb 9a a4 df ed 9f d3 55 00 d9 |..Z..\.......U..|
000001d0 2c 09 3f c5 58 4f 08 22 2e 9c 63 9b 53 92 07 83 |,.?.XO."..c.S...|
000001e0 b7 96 82 de 46 5b 35 b8 ff d2 52 96 66 2a ce ed |....F[5...R.f*..|
000001f0 93 b1 6a be ab 91 6b 1f b1 bc 35 1f 11 6a 48 a6 |..j...k...5..jH.|
00000200 20 63 62 8f e4 e4 07 4b be 79 37 d6 98 00 64 9e | cb....K.y7...d.|
00000210 17 f4 48 65 71 21 0c 79 30 32 a1 eb f5 9a be 5a |..Heq!.y02.....Z|
00000220 8d 7b 17 dd af c4 06 78 3b 0d a9 4a d8 f1 a8 6d |.{.....x;..J...m|
00000230 3d cf 52 a6 34 9d 3a 1c ee ff 83 7a d1 23 47 f1 |=.R.4.:....z.#G.|
00000240 65 9d 57 61 66 d9 66 bd e7 63 ca b9 22 07 36 0b |e.Waf.f..c..".6.|
00000250 5b 9a 20 59 19 25 49 54 a0 3b bf 28 24 5c 58 76 |[. Y.%IT.;.($\Xv|
00000260 1a a9 68 e9 90 dd 6a 66 d8 f3 d3 60 e4 3d af 3a |..h...jf...`.=.:|
00000270 49 d1 0e b8 39 a2 b6 e3 15 6e c0 ff 0d 57 48 05 |I...9....n...WH.|
00000280 c1 44 01 59 fa 9b f7 90 bc 7b 05 c4 f0 1f e8 9f |.D.Y.....{......|
00000290 02 c5 2a 89 7d 1e c4 75 bc b9 af d2 17 89 79 9d |..*.}..u......y.|
000002a0 3c aa 55 db 24 e7 35 08 a0 6d 88 79 61 af 01 82 |<.U.$.5..m.ya...|
000002b0 82 b7 4a f0 d4 89 38 6a fc 82 97 5e 77 09 87 45 |..J...8j...^w..E|
000002c0 5e 2f 21 8c 39 4e 98 76 76 ab 16 25 8e f0 d2 5c |^/!.9N.vv..%...\|
000002d0 a6 ad bd 18 f3 78 f4 2a b2 ac 36 67 2b 67 6a 43 |.....x.*..6g+gjC|
000002e0 95 d6 63 f8 b5 9f 7d 84 26 83 83 3c d3 7a 3b 52 |..c...}.&..<.z;R|
000002f0 68 de f0 d8 49 7f bc 56 b4 70 16 74 ee fa 5b 7b |h...I..V.p.t..[{|
00000300 36 50 6a 54 26 02 7a 3c ee 0b f9 2e a1 20 5c 44 |6PjT&.z<..... \D|
00000310 fd fe fc 17 03 03 00 99 69 60 73 ea a0 71 1a 5e |........i`s..q.^|
00000320 c4 ea 67 f7 b2 e0 34 7c cc 55 67 f3 87 43 c9 68 |..g...4|.Ug..C.h|
00000330 a6 02 84 1d 6c de 1d 90 4c 82 01 5c a5 16 39 97 |....l...L..\..9.|
00000340 67 45 7f fb 0e 43 24 4e ea c5 7b eb f5 bc 1f b6 |gE...C$N..{.....|
00000350 70 2e 95 e4 61 20 f0 8b 24 54 2e 43 9c f1 82 56 |p...a ..$T.C...V|
00000360 9c ca 28 96 64 57 85 a4 e1 d0 f4 be ea b4 7b a2 |..(.dW........{.|
00000370 23 aa 4f c6 06 9c e7 81 eb 4b 62 93 af 93 1c cf |#.O......Kb.....|
00000380 2b fd 5f bd a7 07 e9 c3 c8 97 c1 e4 df f4 74 06 |+._...........t.|
00000390 62 01 32 0c ec a2 40 86 c1 7e da e9 1e 7e 46 67 |b.2...@..~...~Fg|
000003a0 8a c6 ef b5 ce ac 3e 44 fa b0 ff b6 c4 20 aa 65 |......>D..... .e|
000003b0 fb 17 03 03 00 35 c1 a6 e0 e5 bf 91 7a ec 17 85 |.....5......z...|
000003c0 38 1e 32 1e 92 4e 9c 38 8c 02 1b 08 03 0e a3 a2 |8.2..N.8........|
000003d0 8f 2b 73 76 c1 99 48 de e7 39 cf a8 97 e4 30 e6 |.+sv..H..9....0.|
000003e0 75 52 3a f4 6f bf 67 bd 87 c5 30 |uR:.o.g...0|
>>> Flow 3 (client to server)
00000000 17 03 03 00 35 be 06 09 fb e0 58 83 8e 27 5a c0 |....5.....X..'Z.|
00000010 8a 4c 56 ad 79 29 90 99 47 21 2f d4 f4 98 81 a8 |.LV.y)..G!/.....|
00000020 e8 55 d6 bd 26 b1 a9 48 34 ff 40 66 7e 2e 83 ea |.U..&..H4.@f~...|
00000030 ed fe a0 01 73 0b 91 1f c0 1d 17 03 03 00 17 ee |....s...........|
00000040 58 ac 2a e7 26 72 e3 c7 81 2c 02 0f 57 39 56 4f |X.*.&r...,..W9VO|
00000050 43 7a 2d a7 f4 d8 17 03 03 00 13 94 2c 15 0b 04 |Cz-.........,...|
00000060 7a aa 78 3b a6 b8 23 f1 75 b4 b5 2e e7 94 |z.x;..#.u.....|