Skip to content

Commit

Permalink
Merge pull request #137 from Resgrid/develop
Browse files Browse the repository at this point in the history
CU-8687yhbz5 adding option for self-signed certs.
  • Loading branch information
ucswift authored Jun 22, 2024
2 parents 2bd6da3 + 93ce4cb commit 5cffbe3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Core/Resgrid.Config/ApiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public static class ApiConfig
/// Key used for authing with the backend internal apis
/// </summary>
public static string BackendInternalApikey = "";

/// <summary>
/// Used to bypass SSL checks, which is needed for self-signed certs
/// </summary>
public static bool BypassSslChecks = false;
}
}
22 changes: 20 additions & 2 deletions Web/Resgrid.Web.Eventing/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
using Microsoft.IdentityModel.Tokens;
using Org.BouncyCastle.Asn1.Ess;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
using System.Net.Http;

namespace Resgrid.Web.Eventing
{
Expand Down Expand Up @@ -79,8 +80,6 @@ public void ConfigureServices(IServiceCollection services)
bool configResult = ConfigProcessor.LoadAndProcessConfig(Configuration["AppOptions:ConfigPath"]);
bool envConfigResult = ConfigProcessor.LoadAndProcessEnvVariables(Configuration.AsEnumerable());

Framework.Logging.Initialize(ExternalErrorConfig.ExternalErrorServiceUrlForEventing);

var settings = System.Configuration.ConfigurationManager.ConnectionStrings;
var element = typeof(ConfigurationElement).GetField("_readOnly", BindingFlags.Instance | BindingFlags.NonPublic);
var collection = typeof(ConfigurationElementCollection).GetField("_readOnly", BindingFlags.Instance | BindingFlags.NonPublic);
Expand All @@ -98,6 +97,25 @@ public void ConfigureServices(IServiceCollection services)
collection.SetValue(settings, true);
element.SetValue(settings, true);

Framework.Logging.Initialize(ExternalErrorConfig.ExternalErrorServiceUrlForEventing);

if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) =>
{
return true;
}
};
return handler;
});
}

services.AddCors();

services.AddControllers().AddNewtonsoftJson(options =>
Expand Down
18 changes: 18 additions & 0 deletions Web/Resgrid.Web.ServicesCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
using Resgrid.Web.ServicesCore.Middleware;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
using OpenTelemetry.Metrics;
using System.Net.Http;

namespace Resgrid.Web.ServicesCore
{
Expand Down Expand Up @@ -121,6 +122,23 @@ public void ConfigureServices(IServiceCollection services)
collection.SetValue(settings, true);
element.SetValue(settings, true);

if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) =>
{
return true;
}
};
return handler;
});
}

services.AddScoped<IUserStore<Model.Identity.IdentityUser>, IdentityUserStore>();
services.AddScoped<IRoleStore<Model.Identity.IdentityRole>, IdentityRoleStore>();
services.AddScoped<IUserClaimsPrincipalFactory<Model.Identity.IdentityUser>, ClaimsPrincipalFactory<Model.Identity.IdentityUser, Model.Identity.IdentityRole>>();
Expand Down
23 changes: 21 additions & 2 deletions Web/Resgrid.WebCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Configuration;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Audit.Core;
Expand Down Expand Up @@ -56,8 +57,8 @@ namespace Resgrid.Web
{
public class Startup
{
//public IConfiguration Configuration { get; }
public IConfigurationRoot Configuration { get; private set; }
//public IConfiguration Configuration { get; }
public IConfigurationRoot Configuration { get; private set; }
public ILifetimeScope AutofacContainer { get; private set; }
public AutofacServiceLocator Locator { get; private set; }
public IServiceCollection Services { get; private set; }
Expand Down Expand Up @@ -102,6 +103,24 @@ public void ConfigureServices(IServiceCollection services)

Logging.Initialize(ExternalErrorConfig.ExternalErrorServiceUrlForWebsite);


if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) =>
{
return true;
}
};
return handler;
});
}

services.AddScoped<IUserStore<Model.Identity.IdentityUser>, IdentityUserStore>();
services.AddScoped<IRoleStore<Model.Identity.IdentityRole>, IdentityRoleStore>();
services.AddScoped<IUserClaimsPrincipalFactory<Model.Identity.IdentityUser>, ClaimsPrincipalFactory<Model.Identity.IdentityUser, Model.Identity.IdentityRole>>();
Expand Down

0 comments on commit 5cffbe3

Please sign in to comment.