Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

CODESYS 4 Linux:

2021-10-05
5 days ago
  • aseitzinger - 2021-10-05

    hello forum,
    does someone run a recent version of codesys (3.5.17.10) under Wine or Crossover? As this seems to be broken from 3.5.16
    br Arno


    Talk Topic about project #codesys-4-linux

     
  • mondinmr

    mondinmr - 2022-01-18

    I just installed 3.5.17.20 under Wine-staging 7.0, on Ubuntu/Linux 20.04.
    Using installer don't work! I followed step like in Ingo install2.sh.
    Now I'm launching 64bit version, but some native library is needed for package manager.

     
  • mondinmr

    mondinmr - 2022-04-28

    I just tried CODESYS 3.5.18 64 bit.

    WINEARCH=win64
    WINEPREFIX=/home/<myuser>/.wine.codesys
    
    wine winecfg (Select Windows 10 as version)
    
    winetricks -q dotnet48 (Popup require 4.6.2, but 4.8 is realy required)
    winetricks --force -q vcrun2019 (2015-2019 in single package)
    
    wine CODESYS\ 64\ 3.5.18.0.msi (Extracted from ZIP download)
    
    -Deselected gateway due a linux gateway exists;
    -Deselected runtime due linux runtime exists;
    
    Installer work until IPMCLI.exe
    

    IPMCLI.exe fail in .net Culture Expetion:

    0670:err:eventlog:ReportEventW L"Application: IPMCLI.exe\nFramework Version: v4.0.30319\nDescription: The process was terminated due to an unhandled exception.\nException Info: System.Globalization.CultureNotFoundException\n   at System.Globalization.CultureInfo..ctor(System.String, Boolean)\n   at System.Globalization.C"...
    
     

    Last edit: mondinmr 2022-04-28
    • andbat - 2024-03-20

      Good morning @mondinmr,
      I'm trying to install codesys 3.5.20.0 inside bottles (with wine 9.2).
      The full installation seems to be done (exept CodeMeter). When I run Codesys IDE an error related to IPMCLI appear and there is non chanse to open the IDE.
      How did you solve this issue?
      Thanks a lot.

       
  • mondinmr

    mondinmr - 2022-04-30

    Put all locales to en_US.UTF8, let me install and run CODESYS 3.5.18 in wine.
    You can see attached image!
    The problem remain in ncrypt.

    047c:fixme:ncrypt:NCryptOpenStorageProvider (000000005F38E318, L"Microsoft Software Key Storage Provider", 0): stub
    047c:fixme:ncrypt:NCryptSetProperty flags 0x40000000 not supported
    

    This make impossible verify any signature. So is not possible do anything else editing code. Not very useful!

     
    • Ingo

      Ingo - 2022-04-30

      Hi!

      I already encountered the same issue in a different context. The problem
      occurs also when you try to run the simulation, or connect to a PLC with
      encrypted communication.

      I assume it is a bigger task, but I believe the clean solution is to
      implement ncrypt in wine.

      Googling for it, turned out, that there was a fix in this region recently:
      https://www.winehq.org/announce/7.3

      The microsoft installer was the driving force for that.

      Maybe you want to try this new wine version?
      I am already very curious, if it works now...

       
      • mondinmr

        mondinmr - 2022-04-30

        My test was made in 7.7 Staging... So...
        ncrypt is partially implemented, but it's missing CODESYS required API calls.

         

        Last edit: mondinmr 2022-04-30
    • mondinmr

      mondinmr - 2022-05-03

      Ok!
      Let's go!

      1 - I installed WINE Development 7.7 from repository.
      2 - I downloaded 7.7 development source code.
      3 - Go in 7.7 source:

      $ cd src/wine-7.7/
      $ configure --enable-win64
      $ cd dlls/ncrypt
      

      4 - Edit main.c adding this just before SECURITY_STATUS WINAPI NCryptImportKey

      SECURITY_STATUS WINAPI NCryptExportKey(NCRYPT_KEY_HANDLE handle, NCRYPT_KEY_HANDLE decrypt_key,
                                             const WCHAR *type, NCryptBufferDesc *params, BYTE *data,
                                             DWORD datasize, DWORD *pcbResult, DWORD flags)
      {
          struct object *object = (struct object *)(&handle); 
          NTSTATUS status;
          status = BCryptExportKey(object->key.bcrypt_key, NULL, type, data, datasize, pcbResult, 0); 
          return ERROR_SUCCESS;
      }
      

      5 - edit ../../include/ncrypt.h adding this line before
      SECURITY_STATUS WINAPI NCryptImportKey

      SECURITY_STATUS WINAPI NCryptExportKey(NCRYPT_KEY_HANDLE, NCRYPT_KEY_HANDLE,
                                             const WCHAR *, NCryptBufferDesc *, BYTE *,
                                             DWORD, DWORD *, DWORD);
      

      6 - ...

      $ make
      

      7 - copyed resulting ncrypt.dll and .so in ...

      $ sudo cp ncrypt.dll.so /opt/wine-devel/lib64/wine/x86_64-unix/
      $ sudo cp ncrypt.dll /opt/wine-devel/lib64/wine/x86_64-windows/
      $ cp ncrypt.dll /home/marco/.wine.codesys/drive_c/windows/system32/
      

      To be tested and improved!

       
      • mondinmr

        mondinmr - 2022-05-03

        Just tested!
        Function is called.
        I only build this single DLL.
        Some difference on message above:
        - I configured with -prefix=/opt/wine-devel
        - I used make install, but install copied in /opt/wine-
        devel/lib/... and not in /opt/wine-devel/lib64/... so I copied DLL from lib to lib64.
        - I also modified spec file to declare new funcion, marked as STUB.
        Function is called by wine, BCryptExportKey is implemented in WINE, but I translated something in a wrong way and this result in an exception in NCryptFreeObject.

        I think is the right way, but much work is needed.
        I just writed also in wine forum.

        A second problem I think need a solution to make CODESYS working under wine is manage flag 0x4000000 in NCrypt.

         
        • Ingo

          Ingo - 2022-05-04

          Hi @mondinmr ,

          you got me curious. I'm wondering:
          How did you install SP18?

          Did you manage it with the installer, or did you use the install2.sh
          script, or ... ?

          Cheers,
          Ingo

           
          • mondinmr

            mondinmr - 2022-05-04

            Hi Ingo!
            I downloaded install2.sh to see what you are doing.

            I used 3.5.18 64bits, due a wine transition to 64bits in 7.0. They introduced syswow64 for 32bis compatibility and they started to suggest 64bits usage.

            3.5.18 is in zip and not exe file.
            I extracted msi.

            I used winetricks to install dotnet472, arial, corefonts, vcrun2019.
            Aftrer that I dowloaded Edge runtime 2 64 from microsoft, due the one present in prerequisites of 3.5.18 not working.

            A very important step, for me is call winecfg, select windows10, and disable windows decorations managed by windows manager. Wine tricks put it back to Windows 7 so I select 10 just before launch installer.

            Now I'm working on ncrypt dll.

             

            Last edit: mondinmr 2022-05-04
  • mondinmr

    mondinmr - 2022-05-04

    Ok! I patched ncrypt.dll!
    Now signatures are verified!!!!!!!

    Now more tests are needed!

    In attachment there are modified files!

    Now missing of 0x4000000 FLAG managment (i'm not sure), bring randomly to this:

    04b4:err:eventlog:ReportEventW L"Application: CODESYS.exe\nFramework Version: v4.0.30319\nDescription: The process was terminated due to an unhandled exception.\nException Info: System.AccessViolationException\n   at Microsoft.Win32.SafeHandles.SafeNCryptProviderHandle.NCryptFreeObject(IntPtr)\n   at Microsoft.Win32.Safe"...
    04b4:fixme:advapi:DeregisterEventSource (00000000CAFE4242) stub
    
    Unhandled Exception: 04b4:fixme:ver:GetCurrentPackageId (000000000334B020 0000000000000000): stub
    Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indicati
    on that other memory is corrupt.
       at Microsoft.Win32.SafeHandles.SafeNCryptProviderHandle.NCryptFreeObject(IntPtr hObject)
       at Microsoft.Win32.SafeHandles.SafeNCryptProviderHandle.ReleaseNativeHandle()
       at Microsoft.Win32.SafeHandles.SafeNCryptHandle.ReleaseHandle()
       at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
       at System.Runtime.InteropServices.SafeHandle.Finalize()
    wine: Unhandled page fault on read access to FFFFFFFFFFFFFFFF at address 000000017002AEF8 (thread 04b4), starting debugger..
    
     

    Last edit: mondinmr 2022-05-04
  • mondinmr

    mondinmr - 2022-05-04

    Only for test purpose i put a reuturn in NCryptFreeObject after call, this bring in a memory leak, but now installer work, packages are installed, signatures working. So NCRYPT_PERSIST_ONLY_FLAG probability could be managed in a key property avoiding free when this property is set.

    In 3.5.18 Codesys Installer is needed, so dll should compiled also in 32bit, due this program is released only in 32bit (why in 2022??????).

    Some problem persists in online.

    A side comment out off topic... This massive usage of .net and C# is making development system a little bit too heavy.

     

    Last edit: mondinmr 2022-05-04
  • ara32 - 2024-03-22

    Hello!

    I managed to correctly launch CODESYS Developer Studio 3.5.17, almost all functionality works. The only issue remaining is that when connecting to a device and obtaining its public key, the NCryptEncrypt function is called, which is not fully implemented in the DLL source code, resulting in the connection not being established.

    Currently, the code of this function in the Wine repository looks like this:

    SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD insize, void *padding,
                                         BYTE *output, DWORD outsize, DWORD *result, DWORD flags)
    {
        struct object *key_object = (struct object *)key;
    
        TRACE("(%#Ix, %p, %lu, %p, %p, %lu, %p, %#lx)\n", key, input, insize, padding,
              output, outsize, result, flags);
    
        if (flags & ~(NCRYPT_NO_PADDING_FLAG | NCRYPT_PAD_OAEP_FLAG
                    | NCRYPT_PAD_PKCS1_FLAG | NCRYPT_SILENT_FLAG))
        {
            FIXME("Flags %lx not supported\n", flags);
            return NTE_BAD_FLAGS;
        }
    
        if (flags & NCRYPT_NO_PADDING_FLAG || flags & NCRYPT_PAD_OAEP_FLAG)
        {
            FIXME("No padding and oaep padding not supported\n");
            return NTE_NOT_SUPPORTED;
        }
    
        if (key_object->type != KEY) return NTE_INVALID_HANDLE;
    
        return map_ntstatus(BCryptEncrypt(key_object->key.bcrypt_key, input, insize, padding,
                                          NULL, 0, output, outsize, result, flags));
    }
    

    The program crashes due to the NCRYPT_PAD_OAEP_FLAG flag. I'm not proficient in C++, but I attempted to add handling myself, and here's the result:

    SECURITY_STATUS WINAPI NCryptEncrypt(NCRYPT_KEY_HANDLE key, BYTE *input, DWORD insize, void *padding,
                                         BYTE *output, DWORD outsize, DWORD *result, DWORD flags)
    {
        struct object *key_object = (struct object *)key;
    
        TRACE("(%#Ix, %p, %lu, %p, %p, %lu, %p, %#lx)\n", key, input, insize, padding,
              output, outsize, result, flags);
    
        if (flags & ~(NCRYPT_NO_PADDING_FLAG | NCRYPT_PAD_OAEP_FLAG
                    | NCRYPT_PAD_PKCS1_FLAG | NCRYPT_SILENT_FLAG))
        {
            FIXME("Flags %lx not supported\n", flags);
            return NTE_BAD_FLAGS;
        }
    
        if (flags & NCRYPT_NO_PADDING_FLAG)
        {
            FIXME("No padding not supported\n");
            return NTE_NOT_SUPPORTED;
        }
    
        BCRYPT_OAEP_PADDING_INFO oaepInfo = { 0 };
        oaepInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM; 
    
        NTSTATUS status = BCryptEncrypt(key_object->key.bcrypt_key, input, insize, &oaepInfo,
                                        NULL, 0, output, outsize, result, flags);
    
        if (key_object->type != KEY) return NTE_INVALID_HANDLE;
    
        return map_ntstatus(BCryptEncrypt(key_object->key.bcrypt_key, input, insize, padding,
                                          NULL, 0, output, outsize, result, flags));
    }
    

    Now, when calling the connection, it crashes with the error "bcrypt:BCryptEncrypt flags 0x4 not implemented."

    Can anyone help with enhancing this functionality or at least point me in the right direction?

     

    Last edit: ara32 2024-03-22

Log in to post a comment.