|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|