Skip to content

Commit 8115f41

Browse files
authored
Use cpprestsdk v2.10.18 (microsoft#5567)
We are seeing a crash coming from cpprestsdk, which happened after moving to use vcpkg dependencies and updating to v2.10.19. This reverts to the version we knew to be good, but it may be that the actual issue is not from cpprestsdk but from one of the patches from vcpkg. We consume cpprestsdk from a local port overlay that we use to be able to patch it with support for certificate pinning, so the main change is to the script that creates the port overlay. The script makes a copy of the port from the official registry; and this PR updates it so that it can fetch a version from an older commit and not just the latest. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5567)
1 parent f1f9ac3 commit 8115f41

File tree

8 files changed

+154
-469
lines changed

8 files changed

+154
-469
lines changed

src/VcpkgPortOverlay/CreatePortOverlay.ps1

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,111 @@ $OverlayRoot = $PSScriptRoot
44

55
$ErrorActionPreference = "Stop"
66

7-
# Hacky way of getting a single directory from the vcpkg repo:
8-
# - Download the vcpkg repo as a zip to a memory stream
9-
# - Parse the zip archive
10-
# - Extract the files we want
11-
function Get-VcpkgRepoAsZipArchive
7+
8+
# Gets the versions of a port available from the official registry.
9+
# This is read from the versions JSON in the main branch.
10+
# A version looks like this:
11+
# {
12+
# "git-tree": "9f5e160191038cbbd2470e534c43f051c80e7d44",
13+
# "version": "2.10.19",
14+
# "port-version": 3
15+
# }
16+
function Get-PortVersions
1217
{
13-
$vcpkgZipUri = "https://github.com/microsoft/vcpkg/archive/refs/heads/master.zip"
14-
$response = Invoke-WebRequest -Uri $vcpkgZipUri
18+
param(
19+
[Parameter(Mandatory)]
20+
[string]$Port
21+
)
22+
23+
$initial = $Port[0]
24+
$jsonUri = "https://raw.githubusercontent.com/microsoft/vcpkg/heads/master/versions/$initial-/$Port.json"
25+
$versions = (Invoke-WebRequest -Uri $jsonUri).Content | ConvertFrom-Json -Depth 5
26+
return $versions.versions
27+
}
28+
29+
# Gets the git-tree associated with a specific version of a port.
30+
# The git-tree is a git object hash that represents the port directory
31+
# from the appropriate version of the registry.
32+
function Get-PortVersionGitTree
33+
{
34+
param(
35+
[Parameter(Mandatory)]
36+
[string]$Port,
37+
[Parameter(Mandatory)]
38+
[string]$Version,
39+
[Parameter(Mandatory)]
40+
[string]$PortVersion
41+
)
42+
43+
$versions = Get-PortVersions $Port
44+
$versionData = $versions | Where-Object { ($_.version -eq $Version) -and ($_."port-version" -eq $portVersion) }
45+
return $versionData."git-tree"
46+
}
47+
48+
# Fetches and parses a git-tree as a ZIP file
49+
function Get-GitTreeAsArchive
50+
{
51+
param(
52+
[Parameter(Mandatory)]
53+
[string]$GitTree
54+
)
55+
56+
$archiveUri = "https://github.com/microsoft/vcpkg/archive/$gitTree.zip"
57+
$response = Invoke-WebRequest -Uri $archiveUri
1558
$zipStream = [System.IO.MemoryStream]::new($response.Content)
1659
$zipArchive = [System.IO.Compression.ZipArchive]::new($zipStream)
1760
return $zipArchive
1861
}
1962

20-
$VcpkgAsArchive = Get-VcpkgRepoAsZipArchive
21-
22-
# Copies an port from the official registry to this overlay
23-
function New-PortOverlay
63+
# Expands an in-memory archive and writes it to disk
64+
function Expand-ArchiveFromMemory
2465
{
2566
param(
2667
[Parameter(Mandatory)]
27-
[string]$Port
68+
[System.IO.Compression.ZipArchive]$Archive,
69+
[Parameter(Mandatory)]
70+
[string]$Destination
2871
)
2972

30-
$portDir = Join-Path $OverlayRoot $Port
31-
32-
# Delete existing port if needed
33-
if (Test-Path $portDir)
73+
# Delete existing directory
74+
if (Test-Path $Destination)
3475
{
35-
Remove-Item -Force -Recurse $portDir
76+
Remove-Item -Force -Recurse $Destination
3677
}
3778

3879
# Remove length=0 to ignore the directory itself
39-
$portZipEntries = $VcpkgAsArchive.Entries |
40-
Where-Object { ($_.Length -ne 0) -and $_.FullName.StartsWith("vcpkg-master/ports/$Port/") }
41-
42-
if (-not $portZipEntries)
80+
$entries = $archive.Entries | Where-Object { $_.Length -ne 0 }
81+
if (-not $entries)
4382
{
44-
throw "Port $port not found"
83+
throw "Archive is empty"
4584
}
4685

47-
New-Item -Type Directory $portDir | Out-Null
48-
foreach ($zipEntry in $portZipEntries)
86+
New-Item -Type Directory $Destination | Out-Null
87+
foreach ($entry in $entries)
4988
{
50-
$targetPath = Join-Path $portDir $zipEntry.Name
51-
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry, $targetPath)
89+
$targetPath = Join-Path $Destination $entry.Name
90+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $targetPath)
5291
}
5392
}
5493

94+
# Creates a copy of a port version from the official registry in this overlay
95+
function New-PortOverlay
96+
{
97+
param(
98+
[Parameter(Mandatory)]
99+
[string]$Port,
100+
[Parameter(Mandatory)]
101+
[string]$Version,
102+
[Parameter(Mandatory)]
103+
[string]$PortVersion
104+
)
105+
106+
$gitTree = Get-PortVersionGitTree $Port $Version $PortVersion
107+
$archive = Get-GitTreeAsArchive $gitTree
108+
$portDir = Join-Path $OverlayRoot $Port
109+
Expand-ArchiveFromMemory $archive $portDir
110+
}
111+
55112
# Gets a git patch from a GitHub commit
56113
function Get-GitHubPatch
57114
{
@@ -223,13 +280,28 @@ function Update-PortSource
223280

224281
$portDir = Join-Path $OverlayRoot $Port
225282

226-
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}' -NewValue $Commit
283+
# For the REF, we also delete any comments after it that may say the wrong version
284+
Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}( #.*)?$' -NewValue "$Commit # Unreleased"
227285
Set-ParameterInPortFile $Port -ParameterName 'SHA512' -CurrentValuePattern '[0-9a-f]{128}' -NewValue $SourceHash
228286
}
229287

288+
# Updates the port version by one.
289+
function Update-PortVersion
290+
{
291+
param(
292+
[Parameter(Mandatory)]
293+
[string]$Port
294+
)
295+
296+
$portJsonPath = Join-Path $OverlayRoot $Port "vcpkg.json"
297+
$portDefinition = Get-Content $portJsonPath | ConvertFrom-Json
298+
$portDefinition."port-version" += 1
299+
$portDefinition | ConvertTo-Json -Depth 5 | Out-File $portJsonPath
300+
}
230301

231-
New-PortOverlay cpprestsdk
302+
New-PortOverlay cpprestsdk -Version 2.10.18 -PortVersion 4
232303
Add-PatchToPort cpprestsdk -PatchRepo 'microsoft/winget-cli' -PatchCommit '888b4ed8f4f7d25cb05a47210e083fe29348163b' -PatchName 'add-server-certificate-validation.patch' -PatchRoot 'src/cpprestsdk/cpprestsdk'
233304

234-
New-PortOverlay libyaml
235-
Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302'
305+
New-PortOverlay libyaml -Version 0.2.5 -PortVersion 5
306+
Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302'
307+
Update-PortVersion libyaml

src/VcpkgPortOverlay/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The whole directory can be re-created with `.\CreatePortOverlay.ps1`
88
## cpprestsdk
99

1010
We add support for certificate pinning.
11+
Note that we use v2.10.18, which is not the latest.
1112

1213
Changes:
1314
* Add patch file: `add-server-certificate-validation.patch`
@@ -18,4 +19,5 @@ Changes:
1819
We use an unreleased version that fixes a vulnerability.
1920

2021
Changes:
21-
* New source commit: https://github.com/yaml/libyaml/commit/840b65c40675e2d06bf40405ad3f12dec7f35923
22+
* New source commit: https://github.com/yaml/libyaml/commit/840b65c40675e2d06bf40405ad3f12dec7f35923
23+
* Increase the port version so that Component Governance doesn't see it as the vulnerable version anymore

0 commit comments

Comments
 (0)