-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf0dbed
commit 8aeda49
Showing
60 changed files
with
1,167 additions
and
1,112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// The Sisk Framework source code | ||
// Copyright (c) 2023 PROJECT PRINCIPIUM | ||
// | ||
// The code below is licensed under the MIT license as | ||
// of the date of its publication, available at | ||
// | ||
// File name: SslProxyExtensions.cs | ||
// Repository: https://github.com/sisk-http/core | ||
|
||
using Sisk.Core.Http.Hosting; | ||
using System.Security.Authentication; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Sisk.Ssl; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="SslProxy"/>. | ||
/// </summary> | ||
public static class SslProxyExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the <see cref="HttpServerHostContext"/> to use <see cref="SslProxy"/> with the specified parameters. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="HttpServerHostContextBuilder"/> instance to configure.</param> | ||
/// <param name="sslListeningPort">The port number on which the server will listen for SSL/HTTPS connections.</param> | ||
/// <param name="certificate">The SSL/HTTPS certificate to use for encrypting communications.</param> | ||
/// <param name="allowedProtocols">The SSL/HTTPS protocols allowed for the connection. Defaults to <see cref="SslProtocols.Tls12"/> and <see cref="SslProtocols.Tls13"/>.</param> | ||
/// <param name="clientCertificateRequired">Specifies whether a client certificate is required for authentication. Defaults to <c>false</c>.</param> | ||
/// <returns>The configured <see cref="HttpServerHostContextBuilder"/> instance.</returns> | ||
public static HttpServerHostContextBuilder UseSsl( | ||
this HttpServerHostContextBuilder builder, | ||
short sslListeningPort, | ||
X509Certificate certificate, | ||
SslProtocols allowedProtocols = SslProtocols.Tls12 | SslProtocols.Tls13, | ||
bool clientCertificateRequired = false) | ||
{ | ||
var endpoint = DnsUtil.ResolveEndpoint(builder.ServerConfiguration.ListeningHosts[0].Ports[0]); | ||
var secureProxy = new SslProxy(sslListeningPort, certificate, endpoint); | ||
var serverHandler = new SslProxyServerHandler(secureProxy); | ||
|
||
builder.UseHandler(serverHandler); | ||
builder.UseStartupMessage($"The SSL proxy is listening at:\n- https://localhost:{sslListeningPort}/"); | ||
|
||
return builder; | ||
} | ||
} |
Oops, something went wrong.