Using the crypto library from erlang succeeds:
````
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.1 (abort with ^G)
1> crypto:strong_rand_bytes(16).
<<11,212,135,144,175,71,19,174,99,107,69,84,207,22,255,221>>
````
Using the same library from elixir fails:
````
08:41:36.251 [error] Unable to load crypto library. Failed with error:
":load, Library load-call unsuccessful."
OpenSSL might not be installed on this system.
08:41:36.251 [warn] The on_load function for module crypto returned {:error, {:load, 'Library load-call unsuccessful.'}}
** (UndefinedFunctionError) function :crypto.supports/0 is undefined (module :crypto is not available)
(crypto) :crypto.supports()
(ssl) tls_v1.erl:262: :tls_v1.signature_algs/2
(ssl) ssl.erl:1041: :ssl.handle_hashsigns_option/2
(ssl) ssl.erl:728: :ssl.handle_options/2
(ssl) ssl.erl:128: :ssl.connect/4
(hackney) src/hackney_connect.erl:246: :hackney_connect.do_connect/5
(hackney) src/hackney_connect.erl:37: :hackney_connect.connect/5
(hackney) src/hackney.erl:328: :hackney.request/5
```
crypto should work form elixir as well.
How are you starting Elixir and Erlang? Elixir does not do anything in particular to crypto, so it is unlikely to be an Elixir bug. :)
Yes, it's strange. Using crypto straight from iex works as well:
iex(2)> :crypto.strong_rand_bytes(16)
<<106, 213, 80, 219, 233, 136, 129, 19, 254, 58, 199, 203, 28, 140, 34, 95>>
I am running it through iex -S mix
The function that yields the error works as well straight from iex:
iex(1)> :crypto.supports()
[hashs: [:sha, :sha224, :sha256, :sha384, :sha512, :md4, :md5, :ripemd160],
ciphers: [:des3_cbc, :des_ede3, :des3_cbf, :des3_cfb, :aes_cbc, :aes_cbc128,
:aes_cfb8, :aes_cfb128, :aes_cbc256, :aes_ctr, :aes_ecb, :aes_ige256,
:des_cbc, :des_cfb, :des_ecb, :blowfish_cbc, :blowfish_cfb64, :blowfish_ofb64,
:blowfish_ecb, :rc2_cbc, :rc4, :aes_gcm],
public_keys: [:rsa, :dss, :dh, :ec_gf2m, :ecdsa, :ecdh, :srp]]
Do you, by any chance, named your library :crypto or are depending on a project called :crypto?
I have the same issue if I call :observer.start from iex and then call a function on :crypto:
iex(1)> :observer.start
:ok
iex(2)> :crypto.supports
09:28:21.558 [error] Unable to load crypto library. Failed with error:
":load, Library load-call unsuccessful."
OpenSSL might not be installed on this system.
09:28:21.567 [warn] The on_load function for module crypto returned {:error, {:load, 'Library load-call unsuccessful.'}}
If I call :crypto first it works:
iex(1)> :crypto.supports
[hashs: [:sha, :sha224, :sha256, :sha384, :sha512, :md4, :md5, :ripemd160],
ciphers: [:des3_cbc, :des_ede3, :des3_cbf, :des3_cfb, :aes_cbc, :aes_cbc128,
:aes_cfb8, :aes_cfb128, :aes_cbc256, :aes_ctr, :aes_ecb, :aes_ige256,
:des_cbc, :des_cfb, :des_ecb, :blowfish_cbc, :blowfish_cfb64, :blowfish_ofb64,
:blowfish_ecb, :rc2_cbc, :rc4, :aes_gcm],
public_keys: [:rsa, :dss, :dh, :ec_gf2m, :ecdsa, :ecdh, :srp]]
iex(2)> :observer.start
:ok
iex(3)> :crypto.supports
[hashs: [:sha, :sha224, :sha256, :sha384, :sha512, :md4, :md5, :ripemd160],
ciphers: [:des3_cbc, :des_ede3, :des3_cbf, :des3_cfb, :aes_cbc, :aes_cbc128,
:aes_cfb8, :aes_cfb128, :aes_cbc256, :aes_ctr, :aes_ecb, :aes_ige256,
:des_cbc, :des_cfb, :des_ecb, :blowfish_cbc, :blowfish_cfb64, :blowfish_ofb64,
:blowfish_ecb, :rc2_cbc, :rc4, :aes_gcm],
public_keys: [:rsa, :dss, :dh, :ec_gf2m, :ecdsa, :ecdh, :srp]]
Looks like it has something to do with the order applications are loaded.
This issue happens with erl as well so it's unlikely to be an Elixir issue.
@josevalim no lib or dep called crypto
@ericmj I agree, it's not really an elixir issue I think. @josevalim feel free to close this.
For the record and to back up @ericmj observations:
Calling :crypto.supports() first works, but breaks if I first :debugger.start and then :crypto.supports()
This leads to the error mentioned before. I am pretty new to elixir/erlang, but maybe this does ring a bell for somebody else.
What are your erlang versions?
I meant to ask @ericmj, we already know @heiko-braun's. :) Also, how have you both installed it?
I've recompiled erlang from source
I can also reproduce it locally on both my Erlang installs. Closing this as an Erlang bug. I will see if someone has already reported it to the OTP team. Thank you!
Thanks @josevalim
I just got the same issue with the observer and :crypto. Seems like it's not fixed yet.
Got this issue when observer started and sending emails using bamboo. Here is the stacktrace:
Erlang v20.0 and Elixir v1.5.1
18:37:00.287 [error] Unable to load crypto library. Failed with error:
":load, Library load-call unsuccessful (815)."
OpenSSL might not be installed on this system.
18:37:00.289 [warn] The on_load function for module crypto returned:
{:error, {:load, 'Library load-call unsuccessful (815).'}}
** (EXIT from #PID<0.1064.0>) evaluator process exited with reason: an exception was raised:
** (UndefinedFunctionError) function :crypto.supports/0 is undefined (module :crypto is not available)
(crypto) :crypto.supports()
(ssl) tls_record.erl:407: :tls_record.supported_protocol_versions/1
(ssl) tls_record.erl:247: :tls_record.supported_protocol_versions/0
(ssl) tls_record.erl:401: :tls_record.highest_protocol_version/0
(ssl) ssl.erl:638: :ssl.available_suites/1
(ssl) ssl.erl:387: :ssl.cipher_suites/1
(hackney) /Users/sivagollapalli/work/elixir/campaign_mailer/deps/hackney/src/hackney_ssl.erl:65: :hackney_ssl.ciphers/0
(hackney) /Users/sivagollapalli/work/elixir/campaign_mailer/deps/hackney/src/hackney_ssl.erl:57: :hackney_ssl.connect/4
iex(2)>
18:37:00.301 [error] GenServer #PID<0.3824.0> terminating
** (UndefinedFunctionError) function :crypto.supports/0 is undefined (module :crypto is not available)
(crypto) :crypto.supports()
(ssl) tls_record.erl:407: :tls_record.supported_protocol_versions/1
(ssl) tls_record.erl:247: :tls_record.supported_protocol_versions/0
(ssl) tls_record.erl:401: :tls_record.highest_protocol_version/0
(ssl) ssl.erl:638: :ssl.available_suites/1
(ssl) ssl.erl:387: :ssl.cipher_suites/1
(hackney) /Users/sivagollapalli/work/elixir/campaign_mailer/deps/hackney/src/hackney_ssl.erl:65: :hackney_ssl.ciphers/0
(hackney) /Users/sivagollapalli/work/elixir/campaign_mailer/deps/hackney/src/hackney_ssl.erl:57: :hackney_ssl.connect/4
Last message: {:"$gen_cast", {:deliver}}
State: %{current_email: "[email protected]"}
18:37:00.301 [error] Unable to load crypto library. Failed with error:
":load, Library load-call unsuccessful (815)."
OpenSSL might not be installed on this system.
I just observed this error today. I hadn't seen it before. I installed both Erlang and Elixir via asdf, long before today. My specific error:
$ mix dialyzer
Compiling 1 file (.ex)
Finding suitable PLTs
Checking PLT...
[:asn1, :certifi, :compiler, :connection, :crontab, :crypto, :db_connection, :decimal, :ecto, :ecto_sql, :elixir, :hackney, :idna, :jason, :kernel, :logger, :metrics, :mimerl, :pane, :postgrex, :public_key, :scribe, :ssl, :ssl_verify_fun, :stdlib, :telemetry, :tzdata, :unicode_util_compat]
10:45:53.045 [error] Unable to load crypto library. Failed with error:
":load_failed, Failed to load NIF library: 'dlopen(/Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so
Reason: image not found'"
OpenSSL might not be installed on this system.
10:45:53.050 [warn] The on_load function for module crypto returned:
{:error, {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib\n Referenced from: /Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so\n Reason: image not found\''}}
** (UndefinedFunctionError) function :crypto.hash/2 is undefined (module :crypto is not available)
(crypto) :crypto.hash(:sha, <<131, 116, 0, 0, 0, 22, 100, 0, 7, 99, 101, 114, 116, 105, 102, 105, 104, 7, 100, 0, 3, 104, 101, 120, 100, 0, 7, 99, 101, 114, 116, 105, 102, 105, 109, 0, 0, 0, 5, 50, 46, 53, 46, 49, 109, 0, 0, 0, 64, 56, ...>>)
lib/mix/tasks/dialyzer.ex:384: Mix.Tasks.Dialyzer.dependency_hash/0
lib/mix/tasks/dialyzer.ex:247: Mix.Tasks.Dialyzer.check_plt/1
lib/mix/tasks/dialyzer.ex:172: Mix.Tasks.Dialyzer.run/1
(mix) lib/mix/task.ex:331: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
What I did do recently – yesterday – was install the Homebrew docutils package. I had to 'overwrite links' for some Python files/libraries – apparently, because of the impending Python 2 EOL, Homebrew is working on removing Python 2 dependencies.
I wonder if OpenSSL – the version I have installed – depends on those Python 2 libraries.
@kenny-evitt you may need to symlink openssl. Some folks had this issue and I looked into it a while back: https://github.com/kerl/kerl/issues/320#issuecomment-535632734. Hopefully this helps.
@pdgonzalez872 Thanks! Any ideas on how exactly I can symlink OpenSSL? Or why this is suddenly an issue?
This issue seems to be related tho it's more than five (5) years old!:
brew link ... doesn't seem like it can help:
$ brew link openssl
Warning: Refusing to link macOS-provided software: [email protected]
If you need to have [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
$ brew link -f openssl
Warning: Refusing to link macOS-provided software: [email protected]
If you need to have [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
You may have different versions of openssl in your system and brew doesn't want to guess for you (that's my guess). This will show you if you have different versions:
$ ls /usr/local/opt/ | grep open
openssl
[email protected]
[email protected]
Questions:
@pdgonzalez872 Elixir Forum post I just created for this:
Data point I hope will be helpful: This happened to me suddenly after installing Python3 via Homebrew. Uninstalling and rebuilding Erlang didn't work. ðŸ˜
@paulstatezny I also faced the similar problem. For me this worked
brew upgrade erlang
Try this if you haven't got it resolved.
I've run into this error when running tests and (for me) it appears to be a race condition whereby the crypto app needs to be started before I can run tests (honestly that's never happened for me before), resolved by adding Application.ensure_all_started(:crypto) in test_helpers.exs
@paulstatezny I also faced the similar problem. For me this worked
brew upgrade erlangTry this if you haven't got it resolved.
This worked for me. Thanks
Most helpful comment
@paulstatezny I also faced the similar problem. For me this worked
brew upgrade erlangTry this if you haven't got it resolved.