Jump to content

Alberto Paganini

Members
  • Content Count

    37
  • Joined

  • Last visited

Community Reputation

3 Neutral

About Alberto Paganini

Technical Information

  • Delphi-Version
    Delphi XE2

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Alberto Paganini

    tlsv1 alert protocol version

    Ok, I have found out the final issues. It turned out that Windows 7 does not enable TLS 1.2 by default. You have to do it manually by following this process https://support.site24x7.com/portal/en/kb/articles/how-to-check-if-tls-1-2-is-enabled At this stage, the function above started working. Next, I had to add one extra line in a third party code every time TIdSSLIOHandlerSocketOpenSSL is created. The extra line is sslIOHandler.SSLOptions.SSLVersions := [sslvTLSv1_2]; After that, the application started working as before. @Remy LebeauThank you for your help Alberto
  2. Alberto Paganini

    tlsv1 alert protocol version

    It seems I am making progress with this. I have amended the class in a way the application loads the .DLLs residing in the application folder. This is achieved with IdSSLOpenSSLHeaders.IdOpenSSLSetLibPath(). (Thanks to Remi for this post https://stackoverflow.com/questions/13269169/how-to-use-a-dll-outside-of-the-system-path) IdSSLOpenSSL.OpenSSLVersion; confirms now "OpenSSL 1.0.2q 20 Nov 2018" is loaded and this collides with the .DLLs version in the application folder. As far as I can see from the https://www.openssl.org/news/openssl-1.0.2-notes.html the OpenSSL 1.0.2 supports TLS 1.2 for a long time (Jan 2015). Despite that my application still throws "tlsv1 alert protocol version" Is there anything else I should be aware of ? The amended source code is here above if anybody may be interested. Many thanks Alberto function TConnectionClass.GetToken: Boolean; var LJSONObject: TJSONObject; LJSONValue: TJSONValue; {$IFDEF VER230} LJSONPair: TJSONPair; {$ENDIF} LJSONToken: TJSONValue; IdHTTP: TIdHTTP; IdSSL: TIdSSLIOHandlerSocketOpenSSL; IdLogFile: TIdLogFile; sList: TStringList; Path:string; OpenSSLVersion:string; begin begin Result := False; FToken := ''; Path:=ExtractFilePath(ParamStr(0)); IdSSLOpenSSLHeaders.IdOpenSSLSetLibPath(Path); OpenSSLVersion:= IdSSLOpenSSL.OpenSSLVersion; IdHTTP := TIdHTTP.Create(nil); try IdHTTP.HTTPOptions := IdHTTP.HTTPOptions + [hoForceEncodeParams]; IdHTTP.HandleRedirects := True; IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP); IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; IdHTTP.IOHandler := IdSSL; IdLogFile := TIdLogFile.Create(IdHTTP); IdLogFile.Filename := 'c:\' + ChangeFileExt(ExtractFileName(ParamStr(0)), '.log'); IdLogFile.Active := True; IdHTTP.Intercept := IdLogFile; IdHTTP.Request.Accept := 'application/json'; IdHTTP.Request.CustomHeaders.Values['X-Application'] := cBetfair_AppKey; IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded'; sList := TStringList.Create; try sList.Add('username=' + FUserID); sList.Add('password=' + FPassword); LJSONValue := TJSONObject.ParseJSONValue(IdHTTP.Post(URL_LOGIN, sList)); try if LJSONValue is TJSONObject then begin LJSONObject := TJSONObject(LJSONValue); {$IFDEF VER230} LJSONPair := LJSONObject.Get('token'); if LJSONPair <> nil then LJSONToken := LJSONPair.JsonValue else LJSONToken := nil; {$ELSE} LJSONToken := LJSONObject.Values['token']; {$ENDIF} if LJSONToken <> nil then FToken := LJSONToken.Value; end; finally LJSONValue.Free; end; finally sList.Free; end; finally IdHTTP.Free; end; Result := (FToken <> ''); end;
  3. Alberto Paganini

    tlsv1 alert protocol version

    @Remy Lebeau Yes, this is the issue. I have just found out from the provider that "From 1st December only TLS 1.2 and above will be supported". I renamed libeay32.dll and ssleay32.dll in the system32 folder, downloaded the two .DLLs from Github, placed them in the application folder but the error is still the same. The version I have reported is the one found in the properties of the .DLL files. However, the OpenSSLVersion function reports OpenSSL 1.0.0d 8 Feb 2011, and that explains why the .exe is not working any longer. Does it mean my application uses other SSL .DLLs on my hard disk? (yes, I have a few installed by other third-party software. Each of them resides in the relevant application folder) How can I tell my application that the correct .DLL resides in the same folder of the application itself? I don't want to delete the other .DLLs in order not to stop the other applications to work. Many thanks. Alberto
  4. Alberto Paganini

    tlsv1 alert protocol version

    Hello, I have a problem with a Win32 application using Indy. All of a sudden it throws me the following error message: "Error connecting with SSL. error 1409442E:SSL routine:ssl3_read_bytes:tlsv1 alert protocol version" In the beginning, I supposed it had something to do with an obsolete version I manage in my source. The following is the only place in my source where I set the SSL version and it supports the version 1.2 function TConnectionClass.GetToken: Boolean; var LJSONObject: TJSONObject; LJSONValue: TJSONValue; {$IFDEF VER230} LJSONPair: TJSONPair; {$ENDIF} LJSONToken: TJSONValue; IdHTTP: TIdHTTP; IdSSL: TIdSSLIOHandlerSocketOpenSSL; IdLogFile: TIdLogFile; sList: TStringList; begin Result := False; FToken := ''; IdHTTP := TIdHTTP.Create(nil); try IdHTTP.HTTPOptions := IdHTTP.HTTPOptions + [hoForceEncodeParams]; IdHTTP.HandleRedirects := True; IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP); IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; IdHTTP.IOHandler := IdSSL; IdLogFile := TIdLogFile.Create(IdHTTP); IdLogFile.Filename := 'c:\' + ChangeFileExt(ExtractFileName(ParamStr(0)), '.log'); IdLogFile.Active := True; IdHTTP.Intercept := IdLogFile; IdHTTP.Request.Accept := 'application/json'; IdHTTP.Request.CustomHeaders.Values['X-Application'] := cBetfair_AppKey; IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded'; sList := TStringList.Create; try sList.Add('username=' + FUserID); sList.Add('password=' + FPassword); LJSONValue := TJSONObject.ParseJSONValue(IdHTTP.Post(URL_LOGIN, sList)); try if LJSONValue is TJSONObject then begin LJSONObject := TJSONObject(LJSONValue); {$IFDEF VER230} LJSONPair := LJSONObject.Get('token'); if LJSONPair <> nil then LJSONToken := LJSONPair.JsonValue else LJSONToken := nil; {$ELSE} LJSONToken := LJSONObject.Values['token']; {$ENDIF} if LJSONToken <> nil then FToken := LJSONToken.Value; end; finally LJSONValue.Free; end; finally sList.Free; end; finally IdHTTP.Free; end; Result := (FToken <> ''); end; I also tried to amend the options into IdSSL.SSLOptions.SSLVersions := [sslvTLSv1_2]; but the error is still the same Then I updated the SSL .dll files in my system32 folder by downloading the latest version of libeay32.dll and ssleay32.dll from here https://indy.fulgan.com/SSL/ and replace the old files with the new ones. I have double-checked and now the .dll have Version file 1.0.2.21 and Version 1.0.2u Despite these attempts, the application still throws me the same exception. Is there anything else I should change? Many thanks Alberto
  5. Alberto Paganini

    Delete FastMM4 MemoryManager_EventLog.txt

    Thank you David, this did the trick !
  6. Alberto Paganini

    Delete FastMM4 MemoryManager_EventLog.txt

    I did and created this test: program Project3; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, system.Classes, System.SysUtils; var t:tstringlist; begin t:=TStringList.Create; end. I ran it a number of times and the new reports are appended to the old ones. Obviously there must be something wrong in my FastMM4 settings. I will look into that.
  7. I use FastMM4 to check memory leaks and I noticed the report file " MyApplicatoin+MemoryManager_EventLog.txt" is not deleted automatically once I have amended the source and I run my application again. This way if there are still memory leaks they are added to the existing report and this confuses me. Is there an option in FastMM4 to achieve that I am not aware of or do I have to rely on DeleteFile(...) when I run the application ? Many thanks Alberto
  8. Alberto Paganini

    Varialbe set to nil

    @Stefan Glienke I have amended the example according to your advice. program Project3; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, system.Classes, System.SysUtils, Spring; type MyInterface2 = interface ['{8E7BC71F-55EE-4345-8A5B-42C433BE9EBA}'] procedure print; end; MyInterface1 = interface ['{607A66A6-D68C-4980-9FB1-83B325EE9A91}'] procedure SetInterface2(const aInterface: MyInterface2); procedure DoSomethingWithInterface2; end; TMyClass1 = class(TInterfacedObject, MyInterface1) private //RefToInterFace2: Pointer{MyInterface2}; RefToInterFace2: Weak<MyInterface2>; public procedure SetInterface2(const aInterface: MyInterface2); procedure DoSomethingWithInterface2; end; TMyClass2 = class(TInterfacedObject, MyInterface2) private // Ref: MyInterface1; ref: Weak<MyInterface1>; public constructor Create(int: MyInterface1); reintroduce; destructor Destroy; override; // this can be deleted procedure print; end; { TMyClass1 } procedure TMyClass2.print; begin Writeln('TMyClass2.print'); Sleep(1500); end; { TMyClass2 } procedure TMyClass1.DoSomethingWithInterface2; begin if RefToInterFace2 <> nil then begin // MyInterface2(RefToInterFace2).print; RefToInterFace2.Target.print; end; end; procedure TMyClass1.SetInterface2(const aInterface: MyInterface2); begin // RefToInterFace2 := Pointer(aInterface); RefToInterFace2.Target := aInterface; end; constructor TMyClass2.Create(int: MyInterface1); begin inherited Create; if int <> nil then begin Ref.Create(int); Ref.Target.SetInterface2(Self); end; end; destructor TMyClass2.Destroy; begin // if Ref <> nil then // MyInterface1(Ref).SetInterface2(nil); inherited Destroy; end; var aMyClass1: MyInterface1; aMyClass2: MyInterface2; begin aMyClass1 := TMyClass1.Create; aMyClass2 := TMyClass2.Create(aMyClass1); aMyClass1.DoSomethingWithInterface2; end. Is that acceptable? In which case the pointer approach proposed by Remi may cause AV errors? Many thanks Alberto
  9. Alberto Paganini

    Varialbe set to nil

    Hi Remi, I had to amend your code with the following one in order to make the example compile by DX2 procedure TMyClass1.SetInterface2(const aInterface: MyInterface2); begin RefToInterFace2 := Pointer(aInterface); end; The rest is all spot on! I suppose that the advantage to use the second solution is you can call any method of MyInterface1 throughout TMyClass2 by using Ref while in the first one you can do it only in TMyClass2.Create as MyInterface1 is not stored in a variable. Thank you very much for taking the time. Alberto
  10. Alberto Paganini

    Varialbe set to nil

    But If I store the interface in a local variable in TMyClass2, Ref in my example, I have a leak instead. It seems the RTL cannot have access to it. The only way to release the variable is to use a method and call this method from the main begin..end. Here below the minimum example. program Project3; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, system.Classes, System.SysUtils; type MyInterface2 = interface ['{8E7BC71F-55EE-4345-8A5B-42C433BE9EBA}'] procedure print; end; MyInterface1 = interface ['{607A66A6-D68C-4980-9FB1-83B325EE9A91}'] procedure SetInterface2(aInterface: MyInterface2); procedure DoSomethingWithInterface2; end; TMyClass1 = class(TInterfacedObject, MyInterface1) private RefToInterFace2: MyInterface2; public procedure SetInterface2(aInterface: MyInterface2); procedure DoSomethingWithInterface2; destructor Destroy;override; end; TMyClass2 = class(TInterfacedObject, MyInterface2) private Ref: MyInterface1; public constructor Create(int: MyInterface1); reintroduce; procedure print; end; { TMyClass1 } procedure TMyClass2.print; begin Writeln('TMyClass2.print'); Sleep(1500); end; { TMyClass2 } destructor TMyClass1.Destroy; begin SetInterface2(nil);// this isn not executed inherited; end; procedure TMyClass1.DoSomethingWithInterface2; begin RefToInterFace2.print; end; procedure TMyClass1.SetInterface2(aInterface: MyInterface2); begin RefToInterFace2 := aInterface; end; constructor TMyClass2.Create(int: MyInterface1); begin inherited Create; Ref := int; Ref.SetInterface2(Self); end; var aMyClass1: MyInterface1; aMyClass2: MyInterface2; begin aMyClass1 := TMyClass1.Create; aMyClass2 := TMyClass2.Create(aMyClass1); aMyClass1.DoSomethingWithInterface2; aMyClass1.SetInterface2(nil);// this releases the variable end. Is this the only way to release the pointer in the variable or is there a better way? If I add a destructor that is not executed. Many thanks Alberto
  11. Alberto Paganini

    Varialbe set to nil

    I am just investigating on how this works. Having the following code: program Project3; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, system.Classes, System.SysUtils; type MyInterface2 = interface ['{8E7BC71F-55EE-4345-8A5B-42C433BE9EBA}'] procedure print; end; MyInterface1 = interface ['{607A66A6-D68C-4980-9FB1-83B325EE9A91}'] procedure SetInterface2(aInterface: MyInterface2); end; TMyClass1 = class(TInterfacedObject, MyInterface1) private RefToInterFace2: MyInterface2; public procedure SetInterface2(aInterface: MyInterface2); end; TMyClass2 = class(TInterfacedObject, MyInterface2) constructor Create(int: MyInterface1); reintroduce; procedure print; end; { TMyClass1 } procedure TMyClass2.print; begin Writeln('TMyClass2.print'); Sleep(1500); end; { TMyClass2 } procedure TMyClass1.SetInterface2(aInterface: MyInterface2); begin RefToInterFace2 := aInterface; RefToInterFace2.print; end; constructor TMyClass2.Create(int: MyInterface1); begin inherited Create; int.SetInterface2(Self); end; var aMyClass1: MyInterface1; aMyClass2: MyInterface2; begin aMyClass1 := TMyClass1.Create; aMyClass2 := TMyClass2.Create(aMyClass1); end. How does TMyClass1 know there is RefToInterFace2 to be set to nil in order to prevent an AV error? Where is RefToInterFace2:=nil invoked from? I mean, TMyClass1 ancestor does not know about RefToInterFace2 and RefToInterFace2 is not set to nil anywhere in TMyClass1 Many thanks Alberto
  12. Alberto Paganini

    One more memory leak and FastMM4

    Sure, here it is in attach. I just wanted to avoid to attach a minimal example every time. Test3.zip
  13. Alberto Paganini

    One more memory leak and FastMM4

    Ok, I have also implemented QueryInterface, AfterConstruction, BeforeDestruction and NewInstance in my DataModule In this case, there are no leaks in both cases, with our without .AsSingleton. At this stage, I started implementing the other classes, one by one and .AsSingleton in my datamodule started making a difference when I arrived at the class TBetFairAPINGHorseFunctionSimulationBL TBetFairAPINGHorseFunctionSimulationBL = class(TInterfacedObject, ILBS_BetfairAPINGFunctionsBL) private FDM: IMainDMTEST; public constructor Create(aDM: IMainDMTEST); reintroduce; destructor Destroy; override; end; constructor TBetFairAPINGHorseFunctionSimulationBL.Create(aDM: IMainDMTEST); begin inherited create; FDM := aDM; end; destructor TBetFairAPINGHorseFunctionSimulationBL.Destroy; begin FDM := nil; inherited; end; I have added TBetFairAPINGHorseFunctionSimulationBL.Destroy and set FDM=nil in there but this destructor is never executed, don't know why as this class inherits from TInterfacedObject? As the last attempt, I have added a line at the end of the program to try to release the IMainDMTest at the very end of the application but the leak is still there. var FScalpingBL: IScalpingBL; Test: IMainDMTEST; begin RegisterTypes(GlobalContainer); Test := GlobalContainer.Resolve<IMainDMTEST>; FScalpingBL := globalcontainer.Resolve<IScalpingBL>; Test := nil; end. If I remove .AsSingleton when I resolve the interface then I have no more leaks but I have to keep .AsSingleton because this class holds/manages data and several classes have access to it.
  14. Alberto Paganini

    One more memory leak and FastMM4

    Sorry I didn't explain properly. _AddRef and _Release are implemented in my example. It was the other procedures from Jeroen's example that have been left out as you advised. If I create the object as per your example above then there is no leak. I suppose the issue is in the way I resolve the interface in the Spring container.
  15. Alberto Paganini

    One more memory leak and FastMM4

    I looked into TInterfacedObject again and implemented _AddRef and _Release in the same way, leaving out the remaining procedures, the example attached to this post is the updated minimum example. Unfortunately, I still have the same leaks. I started that thread. Now I know why I cannot have access to it any longer. Test2.zip
×