Comparison

net/server.lua @ 846:77244ba297ac

net.server: Some fixes for SSL/TLS handshake handling
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Feb 2009 18:40:17 +0000
parent 815:cf8392613f46
child 850:edbd0d1fce93
comparison
equal deleted inserted replaced
845:fc3dced9801e 846:77244ba297ac
478 end 478 end
479 479
480 if sslctx then -- ssl? 480 if sslctx then -- ssl?
481 ssl = true 481 ssl = true
482 local wrote 482 local wrote
483 local read
483 local handshake = coroutine_wrap( function( client ) -- create handshake coroutine 484 local handshake = coroutine_wrap( function( client ) -- create handshake coroutine
484 local err 485 local err
485 for i = 1, 10 do -- 10 handshake attemps 486 for i = 1, 10 do -- 10 handshake attemps
487 _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
488 _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen
489 read, wrote = nil, nil
486 _, err = client:dohandshake( ) 490 _, err = client:dohandshake( )
487 if not err then 491 if not err then
488 --out_put( "server.lua: ssl handshake done" ) 492 --out_put( "server.lua: ssl handshake done" )
489 _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
490 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions 493 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions
491 handler.sendbuffer = _sendbuffer 494 handler.sendbuffer = _sendbuffer
492 --return dispatch( handler ) 495 -- return dispatch( handler )
493 return true 496 return true
494 else 497 else
495 out_put( "server.lua: error during ssl handshake: ", err ) 498 out_put( "server.lua: error during ssl handshake: ", err )
496 if err == "wantwrite" and not wrote then 499 if err == "wantwrite" and not wrote then
497 _sendlistlen = _sendlistlen + 1 500 _sendlistlen = _sendlistlen + 1
498 _sendlist[ _sendlistlen ] = client 501 _sendlist[ _sendlistlen ] = client
499 wrote = true 502 wrote = true
503 elseif err == "wantread" and not read then
504 _readlistlen = _readlistlen + 1
505 _readlist [ _readlistlen ] = client
506 read = true
500 end 507 end
501 --coroutine_yield( handler, nil, err ) -- handshake not finished 508 --coroutine_yield( handler, nil, err ) -- handshake not finished
502 coroutine_yield( ) 509 coroutine_yield( )
503 end 510 end
504 end 511 end
556 _socketlist[ oldsocket ] = nil 563 _socketlist[ oldsocket ] = nil
557 564
558 handler.starttls = nil 565 handler.starttls = nil
559 needtls = nil 566 needtls = nil
560 567
561 handler.receivedata = handler.handshake 568 handler.readbuffer = handshake
562 handler.dispatchdata = handler.handshake 569 handler.sendbuffer = handshake
563 handshake( socket ) -- do handshake 570 handshake( socket ) -- do handshake
564 end 571 end
565 handler.readbuffer = _readbuffer 572 handler.readbuffer = _readbuffer
566 handler.sendbuffer = _sendbuffer 573 handler.sendbuffer = _sendbuffer
567 end 574 end