From 877b237f6f22fdc098051f550c7b9dcf26afe3ec Mon Sep 17 00:00:00 2001 From: devel71 Date: Fri, 25 Nov 2016 11:40:29 +0100 Subject: [PATCH 01/10] initial commit to qca branch --- ports/qca/0001-fix-path-for-vcpkg.patch | 54 ++++++++++++++ ports/qca/CONTROL | 3 + ports/qca/portfile.cmake | 97 +++++++++++++++++++++++++ ports/qca/qca_load_qtenv.cmake | 40 ++++++++++ 4 files changed, 194 insertions(+) create mode 100644 ports/qca/0001-fix-path-for-vcpkg.patch create mode 100644 ports/qca/CONTROL create mode 100644 ports/qca/portfile.cmake create mode 100644 ports/qca/qca_load_qtenv.cmake diff --git a/ports/qca/0001-fix-path-for-vcpkg.patch b/ports/qca/0001-fix-path-for-vcpkg.patch new file mode 100644 index 0000000000..b48fee18f9 --- /dev/null +++ b/ports/qca/0001-fix-path-for-vcpkg.patch @@ -0,0 +1,54 @@ +From bab44a6614d4a540af56860432bcc0d6bdf420c9 Mon Sep 17 00:00:00 2001 +From: devel +Date: Wed, 23 Nov 2016 16:54:44 +0100 +Subject: [PATCH] fix path for vcpkg + +--- + CMakeLists.txt | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 605621b..a8c3774 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -277,7 +277,7 @@ if(DEVELOPER_MODE) + # To prefer plugins from build tree when run qca from build tree + file(WRITE ${CMAKE_BINARY_DIR}/bin/qt.conf + "[Paths] +-Plugins=${CMAKE_BINARY_DIR}/lib/${QCA_LIB_NAME} ++Plugins=${CMAKE_BINARY_DIR}/bin/${QCA_LIB_NAME} + ") + endif() + +@@ -401,10 +401,10 @@ endif(DOXYGEN_FOUND) + include(CMakePackageConfigHelpers) + configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/QcaConfig.cmake.in" +- "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" +- INSTALL_DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} ++ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" ++ INSTALL_DESTINATION ${CMAKE_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} + ) +-write_basic_config_version_file("${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) ++write_basic_config_version_file("${CMAKE_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) + + if(NOT DEVELOPER_MODE) + +@@ -472,10 +472,10 @@ if(NOT DEVELOPER_MODE) + endif() + endif() + +- install(EXPORT ${QCA_CONFIG_NAME_BASE}Targets DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} FILE ${QCA_CONFIG_NAME_BASE}Targets.cmake) ++ install(EXPORT ${QCA_CONFIG_NAME_BASE}Targets DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} FILE ${QCA_CONFIG_NAME_BASE}Targets.cmake) + install(FILES +- "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" +- "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" +- DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} ++ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" ++ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" ++ DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} + ) + endif() +-- +2.9.2.windows.1 + diff --git a/ports/qca/CONTROL b/ports/qca/CONTROL new file mode 100644 index 0000000000..84465481a1 --- /dev/null +++ b/ports/qca/CONTROL @@ -0,0 +1,3 @@ +Source: qca +Version: 2.2.0 +Description: Qt Cryptographic Api (QCA) diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake new file mode 100644 index 0000000000..cc391b517e --- /dev/null +++ b/ports/qca/portfile.cmake @@ -0,0 +1,97 @@ +# For now only x[64|86]-windows triplet and dynamic linking is supported +# + +if (VCPKG_LIBRARY_LINKAGE STREQUAL static) + message(STATUS "Warning: Static building not supported yet. Building dynamic.") + set(VCPKG_LIBRARY_LINKAGE dynamic) +endif() + +include(vcpkg_common_functions) +include(${CMAKE_CURRENT_LIST_DIR}/qca_load_qtenv.cmake) + +find_program(GIT git) + +# Set git variables to qca version 2.2.0 commit +set(GIT_URL "git://anongit.kde.org/qca.git") +set(GIT_REF "19ec49f89a0a560590ec733c549b92e199792837") # Commit + +# Prepare source dir +if(NOT EXISTS "${DOWNLOADS}/qca.git") + message(STATUS "Cloning") + vcpkg_execute_required_process( + COMMAND ${GIT} clone --bare ${GIT_URL} ${DOWNLOADS}/qca.git + WORKING_DIRECTORY ${DOWNLOADS} + LOGNAME clone + ) +endif() +message(STATUS "Cloning done") + +if(NOT EXISTS "${CURRENT_BUILDTREES_DIR}/src/.git") + message(STATUS "Adding worktree") + file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}) + vcpkg_execute_required_process( + COMMAND ${GIT} worktree add -f --detach ${CURRENT_BUILDTREES_DIR}/src ${GIT_REF} + WORKING_DIRECTORY ${DOWNLOADS}/qca.git + LOGNAME worktree + ) +endif() +message(STATUS "Adding worktree done") + +set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/) + +# Apply the patch to install 'crypto' and 'cmake targets' folder +vcpkg_apply_patches( + SOURCE_PATH ${SOURCE_PATH} + PATCHES ${CMAKE_CURRENT_LIST_DIR}/0001-fix-path-for-vcpkg.patch +) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + CURRENT_PACKAGES_DIR ${CURRENT_PACKAGES_DIR} + OPTIONS + #-DSOURCE=${SOURCE_PATH} + -DBUILD_SHARED_LIBS=ON + -DUSE_RELATIVE_PATHS=ON + -DQT4_BUILD=OFF + -DBUILD_TESTS=OFF + -DBUILD_TOOLS=OFF + -DQCA_SUFFIX=qt5 + OPTIONS_DEBUG + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca-qt5 + OPTIONS_RELEASE + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/bin/Qca-qt5 +) + +vcpkg_install_cmake() + +message(STATUS "Patching files") + +file(RENAME + ${CURRENT_PACKAGES_DIR}/debug/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake + ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake +) + +set(T_DEBUG ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake) +set(T_TARGETS ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets.cmake) + +file(READ ${T_DEBUG} QCA_DEBUG_CONFIG) +string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" QCA_DEBUG_CONFIG "${QCA_DEBUG_CONFIG}") +file(WRITE ${T_DEBUG} "${QCA_DEBUG_CONFIG}") + +file(READ ${T_TARGETS} QCA_TARGET_CONFIG) +string(REPLACE "packages/qca_" "installed/" QCA_TARGET_CONFIG "${QCA_TARGET_CONFIG}") +file(WRITE ${T_TARGETS} "${QCA_TARGET_CONFIG}") + +# Remove unneeded dirs +file(REMOVE_RECURSE + ${CURRENT_BUILDTREES_DIR}/share/man + ${CURRENT_PACKAGES_DIR}/share/man + ${CURRENT_PACKAGES_DIR}/debug/include + ${CURRENT_PACKAGES_DIR}/debug/share +) + +message(STATUS "Patching files done") + +# Handle copyright +file(COPY ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/qca) +file(RENAME ${CURRENT_PACKAGES_DIR}/share/qca/COPYING ${CURRENT_PACKAGES_DIR}/share/qca/copyright) diff --git a/ports/qca/qca_load_qtenv.cmake b/ports/qca/qca_load_qtenv.cmake new file mode 100644 index 0000000000..ee2eb96967 --- /dev/null +++ b/ports/qca/qca_load_qtenv.cmake @@ -0,0 +1,40 @@ +# TODO: Better way to find Qt5 dir +# + +set(_QT5_FOUND FALSE) + +# Already available? +find_package(Qt5Core QUIET) +if(Qt5Core_FOUND) + message(STATUS "Qt5 found by CMake. Version: " ${Qt5Core_VERSION}) + set(_QT5_FOUND TRUE) + return() + +elseif(NOT Qt5Core_FOUND) + # Try to find Qt in the Windows Registry (just msvc2015 and msvc2015_64 for now) + if(${TRIPLET_SYSTEM_ARCH} STREQUAL "x86") + set(_QTKEY "HKEY_CURRENT_USER\\SOFTWARE\\Digia\\Versions\\msvc2015") + elseif(${TRIPLET_SYSTEM_ARCH} STREQUAL "x64") + set(_QTKEY "HKEY_CURRENT_USER\\SOFTWARE\\Digia\\Versions\\msvc2015_64") + endif() + get_filename_component(_QTPATH "[${_QTKEY};InstallDir]" ABSOLUTE) + if(NOT ${_QTPATH} STREQUAL "/registry") # Path should be ok + message(STATUS "Qt found in the registry: ${_QTPATH}") + set(QT5 ${_QTPATH}) + set(_QT5_FOUND TRUE) + endif() +endif(Qt5Core_FOUND) + +if((NOT _QT5_FOUND) AND (NOT DEFINED $ENV{QT5})) + message(STATUS " ") + message(STATUS "QT5 not found.") + message(STATUS "Please set the path to the Qt5 ${TRIPLET_SYSTEM_ARCH} toolchain dir for this session with f. e.:") + message(STATUS " \$env:QT5 = \"path\\to\\Qt\\msvc[_64]\"") + message(FATAL_ERROR "") +elseif(_QT5_FOUND AND (${TARGET_TRIPLET} STREQUAL "x64-windows" OR ${TARGET_TRIPLET} STREQUAL "x86-windows")) + #message(STATUS "Using Qt5: ${QT5}") + #set(ENV{QTDIR} ${QT5}) + set(ENV{PATH} "${QT5}/bin;$ENV{PATH}") +else() + message(FATAL_ERROR "Target triplet: ${TARGET_TRIPLET} not supported yet.") +endif() From cb778ecfbd78f03e8a9361ff9376df108f6bb906 Mon Sep 17 00:00:00 2001 From: devel71 Date: Sat, 26 Nov 2016 13:51:09 +0100 Subject: [PATCH 02/10] [qca] fix cmake file location Added qt5 Build-Depends to CONTROL file. --- ports/qca/0001-fix-path-for-vcpkg.patch | 14 ++++----- ports/qca/CONTROL | 1 + ports/qca/portfile.cmake | 38 ++++++++++++----------- ports/qca/qca_load_qtenv.cmake | 40 ------------------------- 4 files changed, 28 insertions(+), 65 deletions(-) delete mode 100644 ports/qca/qca_load_qtenv.cmake diff --git a/ports/qca/0001-fix-path-for-vcpkg.patch b/ports/qca/0001-fix-path-for-vcpkg.patch index b48fee18f9..d7764c01d1 100644 --- a/ports/qca/0001-fix-path-for-vcpkg.patch +++ b/ports/qca/0001-fix-path-for-vcpkg.patch @@ -26,11 +26,11 @@ index 605621b..a8c3774 100644 "${CMAKE_CURRENT_SOURCE_DIR}/QcaConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" - INSTALL_DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} -+ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" -+ INSTALL_DESTINATION ${CMAKE_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} ++ "${CMAKE_BINARY_DIR}/share/qca/cmake/${QCA_CONFIG_NAME_BASE}Config.cmake" ++ INSTALL_DESTINATION ${CMAKE_BINARY_DIR}/share/qca/cmake ) -write_basic_config_version_file("${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) -+write_basic_config_version_file("${CMAKE_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) ++write_basic_config_version_file("${CMAKE_BINARY_DIR}/share/qca/cmake/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" VERSION ${QCA_LIB_VERSION_STRING} COMPATIBILITY AnyNewerVersion) if(NOT DEVELOPER_MODE) @@ -39,14 +39,14 @@ index 605621b..a8c3774 100644 endif() - install(EXPORT ${QCA_CONFIG_NAME_BASE}Targets DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} FILE ${QCA_CONFIG_NAME_BASE}Targets.cmake) -+ install(EXPORT ${QCA_CONFIG_NAME_BASE}Targets DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} FILE ${QCA_CONFIG_NAME_BASE}Targets.cmake) ++ install(EXPORT ${QCA_CONFIG_NAME_BASE}Targets DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/qca/cmake FILE ${QCA_CONFIG_NAME_BASE}Targets.cmake) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" - DESTINATION ${QCA_LIBRARY_INSTALL_DIR}/cmake/${QCA_CONFIG_NAME_BASE} -+ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}Config.cmake" -+ "${CMAKE_CURRENT_BINARY_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE}/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" -+ DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/cmake/${QCA_CONFIG_NAME_BASE} ++ "${CMAKE_BINARY_DIR}/share/qca/cmake/${QCA_CONFIG_NAME_BASE}Config.cmake" ++ "${CMAKE_BINARY_DIR}/share/qca/cmake/${QCA_CONFIG_NAME_BASE}ConfigVersion.cmake" ++ DESTINATION ${QCA_PREFIX_INSTALL_DIR}/share/qca/cmake ) endif() -- diff --git a/ports/qca/CONTROL b/ports/qca/CONTROL index 84465481a1..30716ca6e8 100644 --- a/ports/qca/CONTROL +++ b/ports/qca/CONTROL @@ -1,3 +1,4 @@ Source: qca Version: 2.2.0 Description: Qt Cryptographic Api (QCA) +Build-Depends: qt5 \ No newline at end of file diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index cc391b517e..fa38970d39 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -7,7 +7,6 @@ if (VCPKG_LIBRARY_LINKAGE STREQUAL static) endif() include(vcpkg_common_functions) -include(${CMAKE_CURRENT_LIST_DIR}/qca_load_qtenv.cmake) find_program(GIT git) @@ -39,48 +38,51 @@ message(STATUS "Adding worktree done") set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/) -# Apply the patch to install 'crypto' and 'cmake targets' folder +# Apply the patch to install to the expected folders vcpkg_apply_patches( SOURCE_PATH ${SOURCE_PATH} PATCHES ${CMAKE_CURRENT_LIST_DIR}/0001-fix-path-for-vcpkg.patch ) +# Configure and build vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} CURRENT_PACKAGES_DIR ${CURRENT_PACKAGES_DIR} OPTIONS - #-DSOURCE=${SOURCE_PATH} -DBUILD_SHARED_LIBS=ON -DUSE_RELATIVE_PATHS=ON -DQT4_BUILD=OFF -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF - -DQCA_SUFFIX=qt5 + -DQCA_SUFFIX=OFF # OPTIONS_DEBUG - -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca-qt5 + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca # OPTIONS_RELEASE - -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/bin/Qca-qt5 + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/bin/Qca # ) vcpkg_install_cmake() +# Patch and copy cmake files message(STATUS "Patching files") -file(RENAME - ${CURRENT_PACKAGES_DIR}/debug/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake - ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake +file(READ + ${CURRENT_PACKAGES_DIR}/debug/share/qca/cmake/QcaTargets-debug.cmake + QCA_DEBUG_CONFIG +) +string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" QCA_DEBUG_CONFIG "${QCA_DEBUG_CONFIG}") +file(WRITE + ${CURRENT_PACKAGES_DIR}/share/qca/cmake/QcaTargets-debug.cmake + "${QCA_DEBUG_CONFIG}" ) -set(T_DEBUG ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets-debug.cmake) -set(T_TARGETS ${CURRENT_PACKAGES_DIR}/share/cmake/Qca-qt5/Qca-qt5Targets.cmake) - -file(READ ${T_DEBUG} QCA_DEBUG_CONFIG) -string(REPLACE "\${_IMPORT_PREFIX}" "\${_IMPORT_PREFIX}/debug" QCA_DEBUG_CONFIG "${QCA_DEBUG_CONFIG}") -file(WRITE ${T_DEBUG} "${QCA_DEBUG_CONFIG}") - -file(READ ${T_TARGETS} QCA_TARGET_CONFIG) +file(READ ${CURRENT_PACKAGES_DIR}/share/qca/cmake/QcaTargets.cmake + QCA_TARGET_CONFIG +) string(REPLACE "packages/qca_" "installed/" QCA_TARGET_CONFIG "${QCA_TARGET_CONFIG}") -file(WRITE ${T_TARGETS} "${QCA_TARGET_CONFIG}") +file(WRITE ${CURRENT_PACKAGES_DIR}/share/qca/cmake/QcaTargets.cmake + "${QCA_TARGET_CONFIG}" +) # Remove unneeded dirs file(REMOVE_RECURSE diff --git a/ports/qca/qca_load_qtenv.cmake b/ports/qca/qca_load_qtenv.cmake deleted file mode 100644 index ee2eb96967..0000000000 --- a/ports/qca/qca_load_qtenv.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# TODO: Better way to find Qt5 dir -# - -set(_QT5_FOUND FALSE) - -# Already available? -find_package(Qt5Core QUIET) -if(Qt5Core_FOUND) - message(STATUS "Qt5 found by CMake. Version: " ${Qt5Core_VERSION}) - set(_QT5_FOUND TRUE) - return() - -elseif(NOT Qt5Core_FOUND) - # Try to find Qt in the Windows Registry (just msvc2015 and msvc2015_64 for now) - if(${TRIPLET_SYSTEM_ARCH} STREQUAL "x86") - set(_QTKEY "HKEY_CURRENT_USER\\SOFTWARE\\Digia\\Versions\\msvc2015") - elseif(${TRIPLET_SYSTEM_ARCH} STREQUAL "x64") - set(_QTKEY "HKEY_CURRENT_USER\\SOFTWARE\\Digia\\Versions\\msvc2015_64") - endif() - get_filename_component(_QTPATH "[${_QTKEY};InstallDir]" ABSOLUTE) - if(NOT ${_QTPATH} STREQUAL "/registry") # Path should be ok - message(STATUS "Qt found in the registry: ${_QTPATH}") - set(QT5 ${_QTPATH}) - set(_QT5_FOUND TRUE) - endif() -endif(Qt5Core_FOUND) - -if((NOT _QT5_FOUND) AND (NOT DEFINED $ENV{QT5})) - message(STATUS " ") - message(STATUS "QT5 not found.") - message(STATUS "Please set the path to the Qt5 ${TRIPLET_SYSTEM_ARCH} toolchain dir for this session with f. e.:") - message(STATUS " \$env:QT5 = \"path\\to\\Qt\\msvc[_64]\"") - message(FATAL_ERROR "") -elseif(_QT5_FOUND AND (${TARGET_TRIPLET} STREQUAL "x64-windows" OR ${TARGET_TRIPLET} STREQUAL "x86-windows")) - #message(STATUS "Using Qt5: ${QT5}") - #set(ENV{QTDIR} ${QT5}) - set(ENV{PATH} "${QT5}/bin;$ENV{PATH}") -else() - message(FATAL_ERROR "Target triplet: ${TARGET_TRIPLET} not supported yet.") -endif() From 282d979c7eb8a2ebaf7a815f688245450e844b29 Mon Sep 17 00:00:00 2001 From: devel71 Date: Sat, 26 Nov 2016 13:56:01 +0100 Subject: [PATCH 03/10] [qca] fix cmake files dir Added qt5 as Build-Depends to CONTROL file. --- ports/qca/CONTROL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/qca/CONTROL b/ports/qca/CONTROL index 30716ca6e8..d3dd43ab58 100644 --- a/ports/qca/CONTROL +++ b/ports/qca/CONTROL @@ -1,4 +1,4 @@ Source: qca Version: 2.2.0 Description: Qt Cryptographic Api (QCA) -Build-Depends: qt5 \ No newline at end of file +Build-Depends: qt5 From 069fb0f9711873d30db4752138a1908e950e413a Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Wed, 30 Nov 2016 10:10:01 +0100 Subject: [PATCH 04/10] formatting portfile --- ports/qca/portfile.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index fa38970d39..0ff913025a 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -54,11 +54,11 @@ vcpkg_configure_cmake( -DQT4_BUILD=OFF -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF - -DQCA_SUFFIX=OFF # + -DQCA_SUFFIX=OFF OPTIONS_DEBUG - -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca # + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca OPTIONS_RELEASE - -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/bin/Qca # + -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/bin/Qca ) vcpkg_install_cmake() From 5a04753a4a99a6210990b25e8773b86ccbffec0b Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Wed, 30 Nov 2016 17:16:59 +0100 Subject: [PATCH 05/10] [qca] added PS script to extract local certs from store --- ports/qca/0001-fix-path-for-vcpkg.patch | 23 +++++++++++----- ports/qca/import-local-certificates.ps1 | 35 +++++++++++++++++++++++++ ports/qca/portfile.cmake | 17 +++++++++++- 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 ports/qca/import-local-certificates.ps1 diff --git a/ports/qca/0001-fix-path-for-vcpkg.patch b/ports/qca/0001-fix-path-for-vcpkg.patch index d7764c01d1..9db22af1d4 100644 --- a/ports/qca/0001-fix-path-for-vcpkg.patch +++ b/ports/qca/0001-fix-path-for-vcpkg.patch @@ -1,14 +1,14 @@ -From bab44a6614d4a540af56860432bcc0d6bdf420c9 Mon Sep 17 00:00:00 2001 -From: devel -Date: Wed, 23 Nov 2016 16:54:44 +0100 +From a3a8d50f3bdcb4df630f7126718c21f23efd7832 Mon Sep 17 00:00:00 2001 +From: Alexander Kaspar +Date: Wed, 30 Nov 2016 15:45:12 +0100 Subject: [PATCH] fix path for vcpkg --- - CMakeLists.txt | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) + CMakeLists.txt | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt -index 605621b..a8c3774 100644 +index 605621b..3b5a9be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,7 +277,7 @@ if(DEVELOPER_MODE) @@ -20,6 +20,15 @@ index 605621b..a8c3774 100644 ") endif() +@@ -320,7 +320,7 @@ else (qca_CERTSTORE) + set( qca_CERTSTORE "${CMAKE_CURRENT_SOURCE_DIR}/certs/rootcerts.pem") + # note that INSTALL_FILES targets are relative to the current installation prefix... + if(NOT DEVELOPER_MODE) +- install(FILES "${qca_CERTSTORE}" DESTINATION "${QCA_PREFIX_INSTALL_DIR}/certs") ++ install(FILES "${qca_CERTSTORE}" DESTINATION "${QCA_PREFIX_INSTALL_DIR}/share/qca/certs") + endif() + endif (qca_CERTSTORE) + message(STATUS "certstore path: " ${qca_CERTSTORE}) @@ -401,10 +401,10 @@ endif(DOXYGEN_FOUND) include(CMakePackageConfigHelpers) configure_package_config_file( @@ -50,5 +59,5 @@ index 605621b..a8c3774 100644 ) endif() -- -2.9.2.windows.1 +2.8.1.windows.1 diff --git a/ports/qca/import-local-certificates.ps1 b/ports/qca/import-local-certificates.ps1 new file mode 100644 index 0000000000..94e68e7661 --- /dev/null +++ b/ports/qca/import-local-certificates.ps1 @@ -0,0 +1,35 @@ +# According to: +# https://www.openssl.org/docs/faq.html#USER16 +# it is up to developers or admins to maintain CAs. +# +# This script imports LocalMachine certificates into rootcerts.pem +# needed by qca. +# +# PS> .\import-local-certificates.ps1 -certstore Root -outpath C:\src\git\vcpkg\ports\qca +# + +param ( + # one of Root, My, CA, ... + [string]$certstore = "Root", + # the path where it should be in qca buildtree (without trailing '\') + [Parameter(Mandatory=$true)][string]$outpath +) + +$certs = (Get-ChildItem -Path 'Cert:\LocalMachine\Root') +$outfile = $outpath + "\rootcerts.pem" + +Write-Host "Importing: " $certs.Count " certificates ..." + +foreach ($cert in $certs) +{ + $certs.GetIssuerName() + $out = New-Object String[] -ArgumentList 3 + $out[0] = "-----BEGIN CERTIFICATE-----" + $out[1] = [System.Convert]::ToBase64String($cert.PublicKey.EncodedKeyValue.RawData, "InsertLineBreaks") + $out[2] = "-----END CERTIFICATE-----" + + [System.IO.File]::AppendAllLines($outfile, $out) +} + +Write-Host "Written to: " $outfile +Write-Host "Importing certificates done." diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index 0ff913025a..b92596ef95 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -53,8 +53,9 @@ vcpkg_configure_cmake( -DUSE_RELATIVE_PATHS=ON -DQT4_BUILD=OFF -DBUILD_TESTS=OFF - -DBUILD_TOOLS=OFF + -DBUILD_TOOLS=ON -DQCA_SUFFIX=OFF + -DQCA_FEATURE_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/share/qca/mkspecs/features OPTIONS_DEBUG -DQCA_PLUGINS_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/debug/bin/Qca OPTIONS_RELEASE @@ -84,6 +85,20 @@ file(WRITE ${CURRENT_PACKAGES_DIR}/share/qca/cmake/QcaTargets.cmake "${QCA_TARGET_CONFIG}" ) +# Move tools +file(COPY ${CURRENT_PACKAGES_DIR}/bin/mozcerts.exe + DESTINATION ${CURRENT_PACKAGES_DIR}/share/qca/tools +) +file(COPY ${CURRENT_PACKAGES_DIR}/bin/qcatool.exe + DESTINATION ${CURRENT_PACKAGES_DIR}/share/qca/tools +) +file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/mozcerts.exe + ${CURRENT_PACKAGES_DIR}/bin/qcatool.exe + ${CURRENT_PACKAGES_DIR}/debug/bin/mozcerts.exe + ${CURRENT_PACKAGES_DIR}/debug/bin/mozcerts.pdb + ${CURRENT_PACKAGES_DIR}/debug/bin/qcatool.exe +) + # Remove unneeded dirs file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/share/man From 03cdf1dc97f05b7fc290c6c6eac1306aae1605ba Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Wed, 30 Nov 2016 21:34:35 +0100 Subject: [PATCH 06/10] [qca] import local certs --- ports/qca/import-local-certificates.ps1 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ports/qca/import-local-certificates.ps1 b/ports/qca/import-local-certificates.ps1 index 94e68e7661..d0e644a50d 100644 --- a/ports/qca/import-local-certificates.ps1 +++ b/ports/qca/import-local-certificates.ps1 @@ -22,13 +22,8 @@ Write-Host "Importing: " $certs.Count " certificates ..." foreach ($cert in $certs) { - $certs.GetIssuerName() - $out = New-Object String[] -ArgumentList 3 - $out[0] = "-----BEGIN CERTIFICATE-----" - $out[1] = [System.Convert]::ToBase64String($cert.PublicKey.EncodedKeyValue.RawData, "InsertLineBreaks") - $out[2] = "-----END CERTIFICATE-----" - - [System.IO.File]::AppendAllLines($outfile, $out) + $outfile = $outpath + "/" + $cert.Thumbprint + ".cer" + Export-Certificate -Cert $cert -FilePath $outfile } Write-Host "Written to: " $outfile From 0f797c7a0127e2575e3ac0ad56d829383ec5b5ae Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Thu, 1 Dec 2016 13:43:36 +0100 Subject: [PATCH 07/10] [qca] working on certstore --- ports/qca/CONTROL | 2 +- ports/qca/import-local-certificates.ps1 | 17 +++++++++---- ports/qca/portfile.cmake | 34 ++++++++++++------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ports/qca/CONTROL b/ports/qca/CONTROL index d3dd43ab58..cbe923bb49 100644 --- a/ports/qca/CONTROL +++ b/ports/qca/CONTROL @@ -1,4 +1,4 @@ Source: qca Version: 2.2.0 -Description: Qt Cryptographic Api (QCA) +Description: Qt Cryptographic Architecture (QCA). Sources: https://cgit.kde.org/qca.git/ Build-Depends: qt5 diff --git a/ports/qca/import-local-certificates.ps1 b/ports/qca/import-local-certificates.ps1 index d0e644a50d..df39cbb014 100644 --- a/ports/qca/import-local-certificates.ps1 +++ b/ports/qca/import-local-certificates.ps1 @@ -5,7 +5,7 @@ # This script imports LocalMachine certificates into rootcerts.pem # needed by qca. # -# PS> .\import-local-certificates.ps1 -certstore Root -outpath C:\src\git\vcpkg\ports\qca +# PS> .\import-local-certificates.ps1 [-certstore Root] -outpath C:\src\git\vcpkg\ports\qca # param ( @@ -15,15 +15,22 @@ param ( [Parameter(Mandatory=$true)][string]$outpath ) -$certs = (Get-ChildItem -Path 'Cert:\LocalMachine\Root') -$outfile = $outpath + "\rootcerts.pem" +$certs = (Get-ChildItem -Path 'Cert:\LocalMachine\Root' -EKU "Server Authentication") +$outfile = $outpath + "rootcerts.pem" Write-Host "Importing: " $certs.Count " certificates ..." foreach ($cert in $certs) { - $outfile = $outpath + "/" + $cert.Thumbprint + ".cer" - Export-Certificate -Cert $cert -FilePath $outfile + $out = New-Object String[] -ArgumentList 5 + + $out[0] = " " + $out[1] = "# " + $cert.Issuer + $out[2] = "-----BEGIN CERTIFICATE-----" + $out[3] = $([Convert]::ToBase64String($cert.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks)) + $out[4] = "-----END CERTIFICATE-----" + + [System.IO.File]::AppendAllLines($outfile,$out) } Write-Host "Written to: " $outfile diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index b92596ef95..bdb5ac1533 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -1,4 +1,8 @@ -# For now only x[64|86]-windows triplet and dynamic linking is supported +# This portfile adds the Qt Cryptographic Arcitecture +# Changes to the original sources by this file: +# No -qt5 suffix, which is recommended just for Linux +# Output directories according to vcpkg +# Updated certstore. See certstore.pem in the output dirs # if (VCPKG_LIBRARY_LINKAGE STREQUAL static) @@ -44,6 +48,16 @@ vcpkg_apply_patches( PATCHES ${CMAKE_CURRENT_LIST_DIR}/0001-fix-path-for-vcpkg.patch ) +# Importing local certificates +message(STATUS "Importing certstore") +file(REMOVE ${SOURCE_PATH}/certs/rootcerts.pem) +vcpkg_execute_required_process( + COMMAND "& ${CMAKE_CURRENT_LIST_DIR}/import-local-certificates.ps1 -outpath ${SOURCE_PATH}/certs/" + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + LOGNAME certimport +) +message(STATUS "Importing certstore done") + # Configure and build vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} @@ -53,7 +67,7 @@ vcpkg_configure_cmake( -DUSE_RELATIVE_PATHS=ON -DQT4_BUILD=OFF -DBUILD_TESTS=OFF - -DBUILD_TOOLS=ON + -DBUILD_TOOLS=OFF -DQCA_SUFFIX=OFF -DQCA_FEATURE_INSTALL_DIR=${CURRENT_PACKAGES_DIR}/share/qca/mkspecs/features OPTIONS_DEBUG @@ -66,7 +80,6 @@ vcpkg_install_cmake() # Patch and copy cmake files message(STATUS "Patching files") - file(READ ${CURRENT_PACKAGES_DIR}/debug/share/qca/cmake/QcaTargets-debug.cmake QCA_DEBUG_CONFIG @@ -85,20 +98,6 @@ file(WRITE ${CURRENT_PACKAGES_DIR}/share/qca/cmake/QcaTargets.cmake "${QCA_TARGET_CONFIG}" ) -# Move tools -file(COPY ${CURRENT_PACKAGES_DIR}/bin/mozcerts.exe - DESTINATION ${CURRENT_PACKAGES_DIR}/share/qca/tools -) -file(COPY ${CURRENT_PACKAGES_DIR}/bin/qcatool.exe - DESTINATION ${CURRENT_PACKAGES_DIR}/share/qca/tools -) -file(REMOVE ${CURRENT_PACKAGES_DIR}/bin/mozcerts.exe - ${CURRENT_PACKAGES_DIR}/bin/qcatool.exe - ${CURRENT_PACKAGES_DIR}/debug/bin/mozcerts.exe - ${CURRENT_PACKAGES_DIR}/debug/bin/mozcerts.pdb - ${CURRENT_PACKAGES_DIR}/debug/bin/qcatool.exe -) - # Remove unneeded dirs file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/share/man @@ -106,7 +105,6 @@ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include ${CURRENT_PACKAGES_DIR}/debug/share ) - message(STATUS "Patching files done") # Handle copyright From 13b0c034ecfc78c683d1924334370f5cfcbeab71 Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Fri, 2 Dec 2016 10:12:57 +0100 Subject: [PATCH 08/10] [qca] downloading cacerts from curl homepage, because used version is very outdated. --- ports/qca/portfile.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index bdb5ac1533..dc360af877 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -48,13 +48,18 @@ vcpkg_apply_patches( PATCHES ${CMAKE_CURRENT_LIST_DIR}/0001-fix-path-for-vcpkg.patch ) -# Importing local certificates +# According to: +# https://www.openssl.org/docs/faq.html#USER16 +# it is up to developers or admins to maintain CAs. +# So we do it here: +# Importing certificates from curl maintainers +# See: https://curl.haxx.se/docs/caextract.html message(STATUS "Importing certstore") file(REMOVE ${SOURCE_PATH}/certs/rootcerts.pem) -vcpkg_execute_required_process( - COMMAND "& ${CMAKE_CURRENT_LIST_DIR}/import-local-certificates.ps1 -outpath ${SOURCE_PATH}/certs/" - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - LOGNAME certimport +file(DOWNLOAD https://curl.haxx.se/ca/cacert.pem + ${SOURCE_PATH}/certs/rootcerts.pem + SHOW_PROGRESS + TLS_VERIFY ON ) message(STATUS "Importing certstore done") From 26793bd449ae34e6a781e765cd364eb16c0e6337 Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Sat, 3 Dec 2016 12:41:39 +0100 Subject: [PATCH 09/10] [qca] Added mk-ca-bundle.pl to generate certstore at build time. --- ports/qca/mk-ca-bundle.pl | 554 ++++++++++++++++++++++++++++++++++++++ ports/qca/portfile.cmake | 18 +- 2 files changed, 566 insertions(+), 6 deletions(-) create mode 100644 ports/qca/mk-ca-bundle.pl diff --git a/ports/qca/mk-ca-bundle.pl b/ports/qca/mk-ca-bundle.pl new file mode 100644 index 0000000000..9574f1dbf9 --- /dev/null +++ b/ports/qca/mk-ca-bundle.pl @@ -0,0 +1,554 @@ +#!/usr/bin/perl -w +# *************************************************************************** +# * _ _ ____ _ +# * Project ___| | | | _ \| | +# * / __| | | | |_) | | +# * | (__| |_| | _ <| |___ +# * \___|\___/|_| \_\_____| +# * +# * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. +# * +# * This software is licensed as described in the file COPYING, which +# * you should have received as part of this distribution. The terms +# * are also available at https://curl.haxx.se/docs/copyright.html. +# * +# * You may opt to use, copy, modify, merge, publish, distribute and/or sell +# * copies of the Software, and permit persons to whom the Software is +# * furnished to do so, under the terms of the COPYING file. +# * +# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# * KIND, either express or implied. +# * +# *************************************************************************** +# This Perl script creates a fresh ca-bundle.crt file for use with libcurl. +# It downloads certdata.txt from Mozilla's source tree (see URL below), +# then parses certdata.txt and extracts CA Root Certificates into PEM format. +# These are then processed with the OpenSSL commandline tool to produce the +# final ca-bundle.crt file. +# The script is based on the parse-certs script written by Roland Krikava. +# This Perl script works on almost any platform since its only external +# dependency is the OpenSSL commandline tool for optional text listing. +# Hacked by Guenter Knauf. +# +use Encode; +use Getopt::Std; +use MIME::Base64; +use strict; +use vars qw($opt_b $opt_d $opt_f $opt_h $opt_i $opt_k $opt_l $opt_m $opt_n $opt_p $opt_q $opt_s $opt_t $opt_u $opt_v $opt_w); +use List::Util; +use Text::Wrap; +my $MOD_SHA = "Digest::SHA"; +eval "require $MOD_SHA"; +if ($@) { + $MOD_SHA = "Digest::SHA::PurePerl"; + eval "require $MOD_SHA"; +} +eval "require LWP::UserAgent"; + +my %urls = ( + 'nss' => + 'https://hg.mozilla.org/projects/nss/raw-file/tip/lib/ckfw/builtins/certdata.txt', + 'central' => + 'https://hg.mozilla.org/mozilla-central/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'aurora' => + 'https://hg.mozilla.org/releases/mozilla-aurora/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'beta' => + 'https://hg.mozilla.org/releases/mozilla-beta/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'release' => + 'https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', +); + +$opt_d = 'release'; + +# If the OpenSSL commandline is not in search path you can configure it here! +my $openssl = 'openssl'; + +my $version = '1.27'; + +$opt_w = 76; # default base64 encoded lines length + +# default cert types to include in the output (default is to include CAs which may issue SSL server certs) +my $default_mozilla_trust_purposes = "SERVER_AUTH"; +my $default_mozilla_trust_levels = "TRUSTED_DELEGATOR"; +$opt_p = $default_mozilla_trust_purposes . ":" . $default_mozilla_trust_levels; + +my @valid_mozilla_trust_purposes = ( + "DIGITAL_SIGNATURE", + "NON_REPUDIATION", + "KEY_ENCIPHERMENT", + "DATA_ENCIPHERMENT", + "KEY_AGREEMENT", + "KEY_CERT_SIGN", + "CRL_SIGN", + "SERVER_AUTH", + "CLIENT_AUTH", + "CODE_SIGNING", + "EMAIL_PROTECTION", + "IPSEC_END_SYSTEM", + "IPSEC_TUNNEL", + "IPSEC_USER", + "TIME_STAMPING", + "STEP_UP_APPROVED" +); + +my @valid_mozilla_trust_levels = ( + "TRUSTED_DELEGATOR", # CAs + "NOT_TRUSTED", # Don't trust these certs. + "MUST_VERIFY_TRUST", # This explicitly tells us that it ISN'T a CA but is otherwise ok. In other words, this should tell the app to ignore any other sources that claim this is a CA. + "TRUSTED" # This cert is trusted, but only for itself and not for delegates (i.e. it is not a CA). +); + +my $default_signature_algorithms = $opt_s = "MD5"; + +my @valid_signature_algorithms = ( + "MD5", + "SHA1", + "SHA256", + "SHA384", + "SHA512" +); + +$0 =~ s@.*(/|\\)@@; +$Getopt::Std::STANDARD_HELP_VERSION = 1; +getopts('bd:fhiklmnp:qs:tuvw:'); + +if(!defined($opt_d)) { + # to make plain "-d" use not cause warnings, and actually still work + $opt_d = 'release'; +} + +# Use predefined URL or else custom URL specified on command line. +my $url; +if(defined($urls{$opt_d})) { + $url = $urls{$opt_d}; + if(!$opt_k && $url !~ /^https:\/\//i) { + die "The URL for '$opt_d' is not HTTPS. Use -k to override (insecure).\n"; + } +} +else { + $url = $opt_d; +} + +my $curl = `curl -V`; + +if ($opt_i) { + print ("=" x 78 . "\n"); + print "Script Version : $version\n"; + print "Perl Version : $]\n"; + print "Operating System Name : $^O\n"; + print "Getopt::Std.pm Version : ${Getopt::Std::VERSION}\n"; + print "MIME::Base64.pm Version : ${MIME::Base64::VERSION}\n"; + print "LWP::UserAgent.pm Version : ${LWP::UserAgent::VERSION}\n" if($LWP::UserAgent::VERSION); + print "LWP.pm Version : ${LWP::VERSION}\n" if($LWP::VERSION); + print "Digest::SHA.pm Version : ${Digest::SHA::VERSION}\n" if ($Digest::SHA::VERSION); + print "Digest::SHA::PurePerl.pm Version : ${Digest::SHA::PurePerl::VERSION}\n" if ($Digest::SHA::PurePerl::VERSION); + print ("=" x 78 . "\n"); +} + +sub warning_message() { + if ( $opt_d =~ m/^risk$/i ) { # Long Form Warning and Exit + print "Warning: Use of this script may pose some risk:\n"; + print "\n"; + print " 1) If you use HTTP URLs they are subject to a man in the middle attack\n"; + print " 2) Default to 'release', but more recent updates may be found in other trees\n"; + print " 3) certdata.txt file format may change, lag time to update this script\n"; + print " 4) Generally unwise to blindly trust CAs without manual review & verification\n"; + print " 5) Mozilla apps use additional security checks aren't represented in certdata\n"; + print " 6) Use of this script will make a security engineer grind his teeth and\n"; + print " swear at you. ;)\n"; + exit; + } else { # Short Form Warning + print "Warning: Use of this script may pose some risk, -d risk for more details.\n"; + } +} + +sub HELP_MESSAGE() { + print "Usage:\t${0} [-b] [-d] [-f] [-i] [-k] [-l] [-n] [-p] [-q] [-s] [-t] [-u] [-v] [-w] []\n"; + print "\t-b\tbackup an existing version of ca-bundle.crt\n"; + print "\t-d\tspecify Mozilla tree to pull certdata.txt or custom URL\n"; + print "\t\t Valid names are:\n"; + print "\t\t ", join( ", ", map { ( $_ =~ m/$opt_d/ ) ? "$_ (default)" : "$_" } sort keys %urls ), "\n"; + print "\t-f\tforce rebuild even if certdata.txt is current\n"; + print "\t-i\tprint version info about used modules\n"; + print "\t-k\tallow URLs other than HTTPS, enable HTTP fallback (insecure)\n"; + print "\t-l\tprint license info about certdata.txt\n"; + print "\t-m\tinclude meta data in output\n"; + print "\t-n\tno download of certdata.txt (to use existing)\n"; + print wrap("\t","\t\t", "-p\tlist of Mozilla trust purposes and levels for certificates to include in output. Takes the form of a comma separated list of purposes, a colon, and a comma separated list of levels. (default: $default_mozilla_trust_purposes:$default_mozilla_trust_levels)"), "\n"; + print "\t\t Valid purposes are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_purposes ) ), "\n"; + print "\t\t Valid levels are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_levels ) ), "\n"; + print "\t-q\tbe really quiet (no progress output at all)\n"; + print wrap("\t","\t\t", "-s\tcomma separated list of certificate signatures/hashes to output in plain text mode. (default: $default_signature_algorithms)\n"); + print "\t\t Valid signature algorithms are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_signature_algorithms ) ), "\n"; + print "\t-t\tinclude plain text listing of certificates\n"; + print "\t-u\tunlink (remove) certdata.txt after processing\n"; + print "\t-v\tbe verbose and print out processed CAs\n"; + print "\t-w \twrap base64 output lines after chars (default: ${opt_w})\n"; + exit; +} + +sub VERSION_MESSAGE() { + print "${0} version ${version} running Perl ${]} on ${^O}\n"; +} + +warning_message() unless ($opt_q || $url =~ m/^(ht|f)tps:/i ); +HELP_MESSAGE() if ($opt_h); + +sub report($@) { + my $output = shift; + + print STDERR $output . "\n" unless $opt_q; +} + +sub is_in_list($@) { + my $target = shift; + + return defined(List::Util::first { $target eq $_ } @_); +} + +# Parses $param_string as a case insensitive comma separated list with optional whitespace +# validates that only allowed parameters are supplied +sub parse_csv_param($$@) { + my $description = shift; + my $param_string = shift; + my @valid_values = @_; + + my @values = map { + s/^\s+//; # strip leading spaces + s/\s+$//; # strip trailing spaces + uc $_ # return the modified string as upper case + } split( ',', $param_string ); + + # Find all values which are not in the list of valid values or "ALL" + my @invalid = grep { !is_in_list($_,"ALL",@valid_values) } @values; + + if ( scalar(@invalid) > 0 ) { + # Tell the user which parameters were invalid and print the standard help message which will exit + print "Error: Invalid ", $description, scalar(@invalid) == 1 ? ": " : "s: ", join( ", ", map { "\"$_\"" } @invalid ), "\n"; + HELP_MESSAGE(); + } + + @values = @valid_values if ( is_in_list("ALL",@values) ); + + return @values; +} + +sub sha256 { + my $result; + if ($Digest::SHA::VERSION || $Digest::SHA::PurePerl::VERSION) { + open(FILE, $_[0]) or die "Can't open '$_[0]': $!"; + binmode(FILE); + $result = $MOD_SHA->new(256)->addfile(*FILE)->hexdigest; + close(FILE); + } else { + # Use OpenSSL command if Perl Digest::SHA modules not available + $result = `"$openssl" dgst -r -sha256 "$_[0]"`; + $result =~ s/^([0-9a-f]{64}) .+/$1/is; + } + return $result; +} + + +sub oldhash { + my $hash = ""; + open(C, "<$_[0]") || return 0; + while() { + chomp; + if($_ =~ /^\#\# SHA256: (.*)/) { + $hash = $1; + last; + } + } + close(C); + return $hash; +} + +if ( $opt_p !~ m/:/ ) { + print "Error: Mozilla trust identifier list must include both purposes and levels\n"; + HELP_MESSAGE(); +} + +(my $included_mozilla_trust_purposes_string, my $included_mozilla_trust_levels_string) = split( ':', $opt_p ); +my @included_mozilla_trust_purposes = parse_csv_param( "trust purpose", $included_mozilla_trust_purposes_string, @valid_mozilla_trust_purposes ); +my @included_mozilla_trust_levels = parse_csv_param( "trust level", $included_mozilla_trust_levels_string, @valid_mozilla_trust_levels ); + +my @included_signature_algorithms = parse_csv_param( "signature algorithm", $opt_s, @valid_signature_algorithms ); + +sub should_output_cert(%) { + my %trust_purposes_by_level = @_; + + foreach my $level (@included_mozilla_trust_levels) { + # for each level we want to output, see if any of our desired purposes are included + return 1 if ( defined( List::Util::first { is_in_list( $_, @included_mozilla_trust_purposes ) } @{$trust_purposes_by_level{$level}} ) ); + } + + return 0; +} + +my $crt = $ARGV[0] || 'ca-bundle.crt'; +(my $txt = $url) =~ s@(.*/|\?.*)@@g; + +my $stdout = $crt eq '-'; +my $resp; +my $fetched; + +my $oldhash = oldhash($crt); + +report "SHA256 of old file: $oldhash"; + +if(!$opt_n) { + report "Downloading $txt ..."; + + # If we have an HTTPS URL then use curl + if($url =~ /^https:\/\//i) { + if($curl) { + if($curl =~ /^Protocols:.* https( |$)/m) { + report "Get certdata with curl!"; + my $proto = !$opt_k ? "--proto =https" : ""; + my $quiet = $opt_q ? "-s" : ""; + my @out = `curl -w %{response_code} $proto $quiet -o "$txt" "$url"`; + if(@out && $out[0] == 200) { + $fetched = 1; + report "Downloaded $txt"; + } + else { + report "Failed downloading via HTTPS with curl"; + if(-e $txt && !unlink($txt)) { + report "Failed to remove '$txt': $!"; + } + } + } + else { + report "curl lacks https support"; + } + } + else { + report "curl not found"; + } + } + + # If nothing was fetched then use LWP + if(!$fetched) { + if($url =~ /^https:\/\//i) { + report "Falling back to HTTP"; + $url =~ s/^https:\/\//http:\/\//i; + } + if(!$opt_k) { + report "URLs other than HTTPS are disabled by default, to enable use -k"; + exit 1; + } + report "Get certdata with LWP!"; + if(!defined(${LWP::UserAgent::VERSION})) { + report "LWP is not available (LWP::UserAgent not found)"; + exit 1; + } + my $ua = new LWP::UserAgent(agent => "$0/$version"); + $ua->env_proxy(); + $resp = $ua->mirror($url, $txt); + if($resp && $resp->code eq '304') { + report "Not modified"; + exit 0 if -e $crt && !$opt_f; + } + else { + $fetched = 1; + report "Downloaded $txt"; + } + if(!$resp || $resp->code !~ /^(?:200|304)$/) { + report "Unable to download latest data: " + . ($resp? $resp->code . ' - ' . $resp->message : "LWP failed"); + exit 1 if -e $crt || ! -r $txt; + } + } +} + +my $filedate = $resp ? $resp->last_modified : (stat($txt))[9]; +my $datesrc = "as of"; +if(!$filedate) { + # mxr.mozilla.org gave us a time, hg.mozilla.org does not! + $filedate = time(); + $datesrc="downloaded on"; +} + +# get the hash from the download file +my $newhash= sha256($txt); + +if(!$opt_f && $oldhash eq $newhash) { + report "Downloaded file identical to previous run\'s source file. Exiting"; + exit; +} + +report "SHA256 of new file: $newhash"; + +my $currentdate = scalar gmtime($filedate); + +my $format = $opt_t ? "plain text and " : ""; +if( $stdout ) { + open(CRT, '> -') or die "Couldn't open STDOUT: $!\n"; +} else { + open(CRT,">$crt.~") or die "Couldn't open $crt.~: $!\n"; +} +print CRT <) { + if (/\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*/) { + print CRT; + print if ($opt_l); + while () { + print CRT; + print if ($opt_l); + last if (/\*\*\*\*\* END LICENSE BLOCK \*\*\*\*\*/); + } + } + elsif(/^# (Issuer|Serial Number|Subject|Not Valid Before|Not Valid After |Fingerprint \(MD5\)|Fingerprint \(SHA1\)):/) { + push @precert, $_; + next; + } + elsif(/^#|^\s*$/) { + undef @precert; + next; + } + chomp; + + # this is a match for the start of a certificate + if (/^CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE/) { + $start_of_cert = 1 + } + if ($start_of_cert && /^CKA_LABEL UTF8 \"(.*)\"/) { + $caname = $1; + } + my %trust_purposes_by_level; + if ($start_of_cert && /^CKA_VALUE MULTILINE_OCTAL/) { + my $data; + while () { + last if (/^END/); + chomp; + my @octets = split(/\\/); + shift @octets; + for (@octets) { + $data .= chr(oct); + } + } + # scan forwards until the trust part + while () { + last if (/^CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST/); + chomp; + } + # now scan the trust part to determine how we should trust this cert + while () { + last if (/^#/); + if (/^CKA_TRUST_([A-Z_]+)\s+CK_TRUST\s+CKT_NSS_([A-Z_]+)\s*$/) { + if ( !is_in_list($1,@valid_mozilla_trust_purposes) ) { + report "Warning: Unrecognized trust purpose for cert: $caname. Trust purpose: $1. Trust Level: $2"; + } elsif ( !is_in_list($2,@valid_mozilla_trust_levels) ) { + report "Warning: Unrecognized trust level for cert: $caname. Trust purpose: $1. Trust Level: $2"; + } else { + push @{$trust_purposes_by_level{$2}}, $1; + } + } + } + + if ( !should_output_cert(%trust_purposes_by_level) ) { + $skipnum ++; + } else { + my $encoded = MIME::Base64::encode_base64($data, ''); + $encoded =~ s/(.{1,${opt_w}})/$1\n/g; + my $pem = "-----BEGIN CERTIFICATE-----\n" + . $encoded + . "-----END CERTIFICATE-----\n"; + print CRT "\n$caname\n"; + print CRT @precert if($opt_m); + my $maxStringLength = length(decode('UTF-8', $caname, Encode::FB_CROAK)); + if ($opt_t) { + foreach my $key (keys %trust_purposes_by_level) { + my $string = $key . ": " . join(", ", @{$trust_purposes_by_level{$key}}); + $maxStringLength = List::Util::max( length($string), $maxStringLength ); + print CRT $string . "\n"; + } + } + print CRT ("=" x $maxStringLength . "\n"); + if (!$opt_t) { + print CRT $pem; + } else { + my $pipe = ""; + foreach my $hash (@included_signature_algorithms) { + $pipe = "|$openssl x509 -" . $hash . " -fingerprint -noout -inform PEM"; + if (!$stdout) { + $pipe .= " >> $crt.~"; + close(CRT) or die "Couldn't close $crt.~: $!"; + } + open(TMP, $pipe) or die "Couldn't open openssl pipe: $!"; + print TMP $pem; + close(TMP) or die "Couldn't close openssl pipe: $!"; + if (!$stdout) { + open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!"; + } + } + $pipe = "|$openssl x509 -text -inform PEM"; + if (!$stdout) { + $pipe .= " >> $crt.~"; + close(CRT) or die "Couldn't close $crt.~: $!"; + } + open(TMP, $pipe) or die "Couldn't open openssl pipe: $!"; + print TMP $pem; + close(TMP) or die "Couldn't close openssl pipe: $!"; + if (!$stdout) { + open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!"; + } + } + report "Parsing: $caname" if ($opt_v); + $certnum ++; + $start_of_cert = 0; + } + undef @precert; + } + +} +close(TXT) or die "Couldn't close $txt: $!\n"; +close(CRT) or die "Couldn't close $crt.~: $!\n"; +unless( $stdout ) { + if ($opt_b && -e $crt) { + my $bk = 1; + while (-e "$crt.~${bk}~") { + $bk++; + } + rename $crt, "$crt.~${bk}~" or die "Failed to create backup $crt.~$bk}~: $!\n"; + } elsif( -e $crt ) { + unlink( $crt ) or die "Failed to remove $crt: $!\n"; + } + rename "$crt.~", $crt or die "Failed to rename $crt.~ to $crt: $!\n"; +} +if($opt_u && -e $txt && !unlink($txt)) { + report "Failed to remove $txt: $!\n"; +} +report "Done ($certnum CA certs processed, $skipnum skipped)."; diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index dc360af877..3050de917b 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -1,5 +1,5 @@ # This portfile adds the Qt Cryptographic Arcitecture -# Changes to the original sources by this file: +# Changes to the original build: # No -qt5 suffix, which is recommended just for Linux # Output directories according to vcpkg # Updated certstore. See certstore.pem in the output dirs @@ -13,6 +13,9 @@ endif() include(vcpkg_common_functions) find_program(GIT git) +vcpkg_find_acquire_program(PERL) +get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY) +set(ENV{PATH} "${PERL_EXE_PATH};$ENV{PATH}") # Set git variables to qca version 2.2.0 commit set(GIT_URL "git://anongit.kde.org/qca.git") @@ -52,15 +55,18 @@ vcpkg_apply_patches( # https://www.openssl.org/docs/faq.html#USER16 # it is up to developers or admins to maintain CAs. # So we do it here: -# Importing certificates from curl maintainers -# See: https://curl.haxx.se/docs/caextract.html message(STATUS "Importing certstore") file(REMOVE ${SOURCE_PATH}/certs/rootcerts.pem) -file(DOWNLOAD https://curl.haxx.se/ca/cacert.pem - ${SOURCE_PATH}/certs/rootcerts.pem - SHOW_PROGRESS +# Using file(DOWNLOAD) to use https +file(DOWNLOAD https://hg.mozilla.org/projects/nss/raw-file/tip/lib/ckfw/builtins/certdata.txt + ${CMAKE_CURRENT_LIST_DIR}/certdata.txt TLS_VERIFY ON ) +vcpkg_execute_required_process( + COMMAND ${PERL} ${CMAKE_CURRENT_LIST_DIR}/mk-ca-bundle.pl -n ${SOURCE_PATH}/certs/rootcerts.pem + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + LOGNAME ca-bundle +) message(STATUS "Importing certstore done") # Configure and build From bf187f318a735307bcf0a42c3879f00293e477cf Mon Sep 17 00:00:00 2001 From: Alexander Kaspar Date: Sat, 3 Dec 2016 12:41:39 +0100 Subject: [PATCH 10/10] [qca] Added mk-ca-bundle.pl to generate certstore at build time. --- ports/qca/import-local-certificates.ps1 | 37 -- ports/qca/mk-ca-bundle.pl | 554 ++++++++++++++++++++++++ ports/qca/portfile.cmake | 18 +- 3 files changed, 566 insertions(+), 43 deletions(-) delete mode 100644 ports/qca/import-local-certificates.ps1 create mode 100644 ports/qca/mk-ca-bundle.pl diff --git a/ports/qca/import-local-certificates.ps1 b/ports/qca/import-local-certificates.ps1 deleted file mode 100644 index df39cbb014..0000000000 --- a/ports/qca/import-local-certificates.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -# According to: -# https://www.openssl.org/docs/faq.html#USER16 -# it is up to developers or admins to maintain CAs. -# -# This script imports LocalMachine certificates into rootcerts.pem -# needed by qca. -# -# PS> .\import-local-certificates.ps1 [-certstore Root] -outpath C:\src\git\vcpkg\ports\qca -# - -param ( - # one of Root, My, CA, ... - [string]$certstore = "Root", - # the path where it should be in qca buildtree (without trailing '\') - [Parameter(Mandatory=$true)][string]$outpath -) - -$certs = (Get-ChildItem -Path 'Cert:\LocalMachine\Root' -EKU "Server Authentication") -$outfile = $outpath + "rootcerts.pem" - -Write-Host "Importing: " $certs.Count " certificates ..." - -foreach ($cert in $certs) -{ - $out = New-Object String[] -ArgumentList 5 - - $out[0] = " " - $out[1] = "# " + $cert.Issuer - $out[2] = "-----BEGIN CERTIFICATE-----" - $out[3] = $([Convert]::ToBase64String($cert.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks)) - $out[4] = "-----END CERTIFICATE-----" - - [System.IO.File]::AppendAllLines($outfile,$out) -} - -Write-Host "Written to: " $outfile -Write-Host "Importing certificates done." diff --git a/ports/qca/mk-ca-bundle.pl b/ports/qca/mk-ca-bundle.pl new file mode 100644 index 0000000000..9574f1dbf9 --- /dev/null +++ b/ports/qca/mk-ca-bundle.pl @@ -0,0 +1,554 @@ +#!/usr/bin/perl -w +# *************************************************************************** +# * _ _ ____ _ +# * Project ___| | | | _ \| | +# * / __| | | | |_) | | +# * | (__| |_| | _ <| |___ +# * \___|\___/|_| \_\_____| +# * +# * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. +# * +# * This software is licensed as described in the file COPYING, which +# * you should have received as part of this distribution. The terms +# * are also available at https://curl.haxx.se/docs/copyright.html. +# * +# * You may opt to use, copy, modify, merge, publish, distribute and/or sell +# * copies of the Software, and permit persons to whom the Software is +# * furnished to do so, under the terms of the COPYING file. +# * +# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# * KIND, either express or implied. +# * +# *************************************************************************** +# This Perl script creates a fresh ca-bundle.crt file for use with libcurl. +# It downloads certdata.txt from Mozilla's source tree (see URL below), +# then parses certdata.txt and extracts CA Root Certificates into PEM format. +# These are then processed with the OpenSSL commandline tool to produce the +# final ca-bundle.crt file. +# The script is based on the parse-certs script written by Roland Krikava. +# This Perl script works on almost any platform since its only external +# dependency is the OpenSSL commandline tool for optional text listing. +# Hacked by Guenter Knauf. +# +use Encode; +use Getopt::Std; +use MIME::Base64; +use strict; +use vars qw($opt_b $opt_d $opt_f $opt_h $opt_i $opt_k $opt_l $opt_m $opt_n $opt_p $opt_q $opt_s $opt_t $opt_u $opt_v $opt_w); +use List::Util; +use Text::Wrap; +my $MOD_SHA = "Digest::SHA"; +eval "require $MOD_SHA"; +if ($@) { + $MOD_SHA = "Digest::SHA::PurePerl"; + eval "require $MOD_SHA"; +} +eval "require LWP::UserAgent"; + +my %urls = ( + 'nss' => + 'https://hg.mozilla.org/projects/nss/raw-file/tip/lib/ckfw/builtins/certdata.txt', + 'central' => + 'https://hg.mozilla.org/mozilla-central/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'aurora' => + 'https://hg.mozilla.org/releases/mozilla-aurora/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'beta' => + 'https://hg.mozilla.org/releases/mozilla-beta/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', + 'release' => + 'https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt', +); + +$opt_d = 'release'; + +# If the OpenSSL commandline is not in search path you can configure it here! +my $openssl = 'openssl'; + +my $version = '1.27'; + +$opt_w = 76; # default base64 encoded lines length + +# default cert types to include in the output (default is to include CAs which may issue SSL server certs) +my $default_mozilla_trust_purposes = "SERVER_AUTH"; +my $default_mozilla_trust_levels = "TRUSTED_DELEGATOR"; +$opt_p = $default_mozilla_trust_purposes . ":" . $default_mozilla_trust_levels; + +my @valid_mozilla_trust_purposes = ( + "DIGITAL_SIGNATURE", + "NON_REPUDIATION", + "KEY_ENCIPHERMENT", + "DATA_ENCIPHERMENT", + "KEY_AGREEMENT", + "KEY_CERT_SIGN", + "CRL_SIGN", + "SERVER_AUTH", + "CLIENT_AUTH", + "CODE_SIGNING", + "EMAIL_PROTECTION", + "IPSEC_END_SYSTEM", + "IPSEC_TUNNEL", + "IPSEC_USER", + "TIME_STAMPING", + "STEP_UP_APPROVED" +); + +my @valid_mozilla_trust_levels = ( + "TRUSTED_DELEGATOR", # CAs + "NOT_TRUSTED", # Don't trust these certs. + "MUST_VERIFY_TRUST", # This explicitly tells us that it ISN'T a CA but is otherwise ok. In other words, this should tell the app to ignore any other sources that claim this is a CA. + "TRUSTED" # This cert is trusted, but only for itself and not for delegates (i.e. it is not a CA). +); + +my $default_signature_algorithms = $opt_s = "MD5"; + +my @valid_signature_algorithms = ( + "MD5", + "SHA1", + "SHA256", + "SHA384", + "SHA512" +); + +$0 =~ s@.*(/|\\)@@; +$Getopt::Std::STANDARD_HELP_VERSION = 1; +getopts('bd:fhiklmnp:qs:tuvw:'); + +if(!defined($opt_d)) { + # to make plain "-d" use not cause warnings, and actually still work + $opt_d = 'release'; +} + +# Use predefined URL or else custom URL specified on command line. +my $url; +if(defined($urls{$opt_d})) { + $url = $urls{$opt_d}; + if(!$opt_k && $url !~ /^https:\/\//i) { + die "The URL for '$opt_d' is not HTTPS. Use -k to override (insecure).\n"; + } +} +else { + $url = $opt_d; +} + +my $curl = `curl -V`; + +if ($opt_i) { + print ("=" x 78 . "\n"); + print "Script Version : $version\n"; + print "Perl Version : $]\n"; + print "Operating System Name : $^O\n"; + print "Getopt::Std.pm Version : ${Getopt::Std::VERSION}\n"; + print "MIME::Base64.pm Version : ${MIME::Base64::VERSION}\n"; + print "LWP::UserAgent.pm Version : ${LWP::UserAgent::VERSION}\n" if($LWP::UserAgent::VERSION); + print "LWP.pm Version : ${LWP::VERSION}\n" if($LWP::VERSION); + print "Digest::SHA.pm Version : ${Digest::SHA::VERSION}\n" if ($Digest::SHA::VERSION); + print "Digest::SHA::PurePerl.pm Version : ${Digest::SHA::PurePerl::VERSION}\n" if ($Digest::SHA::PurePerl::VERSION); + print ("=" x 78 . "\n"); +} + +sub warning_message() { + if ( $opt_d =~ m/^risk$/i ) { # Long Form Warning and Exit + print "Warning: Use of this script may pose some risk:\n"; + print "\n"; + print " 1) If you use HTTP URLs they are subject to a man in the middle attack\n"; + print " 2) Default to 'release', but more recent updates may be found in other trees\n"; + print " 3) certdata.txt file format may change, lag time to update this script\n"; + print " 4) Generally unwise to blindly trust CAs without manual review & verification\n"; + print " 5) Mozilla apps use additional security checks aren't represented in certdata\n"; + print " 6) Use of this script will make a security engineer grind his teeth and\n"; + print " swear at you. ;)\n"; + exit; + } else { # Short Form Warning + print "Warning: Use of this script may pose some risk, -d risk for more details.\n"; + } +} + +sub HELP_MESSAGE() { + print "Usage:\t${0} [-b] [-d] [-f] [-i] [-k] [-l] [-n] [-p] [-q] [-s] [-t] [-u] [-v] [-w] []\n"; + print "\t-b\tbackup an existing version of ca-bundle.crt\n"; + print "\t-d\tspecify Mozilla tree to pull certdata.txt or custom URL\n"; + print "\t\t Valid names are:\n"; + print "\t\t ", join( ", ", map { ( $_ =~ m/$opt_d/ ) ? "$_ (default)" : "$_" } sort keys %urls ), "\n"; + print "\t-f\tforce rebuild even if certdata.txt is current\n"; + print "\t-i\tprint version info about used modules\n"; + print "\t-k\tallow URLs other than HTTPS, enable HTTP fallback (insecure)\n"; + print "\t-l\tprint license info about certdata.txt\n"; + print "\t-m\tinclude meta data in output\n"; + print "\t-n\tno download of certdata.txt (to use existing)\n"; + print wrap("\t","\t\t", "-p\tlist of Mozilla trust purposes and levels for certificates to include in output. Takes the form of a comma separated list of purposes, a colon, and a comma separated list of levels. (default: $default_mozilla_trust_purposes:$default_mozilla_trust_levels)"), "\n"; + print "\t\t Valid purposes are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_purposes ) ), "\n"; + print "\t\t Valid levels are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_mozilla_trust_levels ) ), "\n"; + print "\t-q\tbe really quiet (no progress output at all)\n"; + print wrap("\t","\t\t", "-s\tcomma separated list of certificate signatures/hashes to output in plain text mode. (default: $default_signature_algorithms)\n"); + print "\t\t Valid signature algorithms are:\n"; + print wrap("\t\t ","\t\t ", join( ", ", "ALL", @valid_signature_algorithms ) ), "\n"; + print "\t-t\tinclude plain text listing of certificates\n"; + print "\t-u\tunlink (remove) certdata.txt after processing\n"; + print "\t-v\tbe verbose and print out processed CAs\n"; + print "\t-w \twrap base64 output lines after chars (default: ${opt_w})\n"; + exit; +} + +sub VERSION_MESSAGE() { + print "${0} version ${version} running Perl ${]} on ${^O}\n"; +} + +warning_message() unless ($opt_q || $url =~ m/^(ht|f)tps:/i ); +HELP_MESSAGE() if ($opt_h); + +sub report($@) { + my $output = shift; + + print STDERR $output . "\n" unless $opt_q; +} + +sub is_in_list($@) { + my $target = shift; + + return defined(List::Util::first { $target eq $_ } @_); +} + +# Parses $param_string as a case insensitive comma separated list with optional whitespace +# validates that only allowed parameters are supplied +sub parse_csv_param($$@) { + my $description = shift; + my $param_string = shift; + my @valid_values = @_; + + my @values = map { + s/^\s+//; # strip leading spaces + s/\s+$//; # strip trailing spaces + uc $_ # return the modified string as upper case + } split( ',', $param_string ); + + # Find all values which are not in the list of valid values or "ALL" + my @invalid = grep { !is_in_list($_,"ALL",@valid_values) } @values; + + if ( scalar(@invalid) > 0 ) { + # Tell the user which parameters were invalid and print the standard help message which will exit + print "Error: Invalid ", $description, scalar(@invalid) == 1 ? ": " : "s: ", join( ", ", map { "\"$_\"" } @invalid ), "\n"; + HELP_MESSAGE(); + } + + @values = @valid_values if ( is_in_list("ALL",@values) ); + + return @values; +} + +sub sha256 { + my $result; + if ($Digest::SHA::VERSION || $Digest::SHA::PurePerl::VERSION) { + open(FILE, $_[0]) or die "Can't open '$_[0]': $!"; + binmode(FILE); + $result = $MOD_SHA->new(256)->addfile(*FILE)->hexdigest; + close(FILE); + } else { + # Use OpenSSL command if Perl Digest::SHA modules not available + $result = `"$openssl" dgst -r -sha256 "$_[0]"`; + $result =~ s/^([0-9a-f]{64}) .+/$1/is; + } + return $result; +} + + +sub oldhash { + my $hash = ""; + open(C, "<$_[0]") || return 0; + while() { + chomp; + if($_ =~ /^\#\# SHA256: (.*)/) { + $hash = $1; + last; + } + } + close(C); + return $hash; +} + +if ( $opt_p !~ m/:/ ) { + print "Error: Mozilla trust identifier list must include both purposes and levels\n"; + HELP_MESSAGE(); +} + +(my $included_mozilla_trust_purposes_string, my $included_mozilla_trust_levels_string) = split( ':', $opt_p ); +my @included_mozilla_trust_purposes = parse_csv_param( "trust purpose", $included_mozilla_trust_purposes_string, @valid_mozilla_trust_purposes ); +my @included_mozilla_trust_levels = parse_csv_param( "trust level", $included_mozilla_trust_levels_string, @valid_mozilla_trust_levels ); + +my @included_signature_algorithms = parse_csv_param( "signature algorithm", $opt_s, @valid_signature_algorithms ); + +sub should_output_cert(%) { + my %trust_purposes_by_level = @_; + + foreach my $level (@included_mozilla_trust_levels) { + # for each level we want to output, see if any of our desired purposes are included + return 1 if ( defined( List::Util::first { is_in_list( $_, @included_mozilla_trust_purposes ) } @{$trust_purposes_by_level{$level}} ) ); + } + + return 0; +} + +my $crt = $ARGV[0] || 'ca-bundle.crt'; +(my $txt = $url) =~ s@(.*/|\?.*)@@g; + +my $stdout = $crt eq '-'; +my $resp; +my $fetched; + +my $oldhash = oldhash($crt); + +report "SHA256 of old file: $oldhash"; + +if(!$opt_n) { + report "Downloading $txt ..."; + + # If we have an HTTPS URL then use curl + if($url =~ /^https:\/\//i) { + if($curl) { + if($curl =~ /^Protocols:.* https( |$)/m) { + report "Get certdata with curl!"; + my $proto = !$opt_k ? "--proto =https" : ""; + my $quiet = $opt_q ? "-s" : ""; + my @out = `curl -w %{response_code} $proto $quiet -o "$txt" "$url"`; + if(@out && $out[0] == 200) { + $fetched = 1; + report "Downloaded $txt"; + } + else { + report "Failed downloading via HTTPS with curl"; + if(-e $txt && !unlink($txt)) { + report "Failed to remove '$txt': $!"; + } + } + } + else { + report "curl lacks https support"; + } + } + else { + report "curl not found"; + } + } + + # If nothing was fetched then use LWP + if(!$fetched) { + if($url =~ /^https:\/\//i) { + report "Falling back to HTTP"; + $url =~ s/^https:\/\//http:\/\//i; + } + if(!$opt_k) { + report "URLs other than HTTPS are disabled by default, to enable use -k"; + exit 1; + } + report "Get certdata with LWP!"; + if(!defined(${LWP::UserAgent::VERSION})) { + report "LWP is not available (LWP::UserAgent not found)"; + exit 1; + } + my $ua = new LWP::UserAgent(agent => "$0/$version"); + $ua->env_proxy(); + $resp = $ua->mirror($url, $txt); + if($resp && $resp->code eq '304') { + report "Not modified"; + exit 0 if -e $crt && !$opt_f; + } + else { + $fetched = 1; + report "Downloaded $txt"; + } + if(!$resp || $resp->code !~ /^(?:200|304)$/) { + report "Unable to download latest data: " + . ($resp? $resp->code . ' - ' . $resp->message : "LWP failed"); + exit 1 if -e $crt || ! -r $txt; + } + } +} + +my $filedate = $resp ? $resp->last_modified : (stat($txt))[9]; +my $datesrc = "as of"; +if(!$filedate) { + # mxr.mozilla.org gave us a time, hg.mozilla.org does not! + $filedate = time(); + $datesrc="downloaded on"; +} + +# get the hash from the download file +my $newhash= sha256($txt); + +if(!$opt_f && $oldhash eq $newhash) { + report "Downloaded file identical to previous run\'s source file. Exiting"; + exit; +} + +report "SHA256 of new file: $newhash"; + +my $currentdate = scalar gmtime($filedate); + +my $format = $opt_t ? "plain text and " : ""; +if( $stdout ) { + open(CRT, '> -') or die "Couldn't open STDOUT: $!\n"; +} else { + open(CRT,">$crt.~") or die "Couldn't open $crt.~: $!\n"; +} +print CRT <) { + if (/\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*/) { + print CRT; + print if ($opt_l); + while () { + print CRT; + print if ($opt_l); + last if (/\*\*\*\*\* END LICENSE BLOCK \*\*\*\*\*/); + } + } + elsif(/^# (Issuer|Serial Number|Subject|Not Valid Before|Not Valid After |Fingerprint \(MD5\)|Fingerprint \(SHA1\)):/) { + push @precert, $_; + next; + } + elsif(/^#|^\s*$/) { + undef @precert; + next; + } + chomp; + + # this is a match for the start of a certificate + if (/^CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE/) { + $start_of_cert = 1 + } + if ($start_of_cert && /^CKA_LABEL UTF8 \"(.*)\"/) { + $caname = $1; + } + my %trust_purposes_by_level; + if ($start_of_cert && /^CKA_VALUE MULTILINE_OCTAL/) { + my $data; + while () { + last if (/^END/); + chomp; + my @octets = split(/\\/); + shift @octets; + for (@octets) { + $data .= chr(oct); + } + } + # scan forwards until the trust part + while () { + last if (/^CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST/); + chomp; + } + # now scan the trust part to determine how we should trust this cert + while () { + last if (/^#/); + if (/^CKA_TRUST_([A-Z_]+)\s+CK_TRUST\s+CKT_NSS_([A-Z_]+)\s*$/) { + if ( !is_in_list($1,@valid_mozilla_trust_purposes) ) { + report "Warning: Unrecognized trust purpose for cert: $caname. Trust purpose: $1. Trust Level: $2"; + } elsif ( !is_in_list($2,@valid_mozilla_trust_levels) ) { + report "Warning: Unrecognized trust level for cert: $caname. Trust purpose: $1. Trust Level: $2"; + } else { + push @{$trust_purposes_by_level{$2}}, $1; + } + } + } + + if ( !should_output_cert(%trust_purposes_by_level) ) { + $skipnum ++; + } else { + my $encoded = MIME::Base64::encode_base64($data, ''); + $encoded =~ s/(.{1,${opt_w}})/$1\n/g; + my $pem = "-----BEGIN CERTIFICATE-----\n" + . $encoded + . "-----END CERTIFICATE-----\n"; + print CRT "\n$caname\n"; + print CRT @precert if($opt_m); + my $maxStringLength = length(decode('UTF-8', $caname, Encode::FB_CROAK)); + if ($opt_t) { + foreach my $key (keys %trust_purposes_by_level) { + my $string = $key . ": " . join(", ", @{$trust_purposes_by_level{$key}}); + $maxStringLength = List::Util::max( length($string), $maxStringLength ); + print CRT $string . "\n"; + } + } + print CRT ("=" x $maxStringLength . "\n"); + if (!$opt_t) { + print CRT $pem; + } else { + my $pipe = ""; + foreach my $hash (@included_signature_algorithms) { + $pipe = "|$openssl x509 -" . $hash . " -fingerprint -noout -inform PEM"; + if (!$stdout) { + $pipe .= " >> $crt.~"; + close(CRT) or die "Couldn't close $crt.~: $!"; + } + open(TMP, $pipe) or die "Couldn't open openssl pipe: $!"; + print TMP $pem; + close(TMP) or die "Couldn't close openssl pipe: $!"; + if (!$stdout) { + open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!"; + } + } + $pipe = "|$openssl x509 -text -inform PEM"; + if (!$stdout) { + $pipe .= " >> $crt.~"; + close(CRT) or die "Couldn't close $crt.~: $!"; + } + open(TMP, $pipe) or die "Couldn't open openssl pipe: $!"; + print TMP $pem; + close(TMP) or die "Couldn't close openssl pipe: $!"; + if (!$stdout) { + open(CRT, ">>$crt.~") or die "Couldn't open $crt.~: $!"; + } + } + report "Parsing: $caname" if ($opt_v); + $certnum ++; + $start_of_cert = 0; + } + undef @precert; + } + +} +close(TXT) or die "Couldn't close $txt: $!\n"; +close(CRT) or die "Couldn't close $crt.~: $!\n"; +unless( $stdout ) { + if ($opt_b && -e $crt) { + my $bk = 1; + while (-e "$crt.~${bk}~") { + $bk++; + } + rename $crt, "$crt.~${bk}~" or die "Failed to create backup $crt.~$bk}~: $!\n"; + } elsif( -e $crt ) { + unlink( $crt ) or die "Failed to remove $crt: $!\n"; + } + rename "$crt.~", $crt or die "Failed to rename $crt.~ to $crt: $!\n"; +} +if($opt_u && -e $txt && !unlink($txt)) { + report "Failed to remove $txt: $!\n"; +} +report "Done ($certnum CA certs processed, $skipnum skipped)."; diff --git a/ports/qca/portfile.cmake b/ports/qca/portfile.cmake index dc360af877..072c4b7cb4 100644 --- a/ports/qca/portfile.cmake +++ b/ports/qca/portfile.cmake @@ -1,5 +1,5 @@ # This portfile adds the Qt Cryptographic Arcitecture -# Changes to the original sources by this file: +# Changes to the original build: # No -qt5 suffix, which is recommended just for Linux # Output directories according to vcpkg # Updated certstore. See certstore.pem in the output dirs @@ -13,6 +13,9 @@ endif() include(vcpkg_common_functions) find_program(GIT git) +vcpkg_find_acquire_program(PERL) +get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY) +set(ENV{PATH} "${PERL_EXE_PATH};$ENV{PATH}") # Set git variables to qca version 2.2.0 commit set(GIT_URL "git://anongit.kde.org/qca.git") @@ -52,15 +55,18 @@ vcpkg_apply_patches( # https://www.openssl.org/docs/faq.html#USER16 # it is up to developers or admins to maintain CAs. # So we do it here: -# Importing certificates from curl maintainers -# See: https://curl.haxx.se/docs/caextract.html message(STATUS "Importing certstore") file(REMOVE ${SOURCE_PATH}/certs/rootcerts.pem) -file(DOWNLOAD https://curl.haxx.se/ca/cacert.pem - ${SOURCE_PATH}/certs/rootcerts.pem - SHOW_PROGRESS +# Using file(DOWNLOAD) to use https +file(DOWNLOAD https://raw.githubusercontent.com/mozilla/gecko-dev/master/security/nss/lib/ckfw/builtins/certdata.txt + ${CMAKE_CURRENT_LIST_DIR}/certdata.txt TLS_VERIFY ON ) +vcpkg_execute_required_process( + COMMAND ${PERL} ${CMAKE_CURRENT_LIST_DIR}/mk-ca-bundle.pl -n ${SOURCE_PATH}/certs/rootcerts.pem + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + LOGNAME ca-bundle +) message(STATUS "Importing certstore done") # Configure and build