EtheaDev / Delphi-SAML

A SAML implementation for Delphi developers
Apache License 2.0
25 stars 7 forks source link

Win64 Compatibility #1

Closed fastbike closed 6 months ago

fastbike commented 6 months ago

Thanks for uploading this library. I'm looking to compile the demos for 64 bit use, I've changed some of the conditional defines such as

// the name of the dll
const
{$IFDEF LINUX}
  LIBXMLSEC_SO = 'libxmlsec.so';
{$ELSE}
  LIBXMLSEC_SO = 'libxmlsec.dll';
{$ENDIF}
....
// the uses clause
uses
{$IFDEF WIN32}
  Windows,
{$ENDIF}
{$IFDEF WIN64}
  Windows,
{$ENDIF}
  SysUtils;

I can get the code signing demo to work until the actual call to sign the XML

// this returns -1 instead of zero
  if xmlSecDSigCtxSign(dsigCtx, node) < 0 then

I'm using the same certs, input XML file etc but just with a recent 64 bit version of the DLLs from the https://www.aleksey.com/xmlsec/ website

lminuti commented 6 months ago

With the last commit I've added some conditional defines to load the correct DLL version. But the problem with xmlSecDSigCtxSign remains. If I enable the log a see:

func=xmlSecDSigCtxProcessKeyInfoNode:file=xmldsig.c:line=871:obj=unknown:subj=unknown:error=45:key is not found: 
func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=565:obj=unknown:subj=xmlSecDSigCtxProcessKeyInfoNode:error=1:xmlsec library function failed: 
func=xmlSecDSigCtxSign:file=xmldsig.c:line=303:obj=unknown:subj=xmlSecDSigCtxSignatureProcessNode:error=1:xmlsec library function failed: 

I don't know if it's same for you. I'll try to work on it in the next few days.

lminuti commented 6 months ago

The problem was that on win64 the time_t size change from LongInt to Int64

fastbike commented 6 months ago

The problem was that on win64 the time_t size change from LongInt to Int64

Thank you very much for tracking this down and fixing.

fastbike commented 6 months ago

@lminuti This has not fixed the issue for signing ... The following signatures need to be changed according to the compiler

// Win32
  function xmlSecDSigCtxSign (dsigCtx: xmlSecDSigCtxPtr; tmpl: xmlNodePtr) : Longint; cdecl; external LIBXMLSEC_SO;
  function xmlSecDSigCtxVerify (dsigCtx: xmlSecDSigCtxPtr; node: xmlNodePtr) : Longint; cdecl; external LIBXMLSEC_SO;
// Win64
  function xmlSecDSigCtxSign (dsigCtx: xmlSecDSigCtxPtr; tmpl: xmlNodePtr) : Int64; cdecl; external LIBXMLSEC_SO;
  function xmlSecDSigCtxVerify (dsigCtx: xmlSecDSigCtxPtr; node: xmlNodePtr) : Int64; cdecl; external LIBXMLSEC_SO;

I think a global alias for LongInt is required as this will be used elsewhere too

lminuti commented 6 months ago

longint is correct. The C declaration are

XMLSEC_EXPORT int               xmlSecDSigCtxSign               (xmlSecDSigCtxPtr dsigCtx,
                                                                 xmlNodePtr tmpl);
XMLSEC_EXPORT int               xmlSecDSigCtxVerify             (xmlSecDSigCtxPtr dsigCtx,
                                                                 xmlNodePtr node);

The size of int type in C/C++ in 32bit and 64bit architectures are the same as you can see for examples here: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/64-bit_Windows_Data_Types_Compared_to_32-bit_Windows_Data_Types (you can see both delphi and C++ data types comparison).

If you still have problems probably there's something else wrong. Try to follow these steps: