Browse Source

Enhance `RandomizeAuthServerPassPhraseStep`.

pull/17512/head
maliming 3 years ago
parent
commit
3c59d3960c
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 40
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  2. 54
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RandomizeAuthServerPassPhraseStep.cs
  3. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs
  4. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs
  5. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs
  6. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs
  7. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs
  8. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs
  9. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs
  10. 1
      templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs
  11. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/MyProjectNameAuthServerModule.cs
  12. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameBlazorModule.cs
  13. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs

40
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs

@ -484,29 +484,31 @@ public abstract class ProjectCreationCommandBase
protected Task CreateOpenIddictPfxFilesAsync(ProjectBuildArgs projectArgs)
{
var modules = projectArgs.ExtraProperties[nameof(RandomizeAuthServerPassPhraseStep)].Split(Environment.NewLine);
foreach (var module in modules.Where(x => !string.IsNullOrWhiteSpace(x)))
var module = projectArgs.ExtraProperties[nameof(RandomizeAuthServerPassPhraseStep)];
if (string.IsNullOrWhiteSpace(module))
{
var moduleDirectory = projectArgs.OutputFolder + module;
if (projectArgs.UiFramework != UiFramework.Angular)
{
moduleDirectory = moduleDirectory.Replace("/aspnet-core/", "/");
}
moduleDirectory = Path.GetDirectoryName(projectArgs.SolutionName.CompanyName == null
? moduleDirectory.Replace("MyCompanyName.MyProjectName", projectArgs.SolutionName.ProjectName)
: moduleDirectory.Replace("MyCompanyName", projectArgs.SolutionName.CompanyName).Replace("MyProjectName", projectArgs.SolutionName.ProjectName));
return Task.CompletedTask;
}
if (Directory.Exists(moduleDirectory))
{
CmdHelper.RunCmd($"dotnet dev-certs https -v -ep openiddict.pfx -p {RandomizeAuthServerPassPhraseStep.RandomPassPhrase}", moduleDirectory);
}
else
{
Logger.LogWarning($"Couldn't find the module directory to create openiddict.pfx file: {moduleDirectory}");
}
var moduleDirectory = projectArgs.OutputFolder + module;
if (projectArgs.UiFramework != UiFramework.Angular)
{
moduleDirectory = moduleDirectory.Replace("/aspnet-core/", "/");
}
moduleDirectory = Path.GetDirectoryName(projectArgs.SolutionName.CompanyName == null
? moduleDirectory.Replace("MyCompanyName.MyProjectName", projectArgs.SolutionName.ProjectName)
: moduleDirectory.Replace("MyCompanyName", projectArgs.SolutionName.CompanyName).Replace("MyProjectName", projectArgs.SolutionName.ProjectName));
if (Directory.Exists(moduleDirectory))
{
Logger.LogInformation($"Creating openiddict.pfx file on {moduleDirectory}");
CmdHelper.RunCmd($"dotnet dev-certs https -ep openiddict.pfx -p {RandomizeAuthServerPassPhraseStep.RandomOpenIddictPassword}", moduleDirectory);
}
else
{
Logger.LogWarning($"Couldn't find the module directory to create openiddict.pfx file: {moduleDirectory}");
}
return Task.CompletedTask;
}

54
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RandomizeAuthServerPassPhraseStep.cs

