4 ms·
This is certainly something interesting and worth trying, but I'd recommend starting with 1.2 first, because the handshake isn't encrypted so you can follow alo
by userbinator 5y ago
This is certainly something interesting and worth trying, but I'd recommend starting with 1.2 first, because the handshake isn't encrypted so you can follow along more easily.
I only looked at the TLS 1.3 RFC for a few small things.
As someone who has written implementations of various widely-considered-nontrivial things (mostly image and video codecs, some crypto -- but not TLS, although upon seeing this article, that may change...) for self-educational purposes, I strongly recommend that the official standard be the first thing you look at and refer to during the process. It will clarify a lot of doubts, and in the case of TLS, the RFCs are relatively readable as far as standards go.
I’m not sure why the blocks have the size they do (maybe it’s so that each one will fit inside a TCP packet ???), but in theory I think they could be up to 65535 bytes, since their size field is 2 bytes.
That's due to either MTU or server-side write fragmentation, and the limit is 16K(+overhead). It is a stream to the application layer, but the record-layer protocol breaks it up into chunks of smaller limited size to allow for the integrity checks.
I assume a real TLS implementation would use a thread pool or coroutines or something to manage this.
That's a very strange assumption. Depending on the API, the ones I've used will either just read in a loop until the length is fulfilled or an error occurs; or return an "incomplete message" error meaning that the caller is the one to continue reading. Getting a partial read from a TCP socket is a very common "trap for young players" --- if you don't keep it in mind, you'll write code that appears to work on localhost or inside a fast LAN, but fails intermittently and sometimes mysteriously over the Internet or when there's more latency. You can never assume message boundaries when using TCP.
- eek2121 5y ago100% agree on reading the RFC. I've implemented various protocols as well (SMTP, IMAP, POP, FTP, some crypto and other things, all a couple decades ago), and the cases where I glossed over the RFC have always bitten me.
- andrewf 5y agoGetting a partial read from a TCP socket I wish common test frameworks and/or stdlibs made it easier to "fuzz" this. I've written more than one io.Reader implementation (Golang) that breaks up results from an underlying io.Reader according to a random seed.
- anonymoushn 5y agoWhile you'll usually catch me saying negative things about the Zig Reader and Writer interfaces, this is one thing they make super easy.
- lmm 5y ago>> I assume a real TLS implementation would use a thread pool or coroutines or something to manage this. > That's a very strange assumption. Depending on the API, the ones I've used will either just read in a loop until the length is fulfilled or an error occurs; When you're receiving from a network socket over the Internet, blocking a (real) thread until all the data arrives is pretty inefficient. > or return an "incomplete message" error meaning that the caller is the one to continue reading. That's pretty un-user-friendly. There might be rare cases where a caller really needs precise control, but I'd expect any serious general-purpose library in a serious general-purpose language to "use a thread pool or coroutines or something to manage this". In the overwhelmingly common case what you want while waiting for data from the Internet is to yield to other fibers; a library should guide you towards doing the right thing and make the easy case easy.
- swiftcoder 5y ago> When you're receiving from a network socket over the Internet, blocking a (real) thread until all the data arrives is pretty inefficient. Yes, but it's still how the overwhelming majority of network code functions. It's not really till the rise of libev/libuv and friends that people start moving to non-blocking as a default (I spent pretty much an entire year of my life convincing an AWS team to reclaim 4 GB of thread stacks by moving to non-blocking I/O). >> or return an "incomplete message" error meaning that the caller is the one to continue reading. > That's pretty un-user-friendly. It's also how all non-blocking I/O worked prior to languages adding native async functionality.
- lmm 5y ago> Yes, but it's still how the overwhelming majority of network code functions. It's not really till the rise of libev/libuv and friends that people start moving to non-blocking as a default > It's also how all non-blocking I/O worked prior to languages adding native async functionality. Meh. AOLServer showed that you could do better back when I was in high school. I've given up worrying about ecosystems that haven't got it yet.
- userbinator 5y ago