Last active
September 13, 2023 17:08
-
-
Save scivision/99a4cb17279c6278d7be022ffbdfce16 to your computer and use it in GitHub Desktop.
CMake test if Curl has HSTS enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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