@ -7,9 +7,13 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates;
public class RandomizeAuthServerPassPhraseStep : ProjectBuildPipelineStep
{
protected const string DefaultPassPhrase = "00000000-0000-0000-0000-000000000000";
public readonly static string RandomPassPhrase = Guid.NewGuid().ToString("D");
private const string DefaultPassword = "00000000-0000-0000-0000-000000000000";
private const string KestrelCertificatesDefaultPassword = "Kestrel__Certificates__Default__Password=00000000-0000-0000-0000-000000000000";
private const string LocalhostPfx = "localhost.pfx -p 00000000-0000-0000-0000-000000000000";
private const string DotnetDevCerts = "openiddict.pfx -p 00000000-0000-0000-0000-000000000000";
private const string ProductionEncryptionAndSigningCertificate = "AddProductionEncryptionAndSigningCertificate(\"openiddict.pfx\", \"00000000-0000-0000-0000-000000000000\");";
private readonly static string RandomPassword = Guid.NewGuid().ToString("D");
public readonly static string RandomOpenIddictPassword = Guid.NewGuid().ToString("D");
public override void Execute(ProjectBuildContext context)
{
@ -23,10 +27,10 @@ public class RandomizeAuthServerPassPhraseStep : ProjectBuildPipelineStep
x.Name.EndsWith(".ps1") ||
x.Name.EndsWith(".sh") ||
x.Name.Contains("Dockerfile"))
.Where(x => x.Content.IndexOf(DefaultPassPhrase, StringComparison.InvariantCultureIgnoreCase) >= 0)
.Where(x => x.Content.IndexOf(DefaultPassword, StringComparison.InvariantCultureIgnoreCase) >= 0)
.ToList();
var modules = new List<string>();
string module = null;
foreach (var file in files)
{
file.NormalizeLineEndings();
@ -34,21 +38,43 @@ public class RandomizeAuthServerPassPhraseStep : ProjectBuildPipelineStep
var lines = file.GetLines();
for (var i = 0; i < lines.Length; i++)
{
if (lines[i].Contains(DefaultPassPhrase))
if (lines[i].Contains(KestrelCertificatesDefaultPassword))
{
lines[i] = lines[i].Replace(KestrelCertificatesDefaultPassword,
KestrelCertificatesDefaultPassword.Replace(DefaultPassword,
RandomPassword));
}
if (lines[i].Contains(LocalhostPfx))
{
lines[i] = lines[i].Replace(LocalhostPfx,
LocalhostPfx.Replace(DefaultPassword,
RandomPassword));
}
if (lines[i].Contains(DotnetDevCerts))
{
lines[i] = lines[i].Replace(DefaultPassPhrase, RandomPassPhrase);
if (file.Name.EndsWith("Module.cs", StringComparison.OrdinalIgnoreCase) &&
file.Content.Contains("openiddict.pfx", StringComparison.OrdinalIgnoreCase))
{
modules.Add(file.Name);
}
lines[i] = lines[i].Replace(DotnetDevCerts,
DotnetDevCerts.Replace(DefaultPassword,
RandomOpenIddictPassword));
}
if (lines[i].Contains(ProductionEncryptionAndSigningCertificate))
{
lines[i] = lines[i].Replace(ProductionEncryptionAndSigningCertificate,
ProductionEncryptionAndSigningCertificate.Replace(DefaultPassword,
RandomOpenIddictPassword));
module = file.Name;
}
}
file.SetLines(lines);
}
context.BuildArgs.ExtraProperties.TryAdd(nameof(RandomizeAuthServerPassPhraseStep), string.Empty);
context.BuildArgs.ExtraProperties[nameof(RandomizeAuthServerPassPhraseStep)] += modules.JoinAsString(Environment.NewLine);
if (!module.IsNullOrWhiteSpace())
{
context.BuildArgs.ExtraProperties[nameof(RandomizeAuthServerPassPhraseStep)] = module;
}
}
}

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server.Mongo/MyProjectNameModule.cs

@ -46,6 +46,7 @@ using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.Blazor.Server;
using Volo.Abp.TenantManagement.MongoDB;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameModule.cs

@ -48,6 +48,7 @@ using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.Blazor.Server;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Validation.Localization;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server.Mongo/MyProjectNameHostModule.cs

@ -40,6 +40,7 @@ using Volo.Abp.SettingManagement.MongoDB;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.MongoDB;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;
using Volo.Abp.VirtualFileSystem;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Blazor.WebAssembly/Server/MyProjectNameHostModule.cs

@ -42,6 +42,7 @@ using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;
using Volo.Abp.VirtualFileSystem;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host.Mongo/MyProjectNameModule.cs

@ -40,6 +40,7 @@ using Volo.Abp.SettingManagement.MongoDB;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.MongoDB;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;
using Volo.Abp.Validation.Localization;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Host/MyProjectNameModule.cs

@ -43,6 +43,7 @@ using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Validation.Localization;
using Volo.Abp.VirtualFileSystem;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc.Mongo/MyProjectNameModule.cs

@ -42,6 +42,7 @@ using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.MongoDB;
using Volo.Abp.TenantManagement.Web;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;

1
templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs

@ -44,6 +44,7 @@ using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.Web;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Validation.Localization;

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.AuthServer/MyProjectNameAuthServerModule.cs

@ -31,6 +31,7 @@ using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.UI;
using Volo.Abp.VirtualFileSystem;

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server/MyProjectNameBlazorModule.cs

@ -37,6 +37,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.SettingManagement.Blazor.Server;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement.Blazor.Server;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;
using Volo.Abp.UI.Navigation.Urls;

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs

@ -33,6 +33,7 @@ using Volo.Abp.PermissionManagement.Web;
using Volo.Abp.SettingManagement.Web;
using Volo.Abp.Swashbuckle;
using Volo.Abp.TenantManagement.Web;
using Volo.Abp.OpenIddict;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;

Loading…
Cancel
Save