Hello,
I run Julia on Win 11 within WSL2 (Debian), in general without issues so far. But recently I encountered the following issue with MbedTLS, when I attempt to create a SSLConfig.
MWE
# installing MbedTLS in a clean, temporary environment
using Pkg
Pkg.activate(; temp=true)
Pkg.add("MbedTLS")
using MbedTLS
# creating a SSLConfig
MbedTLS.SSLConfig(false)
I have the same issue with Julia 1.12.0 and 1.10.10.
On Win 11 I donât have the issue also on a ârealâ (not WSL2) Debian system I canât reproduce the issue.
Anyone having an idea how to solve the problem on WSL2 or faced a similar challenge before?
Iâm just ruling out the certificate buf string missing, I doubt itâs supposed to be secret I just shortened it in case (and it seems to come from this 200 KB file bundled with Julia, no wander small binaries canât be made, thatâs many times larger than the memory of my first computer!):
Youâre ultimately calling:
function crt_parse!(chain, buf::String)
ret = ccall((:mbedtls_x509_crt_parse, libmbedx509), Cint,
(Ptr{Cvoid}, Ptr{UInt8}, Csize_t),
chain.data, buf, sizeof(buf)+1)
ret == 0 || mbed_err(ret)
chain
end
[For me ok, since ret == 0, not sure why error/ret code for you exactly and you get an error.]
I donât know why not working for you, but you should know Julia switched to OpenSSL, so you should try with that? I.e. with a package:
using OpenSSL
It doesnât have SSLConfig so not exact same API, I think comparable functionality, not sure, but maybe ssl_set_options is a replacement there.
MbedTLS removed
Itâs a large PR, but seemingly still just replacing, mostly using same API. But note I see in the PR stuff like:
if !(Sys.iswindows() || Sys.isapple())
# On Windows and macOS we use system SSL/crypto libraries
using OpenSSL_jll
and this would bypass OpenSLL, on Windows, i.e. use system crypto, and overlook WSL (which might be a good thing, or not).
Is this only about WSL2? I.e. works on older WSL [version 1]? Probably MbedTLS (or OpenSSL) never worked there with WSL2 that uses a Linux kernel (WSL 1 is a Linux compatibility API without a Linux kernel), nor with original WSL? I canât say for sure if OpenSSL will not work either.
Both packages should still work on Windows (without any WSL), OpenSSL is tested there too, and MbedTLS has support for (but not sure about on WSL, such tests might interfere, since if youâre on Windows, it may be presumed youâre not using WSL):
OpenSLL package also uses iswindows, then not conditional on version.
Note âWSL2 (Ubuntu LTS)â is only a tier 2 platform. That likely translates to later Ubuntu and also e.g. Debian, but doesnât say much about (SSL or TLS, at least in) packages.
Note also there is (but not used by the OpenSSL package):
Sys.detectwsl()
Runtime predicate for testing if Julia is running inside
Windows Subsystem for Linux (WSL).
!!! note
Unlike Sys.iswindows, Sys.islinux etc., this is a runtime test, and thus
cannot meaningfully be used in @static if constructs.
!!! compat âJulia 1.12â
This function requires at least Julia 1.12.
ââ"
function detectwsl()
# We use the same approach as canonical/snapd do to detect WSL
islinux() && (
isfile(â/proc/sys/fs/binfmt_misc/WSLInteropâ)
|| isdir(â/run/WSLâ)
)
end
For my curiosity can you look at that file; I assume you have it, and tell me whatâs in it?
I assume this is to detect WSL 2 (likely also detects original WSL, though not sure; itâs not supported in any (other) way by Julia, nor any longer if I recall by Microsoft).
I checked MbedTLS.DEFAULT_CERT[], it returns the expected string.
I canât check if this also happens on WSL (version 1), I only have WSL2 on my machine.
What I actually try to do is requesting some HTTP endpoints, with self-signed certificates, with HTTP.jl. However, Iâm afraid I can only disable the certificate verification of HTTP.jl with the SSLConfig generated via MbedTLS so I canât use OpenSSL.jl in this case.
Or would you know of any other way to achive that goal?
For now Iâm falling back to the native Windows version.
Also, I donât have a /proc/sys/fs/binfmt_misc/WSLInterop, but /proc/sys/fs/binfmt_misc/WSLInterop-late. It contains the following:
enabled
interpreter /init
flags: P
offset 0
magic 4d5a
However I have the directory /run/WSL/, so Sys.detectwsl() works.