/
index.html.template
2126 lines (1990 loc) · 68.5 KB
/
index.html.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<title>The Illustrated TLS Connection: Every Byte Explained</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="title" content="The Illustrated TLS Connection"/>
<meta name="description" content="Every byte of a TLS connection explained and reproduced"/>
<link rel="stylesheet" href="frombootstrap.css"/>
<link rel="stylesheet" href="illustrated.css"/>
<script src="illustrated.js"></script>
</head>
<body class="illustrated">
<div class="container">
<h1>The Illustrated TLS Connection</h1>
<h3>Every byte of a TLS connection explained and reproduced.</h3>
<div class="outerblock">
<p>In this demonstration a client has connected to a server,
negotiated a TLS 1.2 session, sent "ping", received "pong",
and then terminated the session. Click below to begin
exploring.</p>
</div>
<div class="record client">
<div class="label">Client Hello</div>
<image class="illustration" src="images/key1.png" width="135" height="250"/>
<div class="explanation">
The session begins with the client saying "Hello".
The client provides the following:
<ul>
<li>protocol version
<li>client random data (used later in the handshake)
<li>an optional session id to resume
<li>a list of cipher suites
<li>a list of compression methods
<li>a list of extensions
</ul>
</div>
%file ../captures/caps/clienthello
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>%0</tt> - type is 0x16 (handshake record)
<li><tt>%1 %2</tt> - protocol version is 3.1 (also known as TLS 1.0)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
Interestingly the version is 3.1 (TLS 1.0) instead
of the expected 3.3 (TLS 1.2). Looking through the
golang crypto/tls library we find the following
comment:
<pre><code>if vers == 0 {
// Some TLS servers fail if the record version is
// greater than TLS 1.0 for the initial ClientHello.
vers = VersionTLS10
}</code></pre>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">
<span class="label">Handshake Header</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
Each handshake message starts with a type and a length.
<ul>
<li><tt>%0</tt> - handshake message type 0x01 (client hello)
<li><tt>%1 %2 %3</tt> - payload length of %xxx1 (%ddd1) bytes
</ul>
All data following this header is the payload for this message.
</div>
</span>
<span class="string">
<span class="label">Client Version</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The protocol version of 3.3 (meaning TLS 1.2) is given.
<br/><br/>
This choice of version number (3.3 rather
than 1.2) is due to TLS 1.0 being a minor
revision of the SSL 3.0 protocol, thus being
assigned version 3.1.
</div>
</span>
<span class="string">
<span class="label">Client Random</span>
<span class="bytes">
%next 32
%bytes
</span>
<div class="explanation">
The client provides 32 bytes of cryptographically secure random data.
In this example we've made the random data predictable to make it easier to recognize.
<br/><br/>
The TLS 1.2 spec says that the first 4 bytes
should be the current time in seconds-since-1970
but this is now recommended against as it enables
fingerprinting of hosts and servers.
</div>
</span>
<span class="string">
<span class="label">Session ID</span>
<span class="bytes">
%next 1
%bytes
</span>
<div class="explanation">
The client can provide the ID of a previous
TLS session against this server which it
is able to resume. For this to work both
the server and client will have remembered
key information from the previous connection
in memory. Resuming a connection saves a
lot of computation and network round-trip
time so it is performed whenever possible.
<ul>
<li><tt>%0</tt> - length of zero (no session id is provided)
</ul>
</div>
</span>
<span class="string">
<span class="label">Cipher Suites</span>
<span class="bytes">
%next 34
%bytes
</span>
<div class="explanation">
The client provides an ordered list of which
cryptographic methods it will support for
key exchange, encryption with that exchanged
key, and message authentication method.
The list is in the order preferred by the
client, with highest preference first.
<ul>
<li><tt>%0 %1</tt> - %xx0 (%dd0) bytes of cipher suite data
<li><tt>cc a8</tt> - assigned value for <tt>ECDHE-RSA-CHACHA20-POLY1305-SHA256</tt>
<li><tt>cc a9</tt> - assigned value for <tt>ECDHE-ECDSA-CHACHA20-POLY1305-SHA256</tt>
<li><tt>c0 2f</tt> - assigned value for <tt>ECDHE-RSA-AES128-GCM-SHA256</tt>
<li><tt>c0 30</tt> - assigned value for <tt>ECDHE-RSA-AES256-GCM-SHA384</tt>
<li><tt>c0 2b</tt> - assigned value for <tt>ECDHE-ECDSA-AES128-GCM-SHA256</tt>
<li><tt>c0 2c</tt> - assigned value for <tt>ECDHE-ECDSA-AES256-GCM-SHA384</tt>
<li><tt>c0 13</tt> - assigned value for <tt>ECDHE-RSA-AES128-SHA</tt>
<li><tt>c0 09</tt> - assigned value for <tt>ECDHE-ECDSA-AES128-SHA</tt>
<li><tt>c0 14</tt> - assigned value for <tt>ECDHE-RSA-AES256-SHA</tt>
<li><tt>c0 0a</tt> - assigned value for <tt>ECDHE-ECDSA-AES256-SHA</tt>
<li><tt>00 9c</tt> - assigned value for <tt>RSA-AES128-GCM-SHA256</tt>
<li><tt>00 9d</tt> - assigned value for <tt>RSA-AES256-GCM-SHA384</tt>
<li><tt>00 2f</tt> - assigned value for <tt>RSA-AES128-SHA</tt>
<li><tt>00 35</tt> - assigned value for <tt>RSA-AES256-SHA</tt>
<li><tt>c0 12</tt> - assigned value for <tt>ECDHE-RSA-3DES-EDE-SHA</tt>
<li><tt>00 0a</tt> - assigned value for <tt>RSA-3DES-EDE-SHA</tt>
</ul>
</div>
</span>
<span class="string">
<span class="label">Compression Methods</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The client provides an ordered list of which
compression methods it will support. This
compression would be applied before encryption
(as properly encrypted data is usually incompressible).
<ul>
<li><tt>%0</tt> - %x0 (%d0) bytes of compression methods
<li><tt>00</tt> - assigned value for no compression
</ul>
Compression has characteristics that can weaken
the security of the encrypted data so this feature
has been removed from future TLS protocols.
</div>
</span>
<span class="string">
<span class="label">Extensions Length</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The client has provided a list of optional
extensions which the server can use to
take action or enable new features.
<ul>
<li><tt>%0 %1</tt> - the extensions will take %xx0 (%dd0) bytes of data
</ul>
Each extension will start with two bytes
that indicate which extension it is, followed
by a two-byte content length field, followed
by the contents of the extension.
</div>
</span>
<span class="string">
<span class="label">Extension - Server Name</span>
<span class="bytes">
%next 28
%bytes
</span>
<div class="explanation">
The client has provided the name of the
server it is contacting, also known as SNI
(Server Name Indication).
<br/><br/>
Without this extension a HTTPS server would
not be able to provide service for multiple
hostnames on a single IP address (virtual
hosts) because it couldn't know which
hostname's certificate to send until
after the TLS session was negotiated and the
HTTP request was made.
<ul>
<li><tt>00 00</tt> - assigned value for extension "server name"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>%4 %5</tt> - %xx4 (%dd4) bytes of first (and only) list entry follows
<li><tt>%6</tt> - list entry is type 0x00 "DNS hostname"
<li><tt>%7 %8</tt> - %xx7 (%dd7) bytes of hostname follows
<li><tt>%9 %10 %11 ... %-3 %-2 %-1</tt> - "example.ulfheim.net"
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - Status Request</span>
<span class="bytes">
%next 9
%bytes
</span>
<div class="explanation">
The client provides permission for the
server to provide OCSP information in its response.
OCSP can be used to check whether a certificate
has been revoked.
<br/><br/>
This form of the client sending an empty
extension is necessary because
it is a fatal error for the server
to reply with an extension that the client
did not provide first. Therefore the client
sends an empty form of the extension, and
the server replies with the extension
populated with data.
<ul>
<li><tt>00 05</tt> - assigned value for extension "status request"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>01</tt> - assigned value for "certificate status type: OCSP"
<li><tt>%5 %6</tt> - %xx5 (%dd5) bytes of responderID information
<li><tt>%7 %8</tt> - %xx7 (%dd7) bytes of request extension information
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - Supported Groups</span>
<span class="bytes">
%next 14
%bytes
</span>
<div class="explanation">
The client has indicated that it supports
elliptic curve (EC) cryptography for 4 curves.
To make this extension more generic for
other cryptography types it now calls these
"supported groups" instead of "supported
curves".
<ul>
<li><tt>00 0a</tt> - assigned value for extension "supported groups"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>%4 %5</tt> - %xx4 (%dd4) bytes of data are in the curves list
<li><tt>00 1d</tt> - assigned value for the curve "x25519"
<li><tt>00 17</tt> - assigned value for the curve "secp256r1"
<li><tt>00 18</tt> - assigned value for the curve "secp384r1"
<li><tt>00 19</tt> - assigned value for the curve "secp521r1"
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - EC Point Formats</span>
<span class="bytes">
%next 6
%bytes
</span>
<div class="explanation">
During elliptic curve (EC) cryptography the
client and server will exchange information
on the points selected, in either compressed
or uncompressed form. This extension
indicates that the client can only parse
uncompressed information from the server.
<br/><br/>
In the next version of TLS the ability to
negotiate points does not exist (instead a
single point is pre-selected for each curve),
so this extension would not be sent.
<ul>
<li><tt>00 0b</tt> - assigned value for extension "EC points format"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>%4</tt> - %x4 (%d4) bytes of data are in the supported formats list
<li><tt>00</tt> - assigned value for uncompressed form
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - Signature Algorithms</span>
<span class="bytes">
%next 22
%bytes
</span>
<div class="explanation">
As TLS has developed it has become necessary to
support stronger signature algorithms such
as SHA-256 while still supporting earlier
implementations that used MD5 and SHA1.
This extension indicates which signature
algorithms the client is capable
of using.
<ul>
<li><tt>00 0d</tt> - assigned value for extension "Signature Algorithms"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>%4 %5</tt> - %xx4 (%dd4) bytes of data are in the following list of algorithms
<li><tt>04 01</tt> - assigned value for RSA/PKCS1/SHA256
<li><tt>04 03</tt> - assigned value for ECDSA/SECP256r1/SHA256
<li><tt>05 01</tt> - assigned value for RSA/PKCS1/SHA386
<li><tt>05 03</tt> - assigned value for ECDSA/SECP384r1/SHA384
<li><tt>06 01</tt> - assigned value for RSA/PKCS1/SHA512
<li><tt>06 03</tt> - assigned value for ECDSA/SECP521r1/SHA512
<li><tt>02 01</tt> - assigned value for RSA/PKCS1/SHA1
<li><tt>02 03</tt> - assigned value for ECDSA/SHA1
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - Renegotiation Info</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
The presence of this extension prevents a type of attack performed with TLS renegotiation.
<br/><br/>
The ability to renegotiate a connection has been removed from the next version of this
protocol (TLS 1.3) so this will no longer be necessary.
<ul>
<li><tt>ff 01</tt> - assigned value for extension "Renegotiation Info"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>00</tt> - length of renegotiation data is zero, because this is a new connection
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - SCT</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
The client provides permission for the
server to return a signed certificate
timestamp.
<br/><br/>
This form of the client sending an empty
extension is necessary because
it is a fatal error for the server
to reply with an extension that the client
did not provide first. Therefore the client
sends an empty form of the extension, and
the server replies with the extension
populated with data.
<ul>
<li><tt>00 12</tt> - assigned value for extension "signed certificate timestamp"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
</ul>
</div>
</span>
</span>
</div>
%empty
<div class="record server">
<div class="label">Server Hello</div>
<image class="illustration" src="images/key2.png" width="124" height="250"/>
<div class="explanation">
The server says "Hello" back. The server provides the following:
<ul>
<li>protocol version
<li>server random data (used later in the handshake)
<li>a session id
<li>a selected cipher suite
<li>a selected compression method
<li>a list of extensions
</ul>
</div>
%file ../captures/caps/serverhello
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>%0</tt> - type is 0x16 (handshake record)
<li><tt>%1 %2</tt> - protocol version is 3.3 (TLS 1.2)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">
<span class="label">Handshake Header</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
Each handshake message starts with a type and a length.
<ul>
<li><tt>02</tt> - handshake message type 0x02 (server hello)
<li><tt>%1 %2 %3</tt> - payload length of %xxx1 (%ddd1) bytes
</ul>
All data following this header is the payload for this message.
</div>
</span>
<span class="string">
<span class="label">Server Version</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The protocol version of 3.3 (TLS 1.2) is given.
<br/><br/>
The reason for this version number (3.3
rather than 1.2) is that TLS 1.0 was a minor
revision of the SSL 3.0 protocol created
by Netscape, therefore it was assigned
version 3.1.
</div>
</span>
<span class="string">
<span class="label">Server Random</span>
<span class="bytes">
%next 32
%bytes
</span>
<div class="explanation">
The server provides 32 bytes of cryptographically secure random data.
In this example we've made the random data predictable to make it easier to recognize.
<br/><br/>
The TLS 1.2 spec says that the first 4 bytes
should be the current time in seconds-since-1970
but this is now recommended against as it enables
fingerprinting of hosts and servers.
</div>
</span>
<span class="string">
<span class="label">Session ID</span>
<span class="bytes">
%next 1
%bytes
</span>
<div class="explanation">
The server can provide an ID for this session
which a client can provide on a later session
negotiation in an attempt to re-use the key
data and skip most of the TLS negotiation
process. For this to work both the server
and client will store key information from
the previous connection in memory. Resuming
a connection saves a lot of computation and
network round-trip time so it is performed
whenever possible.
<ul>
<li><tt>00</tt> - length of zero (no session id is provided)
</ul>
</div>
</span>
<span class="string">
<span class="label">Cipher Suite</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The server has selected cipher suite 0xC013
(ECDHE-RSA-AES128-CBC-SHA) from the
list of options given by the client.
</div>
</span>
<span class="string">
<span class="label">Compression Method</span>
<span class="bytes">
%next 1
%bytes
</span>
<div class="explanation">
The server has selected compression method
0x00 ("Null", which performs no compression)
from the list of options given by the client.
</div>
</span>
<span class="string">
<span class="label">Extensions Length</span>
<span class="bytes">
%next 2
%bytes
</span>
<div class="explanation">
The server has returned a list of extensions
to the client. Because the server is
forbidden from replying with an extension
that the client did not send in its hello
message, the server knows that the client
will support all extensions listed.
<ul>
<li><tt>%0 %1</tt> - the extensions will take %xx0 (%dd0) bytes of data
</ul>
</div>
</span>
<span class="string">
<span class="label">Extension - Renegotiation Info</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
The presence of this extension prevents a type of attack performed with TLS renegotiation.
<br/><br/>
The ability to renegotiate a connection has been removed from the next version of this
protocol (TLS 1.3) so this will no longer be necessary.
<ul>
<li><tt>ff 01</tt> - assigned value for extension "Renegotiation Info"
<li><tt>%2 %3</tt> - %xx2 (%dd2) bytes of extension data follows
<li><tt>%4</tt> - length of renegotiation data is zero, because this is a new connection
</ul>
</div>
</span>
</span>
</div>
%empty
<div class="record server">
<div class="label">Server Certificate</div>
<image class="illustration" src="images/key3.png" width="130" height="250"/>
<div class="explanation">
The server provides a certificate containing the following:
<ul>
<li>the hostname of the server
<li>the public key used by this server
<li>proof from a trusted third party that the owner of this hostname holds the private key for this public key
</ul>
<a href="certificate.html" target="_blank">Explore the server certificate</a>.
</div>
%file ../captures/caps/servercert
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>16</tt> - type is 0x16 (handshake record)
<li><tt>%1 %2</tt> - protocol version is 3.3 (TLS 1.2)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">
<span class="label">Handshake Header</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
Each handshake message starts with a type and a length.
<ul>
<li><tt>0b</tt> - handshake message type 0x0B (certificate)
<li><tt>%1 %2 %3</tt> - payload length of %xxx1 (%ddd1) bytes
</ul>
All data following this header is the payload for this message.
</div>
</span>
<span class="string">
<span class="label">Certificates Length</span>
<span class="bytes">
%next 3
%bytes
</span>
<div class="explanation">
The certificate message begins with the
length of all certificate data that will follow.
<ul>
<li><tt>%0 %1 %2</tt> - %xxx0 (%ddd0) bytes of certificates follow
</ul>
</div>
</span>
<span class="string">
<span class="label">Certificate Length</span>
<span class="bytes">
%next 3
%bytes
</span>
<div class="explanation">
The length of the first (and only) certificate.
<ul>
<li><tt>%0 %1 %2</tt> - %xxx0 (%ddd0) bytes of certificate follows
</ul>
</div>
</span>
<span class="string">
<span class="label">Certificate</span>
<span class="bytes">
%next 805
%bytes
</span>
<div class="explanation">
The certificate is in ASN.1 DER
encoding. The details of this format and
the content of this binary payload are
documented <a href="certificate.html" target="_blank">on another page</a>.
<a href="files/server.crt" download="server.crt">The certificate</a>
can be converted to the binary data in this message
at the command line:
<codesample>
<pre><code>$ openssl x509 -outform der < server.crt | hexdump
0000000 30 82 03 21 30 82 02 09 a0 03 02 01 02 02 08 15
0000010 5a 92 ad c2 04 8f 90 30 0d 06 09 2a 86 48 86 f7
... snip ...
</code></pre>
</codesample>
</div>
</span>
</span>
</div>
<div class="calculation server">
<div class="label">Server Key Exchange Generation</div>
<image class="illustration" src="images/key4.png" width="106" height="250"/>
<div class="explanation">
The server must calculate a private/public keypair for key
exchange. The server has chosen to use an elliptical curve
method of key exchange, using the x25519 curve.
<br/><br/>
The private key is chosen by selecting an integer between
1 and 2<sup>256</sup>-1. It does this by generating 32 bytes of
random data. The
<a href="files/server-ephemeral-private.key" download="server-ephemeral-private.key">private key</a>
selected is:
<pre class="ind2"><tt class="longboi">909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf</tt></pre>
The <a href="files/server-ephemeral-public.key" download="server-ephemeral-public.key">public key</a>
is chosen by multiplying the point x=9 on the x25519 curve
by the private key. The public key calculated is:
<pre class="ind2"><tt class="longboi">9fd7ad6dcff4298dd3f96d5b1b2af910a0535b1488d7f8fabb349a982880b615</tt></pre>
The public key calculation can be confirmed with command line tools:
<codesample>
<pre><code>### requires openssl 1.1.0 or higher
$ openssl pkey -noout -text < server-ephemeral-private.key
X25519 Private-Key:
priv:
90:91:92:93:94:95:96:97:98:99:9a:9b:9c:9d:9e:
9f:a0:a1:a2:a3:a4:a5:a6:a7:a8:a9:aa:ab:ac:ad:
ae:af
pub:
9f:d7:ad:6d:cf:f4:29:8d:d3:f9:6d:5b:1b:2a:f9:
10:a0:53:5b:14:88:d7:f8:fa:bb:34:9a:98:28:80:
b6:15
</code></pre>
</codesample>
</div>
</div>
%empty
<div class="record server">
<div class="label">Server Key Exchange</div>
<image class="illustration" src="images/key5.png" width="138" height="250"/>
<div class="explanation">
The server provides information for key exchange. As part of the
key exchange process both the server and the client will have a
keypair of public and private keys, and will send the other party
their public key. The shared encryption key will then be generated
using a combination of each party's private key and the other party's
public key.
<br/><br/>
The parties had agreed on a cipher suite using ECDHE, meaning the
keypairs will be based on a selected <b>E</b>lliptic <b>C</b>urve,
<b>D</b>iffie-<b>H</b>ellman will be used, and the keypairs will
be <b>E</b>phemeral rather than using the public/private key from
the certificate.
</div>
%file ../captures/caps/serverkeyexchange
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>16</tt> - type is 0x16 (handshake record)
<li><tt>03 03</tt> - protocol version is 3.3 (TLS 1.2)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">
<span class="label">Handshake Header</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
Each handshake message starts with a type and a length.
<ul>
<li><tt>0c</tt> - handshake message type 0x0c (server key exchange)
<li><tt>%1 %2 %3</tt> - payload length of %xxx1 (%ddd1) bytes
</ul>
All data following this header is the payload for this message.
</div>
</span>
<span class="string">
<span class="label">Curve Info</span>
<span class="bytes">
%next 3
%bytes
</span>
<div class="explanation">
The server chooses the elliptic curve that points will be calculated from.
<ul>
<li><tt>03</tt> - assigned value for "named_curve": the following bytes will identify a specific curve
<li><tt>00 1d</tt> - curve 0x001d ("curve x25519")
</ul>
</div>
</span>
<span class="string">
<span class="label">Public Key</span>
<span class="bytes">
%next 33
%bytes
</span>
<div class="explanation">
The server provides its public key.
<ul>
<li><tt>%0</tt> - length of %x0 (%d0) bytes
<li><tt>%1 %2 ... %-2 %-1</tt> - public key
</ul>
</div>
</span>
<span class="string">
<span class="label">Signature</span>
<span class="bytes">
%next 260
%bytes
</span>
<div class="explanation">
Because the server is generating ephemeral keys
it is not using the public key provided in
the server certificate. To prove that the
server owns the server certificate (giving the certificate
validity in this TLS session), it signs the
ephemeral public key with the certificate's
private key. This signature can be
validated with the certificate's public
key.
<ul>
<li><tt>04 01</tt> - reserved value for RSA signature with SHA256 hash
<li><tt>%2 %3</tt> - length of signature (%xx2 or %dd2 bytes)
<li><tt>%4 %5 %6 ... %-3 %-2 %-1</tt> - the
computed signature for <tt>SHA256(client_hello_random
+ server_hello_random + curve_info + public_key)</tt>
</ul>
We can compute the signature ourselves using
the <a href="files/server.key" download="server.key">server's private key</a>,
at the command line:
<codesample>
<pre><code>### client random from Client Hello
$ echo -en '\x00\x01\x02\x03\x04\x05\x06\x07' > /tmp/compute
$ echo -en '\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f' >> /tmp/compute
$ echo -en '\x10\x11\x12\x13\x14\x15\x16\x17' >> /tmp/compute
$ echo -en '\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f' >> /tmp/compute
### server random from Server Hello
$ echo -en '\x70\x71\x72\x73\x74\x75\x76\x77' >> /tmp/compute
$ echo -en '\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f' >> /tmp/compute
$ echo -en '\x80\x81\x82\x83\x84\x85\x86\x87' >> /tmp/compute
$ echo -en '\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f' >> /tmp/compute
### the curve info section from this message
$ echo -en '\x03\x00\x1d' >> /tmp/compute
### the public key sections from this msg
$ echo -en '\x20\x9f\xd7\xad\x6d\xcf\xf4\x29' >> /tmp/compute
$ echo -en '\x8d\xd3\xf9\x6d\x5b\x1b\x2a\xf9' >> /tmp/compute
$ echo -en '\x10\xa0\x53\x5b\x14\x88\xd7\xf8' >> /tmp/compute
$ echo -en '\xfa\xbb\x34\x9a\x98\x28\x80\xb6\x15' >> /tmp/compute
$ openssl dgst -sign server.key -sha256 /tmp/compute | hexdump
0000000 04 02 b6 61 f7 c1 91 ee 59 be 45 37 66 39 bd c3
... snip ...
00000f0 7d 87 dc 33 18 64 35 71 22 6c 4d d2 c2 ac 41 fb
</code></pre>
</codesample>
</div>
</span>
</span>
</div>
%empty
<div class="record server">
<div class="label">Server Hello Done</div>
<div class="explanation">
The server indicates it's finished with its half of the handshake.
</div>
%file ../captures/caps/serverhellodone
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>16</tt> - type is 0x16 (handshake record)
<li><tt>03 03</tt> - protocol version is 3.3 (TLS 1.2)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">
<span class="label">Handshake Header</span>
<span class="bytes">
%next 4
%bytes
</span>
<div class="explanation">
Each handshake message starts with a type and a length.
<ul>
<li><tt>0e</tt> - handshake message type 0x0e (server hello done)
<li><tt>%1 %2 %3</tt> - payload length of %ddd1 bytes (no payload)
</ul>
</div>
</span>
</span>
</div>
%empty
<div class="calculation client">
<div class="label">Client Key Exchange Generation</div>
<image class="illustration" src="images/key6.png" width="105" height="250"/>
<div class="explanation">
The client must calculate a private/public keypair for key
exchange. It will do this for the elliptical curve
method of key exchange, using the x25519 curve.
<br/><br/>
The private key is chosen by selecting an integer between
1 and 2<sup>256</sup>-1. It does this by generating 32 bytes of
random data. The
<a href="files/client-ephemeral-private.key" download="client-ephemeral-private.key">private key</a>
selected is:
<pre class="ind2"><tt class="longboi">202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f</tt></pre>
The <a href="files/client-ephemeral-public.key" download="client-ephemeral-public.key">public key</a>
is chosen by multiplying the point x=9 on the x25519 curve
by the private key. The public key calculated is:
<pre class="ind2"><tt class="longboi">358072d6365880d1aeea329adf9121383851ed21a28e3b75e965d0d2cd166254</tt></pre>
The public key calculation can be confirmed at the command line:
<codesample>
<pre><code>### requires openssl 1.1.0 or higher
$ openssl pkey -noout -text < client-ephemeral-private.key
X25519 Private-Key:
priv:
20:21:22:23:24:25:26:27:28:29:2a:2b:2c:2d:2e:
2f:30:31:32:33:34:35:36:37:38:39:3a:3b:3c:3d:
3e:3f
pub:
35:80:72:d6:36:58:80:d1:ae:ea:32:9a:df:91:21:
38:38:51:ed:21:a2:8e:3b:75:e9:65:d0:d2:cd:16:
62:54
</code></pre>
</codesample>
</div>
</div>
<div class="record client">
<div class="label">Client Key Exchange</div>
<image class="illustration" src="images/key7.png" width="116" height="250"/>
<div class="explanation">
The client provides information for key exchange. As part of the
key exchange process both the server and the client will generate a
keypair of public and private keys, and will send the other party
their public key. The shared encryption key will then be generated
using a function of each party's private key and the other party's
public key.
<br/><br/>
The parties had agreed on a cipher suite using ECDHE, meaning the
keypairs will be based on a selected <b>E</b>lliptic <b>C</b>urve,
<b>D</b>iffie-<b>H</b>ellman will be used, and the keypairs will
be <b>E</b>phemeral rather than using a public/private key from
the server certificate.
</div>
%file ../captures/caps/clientkeyexchange
<span class="record-data">
<span class="string">
<span class="label">Record Header</span>
<span class="bytes">
%next 5
%bytes
</span>
<div class="explanation">
TLS sessions are broken into the sending
and receiving of "records", which are blocks
of data with a type, a protocol version,
and a length.
<ul>
<li><tt>16</tt> - type is 0x16 (handshake record)
<li><tt>%1 %2</tt> - protocol version is 3.3 (TLS 1.2)
<li><tt>%3 %4</tt> - the length of the record payload is %xx3 (%dd3) bytes
</ul>
All data following this header is the payload for this record.
</div>
</span>
<span class="string">