Skip to content

Commit

Permalink
Merge pull request #19 from simonegli8/master
Browse files Browse the repository at this point in the history
Added VerifyCertificate Property to PveClientBase to optionally validate server certificate
  • Loading branch information
franklupo authored Apr 2, 2024
2 parents 6de7a1c + 54cd74f commit 7581a27
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Corsinvest.ProxmoxVE.Api/PveClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public ILoggerFactory LoggerFactory
/// </summary>
public TimeSpan? Timeout { get; set; } = null;

/// <summary>
/// If set to true verifies the certificate of the Proxmox API server.
/// </summary>
public bool VerifyCertificate { get; set; } = false;

/// <summary>
/// Get/Set the response type that is going to be returned when doing requests (json, png).
/// </summary>
Expand Down Expand Up @@ -179,14 +184,14 @@ public async Task<Result> Set(string resource, IDictionary<string, object> param
/// Het http client
/// </summary>
/// <returns></returns>
public HttpClient GetHttpClient()
public virtual HttpClient GetHttpClient()
{
#pragma warning disable S4830 // Server certificates should be verified during SSL/TLS connections
var handler = new HttpClientHandler()
{
CookieContainer = new CookieContainer(),
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
CookieContainer = new CookieContainer()
};
#pragma warning disable S4830 // Server certificates should be verified during SSL/TLS connections
if (!VerifyCertificate) handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
#pragma warning restore S4830 // Server certificates should be verified during SSL/TLS connections

var client = new HttpClient(handler);
Expand Down

0 comments on commit 7581a27

Please sign in to comment.