[erlang-questions] new_ssl recv Length parameter

Essien Essien essiene@REDACTED
Thu May 21 14:33:41 CEST 2009


Hi all,

I'm having difficulty getting a new_ssl connection to recieve a
specified Length of data. I've attached two simple server scripts
oldsslserver.erl uses the old_ssl implimentation, while sslserver.erl
uses the new_ssl implementation (specifically, it first accepts on tcp
then upgrades to ssl via ssl_accept).

I have also attached sslclient.erl that connects to each, and attempts
to send a header that when assembled should look like
<<"VERSION",2,1>>, but I send I break it up into <<"VERSION">>, <<2>>,
<<1>> and send them in seperate calls to ssl:send/2. oldsslserver.erl
is able to nicely assemble this back, but sslserver.erl (using the
new_ssl implementation) b0rks badly.

I think I may be missing something, but for the life of me, I can't
figure it out.

erl -man new_ssl says of recv:

              The Length argument is only meaningful when the socket is in raw
              mode and denotes the number of bytes to read. If Length = 0, all
              available bytes are returned. If  Length  >  0,  exactly  Length
              bytes  are  returned, or an error; possibly discarding less than
              Length bytes of data when the socket gets closed from the  other
              side.

As you can see in sslserver.erl I have ssl:setopts/2 on the accepted
ssl socket, to comply with the man page requirement for ssl:recv/2,
but still... foobar!

Any ideas?

cheers,
Essien

PS: Before running the scripts, you will need to change that path to
the SSL certs to point at ones you have created.
You can generate them with:

$ openssl genrsa 2048 > /path/to/key.pem
$ openssl req -new -x509 -key /path/to/key.pem -out /path/to/cert.pem
-nodes -sha1 -batch

Then point the scripts at /path/to/{key,cert}.pem
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oldsslserver.erl
Type: application/octet-stream
Size: 1504 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090521/c0633ef8/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sslclient.erl
Type: application/octet-stream
Size: 925 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090521/c0633ef8/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sslserver.erl
Type: application/octet-stream
Size: 1474 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090521/c0633ef8/attachment-0002.obj>


More information about the erlang-questions mailing list