Skip to content

Commit

Permalink
Support OpenSSL on Windows (microsoft#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse authored Sep 1, 2020
1 parent 55a3362 commit 0050351
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 64 deletions.
29 changes: 29 additions & 0 deletions .azure/azure-pipelines.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ stages:
arch: x64
tls: schannel
extraBuildArgs: -DisableTools -DisableTest
- template: ./templates/build-config-user.yml
parameters:
image: windows-latest
platform: windows
arch: x64
tls: openssl

- stage: build_linux
displayName: Build Linux
Expand Down Expand Up @@ -202,6 +208,13 @@ stages:
localTls: mitls
remoteTls: mitls
testTypes: 'Loopback'
- template: ./templates/run-performance.yml
parameters:
pool: MsQuic-Win-Perf
platform: windows
localTls: openssl
remoteTls: openssl
testTypes: 'Loopback'
- template: ./templates/run-performance.yml
parameters:
image: ubuntu-latest
Expand Down Expand Up @@ -252,6 +265,12 @@ stages:
tls: mitls
logProfile: Full.Light
extraArgs: -Filter -*Unreachable/0:CryptTest/CryptTest.Encryption/2:TlsTest.CertificateError
- template: ./templates/run-bvt.yml
parameters:
image: windows-latest
platform: windows
tls: openssl
extraArgs: -Filter -*TlsTest.CertificateError:ParameterValidation.ValidateServerSecConfig:*AbortiveShutdown*:Basic/WithFamilyArgs.Unreachable/0
- template: ./templates/run-bvt.yml
parameters:
image: ubuntu-latest
Expand Down Expand Up @@ -285,6 +304,11 @@ stages:
image: windows-latest
platform: windows
tls: stub
- template: ./templates/run-spinquic.yml
parameters:
image: windows-latest
platform: windows
tls: openssl
- template: ./templates/run-spinquic.yml
parameters:
image: ubuntu-latest
Expand Down Expand Up @@ -345,6 +369,11 @@ stages:
image: windows-latest
platform: windows
tls: mitls
- template: ./templates/run-quicinterop.yml
parameters:
image: windows-latest
platform: windows
tls: openssl
- template: ./templates/run-quicinterop.yml
parameters:
image: ubuntu-latest
Expand Down
11 changes: 9 additions & 2 deletions .azure/templates/build-config-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ jobs:
${{ if eq(parameters.platform, 'windows') }}:
path: msquic

- task: Cache@2
inputs:
key: '"${{ parameters.platform }}_${{ parameters.arch }}_${{ parameters.tls }}_${{ parameters.extraName }}" | .gitmodules'
path: build/${{ parameters.platform }}/${{ parameters.arch }}_${{ parameters.tls }}/openssl
displayName: Cache OpenSSL
condition: eq('${{ parameters.tls }}', 'openssl')

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
condition: eq('${{ parameters.platform }}', 'linux')
Expand Down Expand Up @@ -51,15 +58,15 @@ jobs:
inputs:
pwsh: true
filePath: scripts/build.ps1
arguments: -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} -Platform ${{ parameters.platform }} ${{ parameters.extraBuildArgs }}
arguments: -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} -Platform ${{ parameters.platform }} -CI ${{ parameters.extraBuildArgs }}

- task: PowerShell@2
displayName: Build Source Code (Release)
condition: contains('${{ parameters.config }}', 'Release')
inputs:
pwsh: true
filePath: scripts/build.ps1
arguments: -Config Release -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} -Platform ${{ parameters.platform }} ${{ parameters.extraBuildArgs }}
arguments: -Config Release -Arch ${{ parameters.arch }} -Tls ${{ parameters.tls }} -Platform ${{ parameters.platform }} -CI ${{ parameters.extraBuildArgs }}

- ${{ if eq(parameters.skipArtifacts, false) }}:
- template: ./upload-artifacts.yml
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
mkdir build
cd build
cmake ..
cmake --build . --target OpenSSL
cmake --build . --target OpenSSL_Build
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand Down
127 changes: 100 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ option(QUIC_SOURCE_LINK "Enables source linking on MSVC" ON)
option(QUIC_PDBALTPATH "Enable PDBALTPATH setting on MSVC" ON)
option(QUIC_CODE_CHECK "Run static code checkers" OFF)
option(QUIC_OPTIMIZE_LOCAL "Optimize code for local machine architecture" OFF)
option(QUIC_CI "CI Specific build optimizations" OFF)

# FindLTTngUST does not exist before CMake 3.6, so disable logging for older cmake versions
if (${CMAKE_VERSION} VERSION_LESS "3.6.0")
Expand Down Expand Up @@ -359,35 +360,107 @@ else()
endif()

