Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active September 13, 2023 17:08
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/99a4cb17279c6278d7be022ffbdfce16 to your computer and use it in GitHub Desktop.
Save scivision/99a4cb17279c6278d7be022ffbdfce16 to your computer and use it in GitHub Desktop.
CMake test if Curl has HSTS enabled
cmake_minimum_required(VERSION 3.6)
set(url https://hsts.badssl.com/hsts-test/status.svg)
set(file ${CMAKE_CURRENT_BINARY_DIR}/status.svg)
file(DOWNLOAD ${url} ${file} LOG log STATUS status TLS_VERIFY true)
message(VERBOSE "log: ${log}")
message(STATUS "status: ${status}")
# check connection headers
string(REGEX MATCH "Strict-Transport-Security.*max-age\=[0-9]+" match "${log}")
if(CMAKE_MATCH_0)
message(STATUS "HSTS: ${CMAKE_MATCH_0}")
else()
message(SEND_ERROR "HSTS: not detected")
endif()
# NOTE: Safari doesn't work from the command line, so Safari is omitted from the search.
find_program(browser
NAMES
"Microsoft Edge" msedge
"Google Chrome" google-chrome chrome
Chromimum chromium-browser chromium
Firefox firefox firefox-bin
PATHS
"$ENV{PROGRAMFILES\(x86\)}/Microsoft/Edge/Application"
"$ENV{PROGRAMFILES}/Google/Chrome/Application"
"$ENV{PROGRAMFILES}/Google/Chromium/Application"
"$ENV{PROGRAMFILES}/Mozilla Firefox"
"/Applications/Microsoft Edge.app/Contents/MacOS/"
"/Applications/Google Chrome.app/Contents/MacOS/"
"/Applications/Chromium.app/Contents/MacOS/"
"/Applications/Firefox.app/Contents/MacOS/"
)
if(browser)
execute_process(COMMAND ${browser} ${file})
else()
message(STATUS "please check ${file} for HSTS test result")
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment