Skip to content

Commit

Permalink
code reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Aug 9, 2024
1 parent cf2d228 commit bd517c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
33 changes: 4 additions & 29 deletions CheckHTTPS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 23 additions & 3 deletions UserAgent.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# 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
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()
12 changes: 4 additions & 8 deletions bad_ssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down

0 comments on commit bd517c5

Please sign in to comment.