if(QUIC_TLS STREQUAL "openssl")
# Configure and build OpenSSL.
set(OPENSSL_DIR ${QUIC_BUILD_DIR}/openssl)
set(OPENSSL_CONFIG_FLAGS
enable-tls1_3 no-makedepend no-dgram no-ssl3 no-psk no-srp
no-weak-ssl-ciphers no-shared no-tests --prefix=${OPENSSL_DIR})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(OPENSSL_CONFIG_CMD ${CMAKE_SOURCE_DIR}/submodules/openssl/Configure
linux-armv4 -DL_ENDIAN
--cross-compile-prefix=${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-)
if (WIN32)
set(OPENSSL_DIR ${QUIC_BUILD_DIR}/openssl)

add_library(OpenSSL_Crypto STATIC IMPORTED)
set_property(TARGET OpenSSL_Crypto PROPERTY IMPORTED_LOCATION_RELEASE ${OPENSSL_DIR}/release/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET OpenSSL_Crypto PROPERTY IMPORTED_LOCATION_DEBUG ${OPENSSL_DIR}/debug/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})


add_library(OpenSSL STATIC IMPORTED)
set_property(TARGET OpenSSL PROPERTY IMPORTED_LOCATION_RELEASE ${OPENSSL_DIR}/release/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET OpenSSL PROPERTY IMPORTED_LOCATION_DEBUG ${OPENSSL_DIR}/debug/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})

target_include_directories(OpenSSL INTERFACE
$<$<CONFIG:Debug>:${OPENSSL_DIR}/debug/include>
$<$<CONFIG:Release>:${OPENSSL_DIR}/release/include>)
target_link_libraries(OpenSSL INTERFACE OpenSSL_Crypto)

if (QUIC_CI AND EXISTS ${OPENSSL_DIR}/release/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "Found existing OpenSSL cache, skipping openssl build")
else()
file(MAKE_DIRECTORY ${OPENSSL_DIR}/debug/include)
file(MAKE_DIRECTORY ${OPENSSL_DIR}/release/include)

set(OPENSSL_CONFIG_FLAGS
enable-tls1_3 no-makedepend no-dgram no-ssl3 no-psk no-srp
no-weak-ssl-ciphers no-shared no-tests VC-WIN64A)

add_custom_target(mkdir_openssl_build_debug
COMMAND if not exist \"${QUIC_BUILD_DIR}/submodules/openssl/debug\" mkdir \"${QUIC_BUILD_DIR}/submodules/openssl/debug\" 2> NUL)
add_custom_target(mkdir_openssl_build_release
COMMAND if not exist \"${QUIC_BUILD_DIR}/submodules/openssl/release\" mkdir \"${QUIC_BUILD_DIR}/submodules/openssl/release\" 2> NUL)
add_custom_command(
DEPENDS mkdir_openssl_build_debug
WORKING_DIRECTORY ${QUIC_BUILD_DIR}/submodules/openssl/debug
OUTPUT ${OPENSSL_DIR}/debug/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${OPENSSL_DIR}/debug/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND perl ${CMAKE_SOURCE_DIR}/submodules/openssl/Configure ${OPENSSL_CONFIG_FLAGS} --debug --prefix=${OPENSSL_DIR}/debug
COMMAND nmake
COMMAND nmake install_dev)

add_custom_command(
DEPENDS mkdir_openssl_build_release
WORKING_DIRECTORY ${QUIC_BUILD_DIR}/submodules/openssl/release
OUTPUT ${OPENSSL_DIR}/release/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${OPENSSL_DIR}/release/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND perl ${CMAKE_SOURCE_DIR}/submodules/openssl/Configure ${OPENSSL_CONFIG_FLAGS} --prefix=${OPENSSL_DIR}/release
COMMAND nmake
COMMAND nmake install_dev)

add_custom_target(OpenSSL_Build_Debug
DEPENDS ${OPENSSL_DIR}/debug/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
DEPENDS ${OPENSSL_DIR}/debug/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})

add_custom_target(OpenSSL_Build_Release
DEPENDS ${OPENSSL_DIR}/release/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
DEPENDS ${OPENSSL_DIR}/release/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})

add_dependencies(OpenSSL_Crypto OpenSSL_Build_Release OpenSSL_Build_Debug)
add_dependencies(OpenSSL OpenSSL_Build_Release OpenSSL_Build_Debug)
endif()
else()
set(OPENSSL_CONFIG_CMD ${CMAKE_SOURCE_DIR}/submodules/openssl/config
CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER})
# Configure and build OpenSSL.
set(OPENSSL_DIR ${QUIC_BUILD_DIR}/openssl)
set(OPENSSL_CONFIG_FLAGS
enable-tls1_3 no-makedepend no-dgram no-ssl3 no-psk no-srp
no-weak-ssl-ciphers no-shared no-tests --prefix=${OPENSSL_DIR})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
set(OPENSSL_CONFIG_CMD ${CMAKE_SOURCE_DIR}/submodules/openssl/Configure
linux-armv4 -DL_ENDIAN
--cross-compile-prefix=${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-)
else()
set(OPENSSL_CONFIG_CMD ${CMAKE_SOURCE_DIR}/submodules/openssl/config
CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER})
endif()
add_custom_target(mkdir_openssl_build
COMMAND mkdir -p ${QUIC_BUILD_DIR}/submodules/openssl)
add_custom_command(
DEPENDS mkdir_openssl_build
WORKING_DIRECTORY ${QUIC_BUILD_DIR}/submodules/openssl
OUTPUT ${OPENSSL_DIR}/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${OPENSSL_DIR}/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND SYSTEM=${CMAKE_HOST_SYSTEM_NAME}
${OPENSSL_CONFIG_CMD} ${OPENSSL_CONFIG_FLAGS}
COMMAND make -j$$(nproc)
COMMAND make install_dev)
add_custom_target(OpenSSL_Build
DEPENDS ${OPENSSL_DIR}/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
DEPENDS ${OPENSSL_DIR}/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})

add_library(OpenSSL_Crypto STATIC IMPORTED)
set_property(TARGET OpenSSL_Crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_DIR}/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(OpenSSL_Crypto OpenSSL_Build)

file(MAKE_DIRECTORY ${OPENSSL_DIR}/include)

add_library(OpenSSL STATIC IMPORTED)
set_property(TARGET OpenSSL PROPERTY IMPORTED_LOCATION ${OPENSSL_DIR}/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})
target_include_directories(OpenSSL INTERFACE ${OPENSSL_DIR}/include)
target_link_libraries(OpenSSL INTERFACE OpenSSL_Crypto)
add_dependencies(OpenSSL OpenSSL_Build)
endif()
add_custom_target(mkdir_openssl_build
COMMAND mkdir -p ${QUIC_BUILD_DIR}/submodules/openssl)
add_custom_command(
DEPENDS mkdir_openssl_build
WORKING_DIRECTORY ${QUIC_BUILD_DIR}/submodules/openssl
OUTPUT ${OPENSSL_DIR}/include
OUTPUT ${OPENSSL_DIR}/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${OPENSSL_DIR}/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND SYSTEM=${CMAKE_HOST_SYSTEM_NAME}
${OPENSSL_CONFIG_CMD} ${OPENSSL_CONFIG_FLAGS}
COMMAND make -j$$(nproc)
COMMAND make install_sw)
add_custom_target(OpenSSL
DEPENDS ${OPENSSL_DIR}/include
DEPENDS ${OPENSSL_DIR}/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
DEPENDS ${OPENSSL_DIR}/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()

if(QUIC_TLS STREQUAL "mitls")
Expand Down
8 changes: 4 additions & 4 deletions scripts/RemoteTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"TestName": "Throughput",
"Remote": {
"Platform": "Windows",
"Tls": ["stub", "schannel", "mitls"],
"Tls": ["stub", "schannel", "mitls", "openssl"],
"Arch": ["x64", "x86", "arm", "arm64"],
"Exe": "quicperf",
"Arguments": {
Expand All @@ -14,7 +14,7 @@
},
"Local": {
"Platform": "Windows",
"Tls": ["stub", "schannel", "mitls"],
"Tls": ["stub", "schannel", "mitls", "openssl"],
"Arch": ["x64", "x86", "arm", "arm64"],
"Exe": "quicperf",
"Arguments": {
Expand Down Expand Up @@ -115,7 +115,7 @@
"TestName": "RPS",
"Remote": {
"Platform": "Windows",
"Tls": ["stub", "schannel", "mitls"],
"Tls": ["stub", "schannel", "mitls", "openssl"],
"Arch": ["x64", "x86", "arm", "arm64"],
"Exe": "quicperf",
"Arguments": {
Expand All @@ -126,7 +126,7 @@
},
"Local": {
"Platform": "Windows",
"Tls": ["stub", "schannel", "mitls"],
"Tls": ["stub", "schannel", "mitls", "openssl"],
"Arch": ["x64", "x86", "arm", "arm64"],
"Exe": "quicperf",
"Arguments": {
Expand Down
25 changes: 21 additions & 4 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ This script provides helpers for building msquic.
.PARAMETER UpdateClog
Build allowing clog to update the sidecar.
.PARAMETER ConfigureOnly
Run configuration only.
.PARAMETER CI
Build is occuring from CI
.EXAMPLE
build.ps1
Expand Down Expand Up @@ -131,7 +137,13 @@ param (
[switch]$Clang = $false,

[Parameter(Mandatory = $false)]
[switch]$UpdateClog = $false
[switch]$UpdateClog = $false,

[Parameter(Mandatory = $false)]
[switch]$ConfigureOnly = $false,

[Parameter(Mandatory = $false)]
[switch]$CI = $false
)

Set-StrictMode -Version 'Latest'
Expand Down Expand Up @@ -270,6 +282,9 @@ function CMake-Generate {
if ($SkipSourceLink) {
$Arguments += " -DQUIC_SOURCE_LINK=OFF"
}
if ($CI) {
$Arguments += " -DQUIC_CI=ON"
}
$Arguments += " ../../.."

CMake-Execute $Arguments
Expand Down Expand Up @@ -334,9 +349,11 @@ if ($UpdateClog) {
Log "Generating files..."
CMake-Generate

# Build the code.
Log "Building..."
CMake-Build
if (!$ConfigureOnly) {
# Build the code.
Log "Building..."
CMake-Build
}

Log "Done."

Expand Down
20 changes: 20 additions & 0 deletions scripts/prepare-machine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ if ($IsWindows) {
# TODO - Check for Windows preview
}

if (($Configuration -eq "Dev") -or ($Configuration -eq "Build")) {
$NasmVersion = "2.15.05"
$NasmPath = Join-Path $env:Programfiles "nasm-$NasmVersion"
$NasmExe = Join-Path $NasmPath "nasm.exe"
if (!(Test-Path $NasmExe)) {
New-Item -Path .\build -ItemType Directory -Force
if ([System.Environment]::Is64BitOperatingSystem) {
Invoke-WebRequest -Uri "https://www.nasm.us/pub/nasm/releasebuilds/$NasmVersion/win64/nasm-$NasmVersion-win64.zip" -OutFile "build\nasm.zip"
} else {
Invoke-WebRequest -Uri "https://www.nasm.us/pub/nasm/releasebuilds/$NasmVersion/win32/nasm-$NasmVersion-win32.zip" -OutFile "build\nasm.zip"
}
Expand-Archive -Path "build\nasm.zip" -DestinationPath $env:Programfiles -Force
$CurrentSystemPath = [Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine)
$CurrentSystemPath = "$CurrentSystemPath;$NasmPath"
[Environment]::SetEnvironmentVariable("PATH", $CurrentSystemPath, [System.EnvironmentVariableTarget]::Machine)
Write-Host "##vso[task.setvariable variable=PATH;]${env:PATH};$NasmPath"
Write-Host "PATH has been updated. You'll need to restart your terminal for this to take affect."
}
}

if (($Configuration -eq "Dev") -or ($Configuration -eq "Test")) {
Install-ClogTool "Microsoft.Logging.CLOG2Text.Windows"
}
Expand Down
6 changes: 1 addition & 5 deletions src/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ if (QUIC_TLS STREQUAL "schannel")
elseif(QUIC_TLS STREQUAL "openssl")
message(STATUS "Configuring for OpenSSL")
set(SOURCES ${SOURCES} selfsign_openssl.c tls_openssl.c)
set(EXTRA_PLATFORM_INCLUDE_DIRECTORIES ${QUIC_BUILD_DIR}/openssl/include)
elseif(QUIC_TLS STREQUAL "mitls")
message(STATUS "Configuring for miTLS")
set(SOURCES ${SOURCES} cert_capi.c selfsign_capi.c tls_mitls.c)
Expand All @@ -61,10 +60,7 @@ set_property(TARGET platform PROPERTY FOLDER "libraries")
target_include_directories(platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES})

if(QUIC_TLS STREQUAL "openssl")
add_dependencies(platform OpenSSL)
target_link_libraries(platform PUBLIC
${QUIC_BUILD_DIR}/openssl/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
${QUIC_BUILD_DIR}/openssl/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX})
target_link_libraries(platform PUBLIC OpenSSL)
elseif(QUIC_TLS STREQUAL "mitls")
target_link_libraries(platform PUBLIC kremlib evercrypt mitls quiccrypto)
endif()
Loading

0 comments on commit 0050351

Please sign in to comment.