On Sun, Oct 7, 2012 at 11:34 PM, Justin Meltzer <[email protected]> wrote:
> Aww shucks :/
>
> Out of curiosity, how does the _push method on the Cryptostream prototype
> know where one message ends and the other begins?

It doesn't, it feeds openssl encrypted data until decrypted data pops
out at the other side (or vice versa, of course).

> It seems to me that the while/do loop continues to call _pusher (which calls
> SSL_read under the hood) until either the buffer is all used up or the
> SSL_read function can't read anything (it returns -1). Then it'll emit a
> data event only if it has actually read a non-negative number of bytes.
>
> When I was debugging, it occurred to me that maybe the data was coming in
> slowly in chunks so that after it had read the first one or two chunks from
> SSL_read, the next tick of the while loop fired so quickly that it returned
> -1 before the next chunk of data had reached the C buffer. Then it emitted
> this first part of the data as if it were its own isolated grouping. Is this
> possible?

I'm not sure if I'm following you. Encryption and decryption in the
current implementation are synchronous. That while loop in lib/tls.js
doesn't get split over multiple ticks of the event loop.

For the record, SSL and TLS work like this:

1) they are frame based
2) a frame contains one or more messages
3) a message is either a protocol message or data

Frames and messages can span multiple TCP packets. If you feed openssl
input that contains only partial messages, or protocol messages and no
data, nothing comes out at the other side.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to