Skip to content

Commit b300a90

Browse files
Merge pull request #58 from TransactionProcessing/task/httpssecurity
Use HTTPS Security Service
2 parents 4586957 + 0a27cfc commit b300a90

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ ClientBin/
228228
*.dbmdl
229229
*.dbproj.schemaview
230230
*.jfm
231-
*.pfx
231+
#*.pfx
232232
*.publishsettings
233233
orleans.codegen.cs
234234

MessagingService.IntegrationTests/Common/DockerHelper.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,21 @@ public override async Task StartContainersForScenarioRun(String scenarioName)
171171
this.MessagingServicePort = messagingServiceContainer.ToHostExposedEndpoint("5006/tcp").Port;
172172

173173
// Setup the base address resolvers
174-
String SecurityServiceBaseAddressResolver(String api) => $"http://127.0.0.1:{this.SecurityServicePort}";
174+
String SecurityServiceBaseAddressResolver(String api) => $"https://127.0.0.1:{this.SecurityServicePort}";
175175
String MessagingServiceBaseAddressResolver(String api) => $"http://127.0.0.1:{this.MessagingServicePort}";
176176

177-
HttpClient httpClient = new HttpClient();
177+
HttpClientHandler clientHandler = new HttpClientHandler
178+
{
179+
ServerCertificateCustomValidationCallback = (message,
180+
certificate2,
181+
arg3,
182+
arg4) =>
183+
{
184+
return true;
185+
}
186+
187+
};
188+
HttpClient httpClient = new HttpClient(clientHandler);
178189
this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient);
179190
this.MessagingServiceClient = new MessagingServiceClient(MessagingServiceBaseAddressResolver, httpClient);
180191
}

MessagingService.IntegrationTests/MessagingService.IntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
<ItemGroup>
1010
<PackageReference Include="ClientProxyBase" Version="1.0.5" />
11-
<PackageReference Include="Ductus.FluentDocker" Version="2.7.3" />
11+
<PackageReference Include="Ductus.FluentDocker" Version="2.10.7" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
1313
<PackageReference Include="SecurityService.Client" Version="1.0.5" />
14-
<PackageReference Include="Shared.IntegrationTesting" Version="1.0.5" />
14+
<PackageReference Include="Shared.IntegrationTesting" Version="1.0.7" />
1515
<PackageReference Include="Shouldly" Version="4.0.3" />
1616
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.5.14" />
1717
<PackageReference Include="SpecFlow.xUnit" Version="3.5.14" />

MessagingService/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ COPY . .
1616
WORKDIR "/src/MessagingService"
1717
RUN dotnet build "MessagingService.csproj" -c Release -o /app/build
1818

19+
# Sort out certificate stuff here
20+
RUN openssl x509 -inform DER -in /src/MessagingService/aspnetapp-root-cert.cer -out /src/MessagingService/aspnetapp-root-cert.crt
21+
RUN cp /src/MessagingService/aspnetapp-root-cert.crt /usr/local/share/ca-certificates/
22+
RUN update-ca-certificates
23+
1924
FROM build AS publish
2025
RUN dotnet publish "MessagingService.csproj" -c Release -o /app/publish
2126

MessagingService/Startup.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,20 @@ private void ConfigureMiddlewareServices(IServiceCollection services)
282282
})
283283
.AddJwtBearer(options =>
284284
{
285-
//options.SaveToken = true;
285+
options.BackchannelHttpHandler = new HttpClientHandler
286+
{
287+
ServerCertificateCustomValidationCallback =
288+
(message, certificate, chain, sslPolicyErrors) => true
289+
};
286290
options.Authority = ConfigurationReader.GetValue("SecurityConfiguration", "Authority");
287291
options.Audience = ConfigurationReader.GetValue("SecurityConfiguration", "ApiName");
288-
options.RequireHttpsMetadata = false;
292+
289293
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
290-
{
291-
ValidateIssuer = true,
292-
ValidateAudience = false,
293-
ValidAudience = ConfigurationReader.GetValue("SecurityConfiguration", "ApiName"),
294-
ValidIssuer = ConfigurationReader.GetValue("SecurityConfiguration", "Authority"),
295-
};
294+
{
295+
ValidateAudience = false,
296+
ValidAudience = ConfigurationReader.GetValue("SecurityConfiguration", "ApiName"),
297+
ValidIssuer = ConfigurationReader.GetValue("SecurityConfiguration", "Authority"),
298+
};
296299
options.IncludeErrorDetails = true;
297300
});
298301

MessagingService/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ApiVersion": "1.0.9",
2525
"SubscriptionFilter": "Messaging",
2626
"UseConnectionStringConfig": false,
27-
"SecurityService": "http://192.168.1.133:5001",
27+
"SecurityService": "https://192.168.1.133:5001",
2828
"EmailProxy": "Smtp2Go",
2929
"SMSProxy": "TheSMSWorks",
3030
"SMTP2GoBaseAddress": "https://api.smtp2go.com/v3/",
@@ -44,7 +44,7 @@
4444
},
4545
"SecurityConfiguration": {
4646
"ApiName": "messagingService",
47-
"Authority": "http://192.168.1.133:5001"
47+
"Authority": "https://192.168.1.133:5001"
4848
},
4949
"AllowedHosts": "*"
5050
}
820 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)