Lazarus

Programming => Operating Systems => Android => Topic started by: Mrbeam on September 23, 2019, 10:39:19 am

Title: [SOLVED] LAMW and openssl
Post by: Mrbeam 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.
Title: Re: LAMW and openssl
Post by: svd71 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.
Title: Re: LAMW and openssl
Post by: jmpessoa 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!



Title: Re: LAMW and openssl
Post by: Mrbeam 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;
Title: Re: LAMW and openssl
Post by: svd71 on September 24, 2019, 02:56:35 pm
Download link
Title: Re: LAMW and openssl
Post by: jmpessoa 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!
Title: Re: LAMW and openssl
Post by: Mrbeam 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.
Title: Re: LAMW and openssl
Post by: jmpessoa 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!
Title: Re: LAMW and openssl
Post by: Mrbeam on September 26, 2019, 10:54:36 am
32bit
https://www.dropbox.com/s/8bnotyqug42pghi/OpensslLibs.zip (https://www.dropbox.com/s/8bnotyqug42pghi/OpensslLibs.zip)
Title: Re: LAMW and openssl
Post by: Thaddy on September 26, 2019, 10:59:44 am
Aren't those 32 bit INTEL?
Title: Re: LAMW and openssl
Post by: Josh on September 26, 2019, 05:31:43 pm
followin has .so for 1.1.1
https://github.com/KDAB/android_openssl
Title: Re: LAMW and openssl
Post by: jmpessoa on September 26, 2019, 06:01:22 pm

NEW! jSFTPClient  [LAMW] component!

[based on java/jsch library]

NEW!  demo "AppSFTPClientDemo1"

Thanks to All!
Title: Re: LAMW and openssl
Post by: svd71 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?
Title: Re: LAMW and openssl
Post by: Mrbeam 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!
Title: Re: [SOLVED] LAMW and openssl
Post by: jmpessoa 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!!
Title: Re: LAMW and openssl
Post by: schumi on September 27, 2019, 06:01:51 pm
Solved!

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

Thank you all!
I am interestet too

thanks
Title: Re: [SOLVED] LAMW and openssl
Post by: Mrbeam on September 28, 2019, 10:52:55 am
Demo
https://www.dropbox.com/s/5k5cvfxlgumrb69/AppDemoHttpGet.zip (https://www.dropbox.com/s/5k5cvfxlgumrb69/AppDemoHttpGet.zip)

Already compiled project for arm7, has OpenSSL libs compiled by me.

If you need 64bit or newer versions download OpenSSL libs from @josh link.

EDIT:
There are some problems with the demo.

After http.UserAgent := UserAgent; add line
Code: Pascal  [Select][+][-]
  1. http.Headers.Append('content-type: text/html; charset=UTF-8');

After ShowMessage('Too many redirects!'); add
Code: Pascal  [Select][+][-]
  1. l.Free;
  2. http.Free;

Replace jTextView1.Append(Utf8EscapeControlChars(response)); with
Code: Pascal  [Select][+][-]
  1. jTextView1.Append(response);
TinyPortal © 2005-2018