From bd517c55f5b539dd12701943594c1cbb9d2ac73e Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 9 Aug 2024 14:56:56 -0400 Subject: [PATCH] code reuse --- CheckHTTPS.cmake | 33 ++++----------------------------- UserAgent.cmake | 26 +++++++++++++++++++++++--- bad_ssl.cmake | 12 ++++-------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/CheckHTTPS.cmake b/CheckHTTPS.cmake index cd64ab1..5dc0d55 100644 --- a/CheckHTTPS.cmake +++ b/CheckHTTPS.cmake @@ -26,39 +26,14 @@ https://expired.badssl.com https://wrong.host.badssl.com https://self-signed.badssl.com https://untrusted-root.badssl.com -https://revoked.badssl.com https://null.badssl.com +https://revoked.badssl.com +https://pinning-test.badssl.com +https://tls-v1-0.badssl.com ) -# passes with CMake 3.26 due to cURL -# https://pinning-test.badssl.com -# https://tls-v1-0.badssl.com - - # --- helper functions -function(user_agent) - -# Get CMake's user agent -file(DOWNLOAD https://www.whatsmyua.info/api/v1/ua ua.json) -file(READ ua.json meta) -string(JSON ua GET ${meta} 0 ua rawUa) - -message(STATUS "User agent: ${ua}") -if(DEFINED ENV{SSL_CERT_FILE}) - message(STATUS "SSL_CERT_FILE: $ENV{SSL_CERT_FILE}") -endif() - -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) - execute_process(COMMAND ${CMAKE_COMMAND} -E capabilities OUTPUT_VARIABLE cap) - - string(JSON has_tls GET ${cap} "tls") - message(STATUS "TLS: ${has_tls}") -endif() - -endfunction() - - function(check_url url ok) file(DOWNLOAD ${url} @@ -87,7 +62,7 @@ endif() message(STATUS "CMake ${CMAKE_VERSION}") - +include(${CMAKE_CURRENT_LIST_DIR}/UserAgent.cmake) user_agent() foreach(u IN LISTS url_good) diff --git a/UserAgent.cmake b/UserAgent.cmake index d7beeb4..280ce0e 100644 --- a/UserAgent.cmake +++ b/UserAgent.cmake @@ -1,8 +1,9 @@ # get CMake UserAgent (cURL version) -cmake_minimum_required(VERSION 3.19) +function(user_agent) -set(url "https://www.whatsmyua.info/api/v1/ua") -set(file "${CMAKE_CURRENT_BINARY_DIR}/ua.json") +# Get CMake's user agent +set(url https://www.whatsmyua.info/api/v1/ua) +set(file ${CMAKE_CURRENT_BINARY_DIR}/ua.json) file(DOWNLOAD ${url} ${file}) # CMake UserAgent like curl/7.69.0 @@ -10,5 +11,24 @@ file(READ ${file} json) string(JSON ua GET ${json} 0 "ua" "rawUa") +message(STATUS "User agent: ${ua}") +if(DEFINED ENV{SSL_CERT_FILE}) + message(STATUS "SSL_CERT_FILE: $ENV{SSL_CERT_FILE}") +endif() + +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) + execute_process(COMMAND ${CMAKE_COMMAND} -E capabilities OUTPUT_VARIABLE cap) + + string(JSON has_tls GET ${cap} "tls") + message(STATUS "TLS: ${has_tls}") +endif() + message(STATUS "CMake ${CMAKE_VERSION} ${ua}") + +endfunction() + + +if(CMAKE_SCRIPT_MODE_FILE) + user_agent() +endif() diff --git a/bad_ssl.cmake b/bad_ssl.cmake index 1b72564..550a71e 100644 --- a/bad_ssl.cmake +++ b/bad_ssl.cmake @@ -2,14 +2,10 @@ cmake_minimum_required(VERSION 3.19) set(CMAKE_TLS_VERIFY ON) -# Get CMake's vendored cURL version -file(DOWNLOAD https://www.whatsmyua.info/api/v1/ua ua.json) -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} +include(${CMAKE_CURRENT_LIST_DIR}/UserAgent.cmake) +user_agent() + +message(STATUS "TLS_CAINFO: ${CMAKE_TLS_CAINFO} SSL_CERT_DIR: $ENV{SSL_CERT_DIR} SSL_CERT_FILE: $ENV{SSL_CERT_FILE}" )