OpenSSL not getting linked with homebrew on El Capitan 10.11.6

I am trying to code in C on OS X (El Capitan) and need to use OpenSSL. OS ships with version 0.9.8zh 14 Jan 2016.

I used homebrew to upgrade and install openssl (got version 1.0.2h) but am unable to link it correctly to use it. This is what is did:

brew update

brew install openssl

brew link --force openssl

which gave me error saying

Warning: Refusing to link: openssl.

My path references /usr/local/bin as the first one.

Ran this command: ln -s /usr/local/Cellar/openssl/1.0.2j/include/openssl /usr/local/include/openssl

(found this solution here: Openssl with El Capitan among other places)

got no error output, so I assumed this worked. But..

which openssl gives me this output: /usr/local/bin/openssl

openssl version gives me this output: OpenSSL 0.9.8zh 14 Jan 2016

All I'm trying to do is run some CLI commands/ write some C code edited in plain vi editor, compiled using gcc. I am including openssl in header files using

 #include <openssl/sha.h>
#include <openssl/ripemd.h>

Also, the command I am running on CLI which led me to this path was this (if that helps):

openssl dgst -sha256 -sign ec-priv.pem ex-message.txt >ex-signature.der.

Gives me an error:

EVP_SignFinal:wrong public key type.

Googling led me to understand it's cause of an old OpenSSL version which I need to update.

Any ideas on how to proceed here?


Solution 1:

You'll need to make sure you open a new shell after performing the link. (I updated my medium article you linked for future reference: Openssl with El Capitan).

Solution 2:

From Brew refusing to link openssl on Stack Overflow and Issue 3964, .Net GitHub (I think it was first reported with .Net):

I looked into the other option that was suggested for setting the rpath on the library. I think the following is a better solution that will only effect this specific library.

sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib

and/or if you have NETCore 1.0.1 installed perform the same command for 1.0.1 as well:

sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.1/System.Security.Cryptography.Native.dylib

In effect, rather than telling the operating system to always use the homebrew version of SSL and potentially causing something to break, we're telling dotnet how to find the correct library.


which openssl gives me this output: /usr/local/bin/openssl

openssl version gives me this output: OpenSSL 0.9.8zh 14 Jan 2016

Add an rpath to the openssl executable. OpenSSL's build system does not supply an rpath. At runtime, your new executable links to the old libraries.