#1 2018-04-15 10:49:10

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

What's the correct way to connect a https-enabled mORMot rest server?

Situation
===
I compiled the '04 - HTTP Client-Server' official mORMot sample and have successfully deployed it on a Windows 2016 server behind IIS 10, the server has both http/80 and https/443 ports open, and both are redirected to the background mORMot rest server using the IIS URL Rewrite module.

The IIS-as-the-reverse-proxy part is already working, because I was able to connect to the remote mORMot server using:

TSQLHttpClient.Create('server.mysite.com','80', Form1.Model);

The https part is also working, because open 'https://server.mysite.com/root' with a web browser I can get the correct result from Project04Server.exe, which is:

{
"errorCode": 403,
"errorText": "Authentication Failed: Invalid signature (0)"
}

The problem
===
The problem is that Project04Client.exe cannot connect to the remote Project04Server.exe, I have tried all the following forms but failed with various errors:

  Form1.Database := TSQLHttpClient.Create('server.mysite.com','80', Form1.Model);  // ok, but not https

  Form1.Database := TSQLHttpClient.Create('server.mysite.com','443',Form1.Model); // failed, ServerTimestampSynchronize will fail
  Form1.Database := TSQLHttpClient.Create('https://server.mysite.com','443',Form1.Model); // failed, ServerTimestampSynchronize will fail
  Form1.Database := TSQLHttpClient.Create('https://server.mysite.com','80',Form1.Model); // failed, ServerTimestampSynchronize will fail


  Form1.Database := TSQLHttpsClient.Create('https://server.mysite.com', Form1.Model, 443);  // failed, ServerTimestampSynchronize will fail
  Form1.Database := TSQLHttpClientWinINet.Create('https://server.mysite.com', Form1.Model, 443);  // failed, ServerTimestampSynchronize will fail

  myUri.From('https://server.mysite.com');
  Form1.Database := NewSQLHttpClient(myUri, Form1.Model, False); // Access Violation

  Form1.Database := TSQLHttpClientRequest(TSQLHttpsClient).Create('server.mysite.com', '443',
    Form1.Model, True); // Access Violation

What is the correct way to connect a https-enabled mORMot rest server?
Thanks!

Last edited by edwinsn (2018-04-15 11:10:38)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2018-04-15 11:00:11

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: What's the correct way to connect a https-enabled mORMot rest server?

OK, right after posting the question, I found the answer:

  Form1.Database := TSQLHttpClientWinHTTP.Create('server.mysite.com','443', Form1.Model, True);  // ok! it's httpS!

Hope it helps for somebody else wink

But I guess the global NewSQLHttpClient function still has the Access Violation issue.

Last edited by edwinsn (2018-04-15 11:05:57)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2018-04-16 08:19:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

The access violation problem comes very probably from your misuse of model.

Offline

#4 2019-03-21 14:46:14

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

edwinsn wrote:

But I guess the global NewSQLHttpClient function still has the Access Violation issue.

I think you are right. I guess I found a mistype in NewSQLHttpClient function. There we have:

result := TSQLHttpClientRequest(TSQLHttpsClient).Create(aURI.Server, aURI.Port, aModel,
      aURI.Https, AnsiString(aProxyName), AnsiString(aProxyByPass));

I suppose, that there is some tiny mess with the brackets wink

The correct code should be:

result := TSQLHttpClientRequest(TSQLHttpsClient.Create(aURI.Server, aURI.Port, aModel,
      aURI.Https, AnsiString(aProxyName), AnsiString(aProxyByPass)));

upd: I've created a pull request for that

Last edited by Vitaly (2019-03-21 15:37:15)

Offline

#5 2019-03-21 15:36:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

I don't think so.

We test for  TSQLHttpsClient.InheritsFrom(TSQLHttpClientRequest) before it, and use the correct meta-class constructor if it supports it.

For instance, on Android, TSQLHttpsClient = TSQLHttpClientWinSock and your modification won't compile.

Offline

#6 2019-03-21 15:47:02

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

Well, maybe you are right - I'm not so experienced in such constructions.

But, anyway, in Delphi VCL the function works fine with the suggested code, and the original function fails with AV in inherited TSQLRest.Create(aModel: TSQLModel) constructor

I'm not insisting on updating your code wink I've already created the copy of function and using it in my project - just worried about others, who can face the same problem

Last edited by Vitaly (2019-03-21 15:57:18)

Offline

#7 2019-03-21 16:17:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,671
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

After more investigation, there was in fact a problem, mainly due to the non uniformity of the class constructors: TSQLHttpClientRequest did have another set of parameters.

So I get rid of the NewSQLHttpClient() function, and a simple constructor is to be used instead, for any kind of class.
See https://synopse.info/fossil/info/5008dfb3fc

You can now directly use TSQLHttpsClient.Create() on all platforms.

Offline

#8 2019-03-21 17:20:35

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: What's the correct way to connect a https-enabled mORMot rest server?

Yep, that's working good, and constructor using looks even better than NewSQLHttpClient using smile Thanks!

Offline

Board footer

Powered by FluxBB