Recent

Author Topic: [SOLVED] LAMW and openssl  (Read 842 times)

Mrbeam

  • New member
  • *
  • Posts: 6
[SOLVED] LAMW and openssl
« on: September 23, 2019, 10:39:19 am »
I'm trying to port a working desktop app that needs openssll support to android.

I'm using fphttpclient but when I try to access eg. https://www.google.com I get error

"Cannot create a X509 certificate without SLL support"

I've added libcrypto.so and libssl.so to libs folder next to libcontrols.so (libcrypto.so and libssl.so tested and working with qt for android) but I get same error message.
« Last Edit: September 27, 2019, 10:18:15 am by Mrbeam »

svd71

  • New Member
  • *
  • Posts: 12
Re: LAMW and openssl
« Reply #1 on: September 23, 2019, 11:07:20 am »
Under Android Strudio did I with the import of two libraries: jgss.jar and jsch(http://www.jcraft.com/jsch/). It work fine. You need to do the only couple of wrapper classes from jsch.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1455
Re: LAMW and openssl
« Reply #2 on: September 23, 2019, 11:28:46 pm »


Hi, svd71!

Can you put in some online drive a simple "Android Studio" [project] example?

I can try implement a LAMW component wrapper.....

Thank you!



Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mrbeam

  • New member
  • *
  • Posts: 6
Re: LAMW and openssl
« Reply #3 on: September 24, 2019, 01:01:49 pm »
I did more tests and the problem is not ssl library, it's not working with "http" either. App cannot create socket handler even though is has internet access permission.

If you want to try just create a new LAMW Gui project, drop a button and:

procedure TAndroidModule1.HttpClientGetSocketHandler(Sender: TObject;
    const UseSSL: Boolean; out AHandler: TSocketHandler);
begin
  If UseSSL then begin
    AHandler:=TSSLSocketHandler.Create;
    TSSLSocketHandler(AHandler).SSLType:=stTLSv1_2;
  end else
    AHandler:=TSocketHandler.Create;
end;

procedure TAndroidModule1.jButton1Click(Sender: TObject);
var s:string;
    http: TFPHttpClient;
begin
    if (InitSSLInterface) then
        ShowMessage('SSL libs ok!')
    else
        ShowMessage('No SSL libs!');
    http:=TFPHttpClient.Create(nil);
    http.OnGetSocketHandler := @HttpClientGetSocketHandler;
    http.AllowRedirect:=True;
    http.AddHeader('User-Agent','Mozilla');
    try
        s:=http.Get('https://www.google.com');
    except
        on E: Exception do
            ShowMessage(E.Message);
    end;
end;

svd71

  • New Member
  • *
  • Posts: 12
Re: LAMW and openssl
« Reply #4 on: September 24, 2019, 02:56:35 pm »
Download link
« Last Edit: September 26, 2019, 06:49:49 pm by svd71 »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1455
Re: LAMW and openssl
« Reply #5 on: September 24, 2019, 06:38:00 pm »
@Mrbeam
Quote
http.OnGetSocketHandler := @HttpClientGetSocketHandler;

In "mode delphi" change to:
Code: Pascal  [Select]
  1. http.OnGetSocketHandler := HttpClientGetSocketHandler;
  2.  

What you need? A ftp client? a http client? etc...?


@svd71

I will try your code!

[curiosity: you can try LAMW "jcMikrotikRouterOS" component,
demo "AppJCenterMikrotikRouterOSDemo1"]

Thank you!
« Last Edit: September 24, 2019, 07:06:40 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mrbeam

  • New member
  • *
  • Posts: 6
Re: LAMW and openssl
« Reply #6 on: September 25, 2019, 09:33:28 am »
Thank you!

I need http(s) only.

My original project was in QT c++, with qt widgets on desktop and qml on android for gui, but both versions were sharing the same logic code in c++.

Now I ported desktop version to fpc Lazarus and I need cross platform http requests and multithreading.

Multithreading tested and working cross platform but I can't make http client to work. I only need LAMW for gui and keep all logic in native fpc, project is big and I can't keep it updated on all platforms if they don't share the same logic code.

I'm on Ubuntu 18.04, I don't have Android Studio installed, and I have 0 experience with java.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1455
Re: LAMW and openssl
« Reply #7 on: September 25, 2019, 05:10:54 pm »
Quote
I've added libcrypto.so and libssl.so to libs folder next to libcontrols.so (libcrypto.so and libssl.so tested and working with qt for android) but I get same error message.

Do you have "libcrypto.so" and "libssl.so"  compiled for "arm-android" [32 bits] and "aarch64-android"?

If yes, please, put its in some open/online drive... I will try some tests....

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mrbeam

  • New member
  • *
  • Posts: 6
Re: LAMW and openssl
« Reply #8 on: September 26, 2019, 10:54:36 am »

Thaddy

  • Hero Member
  • *****
  • Posts: 8939
Re: LAMW and openssl
« Reply #9 on: September 26, 2019, 10:59:44 am »
Aren't those 32 bit INTEL?
Most people that want to use threading should learn to patch their jeans first: use a needle.

josh

  • Hero Member
  • *****
  • Posts: 754
Re: LAMW and openssl
« Reply #10 on: September 26, 2019, 05:31:43 pm »
followin has .so for 1.1.1
https://github.com/KDAB/android_openssl
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1455
Re: LAMW and openssl
« Reply #11 on: September 26, 2019, 06:01:22 pm »

NEW! jSFTPClient  [LAMW] component!

[based on java/jsch library]

NEW!  demo "AppSFTPClientDemo1"

Thanks to All!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

svd71

  • New Member
  • *
  • Posts: 12
Re: LAMW and openssl
« Reply #12 on: September 26, 2019, 06:17:33 pm »
thank. But I think, that SFTP isn't a target. SSH.Execute() is better as some thnig other.

PS: A brange from hier:
 
   https://github.com/jmpessoa/lazandroidmodulewizard

and
  oficial update from Lazarus (over menu Package->Online Package Manager) have many diffrent methods which skipped on github.

It is ok?
« Last Edit: September 26, 2019, 07:10:02 pm by svd71 »

Mrbeam

  • New member
  • *
  • Posts: 6
Re: LAMW and openssl
« Reply #13 on: September 27, 2019, 10:17:56 am »
Solved!

I tried THTTPSend from synapse and everything working on both desktop and mobile without any changes.

Thank you all!

jmpessoa

  • Hero Member
  • *****
  • Posts: 1455
Re: [SOLVED] LAMW and openssl
« Reply #14 on: September 27, 2019, 04:56:39 pm »

Quote
I tried THTTPSend from synapse and everything working on both desktop and mobile without any changes.

Great!!

Please,  put a simple LAMW example in some open/online drive...

So,  I will commit it to the LAMW github!

Thank you!!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard