Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Able to Compile and Install the themis in windows for Java. #316

Closed
sourabhlodha opened this issue Jul 31, 2018 · 28 comments
Closed

Not Able to Compile and Install the themis in windows for Java. #316

sourabhlodha opened this issue Jul 31, 2018 · 28 comments
Labels
clarification needed O-Linux 🐧 Operating system: Linux O-Windows 🖥️ Operating system: Windows

Comments

@sourabhlodha
Copy link

I have:
Read the documentation and follow the same step but not able to install the themis in windows system for Java Version.

Kindly provide me the solution ASAP

Thanks
Sourabh Lodha

@karenswry
Copy link
Contributor

karenswry commented Jul 31, 2018

Hello, Sourabh!
For us to be able to help you, please fill in the issue template below (you saw it when opening the Issue) with the details about your system and the exact issues you're having.

Thank you
Karen.


Issue template:

I have:

  • searched open and closed issues for duplicates

Issue description

Describe here the issue that you are experiencing.

Environment info

OS: OS name and version

Themis version: 0.0.0

Installation way:

  • downloaded tag from github
  • via package manager
  • built from source

Crypto provider: OpenSSL / BoringSSL / LibreSSL (v0.0.0)

Link to the example project

. . .

@sourabhlodha
Copy link
Author

Hello @karenswry

I have searched from open and closed issues for duplicates.

I am not able to install this on windows10 os.I want to use this library in Java For Encryption and decryption.

Environment info
OS:Windows 10
Themis version :Latest download from github
Installation way
Downloaded tag from github
Crypto Provider:OpenSSL

Link to project:
Used the Example present in repoitory.

@sourabhlodha
Copy link
Author

@karenswry

While I am running the jni code. I am facing the error in Line
System.loadLibrary("themis jni"); //Not Able to find the themis jni.

Can you guide me how to fix this issue? Even While I compile in Ubuntu Xenial.I get the build with this libsoter.so,libthemis.so,libthemis.a.

Regards
Sourabh Lodha

@vixentael
Copy link
Contributor

@sourabhlodha
please provide steps you are doing and exact error messages you have.

This error means that jni was not built

System.loadLibrary("themis jni"); //Not Able to find the themis jni.

Have you done make themis_jni step described in Java and Android Howto?

@sourabhlodha
Copy link
Author

@vixentael
Steps to be followed:-
1.Make Install //It will generate the build

