Example #1
0
        public static string OpenSSL_version(LibraryName library = LibraryName.unknown)
        {
            if (library == LibraryName.unknown)
            {
                library = DefaultLibrary;
            }

            switch (library)
            {
            case LibraryName.libssl_so_1_1:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libssl_so_1_1.OpenSSL_version()));

            case LibraryName.libssl_so_1_1_0:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libssl_so_1_1_0.OpenSSL_version()));

            case LibraryName.libcrypto_dll:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libcrypto_dll.OpenSSL_version()));

            case LibraryName.libcrypto_x64_dll:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libcrypto_x64_dll.OpenSSL_version()));

            case LibraryName.libcrypto_1_1_dll:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libcrypto_1_1_dll.OpenSSL_version()));

            case LibraryName.libcrypto_1_1_x64_dll:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libcrypto_1_1_x64_dll.OpenSSL_version()));

            //case LibraryName.libssl:
            default:
                return(Marshal.PtrToStringAuto(InteropOpenSSL11_libssl.OpenSSL_version()));
            }
        }
Example #2
0
        public static LibraryName GetDefaultLibrary()
        {
            try
            {
                var ptr = InteropOpenSSL11_libssl_so_1_1_0.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libssl_so_1_1_0);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libssl.so.1.1.0: {ex}");
            }

            try
            {
                var ptr = InteropOpenSSL11_libssl_so_1_1.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libssl_so_1_1);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libssl.so.1.1: {ex}");
            }

            try
            {
                var ptr = InteropOpenSSL11_libcrypto_dll.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libcrypto_dll);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libcrypto.dll: {ex}");
            }

            try
            {
                var ptr = InteropOpenSSL11_libcrypto_x64_dll.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libcrypto_x64_dll);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libcrypto.dll: {ex}");
            }

            try
            {
                var ptr = InteropOpenSSL11_libcrypto_1_1_dll.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libcrypto_1_1_dll);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libcrypto.dll: {ex}");
            }

            try
            {
                var ptr = InteropOpenSSL11_libcrypto_1_1_x64_dll.OpenSSL_version();
                if (ptr != IntPtr.Zero)
                {
                    return(LibraryName.libcrypto_1_1_x64_dll);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"Failed to load OpenSSL1.1 from libcrypto.dll: {ex}");
            }


            return(LibraryName.libssl);
        }