Class: OverSIP::WebSocket::WssServer
- Inherits:
-
WsServer
- Object
- EM::Connection
- Connection
- WsServer
- OverSIP::WebSocket::WssServer
- Defined in:
- lib/oversip/websocket/listeners/wss_server.rb
Direct Known Subclasses
Constant Summary collapse
- TLS_HANDSHAKE_MAX_TIME =
4
Constants inherited from WsServer
OverSIP::WebSocket::WsServer::HDR_SUPPORTED_WEBSOCKET_VERSIONS, OverSIP::WebSocket::WsServer::HEADERS_MAX_SIZE, OverSIP::WebSocket::WsServer::WS_MAGIC_GUID_04, OverSIP::WebSocket::WsServer::WS_VERSIONS
Constants included from SIP::MessageProcessor
SIP::MessageProcessor::MSG_TYPE
Instance Attribute Summary
Attributes inherited from WsServer
#client_closed, #outbound_flow_token, #ws_established
Attributes inherited from Connection
Instance Method Summary collapse
- #post_init ⇒ Object
- #ssl_handshake_completed ⇒ Object
- #ssl_verify_peer(pem) ⇒ Object
- #unbind(cause = nil) ⇒ Object
Methods inherited from WsServer
#accept_ws_handshake, #check_http_request, #do_on_connection_callback, #http_reject, #parse_http_headers, #post_connection, #process_received_data, #receive_data, #remote_desc, #remote_ip, #remote_ip_type, #remote_port, #send_sip_msg, #transport
Methods inherited from Connection
#close, #initialize, #open?, outbound_listener?, reliable_transport_listener?
Methods included from Logger
close, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str
Constructor Details
This class inherits a constructor from OverSIP::WebSocket::Connection
Instance Method Details
#post_init ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/oversip/websocket/listeners/wss_server.rb', line 8 def post_init @client_pems = [] @client_last_pem = false start_tls({ :verify_peer => true, :cert_chain_file => ::OverSIP.tls_public_cert, :private_key_file => ::OverSIP.tls_private_cert, :use_tls => false # USE SSL instead of TLS. TODO: yes? }) # If the remote client does never send us a TLS certificate # after the TCP connection we would leak by storing more and # more messages in @pending_messages array. @timer_tls_handshake = ::EM::Timer.new(TLS_HANDSHAKE_MAX_TIME) do unless @connected log_system_notice "TLS handshake not performed within #{TLS_HANDSHAKE_MAX_TIME} seconds, closing the connection" close_connection end end end |
#ssl_handshake_completed ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/oversip/websocket/listeners/wss_server.rb', line 45 def ssl_handshake_completed log_system_debug ("TLS connection established from " << remote_desc) if $oversip_debug # @connected in WssServer means "TLS connection" rather than # just "TCP connection". @connected = true @timer_tls_handshake.cancel if @timer_tls_handshake if ::OverSIP::WebSocket.callback_on_client_tls_handshake # Set the state to :waiting_for_on_client_tls_handshake so data received after TLS handshake but before # user callback validation is just stored. @state = :waiting_for_on_client_tls_handshake # Run OverSIP::WebSocketEvents.on_client_tls_handshake. ::Fiber.new do begin log_system_debug "running OverSIP::SipWebSocketEvents.on_client_tls_handshake()..." if $oversip_debug ::OverSIP::WebSocketEvents.on_client_tls_handshake self, @client_pems # If the user of the peer has not closed the connection then continue. unless @local_closed or error? @state = :init # Call process_received_data() to process possible data received in the meanwhile. process_received_data else log_system_debug "connection closed during OverSIP::SipWebSocketEvents.on_client_tls_handshake(), aborting" if $oversip_debug end rescue ::Exception => e log_system_error "error calling OverSIP::WebSocketEvents.on_client_tls_handshake():" log_system_error e close_connection end end.resume end end |
#ssl_verify_peer(pem) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oversip/websocket/listeners/wss_server.rb', line 31 def ssl_verify_peer pem # TODO: Dirty workaround for bug https://github.com/eventmachine/eventmachine/issues/194. return true if @client_last_pem == pem @client_last_pem = pem @client_pems << pem log_system_debug "received certificate num #{@client_pems.size} from client" if $oversip_debug # Validation must be done in ssl_handshake_completed after receiving all the certs, so return true. return true end |
#unbind(cause = nil) ⇒ Object
82 83 84 85 |
# File 'lib/oversip/websocket/listeners/wss_server.rb', line 82 def unbind cause=nil @timer_tls_handshake.cancel if @timer_tls_handshake super end |