Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit e362a25

Browse files
committed
certificates
1 parent 8571a3d commit e362a25

20 files changed

Lines changed: 591 additions & 39 deletions

File tree

docker-compose.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
version: "3"
2+
3+
networks:
4+
jpproject_network:
5+
driver: bridge
6+
ipam:
7+
driver: default
8+
config:
9+
- subnet: 172.20.0.0/16
210
services:
311

412
# #############################
@@ -8,7 +16,7 @@
816
# image: redis:alpine
917
# ports:
1018
# - "16379:6379"
11-
19+
1220

1321
#############################
1422
# Database
@@ -27,7 +35,10 @@
2735
test: [ "CMD", "sqlcmd", "-U", "sa", "-P", "Password1", "-Q", "select 1" ]
2836
interval: 1s
2937
retries: 30
30-
38+
39+
networks:
40+
jpproject_network:
41+
ipv4_address: 172.20.0.5
3142
#############################
3243
# Server SSO
3344
#############################
@@ -39,16 +50,23 @@
3950
dockerfile: sso.dockerfile
4051

4152
ports:
42-
- "5000:5000"
53+
- "5001:80"
54+
- "5000:443"
4355

4456
depends_on:
4557
- database
4658

4759
environment:
4860
SQLSERVER_CONNECTION: "Server=database,1433;Initial Catalog=JpProject;Persist Security Info=False;User ID=sa;Password=@Password1;MultipleActiveResultSets=False;Connection Timeout=30;"
4961
ASPNETCORE_ENVIRONMENT: "Development"
50-
ISSUER_URI: "http://localhost:5000"
51-
AMBIENT: "linux"
62+
ISSUER_URI: "https://localhost:5000"
63+
ASPNETCORE_Kestrel__Certificates__Default__Password: ".pxCpE]yttwC&b&hriw#,7K^_}A7xezRH3=EisJKn3]8.H}^Unzd+ebw]zzv_=d3"
64+
ASPNETCORE_Kestrel__Certificates__Default__Path: "/root/.dotnet/https/jpproject.pfx"
65+
ASPNETCORE_URLS: https://+:443;http://+:80
66+
67+
networks:
68+
jpproject_network:
69+
ipv4_address: 172.20.0.6
5270

5371
#############################
5472
# Management API
@@ -60,7 +78,8 @@
6078
dockerfile: user-management.dockerfile
6179

6280
ports:
63-
- "5003:5003"
81+
- "5003:443"
82+
- "5002:80"
6483

6584
depends_on:
6685
- database
@@ -69,9 +88,18 @@
6988
environment:
7089
SQLSERVER_CONNECTION: "Server=database,1433;Initial Catalog=JpProject;Persist Security Info=False;User ID=sa;Password=@Password1;MultipleActiveResultSets=False;Connection Timeout=30;"
7190
ASPNETCORE_ENVIRONMENT: "Development"
72-
AUTHORITY: "http://sso:5000"
91+
AUTHORITY: "http://localhost"
92+
ASPNETCORE_Kestrel__Certificates__Default__Password: ".pxCpE]yttwC&b&hriw#,7K^_}A7xezRH3=EisJKn3]8.H}^Unzd+ebw]zzv_=d3"
93+
ASPNETCORE_Kestrel__Certificates__Default__Path: "/root/.dotnet/https/jpproject.pfx"
94+
ASPNETCORE_URLS: https://+:443;http://+:80
7395
VALIDATE_ISSUER: "false"
74-
AMBIENT: "linux"
96+
97+
extra_hosts:
98+
- "localhost:172.20.0.6"
99+
100+
networks:
101+
jpproject_network:
102+
ipv4_address: 172.20.0.7
75103

76104
#############################
77105
# User management UI
@@ -84,4 +112,8 @@
84112
dockerfile: ui-user-management.dockerfile
85113

86114
ports:
87-
- 4200:80
115+
- 4200:80
116+
117+
networks:
118+
jpproject_network:
119+
ipv4_address: 172.20.0.8

keys/JPProjectOAuth.cer

-791 Bytes
Binary file not shown.

keys/JpProjectOAuth.pvk

