Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-8687yhbz5 adding option for self-signed certs. #137

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading