funbox/smppex

ESME doesn't work with SSL/TLS

Closed this issue · 3 comments

Generate a server key and cert:

openssl genrsa 1024 > host.key
openssl req -new -x509 -nodes -sha1 -days 365 -key host.key -out host.crt

The SMSC starts fine:

{:ok, mc_server} = SMPPEX.MC.start({__MODULE__, %{}}, [
 transport_opts: [
   port:  8443,
   certfile: '/priv/host.crt',
   keyfile: '/priv/host.key'
 ],
 transport: :ranch_ssl
])

But then ESME opens the conenction but it just does nothing:

host = "localhost"
port = 8443
SMPPEX.ESME.start_link(host, port, {__MODULE__, %{}}, [transport: :ranch_ssl])

And the SMSC disconnects the ESME for not starting the session in time:

iex(5)> time=13:56:12.569 level=info       Session #PID<0.740.1>, being stopped by timers(session_init_timer)
time=13:56:12.569 level=error  GenServer #PID<0.740.1> terminating
** (stop) {:timers, :session_init_timer}
Last message: {:check_timers, -576460635659}

From what I can tell, start_link returns fine, but my SMPPEX module's init never gets called.

Update: so init does get called, but nothing else gets called after that. The way we usually bind is to send a message to self in init and then have it bind inside handle_info. But that bind never gets called

  defmodule ESME do
    use SMPPEX.Session
    alias SMPPEX.Pdu

    def start_link(%{host: host, port: port} = opts) do
      IO.puts "Starting ESME #{host}:#{port} as `#{opts[:system_id]}`"
      SMPPEX.ESME.start_link(host, port, {__MODULE__, opts}, [transport: :ranch_ssl])
    end

    def init(_, _, %{system_id: system_id, password: password} = opts) do
      IO.puts "init"
      Process.flag(:trap_exit, true)
      Kernel.send(self(), :bind)
      {:ok, opts}
    end

    def handle_info(:bind, st) do
      IO.puts "binding"
      pdu = Pdu.Factory.bind_transceiver(st.system_id, st.password)
      {:noreply, [pdu], st}
    end
  end

So it seems this problem isn't solved yet :/ Now the connection establishes, ssl handshake happens, bind packet gets sent, and the server sends back a bind response, however ESME never receives the package. Must be a configuration thing, maybe the socket is waiting for more data