Search code examples
opensslnode-gyp

Can node-gyp extension call extension linked OpenSSL instead of node OpenSSL?


Running on linux-wmxt 4.16.8-1-default (Tumbleweed).

I have a library that calls the openssl 1.0 API. I can either dynamically link or statically link. Either produces the same result.

If I run this from a C test harness, it works fine.

The same calls using node via the node-gyp extension produces memory faults which I believe are due to the calls being routed to the node version of the API calls which, I believe, uses openssl 1.1 (not ABI compatible with 1.0).

:
#17 0x12838e1 in ASN1_item_d2i_bio (/home/me/.nvm/versions/node/v10.1.0/bin/node+0x12838e1)
#18 0x7f808108687e in _extractp7certs /home/me/Projects/git/test.sdk.c/c/test/src/testcrypto.c:678
:
SUMMARY: AddressSanitizer: heap-buffer-overflow

Exactly the same code base (statically linked) on MacOS High Sierra works fine with node 9.9.

Before diving into this any further: a simple question. Is there a way to make node-gyp ensure that my code calls my version of OpenSSL rather than Nodes? Or will I have to update my code to openssl 1.1?


Solution

  • I did try various changes to binding.gyp, such as

    {
      "targets": [
        {
          "target_name": "myid",
          "include_dirs": [ "../dep/include" ],
          "sources": [ "./src/myid.c" ],
          "libraries": [
                "/home/me/local/lib64/libcrypto.so",
                "/home/me/local/lib64/libssl.so",
                "/home/me/local/lib64/libcurl.so",
                "/home/me/local/lib64/libxmlsec1.so",
                "../dep/slib/libmylib.so"
            ]
        }
        ]
    }
    

    These 1.0 libraries were build with:

    openssl: ./config --prefix=$HOME/local --openssldir=$HOME/local/openssl

    libcurl: ./configure --prefix=$HOME/local --with-ssl=$HOME/local --disable-ldap

    libxmlsec1: ./configure --prefix=$HOME/local --without-libxslt --with-openssl=$HOME/local

    Same result. So I bit the bullet and upgraded my code to be compatible with OpenSSL 1.1+.

    Now the node binding works.