Skip to content

Commit ae67956

Browse files
committed
FEAT: Added Server Name Indication extension into TLS scheme
More details: https://tools.ietf.org/html/rfc6066#section-3 TLS does not provide a mechanism for a client to tell a server the name of the server it is contacting. It may be desirable for clients to provide this information to facilitate secure connections to servers that host multiple 'virtual' servers at a single underlying network address. In order to provide any of the server names, clients MAY include an extension of type "server_name" in the (extended) client hello.
1 parent d494aad commit ae67956

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/mezz/prot-tls.r

+24-3
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,31 @@ client-hello: function [
408408
] [
409409
change-state ctx 'CLIENT_HELLO
410410
with ctx [
411-
;initialize checksum port(s)
411+
412+
extensions: make binary! 16
413+
414+
;- Server Name Indication (extension)
415+
; https://tools.ietf.org/html/rfc6066#section-3
416+
if all [
417+
ctx/connection
418+
host-name: ctx/connection/spec/host
419+
][
420+
host-name: to binary! host-name
421+
length-name: length? host-name
422+
423+
binary/write extensions compose [
424+
UI16 0 ; extension type (server_name=0)
425+
UI16 (5 + length-name)
426+
UI16 (3 + length-name)
427+
UI8 0
428+
UI16 :length-name
429+
BYTES :host-name
430+
]
431+
]
412432

413433
;precomputing the extension's lengths so I can write them in one WRITE call
414434
length-signatures: 2 + length? supported-signature-algorithms
415-
length-extensions: 4 + length-signatures
435+
length-extensions: 4 + length-signatures + length? extensions
416436
length-message: 41 + length-extensions + length? suported-cipher-suites
417437
length-record: 4 + length-message
418438

@@ -434,6 +454,7 @@ client-hello: function [
434454
UI16 13 ; extension type: signature-algorithms
435455
UI16 :length-signatures ; note: there is another length following
436456
UI16BYTES :supported-signature-algorithms
457+
BYTES :extensions
437458
]
438459

439460
out/buffer: head out/buffer
@@ -1376,7 +1397,7 @@ TLS-read-handshake-message: function [
13761397
signature: decode 'der signature
13771398
]
13781399
;note tls1.3 is different a little bit here!
1379-
message-hash <> signature/sequence/octet_string
1400+
(probe message-hash) <> probe signature/sequence/octet_string
13801401
][
13811402
log-error "Failed to validate signature"
13821403
if error? err [print err]

0 commit comments

Comments
 (0)