Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active September 13, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/6e7bae1dcde00d1f42572ba4092ef750 to your computer and use it in GitHub Desktop.
Save scivision/6e7bae1dcde00d1f42572ba4092ef750 to your computer and use it in GitHub Desktop.
CMAKE_TLS_VERIFY with bad and good TLS and get Curl version
cmake_minimum_required(VERSION 3.19)
set(CMAKE_TLS_VERIFY ON)
set(ua_url https://www.whatsmyua.info/api/v1/ua)
# Get CMake's vendored cURL version
file(DOWNLOAD ${ua_url} ua.json TIMEOUT 10 STATUS ret)
list(GET ret 0 status)
if(NOT status EQUAL 0)
message(FATAL_ERROR "Failed to download ${ua_url} error code ${status}")
endif()
file(READ ua.json meta)
string(JSON ua GET ${meta} 0 ua rawUa)
message(STATUS "CMake ${CMAKE_VERSION}
cURL version: ${ua}
TLS_CAINFO: ${CMAKE_TLS_CAINFO}
SSL_CERT_FILE: $ENV{SSL_CERT_FILE}"
)
function(ssl url)
file(DOWNLOAD ${url} STATUS ret TIMEOUT 10)
list(GET ret 0 status)
list(GET ret 1 msg)
if(status EQUAL 0)
message(STATUS "${url}:${status}: ${msg}")
else()
message(SEND_ERROR "${url}:${status}: ${msg}")
endif()
endfunction(ssl)
message(STATUS "These tests should fail.")
ssl(https://expired.badssl.com/)
ssl(https://untrusted-root.badssl.com/)
message(STATUS "These tests should work OK.")
ssl(https://hsts.badssl.com/)
ssl(https://sha256.badssl.com/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment