Skip to content

Commit 0a1b61a

Browse files
Updates to .net 9. Closes #934 (#940)
1 parent 5d5b3a7 commit 0a1b61a

File tree

10 files changed

+158
-158
lines changed

10 files changed

+158
-158
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Setup .NET
4747
uses: actions/setup-dotnet@v4
4848
with:
49-
dotnet-version: 8.0.x
49+
dotnet-version: 9.0.x
5050

5151
# Initializes the CodeQL tools for scanning.
5252
- name: Initialize CodeQL

.github/workflows/create-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup .NET
2323
uses: actions/setup-dotnet@v4
2424
with:
25-
dotnet-version: 8.0.x
25+
dotnet-version: 9.0.x
2626
- name: Rename executable for beta
2727
if: contains(github.ref_name, '-beta')
2828
run: |
@@ -47,7 +47,7 @@ jobs:
4747
if: matrix.architecture == 'win-x64'
4848
run: dotnet build ./dev-proxy-abstractions/dev-proxy-abstractions.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release --no-self-contained
4949
- name: Add plugins to output
50-
run: cp ./dev-proxy/bin/Release/net8.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r
50+
run: cp ./dev-proxy/bin/Release/net9.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r
5151
- name: Remove unnecessary files
5252
run: |
5353
pushd
@@ -74,7 +74,7 @@ jobs:
7474
uses: thedoctor0/zip-release@master
7575
with:
7676
filename: '../../../../dev-proxy-abstractions-${{ github.ref_name }}.zip'
77-
directory: './dev-proxy-abstractions/bin/Release/net8.0'
77+
directory: './dev-proxy-abstractions/bin/Release/net9.0'
7878
exclusions: '*.json'
7979
- name: Upload abstractions
8080
if: matrix.architecture == 'win-x64'

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET
2020
uses: actions/setup-dotnet@v4
2121
with:
22-
dotnet-version: 8.0.x
22+
dotnet-version: 9.0.x
2323
- name: Restore workloads
2424
run: dotnet workload restore
2525
- name: Restore dependencies

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/dev-proxy/bin/Debug/net8.0/devproxy.dll",
13+
"program": "${workspaceFolder}/dev-proxy/bin/Debug/net9.0/devproxy.dll",
1414
"args": [],
15-
"cwd": "${workspaceFolder}/dev-proxy/bin/Debug/net8.0",
15+
"cwd": "${workspaceFolder}/dev-proxy/bin/Debug/net9.0",
1616
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
1717
"console": "integratedTerminal",
1818
"stopAtEntry": false,

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The best way to contribute initially is to download and try Dev Proxy and then g
44

55
## Our foundation
66

7-
The Dev Proxy is built with .NET 6 and uses the [Titanium.Web.Proxy](https://github.com/justcoding121/titanium-web-proxy).
7+
The Dev Proxy is built with .NET 9 and uses the [Unobtanium Web Proxy](https://github.com/svrooij/unobtanium-web-proxy).
88

99
## Reporting issues and suggesting new features
1010

dev-proxy-abstractions/dev-proxy-abstractions.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<RootNamespace>Microsoft.DevProxy.Abstractions</RootNamespace>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
@@ -10,11 +10,11 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
15-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
17-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
1818
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
1919
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
2020
<PackageReference Include="Unobtanium.Web.Proxy" Version="0.1.5" />

dev-proxy-plugins/dev-proxy-plugins.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<RootNamespace>Microsoft.DevProxy.Plugins</RootNamespace>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
@@ -17,15 +17,15 @@
1717
<Private>false</Private>
1818
<ExcludeAssets>runtime</ExcludeAssets>
1919
</PackageReference>
20-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10">
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0">
2121
<Private>false</Private>
2222
<ExcludeAssets>runtime</ExcludeAssets>
2323
</PackageReference>
24-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0">
24+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0">
2525
<Private>false</Private>
2626
<ExcludeAssets>runtime</ExcludeAssets>
2727
</PackageReference>
28-
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.1.2">
28+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.2.0">
2929
<Private>false</Private>
3030
<ExcludeAssets>runtime</ExcludeAssets>
3131
</PackageReference>

dev-proxy/CertificateDiskCache.cs

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// Licensed under the MIT License.
3-
4-
using System.Security.Cryptography.X509Certificates;
5-
using Titanium.Web.Proxy.Certificates.Cache;
6-
using Titanium.Web.Proxy.Helpers;
7-
8-
namespace Microsoft.DevProxy;
9-
10-
// based on https://github.com/justcoding121/titanium-web-proxy/blob/9e71608d204e5b67085656dd6b355813929801e4/src/Titanium.Web.Proxy/Certificates/Cache/DefaultCertificateDiskCache.cs
11-
public sealed class CertificateDiskCache : ICertificateCache
12-
{
13-
private const string DefaultCertificateDirectoryName = "crts";
14-
private const string DefaultCertificateFileExtension = ".pfx";
15-
private const string DefaultRootCertificateFileName = "rootCert" + DefaultCertificateFileExtension;
16-
private const string ProxyConfigurationFolderName = "dev-proxy";
17-
18-
private string? rootCertificatePath;
19-
20-
public Task<X509Certificate2?> LoadRootCertificateAsync(string pathOrName, string password, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken)
21-
{
22-
var path = GetRootCertificatePath(pathOrName, false);
23-
return Task.FromResult(LoadCertificate(path, password, storageFlags));
24-
}
25-
26-
public Task SaveRootCertificateAsync(string pathOrName, string password, X509Certificate2 certificate, CancellationToken cancellationToken)
27-
{
28-
var path = GetRootCertificatePath(pathOrName, true);
29-
var exported = certificate.Export(X509ContentType.Pkcs12, password);
30-
File.WriteAllBytes(path, exported);
31-
return Task.CompletedTask;
32-
}
33-
34-
public Task<X509Certificate2?> LoadCertificateAsync(string subjectName, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken)
35-
{
36-
var filePath = Path.Combine(GetCertificatePath(false), subjectName + DefaultCertificateFileExtension);
37-
return Task.FromResult(LoadCertificate(filePath, string.Empty, storageFlags));
38-
}
39-
40-
public Task SaveCertificateAsync(string subjectName, X509Certificate2 certificate, CancellationToken cancellationToken)
41-
{
42-
var filePath = Path.Combine(GetCertificatePath(true), subjectName + DefaultCertificateFileExtension);
43-
var exported = certificate.Export(X509ContentType.Pkcs12);
44-
File.WriteAllBytes(filePath, exported);
45-
return Task.CompletedTask;
46-
}
47-
48-
public void Clear()
49-
{
50-
try
51-
{
52-
var path = GetCertificatePath(false);
53-
if (Directory.Exists(path)) Directory.Delete(path, true);
54-
}
55-
catch (Exception)
56-
{
57-
// do nothing
58-
}
59-
}
60-
61-
private static X509Certificate2? LoadCertificate(string path, string password, X509KeyStorageFlags storageFlags)
62-
{
63-
byte[] exported;
64-
65-
if (!File.Exists(path)) return null;
66-
67-
try
68-
{
69-
exported = File.ReadAllBytes(path);
70-
}
71-
catch (IOException)
72-
{
73-
// file or directory not found
74-
return null;
75-
}
76-
77-
return new X509Certificate2(exported, password, storageFlags);
78-
}
79-
80-
private string GetRootCertificatePath(string pathOrName, bool create)
81-
{
82-
if (Path.IsPathRooted(pathOrName)) return pathOrName;
83-
84-
return Path.Combine(GetRootCertificateDirectory(create),
85-
string.IsNullOrEmpty(pathOrName) ? DefaultRootCertificateFileName : pathOrName);
86-
}
87-
88-
private string GetCertificatePath(bool create)
89-
{
90-
var path = GetRootCertificateDirectory(create);
91-
92-
var certPath = Path.Combine(path, DefaultCertificateDirectoryName);
93-
if (create && !Directory.Exists(certPath)) Directory.CreateDirectory(certPath);
94-
95-
return certPath;
96-
}
97-
98-
private string GetRootCertificateDirectory(bool create)
99-
{
100-
if (rootCertificatePath == null)
101-
{
102-
if (RunTime.IsUwpOnWindows)
103-
{
104-
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProxyConfigurationFolderName);
105-
}
106-
else if (RunTime.IsLinux)
107-
{
108-
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ProxyConfigurationFolderName);
109-
}
110-
else if (RunTime.IsMac)
111-
{
112-
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ProxyConfigurationFolderName);
113-
}
114-
else
115-
{
116-
var assemblyLocation = AppContext.BaseDirectory;
117-
118-
var path = Path.GetDirectoryName(assemblyLocation);
119-
120-
rootCertificatePath = path ?? throw new NullReferenceException();
121-
}
122-
}
123-
124-
if (create && !Directory.Exists(rootCertificatePath))
125-
{
126-
Directory.CreateDirectory(rootCertificatePath);
127-
}
128-
129-
return rootCertificatePath;
130-
}
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Security.Cryptography.X509Certificates;
5+
using Titanium.Web.Proxy.Certificates.Cache;
6+
using Titanium.Web.Proxy.Helpers;
7+
8+
namespace Microsoft.DevProxy;
9+
10+
// based on https://github.com/justcoding121/titanium-web-proxy/blob/9e71608d204e5b67085656dd6b355813929801e4/src/Titanium.Web.Proxy/Certificates/Cache/DefaultCertificateDiskCache.cs
11+
public sealed class CertificateDiskCache : ICertificateCache
12+
{
13+
private const string DefaultCertificateDirectoryName = "crts";
14+
private const string DefaultCertificateFileExtension = ".pfx";
15+
private const string DefaultRootCertificateFileName = "rootCert" + DefaultCertificateFileExtension;
16+
private const string ProxyConfigurationFolderName = "dev-proxy";
17+
18+
private string? rootCertificatePath;
19+
20+
public Task<X509Certificate2?> LoadRootCertificateAsync(string pathOrName, string password, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken)
21+
{
22+
var path = GetRootCertificatePath(pathOrName, false);
23+
return Task.FromResult(LoadCertificate(path, password, storageFlags));
24+
}
25+
26+
public Task SaveRootCertificateAsync(string pathOrName, string password, X509Certificate2 certificate, CancellationToken cancellationToken)
27+
{
28+
var path = GetRootCertificatePath(pathOrName, true);
29+
var exported = certificate.Export(X509ContentType.Pkcs12, password);
30+
File.WriteAllBytes(path, exported);
31+
return Task.CompletedTask;
32+
}
33+
34+
public Task<X509Certificate2?> LoadCertificateAsync(string subjectName, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken)
35+
{
36+
var filePath = Path.Combine(GetCertificatePath(false), subjectName + DefaultCertificateFileExtension);
37+
return Task.FromResult(LoadCertificate(filePath, string.Empty, storageFlags));
38+
}
39+
40+
public Task SaveCertificateAsync(string subjectName, X509Certificate2 certificate, CancellationToken cancellationToken)
41+
{
42+
var filePath = Path.Combine(GetCertificatePath(true), subjectName + DefaultCertificateFileExtension);
43+
var exported = certificate.Export(X509ContentType.Pkcs12);
44+
File.WriteAllBytes(filePath, exported);
45+
return Task.CompletedTask;
46+
}
47+
48+
public void Clear()
49+
{
50+
try
51+
{
52+
var path = GetCertificatePath(false);
53+
if (Directory.Exists(path)) Directory.Delete(path, true);
54+
}
55+
catch (Exception)
56+
{
57+
// do nothing
58+
}
59+
}
60+
61+
private static X509Certificate2? LoadCertificate(string path, string password, X509KeyStorageFlags storageFlags)
62+
{
63+
byte[] exported;
64+
65+
if (!File.Exists(path)) return null;
66+
67+
try
68+
{
69+
exported = File.ReadAllBytes(path);
70+
}
71+
catch (IOException)
72+
{
73+
// file or directory not found
74+
return null;
75+
}
76+
77+
return X509CertificateLoader.LoadPkcs12(exported, password, storageFlags);
78+
}
79+
80+
private string GetRootCertificatePath(string pathOrName, bool create)
81+
{
82+
if (Path.IsPathRooted(pathOrName)) return pathOrName;
83+
84+
return Path.Combine(GetRootCertificateDirectory(create),
85+
string.IsNullOrEmpty(pathOrName) ? DefaultRootCertificateFileName : pathOrName);
86+
}
87+
88+
private string GetCertificatePath(bool create)
89+
{
90+
var path = GetRootCertificateDirectory(create);
91+
92+
var certPath = Path.Combine(path, DefaultCertificateDirectoryName);
93+
if (create && !Directory.Exists(certPath)) Directory.CreateDirectory(certPath);
94+
95+
return certPath;
96+
}
97+
98+
private string GetRootCertificateDirectory(bool create)
99+
{
100+
if (rootCertificatePath == null)
101+
{
102+
if (RunTime.IsUwpOnWindows)
103+
{
104+
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProxyConfigurationFolderName);
105+
}
106+
else if (RunTime.IsLinux)
107+
{
108+
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ProxyConfigurationFolderName);
109+
}
110+
else if (RunTime.IsMac)
111+
{
112+
rootCertificatePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ProxyConfigurationFolderName);
113+
}
114+
else
115+
{
116+
var assemblyLocation = AppContext.BaseDirectory;
117+
118+
var path = Path.GetDirectoryName(assemblyLocation);
119+
120+
rootCertificatePath = path ?? throw new NullReferenceException();
121+
}
122+
}
123+
124+
if (create && !Directory.Exists(rootCertificatePath))
125+
{
126+
Directory.CreateDirectory(rootCertificatePath);
127+
}
128+
129+
return rootCertificatePath;
130+
}
131131
}

0 commit comments

Comments
 (0)