-1.18 KB
Binary file not shown.

keys/cert.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
param (
2+
[Parameter(Mandatory=$true)][string]$certificatename,
3+
[Parameter(Mandatory=$true)][SecureString]$certificatepassword
4+
)
5+
# setup certificate properties including the commonName (DNSName) property for Chrome 58+
6+
$certificate = New-SelfSignedCertificate `
7+
-Subject localhost `
8+
-DnsName localhost `
9+
-KeyAlgorithm RSA `
10+
-KeyLength 2048 `
11+
-NotBefore (Get-Date) `
12+
-NotAfter (Get-Date).AddYears(2) `
13+
-CertStoreLocation "cert:CurrentUser\My" `
14+
-FriendlyName "Localhost Certificate for .NET Core" `
15+
-HashAlgorithm SHA256 `
16+
-KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
17+
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
18+
$certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
19+
# create temporary certificate path
20+
$tmpPath = "C:\tmp"
21+
If(!(test-path $tmpPath))
22+
{
23+
New-Item -ItemType Directory -Force -Path $tmpPath
24+
}
25+
# set certificate password here
26+
$pfxPassword = $certificatepassword
27+
$pfxFilePath = $tmpPath + "\" + $certificatename + ".pfx"
28+
$cerFilePath = $tmpPath + "\" + $certificatename + ".cer"
29+
# create pfx certificate
30+
Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
31+
Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
32+
# import the pfx certificate
33+
Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
34+
# trust the certificate by importing the pfx certificate into your trusted root
35+
Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
36+
# optionally delete the physical certificates (don’t delete the pfx file as you need to copy this to your app directory)
37+
# Remove-Item $pfxFilePath
38+
Remove-Item $cerFilePath

src/Backend/Jp.UserManagement/Configuration/SwaggerConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static IServiceCollection AddSwagger(this IServiceCollection services)
2323
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
2424
{
2525
Flow = "implicit",
26-
AuthorizationUrl = "http://localhost:5000/connect/authorize",
26+
AuthorizationUrl = "https://localhost:5000/connect/authorize",
2727
Scopes = new Dictionary<string, string> {
2828
{ "UserManagementApi.owner-content", "User Management API - full access" },
2929
}

src/Backend/Jp.UserManagement/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"environmentVariables": {
2626
"ASPNETCORE_ENVIRONMENT": "Development"
2727
},
28-
"applicationUrl": "http://localhost:5003;https://localhost:5002"
28+
"applicationUrl": "https://localhost:5003;http://localhost:5002"
2929
},
3030
"Docker": {
3131
"commandName": "Docker",

src/Backend/Jp.UserManagement/Startup.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,25 @@ public void ConfigureServices(IServiceCollection services)
4545
services.AddIdentity(Configuration);
4646
services.ConfigureCors();
4747

48-
var authorityUri = Environment.GetEnvironmentVariable("AUTHORITY") ?? "http://localhost:5000";
48+
var authorityUri = Environment.GetEnvironmentVariable("AUTHORITY") ?? "https://localhost:5000";
4949
_logger.LogInformation($"Authority URI: {authorityUri}");
5050
services.AddAuthentication(options =>
5151
{
5252
options.DefaultAuthenticateScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
5353
options.DefaultChallengeScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
54-
5554
})
5655
.AddIdentityServerAuthentication(options =>
5756
{
5857
options.Authority = authorityUri;
5958
options.RequireHttpsMetadata = false;
6059
options.ApiSecret = "Q&tGrEQMypEk.XxPU:%bWDZMdpZeJiyMwpLv4F7d**w9x:7KuJ#fy,E8KPHpKz++";
6160
options.ApiName = "UserManagementApi";
62-
63-
6461
options.JwtBearerEvents.OnMessageReceived = (messae) =>
6562
{
6663
messae.Options.TokenValidationParameters.ValidateIssuer = bool.Parse(Environment.GetEnvironmentVariable("VALIDATE_ISSUER") ?? "true");
6764
return Task.CompletedTask;
6865
};
66+
6967
});
7068

7169
services.AddSwagger();

0 commit comments

Comments
 (0)