crypto/tls: implement TLS 1.3 PSK authentication (server side)

Added some assertions to testHandshake, but avoided checking the error
of one of the Close() because the one that would lose the race would
write the closeNotify to a connection closed on the other side which is
broken on js/wasm (#28650). Moved that Close() after the chan sync to
ensure it happens second.

Accepting a ticket with client certificates when NoClientCert is
configured is probably not a problem, and we could hide them to avoid
confusing the application, but the current behavior is to skip the
ticket, and I'd rather keep behavior changes to a minimum.

Updates #9671

Change-Id: I93b56e44ddfe3d48c2bef52c83285ba2f46f297a
Reviewed-on: https://go-review.googlesource.com/c/147445
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Filippo Valsorda 2018-11-05 15:59:08 -05:00
parent dc9021e679
commit 166c58b85c
25 changed files with 1959 additions and 954 deletions

View file

@ -1,90 +1,101 @@
>>> Flow 1 (client to server)
00000000 16 03 01 00 c6 01 00 00 c2 03 03 e9 1f 49 f4 6e |.............I.n|
00000010 6a 47 e9 46 ae 43 1b b4 00 98 20 27 a7 a6 21 76 |jG.F.C.... '..!v|
00000020 fc 6b 35 d7 12 33 28 fb 2d 00 69 20 c9 28 5e 43 |.k5..3(.-.i .(^C|
00000030 c9 36 a0 b9 c4 68 0f fd d3 ce c6 39 3c 17 26 b1 |.6...h.....9<.&.|
00000040 4c d5 36 50 59 fd cd 47 8f 43 eb 33 00 08 13 02 |L.6PY..G.C.3....|
00000000 16 03 01 00 c6 01 00 00 c2 03 03 39 95 ab cc 1c |...........9....|
00000010 64 13 9d 19 2e 3e 73 33 48 b1 a9 f7 88 14 5a 83 |d....>s3H.....Z.|
00000020 19 f7 b5 08 8d e4 80 09 72 21 99 20 23 ad 4c 2c |........r!. #.L,|
00000030 66 84 1e e8 c3 0c 9f 66 19 76 df a3 e0 62 cd 7d |f......f.v...b.}|
00000040 95 85 70 4f 37 fb 39 58 50 b1 d5 7b 00 08 13 02 |..pO7.9XP..{....|
00000050 13 03 13 01 00 ff 01 00 00 71 00 00 00 0e 00 0c |.........q......|
00000060 00 00 09 31 32 37 2e 30 2e 30 2e 31 00 0b 00 04 |...127.0.0.1....|
00000070 03 00 01 02 00 0a 00 0c 00 0a 00 1d 00 17 00 1e |................|
00000080 00 19 00 18 00 16 00 00 00 17 00 00 00 0d 00 04 |................|
00000090 00 02 08 04 00 2b 00 03 02 03 04 00 2d 00 02 01 |.....+......-...|
000000a0 01 00 33 00 26 00 24 00 1d 00 20 a4 ab a1 75 b6 |..3.&.$... ...u.|
000000b0 95 db 0e d6 fd 95 57 3b 3f 08 5e cd cc 19 d0 7b |......W;?.^....{|
000000c0 7b cd 67 34 d3 da 65 e5 e6 8d 0c |{.g4..e....|
000000a0 01 00 33 00 26 00 24 00 1d 00 20 be 29 89 8d 44 |..3.&.$... .)..D|
000000b0 4d e5 51 88 7a 1a 56 52 a8 86 74 13 0e e9 a5 a7 |M.Q.z.VR..t.....|
000000c0 b6 7f 38 b3 ef 62 e6 b0 c5 2a 0a |..8..b...*.|
>>> Flow 2 (server to client)
00000000 16 03 03 00 7a 02 00 00 76 03 03 00 00 00 00 00 |....z...v.......|
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 c9 28 5e 43 |........... .(^C|
00000030 c9 36 a0 b9 c4 68 0f fd d3 ce c6 39 3c 17 26 b1 |.6...h.....9<.&.|
00000040 4c d5 36 50 59 fd cd 47 8f 43 eb 33 13 02 00 00 |L.6PY..G.C.3....|
00000020 00 00 00 00 00 00 00 00 00 00 00 20 23 ad 4c 2c |........... #.L,|
00000030 66 84 1e e8 c3 0c 9f 66 19 76 df a3 e0 62 cd 7d |f......f.v...b.}|
00000040 95 85 70 4f 37 fb 39 58 50 b1 d5 7b 13 02 00 00 |..pO7.9XP..{....|
00000050 2e 00 2b 00 02 03 04 00 33 00 24 00 1d 00 20 2f |..+.....3.$... /|
00000060 e5 7d a3 47 cd 62 43 15 28 da ac 5f bb 29 07 30 |.}.G.bC.(.._.).0|
00000070 ff f6 84 af c4 cf c2 ed 90 99 5f 58 cb 3b 74 14 |.........._X.;t.|
00000080 03 03 00 01 01 17 03 03 00 17 24 64 74 26 90 fe |..........$dt&..|
00000090 68 e7 db 87 79 32 3b 7c 2c e8 2e 2d d0 d1 d2 97 |h...y2;|,..-....|
000000a0 62 17 03 03 02 6d 41 22 d8 7d 6c 44 d0 6e 2b 79 |b....mA".}lD.n+y|
000000b0 bd d5 56 10 2a a6 41 c4 7f 2c 1f 01 b5 3a b2 e7 |..V.*.A..,...:..|
000000c0 44 6f c2 d2 2b 83 74 80 46 8e 7e 24 81 b0 8e c4 |Do..+.t.F.~$....|
000000d0 f0 90 03 89 03 b1 89 c5 28 b4 cc bc 3d df a9 25 |........(...=..%|
000000e0 db f5 f1 1c f2 f3 04 15 d6 f7 f7 c3 03 24 dd e0 |.............$..|
000000f0 19 22 62 67 3a 80 f8 f7 83 ca 5c 3f eb 9b 6e 98 |."bg:.....\?..n.|
00000100 8a 2f ba c2 ed bc dd 28 75 1f a2 27 42 89 39 3e |./.....(u..'B.9>|
00000110 01 e0 88 73 0f bb f4 cc 7c 75 3a 3f b4 68 04 be |...s....|u:?.h..|
00000120 4e d7 c2 2c 8d 41 df 6c 44 b3 1b 35 dc 46 36 3f |N..,.A.lD..5.F6?|
00000130 f0 dc e4 cc c3 ca 3b bf 3f fa bf 87 7c 2e 65 e1 |......;.?...|.e.|
00000140 d3 4b 2c 2a 6b 1a 57 8c 76 06 53 02 ef 79 d4 6f |.K,*k.W.v.S..y.o|
00000150 93 f0 36 f9 cb 13 05 b3 8c 22 16 fd 0a c2 e8 45 |..6......".....E|
00000160 fa 46 e7 ce f2 35 9f 32 88 97 67 46 e9 0c 13 77 |.F...5.2..gF...w|
00000170 30 b8 f3 59 71 e6 65 4f f5 5b 06 6e 9a 7f 7a 24 |0..Yq.eO.[.n..z$|
00000180 c5 e6 05 eb 8a ec 4d 0f 73 2c 6d aa 54 3d 5c 40 |......M.s,m.T=\@|
00000190 44 68 7f e6 52 b1 02 37 8c a0 be c8 3a f0 74 85 |Dh..R..7....:.t.|
000001a0 4e 0a 20 46 6c 3c 42 e7 94 18 02 30 a7 43 e7 c9 |N. Fl<B....0.C..|
000001b0 11 c0 19 45 39 04 64 66 3e 9c 2a e4 bb 86 b8 92 |...E9.df>.*.....|
000001c0 3d 77 1e 4e 13 51 7e 38 ba 06 b1 62 99 6c 98 8d |=w.N.Q~8...b.l..|
000001d0 87 b4 59 01 93 d3 84 80 6f e6 07 18 e0 a3 07 5d |..Y.....o......]|
000001e0 b7 97 1a 8b ed 78 20 d1 28 0e 60 dc 51 37 b1 07 |.....x .(.`.Q7..|
000001f0 81 b1 0b d8 81 f4 79 bf 3d ae 60 32 22 2b c5 9c |......y.=.`2"+..|
00000200 d1 37 3a f8 71 22 49 c2 a7 1e 5a 56 c1 c4 b4 5d |.7:.q"I...ZV...]|
00000210 2a 08 60 c6 75 2a 10 3e c0 84 77 dd 1d a6 be 8c |*.`.u*.>..w.....|
00000220 a7 2a 20 6b e1 20 bb bd 03 fb c1 2c 33 fb 97 64 |.* k. .....,3..d|
00000230 88 31 75 df 6e b3 49 dd e8 f2 b8 13 ca d5 24 40 |.1u.n.I.......$@|
00000240 e6 0b e5 7e 12 cb 20 60 b0 0a 72 b6 a5 93 2d ea |...~.. `..r...-.|
00000250 74 22 48 b7 7e 10 bf 81 55 eb 3d 0c 33 f6 37 66 |t"H.~...U.=.3.7f|
00000260 04 2a 1b 9c 3e 0a 06 0d 53 88 f0 cf 4f 52 c4 a1 |.*..>...S...OR..|
00000270 31 ff b0 8e 5c 8e c3 cc 0d a1 68 cb f6 2e 0f 57 |1...\.....h....W|
00000280 06 f9 d6 80 e5 ac b8 24 1f ef 6e b9 5c 32 a4 e1 |.......$..n.\2..|
00000290 44 14 99 75 6e 57 d6 6b 51 5f 16 ee 65 c6 fc 96 |D..unW.kQ_..e...|
000002a0 4e ea 83 85 3f c9 f6 5b b8 14 5e 6a 41 2b 0f 91 |N...?..[..^jA+..|
000002b0 ab 79 f4 3d 0e 63 2a 99 eb 4a e9 07 b8 cd fb d2 |.y.=.c*..J......|
000002c0 ad 33 e6 48 25 b2 b3 29 a6 fc 14 84 a5 ee 53 44 |.3.H%..)......SD|
000002d0 d4 b2 93 db 86 a6 b2 b3 ea 22 3d a7 52 db 53 56 |........."=.R.SV|
000002e0 96 20 24 59 6c b6 10 c2 f4 88 9a ff 69 d3 92 0c |. $Yl.......i...|
000002f0 da e7 67 63 af 3f 94 c2 06 9f da 8a 78 f5 6d 4d |..gc.?......x.mM|
00000300 3d 7b fe 43 6c 71 82 ce 34 07 4b e2 57 05 f8 5c |={.Clq..4.K.W..\|
00000310 dc 17 03 17 03 03 00 99 97 2b be f7 da 39 40 7e |.........+...9@~|
00000320 9f bd 0a 93 db c8 0d 89 e9 b8 52 5c f6 83 6d 6c |..........R\..ml|
00000330 d9 44 1a 3a fe 39 05 f5 c3 25 5e 5e 92 4d 84 d9 |.D.:.9...%^^.M..|
00000340 0e bc f2 27 09 e0 ba 70 f1 0a 9d 6a af b5 e7 90 |...'...p...j....|
00000350 8c 91 c7 82 9b d4 8b 88 dc 16 ec 33 2c 81 e7 4f |...........3,..O|
00000360 ad dd c1 c5 c6 59 36 d4 aa 39 f1 6f de 93 a7 0e |.....Y6..9.o....|
00000370 39 e4 f3 cf 01 b3 ed ad 10 01 70 20 60 ac 6a c5 |9.........p `.j.|
00000380 ec ec f9 fb 7c 40 72 10 c4 99 8f 10 eb b0 08 4e |....|@r........N|
00000390 dd 3f 65 a4 34 c0 69 94 2a 7c 2d cb 33 3b d5 b9 |.?e.4.i.*|-.3;..|
000003a0 03 e0 e9 63 37 54 73 6a 34 ad c9 65 d1 d4 d7 6b |...c7Tsj4..e...k|
000003b0 38 17 03 03 00 45 1c f4 15 86 6e b6 2d cd 84 30 |8....E....n.-..0|
000003c0 55 82 13 52 d9 c9 3f 01 27 ee 01 9c d4 da be ab |U..R..?.'.......|
000003d0 be 10 4d 82 55 32 86 a0 7b 74 bc 15 aa 68 3a e4 |..M.U2..{t...h:.|
000003e0 a1 3a d9 0e b6 c3 60 48 b4 7d e1 77 9d ce f9 41 |.:....`H.}.w...A|
000003f0 5f f7 d5 db ea 1f 6e b1 11 cd ca |_.....n....|
00000080 03 03 00 01 01 17 03 03 00 17 49 c6 88 9c 3b 2f |..........I...;/|
00000090 3a 0a e6 8e 75 d0 39 11 ad 08 87 17 2c 14 96 28 |:...u.9.....,..(|
000000a0 85 17 03 03 02 6d 2a d6 89 4d 5d f3 6c 28 97 dd |.....m*..M].l(..|
000000b0 4e 45 88 e8 90 a4 f3 45 86 cf 59 d6 61 6e 1a a7 |NE.....E..Y.an..|
000000c0 b7 35 7e 9c 6e 11 19 c4 1b 89 b9 5a 7c aa 1f 96 |.5~.n......Z|...|
000000d0 e2 36 6d 54 09 12 2f 28 12 20 a3 41 06 bd 44 3c |.6mT../(. .A..D<|
000000e0 73 be d3 8c 78 18 a1 63 ad f9 9d 41 20 5e 32 55 |s...x..c...A ^2U|
000000f0 8e 18 c1 d8 b0 93 13 7e 88 a0 af 8a 59 e2 af 43 |.......~....Y..C|
00000100 d2 82 66 ba c5 a1 97 94 e8 63 40 1b 8f c4 eb 49 |..f......c@....I|
00000110 19 91 65 e9 54 d3 90 76 d6 f8 ff 15 20 31 3c 86 |..e.T..v.... 1<.|
00000120 88 8a 43 be 77 a0 28 de fa 9f d5 30 14 a8 35 2f |..C.w.(....0..5/|
00000130 5e ee 9d cf b5 69 d1 f5 f6 55 d1 1a 61 3f 4c a1 |^....i...U..a?L.|
00000140 97 38 5b 87 7e ce 88 23 8a d0 bd fc 4b c5 da f7 |.8[.~..#....K...|
00000150 25 6c 6c 0b ec 61 50 72 97 6b f7 fe 9b 5b 5a f9 |%ll..aPr.k...[Z.|
00000160 59 19 71 10 74 2d 14 8c 1b 52 8b 39 1c 56 ea 7e |Y.q.t-...R.9.V.~|
00000170 7a c9 8f 7c bd db 1e c5 02 9f 42 8b 63 ee 13 52 |z..|......B.c..R|
00000180 fe 46 40 de 7b 97 27 b0 16 87 75 96 c7 1c 88 5d |.F@.{.'...u....]|
00000190 2e 64 7f a8 df e0 16 b9 ee 27 7e b3 98 99 f7 4a |.d.......'~....J|
000001a0 83 05 78 bb 59 07 8e 1a 46 1d 0f 45 87 ae d9 ae |..x.Y...F..E....|
000001b0 6f 42 ed b1 72 14 8c 9d 33 72 95 ac 12 bb a0 20 |oB..r...3r..... |
000001c0 56 a8 8a 23 e4 51 6a 89 f5 8e bc 55 5a e2 8d 78 |V..#.Qj....UZ..x|
000001d0 84 24 55 99 cf 37 61 8c 7e 46 17 f3 26 ca 27 ec |.$U..7a.~F..&.'.|
000001e0 f4 04 f6 76 1d cf 82 0c bd 85 82 81 06 f1 96 ce |...v............|
000001f0 78 54 6c eb a0 f8 cf 30 6a 10 17 08 e6 94 83 4f |xTl....0j......O|
00000200 56 34 80 ef ac fa ab e7 59 9e 6b f9 f8 38 76 cc |V4......Y.k..8v.|
00000210 3b 09 b0 16 3f 3f 5c d3 6a ad d9 2c 65 d8 ce b4 |;...??\.j..,e...|
00000220 19 53 c4 c9 d1 82 e8 19 72 ec bc 85 ef 3a 6e e5 |.S......r....:n.|
00000230 ba 3c f8 37 98 98 80 47 5f 47 4f cd ed f5 0e bc |.<.7...G_GO.....|
00000240 4e 14 a2 7d 8d 43 0b 18 ba 3b 10 50 e4 18 fc ac |N..}.C...;.P....|
00000250 0e 01 21 73 68 da 50 51 8a 64 b6 18 28 ca e3 a4 |..!sh.PQ.d..(...|
00000260 aa d2 5c 28 ff 64 fd cb 28 00 db b1 5c bf 75 81 |..\(.d..(...\.u.|
00000270 bb d2 8c df 5c 26 70 1d d6 fe 7a 94 65 27 93 72 |....\&p...z.e'.r|
00000280 bc ba 17 92 8f be 61 ec f5 88 04 ed fb cc f3 5c |......a........\|
00000290 71 d0 a4 5d 13 a6 a3 82 89 e8 9e 1a 8e 31 fd 2f |q..].........1./|
000002a0 57 53 98 d5 1f c4 3f 8e 92 7f 1b 90 a3 ad 6c 96 |WS....?.......l.|
000002b0 42 cc f2 f0 1c 8d 3f 31 fd b2 53 29 79 16 9a 96 |B.....?1..S)y...|
000002c0 fd d6 fe d4 3f 13 aa 39 73 d4 73 6d 9a ff f6 db |....?..9s.sm....|
000002d0 52 0a 1e 76 71 0f d3 ee de a8 b3 05 3b 24 c4 72 |R..vq.......;$.r|
000002e0 67 78 f1 be df c5 c0 87 32 60 28 96 8e b2 2e 3f |gx......2`(....?|
000002f0 7d e9 aa b7 66 57 ee 67 e6 ac 70 da 60 ce c2 00 |}...fW.g..p.`...|
00000300 55 2f 20 25 39 a5 5e b9 65 c3 00 63 c7 5a a9 31 |U/ %9.^.e..c.Z.1|
00000310 de fe 65 17 03 03 00 99 95 83 6d be 56 ef 4f a3 |..e.......m.V.O.|
00000320 96 5f a8 3d d5 a1 f3 8e 9a 8c 40 35 f4 12 2c 0a |._.=......@5..,.|
00000330 b3 02 3b d2 14 d8 a4 f1 12 01 be e1 8a 6b 5f 01 |..;..........k_.|
00000340 71 de ac 70 e9 7a 90 78 2e 2a a8 29 64 20 85 dd |q..p.z.x.*.)d ..|
00000350 57 09 cf 48 29 d0 63 42 bc 9b ec 0c e2 2d 41 d0 |W..H).cB.....-A.|
00000360 cb d8 68 46 b7 17 fc 1d 95 12 5a 4c c3 10 67 32 |..hF......ZL..g2|
00000370 f7 7a 14 55 63 fb 57 6e 59 ee b6 66 b8 65 e1 37 |.z.Uc.WnY..f.e.7|
00000380 e6 7c 6c 07 8b d1 84 80 01 11 ce 7f 20 f0 4d 42 |.|l......... .MB|
00000390 a7 67 01 12 e6 b5 9b d4 6a fe 38 37 71 ca 60 d6 |.g......j.87q.`.|
000003a0 12 d7 00 b5 26 c3 97 1d 9f 37 6a 82 31 ef c3 12 |....&....7j.1...|
000003b0 bc 17 03 03 00 45 65 1e cf 1f 1e 73 93 8d 66 54 |.....Ee....s..fT|
000003c0 47 b0 73 9f d1 a4 9d 3b b0 72 b4 f2 5f 06 e1 d2 |G.s....;.r.._...|
000003d0 1f bb 3d 13 48 7c 7a e0 19 15 9f aa a5 ed 09 18 |..=.H|z.........|
000003e0 2e 4e 8a cd 66 2b 9c b3 fe 99 b0 57 06 2e b3 a0 |.N..f+.....W....|
000003f0 79 92 c1 bb 0e 29 44 02 f1 b0 43 17 03 03 00 a3 |y....)D...C.....|
00000400 52 cd d9 d7 60 1c f5 06 83 aa 2f e0 0c 0f 5e 6d |R...`...../...^m|
00000410 0f 29 93 b9 ae 50 04 c6 f7 d3 ff c7 d1 ac 9d 43 |.)...P.........C|
00000420 d7 b5 76 7a 16 b7 2c b7 79 48 a4 c3 28 2a 86 10 |..vz..,.yH..(*..|
00000430 d1 24 7c 04 ed af 1f 8a 0b 18 29 97 7a 7a 47 3f |.$|.......).zzG?|
00000440 1f fe ba 9c 72 d9 9b ae 9b 83 5f f4 5a 4f 10 b8 |....r....._.ZO..|
00000450 e5 45 35 76 77 a2 ac 99 1c bc 78 cf 6f 62 ef ef |.E5vw.....x.ob..|
00000460 9b 1b 90 eb 95 6b a1 25 82 b7 c1 1b 6f da 10 4c |.....k.%....o..L|
00000470 aa 3e a8 ba dd 77 b1 39 a0 b2 6a 11 18 44 2a 8d |.>...w.9..j..D*.|
00000480 58 9a 53 31 e1 d1 ec 8b 47 95 63 67 44 67 8d 09 |X.S1....G.cgDg..|
00000490 2f 16 f5 19 cd 65 1d 52 d7 bd 19 f0 bb ec 7b 55 |/....e.R......{U|
000004a0 33 4f 84 |3O.|
>>> Flow 3 (client to server)
00000000 14 03 03 00 01 01 17 03 03 00 45 e9 b8 73 86 f8 |..........E..s..|
00000010 0c ba 6d ee 91 c4 70 d6 06 df 59 f8 28 21 92 3d |..m...p...Y.(!.=|
00000020 a5 ad 7c d3 08 ad ea f6 9f c8 d6 8a b1 f0 fc d2 |..|.............|
00000030 52 91 e8 1b b4 0b b9 a0 6e 48 18 d8 fb fe 3e d1 |R.......nH....>.|
00000040 d9 81 d5 9f 6a bd 83 74 c5 2d fb 42 95 57 5b 23 |....j..t.-.B.W[#|
00000000 14 03 03 00 01 01 17 03 03 00 45 07 3f db d9 c7 |..........E.?...|
00000010 05 fd c4 0c 2d ae ee d8 d7 e7 ac 46 19 a2 17 e5 |....-......F....|
00000020 5e 10 30 65 05 be e0 c7 1e b3 e2 16 a4 d6 69 e1 |^.0e..........i.|
00000030 2c ff 18 ba e4 8f d0 3d 12 45 df c3 d4 08 0d e6 |,......=.E......|
00000040 94 6e 83 6d 99 9d f3 f1 02 48 6b 6f d1 2d f0 c6 |.n.m.....Hko.-..|
>>> Flow 4 (server to client)
00000000 17 03 03 00 1e 64 cd 12 df 96 8c 5d a7 8f 92 98 |.....d.....]....|
00000010 c9 f7 16 11 4e 37 48 dd 55 b2 c6 4c 91 82 8d a8 |....N7H.U..L....|
00000020 01 8b a3 17 03 03 00 13 68 92 77 f7 88 86 d9 3c |........h.w....<|
00000030 4a 52 35 b2 2c b7 24 03 3c db 6c |JR5.,.$.<.l|
00000000 17 03 03 00 1e 2a 3d 96 b4 6a 9e 7f 7f ca e0 8e |.....*=..j......|
00000010 41 4e bd 82 86 61 b8 59 19 e4 97 02 c2 00 7e 69 |AN...a.Y......~i|
00000020 81 b0 64 17 03 03 00 13 63 91 94 1a a3 51 bf 95 |..d.....c....Q..|
00000030 9e 09 a2 a1 f0 01 57 93 00 71 49 |......W..qI|