fwoodruff
How do I get this SSL listener to work?
I appreciate this question is highly similar to another I asked yesterday. However, while the solution there works on MacOS, on Debian I am getting different errors, and a different set of problems.
First I create a new project with mix new tls_question. I have added :crypto and :ssl to mix.exs like so:
def application do
[
extra_applications: [:logger, :crypto, :ssl]
]
end
I have then generated an SSL certificate with
openssl req -nodes -new -x509 -keyout key.pem -out cert.pem
and moved key.pem and cert.pem into the project folder.
I then have the following minimal program
defmodule TlsQuestion do
def main do
:ssl.start()
{:ok, listen_socket} = :ssl.listen(8000,
[ certs_keys: [%{
:keyfile => "key.pem",
:certfile => "cert.pem",
}],
reuseaddr: true,
])
end
end
TlsQuestion.main()
Calling mix run, I get the error:
== Compilation error in file lib/tls_question.ex ==
** (exit) :badarg
(kernel) inet_tcp.erl:142: :inet_tcp.listen/2
(ssl) tls_socket.erl:51: :tls_socket.listen/3
(ssl) ssl.erl:145: :ssl.listen/2
lib/tls_question.ex:4: TlsQuestion.main/0
Most Liked
jjcarstens
Well, you have a few options:
-
Do you need multiple certs with
:certs_keys?- If not, just use the
certfileandkeyfileoption directly which should work with OTP 21
- If not, just use the
-
If yes, do you need Java? That can be disabled. You would also need to install openSSL on the rpi and specify both of these in
KERL_CONFIGURE_OPTIONS.- Internet search would probably serve up several sources that show how to compile for raspberry pi, but the just is you would need
KERL_CONFIGURE_OPTIONS="--without-javac --with-ssl=/path/to/openssl/install" - OTP also has some documentation on compilation, including who to cross compile OTP for raspberry pi on MacOS (you may not have MacOS available, but this would at least be a good starting point to cross-compile)
- The Erlang Forum may be the best place to find info and help for compiling OTP on raspberry pi
- Also note that it will take hours and really peg the CPU of the raspberry pi just due to the design of the processor and intensity of the compilation
- Internet search would probably serve up several sources that show how to compile for raspberry pi, but the just is you would need
-
Are you using the whole raspberry pi OS? Or just to run Erlang/Elixir on it?
- If you only need Erlang/Elixir, then Nerves is also an option. In a nutshell, it is all the tooling to compile a firmware and run the beam+Elixir app directly on devices and Raspberry pi is officially supported. OTP is already precompiled for you as part of the tooling (See HexDocs for more documentation)