After that I used the jni example to run the code but got the exception
com.cossacklabs.themis.KeypairGenerator.generateKeys(I)[[B

Can you guide me how to run a themis with simple example.

Thanks
Sourabh Lodha

@sourabhlodha
Copy link
Author

@vixentael

I tried with set the path of build files in java but facing same error
no themis_jni in java.library.path

@vixentael
Copy link
Contributor

@sourabhlodha

Can you please check if you call make themis_jni?

Step by step guide for Java and Android described below
https://github.com/cossacklabs/themis/wiki/Java-and-Android-Howto#building-themis-for-java

@sourabhlodha
Copy link
Author

@vixentael

I can use this command and it will create libthemis_jni.so but not able to use in java project.

@karenswry
Copy link
Contributor

You said you were getting the same outcome in Ubuntu Xenial. Could you please describe your steps and errors you're getting in Ubuntu?

@sourabhlodha
Copy link
Author

@karenswry
I install the openSSL and then clone the git repository.After that I run the command make themis_jni and it will build the project and I get the file of libthemis_jni.so,libsorter.a ,libthemis.a and obj.

After that I create a simple java project and copy all files from here
https://github.com/cossacklabs/themis/tree/master/src/wrappers/themis/java/com/cossacklabs/themis

Then create a main class
In Main Method
Keypair pair = KeypairGenerator.generateKeypair();
PrivateKey privateKey = pair.getPrivateKey();
PublicKey publicKey = pair.getPublicKey();
SecureMessage encryptor = new SecureMessage(privateKey, publicKey);
String test="Hello World";
byte[] encryptedMessage = encryptor.wrap(test.getBytes());
System.out.println(encryptedMessage);

Use this code to run.

But Facing error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no themis_jni in java.library.path

I tried by import libthemis_jni.so as jar but it also giving error.

Now I am stuck here.

Can you share steps what should I do after this?

@karenswry
Copy link
Contributor

Try looking more closely into the following piece of the Themis documentation and see the examples. Also - this is how we compile Themis using Circle CI.
We are trying to figure out what could be going wrong in your case and the more details you provide, the easier it will be to help you.
Thank you.
Karen

@sourabhlodha
Copy link
Author

@karenswry
Can you explain this line
System.loadLibrary("themis_jni");

I changed to
System.loadLibrary("libthemis_jni.so");

Now it will show me the error.
Can you tell me what will be exactly themis_jni is the .so file or some folder.

@vixentael
Copy link
Contributor

@sourabhlodha

According to error message you got, I think one step you're missing is to provide a library path for compiled Themis library in your project.

  1. After running make themis_jni you should see libthemis_jni.so in /build folder. This is complied Themis library for Java.
  2. Copy libthemis_jni.so to your project into /lib folder (I prefer lib folder, but it depends on how do you usually link compiled libraries).
  3. Specify path to libthemis_jni library in your project either using -Djava.library.path=<path-to-your-project-folder>/lib or using your IDE (https://www.chilkatsoft.com/java-loadlibrary-windows.asp, https://stackoverflow.com/questions/19308010/how-to-set-the-java-library-path-in-intellij-idea).
  4. Copy all .java files from src/wrappers/themis/java/com/cossacklabs/themis to your project.
  5. import com.cossacklabs.themis.*; in your code.
  6. Use your code
Keypair pair = KeypairGenerator.generateKeypair();
PrivateKey privateKey = pair.getPrivateKey();
PublicKey publicKey = pair.getPublicKey();
SecureMessage encryptor = new SecureMessage(privateKey, publicKey);
String test="Hello World";
byte[] encryptedMessage = encryptor.wrap(test.getBytes());
System.out.println(encryptedMessage);

Tell me if it helped

@sourabhlodha
Copy link
Author

sourabhlodha commented Aug 1, 2018

@vixentael
I am getting this error
/usr/lib/jvm/java-8-openjdk-amd64/bin/java: symbol lookup error: /home/sourabh/libthemis_jni.so: undefined symbol: EVP_PKEY_new

@vixentael
Copy link
Contributor

Which step is causing this error?

@sourabhlodha
Copy link
Author

@vixentael
The error occur in mention below line.
byte[] encryptedMessage = encryptor.wrap(test.getBytes());

@vixentael
Copy link
Contributor

Okay, so basically you were able to compile libthemis_jni.so, put it to the correct folder, run the app, and now you see error.

EVP_PKEY_new is method from OpenSSL library.

The error log bin/java: symbol lookup error means that java can't find and link OpenSSL library while running your project.

Please specify what OpenSSL version do you use and where is it located. This issue might be helpful.

Meanwhile, we have updated example projects for Java and Android.

https://github.com/cossacklabs/themis-java-examples

Examples were built on MacOS, so libthemis_jni is compiled as suffix dylib library, however they illustrate how to link library to the project and how to use it.

You can download java-example, change libthemis_jni.dylib to your libthemis_jni.so and try to compile the project.

@sourabhlodha
Copy link
Author

@vixentael
I tried to configure openssl but still facing same issue
/usr/lib/jvm/java-8-openjdk-amd64/bin/java: symbol lookup error: /home/sourabh/libthemis_jni.so: undefined symbol: EVP_PKEY_new

@sourabhlodha
Copy link
Author

@vixentael
I also tried the given example mention above in your last solution.But it also give me the error
/usr/lib/jvm/java-8-openjdk-amd64/bin/java: symbol lookup error: /home/sourabh/libthemis_jni.so: undefined symbol: EVP_sha256

@karenswry
Copy link
Contributor

@sourabhlodha
It looks like you’re having problems with OpenSSL in your system.
Try running this example - it will help clarify if your OpenSSL and Java environment are configured correctly. Please note that in the example the fragment that deals with encryption is commented out and by default, the example performs decryption. You need to uncomment it first and try encrypting something:
https://www.javatips.net/api/haox-master/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/OpenSSL.java

@sourabhlodha
Copy link
Author

@karenswry
I tried this but still not able to resolve the issue.
If possible can you share me any example for windows10 64bit.

@vixentael
Copy link
Contributor

Hi @sourabhlodha

We prepared a step-by-step instruction how to install and compile Themis and run example project on Ubuntu Xenial.

Most steps are described in Java and Android Howto, however we provide you a necessary explanations for each of them:

1. We installed clean Ubuntu Xenial with java:

shad@cl:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

shad@cl:~$ dpkg -l | grep jdk
ii  default-jdk                    2:1.8-56ubuntu2             amd64  Standard Java or Java compatible Development Kit
ii  default-jdk-headless           2:1.8-56ubuntu2             amd64  Standard Java or Java compatible Development Kit (headless)
ii  openjdk-8-jdk:amd64            8u171-b11-0ubuntu0.16.04.1  amd64  OpenJDK Development Kit (JDK)
ii  openjdk-8-jdk-headless:amd64   8u171-b11-0ubuntu0.16.04.1  amd64  OpenJDK Development Kit (JDK) (headless)
ii  openjdk-8-jre:amd64            8u171-b11-0ubuntu0.16.04.1  amd64  OpenJDK Java runtime, using Hotspot JIT
ii  openjdk-8-jre-headless:amd64   8u171-b11-0ubuntu0.16.04.1  amd64  OpenJDK Java runtime, using Hotspot JIT

2. Download and install JetBrains IDEA as Java IDE

### Download, install and Run Idea
cd ~
# download ideaIC.tar.gz
tar xfz ideaIC*
sudo mv ./idea-IC-* /opt/
cd /opt/idea-IC-*/bin/
./idea.sh

3. Install all dependencies, download and install Themis

### Install themis
sudo apt -y install git build-essential openssl libssl-dev default-jre default-jdk
cd ~
git clone https://github.com/cossacklabs/themis.git
cd themis/
make
make themis_jni
sudo make install

4. Download Themis java example project and change libthemis_jni.dylib to libthemis_jni.so compiled on previous step

### Download and prepare project
cd ~
git clone https://github.com/cossacklabs/themis-java-examples.git
cp /usr/lib/libthemis_jni.so ~/themis-java-examples/java-example/lib/
rm ~/themis-java-examples/java-example/lib/libthemis_jni.dylib

5. Run project in IDEA

  • open Idea
  • open ~/themis-java-examples/java-example folder
  • set SDK
  • build
  • run

6. See successfully compiled up and running Themis java example project:

screen_sharing_picture_august_3 _2018_at_13 36 30_gmt_3


If performing these steps will lead to OpenSSL configuration errors on your system, most likely something is wrong with OpenSSL installation on your system.

@sourabhlodha
Copy link
Author

Hi @vixentael

Can you share the steps in windows also as It doesn't work in Ubuntu so Let me try with Windows10 64 bit OS.

@vixentael
Copy link
Contributor

@sourabhlodha

We provided a full step-by-step guide for compiling and using Themis on Ubuntu Xenial, as you previously asked. Which step is failing on your side?


Themis doesn't have ready-to-use installation command for Windows, you should compile it from sources using GCC.

Basically, you have two options:

Compiling directly on Windows

  1. Install OpenSSL for Windows.
  2. Install GCC for Windows, for example MinGW-w64.
  3. Update makefile to be run for Windows:
    • set SHARED_EXT to dll as library extension
    • update CFLAGS, LDFLAGS with correct paths for your system.
  4. Run make.

Compiling on Ubuntu for Windows x64
(preffered)

  1. Install GCC compiler for producing Windows executables, this posts suggests using mingw-w64, for example:

sudo apt-get install mingw-w64

  1. Run x86_64-w64-mingw32-gcc as your gcc compiler.
  2. Update makefile to generate dll:
    • set SHARED_EXT to dll as library extension
  3. Run make.

If you succeed in compiling themis.dll library for Windows, consider opening a PR with makefile changes, we would be grateful to merge it.

@vixentael
Copy link
Contributor

@sourabhlodha, any updates?

@sourabhlodha
Copy link
Author

@vixentael Not able to run in my project.

@vixentael
Copy link
Contributor

Sorry to hear that.

Themis makefile is targeted to run on Unix/Linux environments, but we do manual building and testing on Windows OS using steps as I described above.

Would you mind sharing particular steps that are failing for you either for Windows or for Ubuntu, so we can help you?

@vixentael vixentael added the O-Linux 🐧 Operating system: Linux label Aug 22, 2018
@vixentael
Copy link
Contributor

Dear @sourabhlodha, it's a pity that both ways to solve a problem didn't work for you.

We will consider this issue closed, but we're happy to answer any questions about our products and libraries if you have them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification needed O-Linux 🐧 Operating system: Linux O-Windows 🖥️ Operating system: Windows
Projects
None yet
Development

No branches or pull requests

3 participants