cossacklabs / themis

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
https://www.cossacklabs.com/themis
Apache License 2.0
1.88k stars 144 forks source link

macOS NodeJS installation problem #237

Closed kevincittadini closed 7 years ago

kevincittadini commented 7 years ago

If I run the command make install in the just cloned Themis repo, i get this error

 make install
-n link 
soter_static                   [WARNINGS]
ar rcs build/libsoter.a build/obj/soter/soter_container.o build/obj/soter/soter_crc32.o build/obj/soter/soter_hmac.o build/obj/soter/soter_kdf.o build/obj/soter/soter_sign.o build/obj/soter/ed25519/fe_0.o build/obj/soter/ed25519/fe_1.o build/obj/soter/ed25519/fe_add.o build/obj/soter/ed25519/fe_cmov.o build/obj/soter/ed25519/fe_copy.o build/obj/soter/ed25519/fe_frombytes.o build/obj/soter/ed25519/fe_invert.o build/obj/soter/ed25519/fe_isnegative.o build/obj/soter/ed25519/fe_isnonzero.o build/obj/soter/ed25519/fe_mul.o build/obj/soter/ed25519/fe_neg.o build/obj/soter/ed25519/fe_pow22523.o build/obj/soter/ed25519/fe_sq.o build/obj/soter/ed25519/fe_sq2.o build/obj/soter/ed25519/fe_sub.o build/obj/soter/ed25519/fe_tobytes.o build/obj/soter/ed25519/ge_add.o build/obj/soter/ed25519/ge_cmp.o build/obj/soter/ed25519/ge_double_scalarmult.o build/obj/soter/ed25519/ge_frombytes.o build/obj/soter/ed25519/ge_frombytes_no_negate.o build/obj/soter/ed25519/ge_madd.o build/obj/soter/ed25519/ge_msub.o build/obj/soter/ed25519/ge_p1p1_to_p2.o build/obj/soter/ed25519/ge_p1p1_to_p3.o build/obj/soter/ed25519/ge_p2_0.o build/obj/soter/ed25519/ge_p2_dbl.o build/obj/soter/ed25519/ge_p2_to_p3.o build/obj/soter/ed25519/ge_p3_0.o build/obj/soter/ed25519/ge_p3_dbl.o build/obj/soter/ed25519/ge_p3_sub.o build/obj/soter/ed25519/ge_p3_to_cached.o build/obj/soter/ed25519/ge_p3_to_p2.o build/obj/soter/ed25519/ge_p3_tobytes.o build/obj/soter/ed25519/ge_precomp_0.o build/obj/soter/ed25519/ge_scalarmult.o build/obj/soter/ed25519/ge_scalarmult_base.o build/obj/soter/ed25519/ge_sub.o build/obj/soter/ed25519/ge_tobytes.o build/obj/soter/ed25519/gen_rand_32.o build/obj/soter/ed25519/keypair.o build/obj/soter/ed25519/open.o build/obj/soter/ed25519/sc_muladd.o build/obj/soter/ed25519/sc_reduce.o build/obj/soter/ed25519/sign.o build/obj/soter/openssl/soter.o build/obj/soter/openssl/soter_asym_cipher.o build/obj/soter/openssl/soter_asym_ka.o build/obj/soter/openssl/soter_ec_key.o build/obj/soter/openssl/soter_ecdsa_common.o build/obj/soter/openssl/soter_hash.o build/obj/soter/openssl/soter_rand.o build/obj/soter/openssl/soter_rsa_common.o build/obj/soter/openssl/soter_rsa_key.o build/obj/soter/openssl/soter_rsa_key_pair_gen.o build/obj/soter/openssl/soter_sign_ecdsa.o build/obj/soter/openssl/soter_sign_rsa.o build/obj/soter/openssl/soter_sym.o build/obj/soter/openssl/soter_verify_ecdsa.o build/obj/soter/openssl/soter_verify_rsa.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: build/libsoter.a(keypair.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: build/libsoter.a(open.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: build/libsoter.a(sign.o) has no symbols
-n link 
themis_static                  [OK]
-n link 
soter_shared                   [ERRORS]
cc -shared -o build/libsoter.dylib build/obj/soter/soter_container.o build/obj/soter/soter_crc32.o build/obj/soter/soter_hmac.o build/obj/soter/soter_kdf.o build/obj/soter/soter_sign.o build/obj/soter/ed25519/fe_0.o build/obj/soter/ed25519/fe_1.o build/obj/soter/ed25519/fe_add.o build/obj/soter/ed25519/fe_cmov.o build/obj/soter/ed25519/fe_copy.o build/obj/soter/ed25519/fe_frombytes.o build/obj/soter/ed25519/fe_invert.o build/obj/soter/ed25519/fe_isnegative.o build/obj/soter/ed25519/fe_isnonzero.o build/obj/soter/ed25519/fe_mul.o build/obj/soter/ed25519/fe_neg.o build/obj/soter/ed25519/fe_pow22523.o build/obj/soter/ed25519/fe_sq.o build/obj/soter/ed25519/fe_sq2.o build/obj/soter/ed25519/fe_sub.o build/obj/soter/ed25519/fe_tobytes.o build/obj/soter/ed25519/ge_add.o build/obj/soter/ed25519/ge_cmp.o build/obj/soter/ed25519/ge_double_scalarmult.o build/obj/soter/ed25519/ge_frombytes.o build/obj/soter/ed25519/ge_frombytes_no_negate.o build/obj/soter/ed25519/ge_madd.o build/obj/soter/ed25519/ge_msub.o build/obj/soter/ed25519/ge_p1p1_to_p2.o build/obj/soter/ed25519/ge_p1p1_to_p3.o build/obj/soter/ed25519/ge_p2_0.o build/obj/soter/ed25519/ge_p2_dbl.o build/obj/soter/ed25519/ge_p2_to_p3.o build/obj/soter/ed25519/ge_p3_0.o build/obj/soter/ed25519/ge_p3_dbl.o build/obj/soter/ed25519/ge_p3_sub.o build/obj/soter/ed25519/ge_p3_to_cached.o build/obj/soter/ed25519/ge_p3_to_p2.o build/obj/soter/ed25519/ge_p3_tobytes.o build/obj/soter/ed25519/ge_precomp_0.o build/obj/soter/ed25519/ge_scalarmult.o build/obj/soter/ed25519/ge_scalarmult_base.o build/obj/soter/ed25519/ge_sub.o build/obj/soter/ed25519/ge_tobytes.o build/obj/soter/ed25519/gen_rand_32.o build/obj/soter/ed25519/keypair.o build/obj/soter/ed25519/open.o build/obj/soter/ed25519/sc_muladd.o build/obj/soter/ed25519/sc_reduce.o build/obj/soter/ed25519/sign.o build/obj/soter/openssl/soter.o build/obj/soter/openssl/soter_asym_cipher.o build/obj/soter/openssl/soter_asym_ka.o build/obj/soter/openssl/soter_ec_key.o build/obj/soter/openssl/soter_ecdsa_common.o build/obj/soter/openssl/soter_hash.o build/obj/soter/openssl/soter_rand.o build/obj/soter/openssl/soter_rsa_common.o build/obj/soter/openssl/soter_rsa_key.o build/obj/soter/openssl/soter_rsa_key_pair_gen.o build/obj/soter/openssl/soter_sign_ecdsa.o build/obj/soter/openssl/soter_sign_rsa.o build/obj/soter/openssl/soter_sym.o build/obj/soter/openssl/soter_verify_ecdsa.o build/obj/soter/openssl/soter_verify_rsa.o -L/usr/local/lib -L/usr/lib -lcrypto 
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [soter_shared] Error 1

If then I try to install jsthemis this is the error given

> jsthemis@0.9.5 preinstall /path/to/node_modules/jsthemis
> node-gyp configure && node-gyp build

  CXX(target) Release/obj.target/jsthemis/addon.o
In file included from ../addon.cpp:20:
../secure_session.hpp:22:10: fatal error: 'themis/themis.h' file not found
#include <themis/themis.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/jsthemis/addon.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build"
gyp ERR! cwd /path/to/node_modules/jsthemis
gyp ERR! node -v v8.6.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm WARN lottie-react-native@1.1.1 requires a peer of react@>=15.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-branch@2.0.0-beta.3 requires a peer of react@>=15.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-gesture-handler@1.0.0-alpha.23 requires a peer of react@> 15.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! jsthemis@0.9.5 preinstall: `node-gyp configure && node-gyp build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the jsthemis@0.9.5 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2017-10-03T14_13_55_058Z-debug.log

I've OpenSSL and LibreSSL installed via Homebrew. I've tried to solve all brew doctor notices.

I'm on macOS Sierra 10.12.6

I also do believe that some needed libraries are under /usr/lib whilst perhaps they should be under /usr/local/lib ? There's a missing /usr/include folder as well.

vixentael commented 7 years ago

I think it means that make script cannot find OpenSSL.

  1. Please, run
    $ brew --prefix openssl

You should see smth like /usr/local/opt/openssl

  1. Also please run
    $ which openssl

to make sure that MacOS knows the path to openssl.

  1. You can configure Make script with path to openssl directly, like this:
make install CRYPTO_ENGINE_PATH=openssl CRYPTO_ENGINE_INCLUDE_PATH=<path_to_openssl>/openssl/include CRYPTO_ENGINE_LIB_PATH=<path_to_openssl>/openssl/lib

These params define to use openssl directly. On my Mac command looks like this:

make install CRYPTO_ENGINE_PATH=openssl CRYPTO_ENGINE_INCLUDE_PATH=/usr/local/opt/openssl/include CRYPTO_ENGINE_LIB_PATH=/usr/local/opt/openssl/lib

but it might be different in your case

kevincittadini commented 7 years ago

Yes, running the last command successfully installs Themis via Make. Thanks a lot.

This said, the problem with npm install remains. Different error though.

1 warning generated.
  SOLINK_MODULE(target) Release/jsthemis.node
clang: error: no such file or directory: '/usr/lib/libthemis.a'
clang: error: no such file or directory: '/usr/lib/libsoter.a'
make: *** [Release/jsthemis.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 16.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build"
gyp ERR! cwd /path/to/node_modules/jsthemis
gyp ERR! node -v v8.6.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm WARN lottie-react-native@1.1.1 requires a peer of react@>=15.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-branch@2.0.0-beta.3 requires a peer of react@>=15.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN react-native-gesture-handler@1.0.0-alpha.23 requires a peer of react@> 15.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! jsthemis@0.9.5 preinstall: `node-gyp configure && node-gyp build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the jsthemis@0.9.5 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
vixentael commented 7 years ago

It's our fault, we strictly use /usr/lib/ path instead of /usr/local/lib preferred on MacOS.

We've pushed super-small fix #238, however, it takes time to re-build and re-distribute the lib.

@kevincittadini can you please check changes locally?

  1. Please clone latest repo (master branch, including last pull request).
  2. Open src/wrappers/themis/jsthemis/ folder
  3. Run
    $ node-gyp configure && node-gyp build

3.5 Install nan if it's not found (npm install nan)

  1. Building result should be success

Please let me know if it helped, we will update npm package then.

Thank you!

kevincittadini commented 7 years ago

Success. No errors given. Everything seems nice and ok. So, will I have to wait till the package is updated right?

Thank you so much for your fast reply and solutions.

vixentael commented 7 years ago

Consider this as quick hack :) You can use this workaround as quick solution, we will update package next days. I'll let you know right after we publish update :)

kevincittadini commented 7 years ago

So, I've copied the full directory jsthemis (after the $ node-gyp configure && node-gyp build) inside the node_modules directory of my project. Is this the right way?

This is my code var themis = require('themis');

Node throws this error:

Unable to resolve module 'jsthemis'

I'm surely missing something :)

Lagovas commented 7 years ago

var themis = require('jsthemis'); is correct and now you can try just npm install jsthemis inside your project directory (we published fixed jsthemis package to npmjs registry)

kevincittadini commented 7 years ago

After running npm install jsthemis, the console is looping on this

jsthemis@0.9.6-1 preinstall /path/to/node_modules/jsthemis
npm install && node-gyp configure && node-gyp build

This 2 lines keeps echoing

Lagovas commented 7 years ago

yeah, my fault, sorry until we fix that, you can try your previous steps (with manual building with node-gyp) and import jsthemis package instead themis: var themis = require('jsthemis');

kevincittadini commented 7 years ago

This is my folder structure now under /path/to/node_modules/jsthemis/ I'm using ReactNative now, and in my .js file, when I import the package with: var themis = require('jsthemis');

The system goes Unable to resolve module 'jsthemis' from File.js: Module does not exist in the module map or in these directories: /path/to/node_modules Before you ask: Yes, I tried to rebuild everything and clear various caches. Still got "unable to resolve module 'jsthemis'".

Lagovas commented 7 years ago

please try now npm install jsthemis or pull new changes from our repository (git pull) and install to your project with npm install /absolute/path/themis/src/wrappers/themis/jsthemis from sources

kevincittadini commented 7 years ago

Ok, no installation problems. Thank you for that.

Still Unable to resolve module 'jsthemis' from File.js: Module does not exist in the module map or in these directories: /path/to/node_modules error remains.

Lagovas commented 7 years ago

as I understand now you have next structure:

project_folder:
 - node_modules
 - - module1
 - - module2
 - - jsthemis
 - some.js
 - some2.js
  1. do you have jsthemis in node_modules?
  2. can you run node -e "require('jsthemis');" inside ? Is it prints any errors or nothing?
kevincittadini commented 7 years ago

No errors running that on console. No output at all in fact. I'm using ReactNative. Also tried to wipe all caches.

Lagovas commented 7 years ago

if no errors and empty output then nodejs can find jsthemis correctly and the problem somewhere else (https://github.com/facebook/react-native/issues/14209 maybe this will help)

kevincittadini commented 7 years ago

I can confirm that jsthemis works fine now as of version 0.9.6-3. Of course outside of ReactNative. I tried it in a classic index.js file and works fine.

Thanks a lot for your support and your fast replies.

vixentael commented 7 years ago

Thank you @kevincittadini for reaching out :) You helped to make Themis better :)