Skip to content

Commit

Permalink
openssl: add 1.1.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
alaviss committed Jun 7, 2024
1 parent 3e9e7c7 commit 7996ea2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
uses: johnwason/vcpkg-action@v6
with:
pkgs: >-
openssl
pcre
sqlite3
triplet: x64-mingw-dynamic-release
Expand Down Expand Up @@ -243,12 +244,30 @@ jobs:
- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$prefix = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release"
$binPath = Join-Path $prefix "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
$pcPath = (Join-Path $prefix "lib" "pkgconfig"), (Join-Path $prefix "share" "pkgconfig"), $env:PKG_CONFIG_PATH
"PKG_CONFIG_PATH=$($pcPath -join ";")" | Out-File -Append $env:GITHUB_ENV
shell: pwsh

- name: Run tester
run: ./koch.py test --batch:'${{ matrix.batch }}_${{ matrix.total_batch }}' --tryFailing all
run: |
extraArgs=()
if command -v pkg-config 2>&1 >/dev/null; then
extraArgs+=(
"-d:nimLibcryptoLinkFlags:$(pkg-config --libs libcrypto)"
"-d:nimLibsslLinkFlags:$(pkg-config --libs libssl)"
)
sslVer=$(pkg-config --modversion libssl)
if [[ $sslVer == 1.1.1* ]]; then
extraArgs+=("-d:nimOpenssl111")
fi
fi
./koch.py test --batch:'${{ matrix.batch }}_${{ matrix.total_batch }}' --tryFailing all "${extraArgs[@]}"
- name: Print all test errors
if: failure()
Expand Down
6 changes: 5 additions & 1 deletion lib/pure/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,11 @@ when defineSsl:
## When name starts with a dot it will be matched by a certificate valid for any subdomain
when not defined(nimDisableCertificateValidation) and not defined(windows):
assert socket.isSsl
let certificate = socket.sslHandle.SSL_get0_peer_certificate()
when not defined(nimOpenssl111):
let certificate = socket.sslHandle.SSL_get0_peer_certificate()
else:
let certificate = socket.sslHandle.SSL_get_peer_certificate()
defer: X509_free(certificate)
if certificate.isNil:
raiseSSLError("No SSL certificate found.")

Expand Down
8 changes: 6 additions & 2 deletions lib/wrappers/openssl/ssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,13 @@ proc SSL_get_psk_identity*(ssl: ptr SSL): cstring {.importc, cdecl.}
proc SSL_get_psk_identity_hint*(ssl: ptr SSL): cstring {.importc, cdecl.}
proc SSL_get_verify_result*(ssl: ptr SSL): clong {.importc, cdecl.}

proc SSL_get0_peer_certificate*(ssl: ptr SSL): ptr X509 {.importc, cdecl.}
proc SSL_get0_verified_chain*(ssl: ptr SSL): ptr STACK_OF[X509] {.importc, cdecl.}
proc SSL_get1_peer_certificate*(ssl: ptr SSL): ptr X509 {.importc, cdecl.}

when not defined(nimOpenssl111):
proc SSL_get0_peer_certificate*(ssl: ptr SSL): ptr X509 {.importc, cdecl.}
proc SSL_get1_peer_certificate*(ssl: ptr SSL): ptr X509 {.importc, cdecl.}
else:
proc SSL_get_peer_certificate*(ssl: ptr SSL): ptr X509 {.importc, cdecl.}

proc SSL_accept*(ssl: ptr SSL): cint {.importc, cdecl.}
proc SSL_connect*(ssl: ptr SSL): cint {.importc, cdecl.}
Expand Down

0 comments on commit 7996ea2

Please sign in to comment.