Skip to content

Commit a0082c2

Browse files
authored
Merge pull request #1002 from gep13/issue-1000
(#1000) Do not display sensitive persisted package arguments
2 parents c9a531f + 47e2093 commit a0082c2

File tree

13 files changed

+71
-71
lines changed

13 files changed

+71
-71
lines changed

Source/ChocolateyGui.Common.Windows/Bootstrapper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class Bootstrapper : BootstrapperBase
3737
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();
3838

3939
#pragma warning disable SA1202
40-
public static readonly string ChocolateyGuiInstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
40+
public static readonly string ChocolateyGuiInstallLocation = _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
4141
public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall";
42-
public static readonly string ChocolateyInstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
43-
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.combine_paths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");
42+
public static readonly string ChocolateyInstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
43+
public static readonly string LicensedGuiAssemblyLocation = _fileSystem.CombinePaths(ChocolateyInstallLocation, "extensions", "chocolateygui", "chocolateygui.licensed.dll");
4444

45-
public static readonly string ChocolateyGuiCommonAssemblyLocation = _fileSystem.combine_paths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.dll");
46-
public static readonly string ChocolateyGuiCommonWindowsAssemblyLocation = _fileSystem.combine_paths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.Windows.dll");
45+
public static readonly string ChocolateyGuiCommonAssemblyLocation = _fileSystem.CombinePaths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.dll");
46+
public static readonly string ChocolateyGuiCommonWindowsAssemblyLocation = _fileSystem.CombinePaths(ChocolateyGuiInstallLocation, "ChocolateyGui.Common.Windows.dll");
4747

4848
public static readonly string ChocolateyGuiCommonAssemblySimpleName = "ChocolateyGui.Common";
4949
public static readonly string ChocolateyGuiCommonWindowsAssemblySimpleName = "ChocolateyGui.Common.Windows";

Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ChocolateyService(IMapper mapper, IProgressService progressService, IChoc
6060
_configService = configService;
6161
_choco = Lets.GetChocolatey(initializeLogging: false).SetCustomLogging(new SerilogLogger(Logger, _progressService), logExistingMessages: false, addToExistingLoggers: true);
6262

63-
_localAppDataPath = _fileSystem.combine_paths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Chocolatey GUI");
63+
_localAppDataPath = _fileSystem.CombinePaths(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), "Chocolatey GUI");
6464
}
6565

6666
public Task<bool> IsElevated()
@@ -73,7 +73,7 @@ public async Task<IEnumerable<Package>> GetInstalledPackages()
7373
_choco.Set(
7474
config =>
7575
{
76-
config.CommandName = CommandNameType.list.ToString();
76+
config.CommandName = CommandNameType.List.ToString();
7777
});
7878

7979
var chocoConfig = _choco.GetConfiguration();
@@ -91,7 +91,7 @@ public async Task<IEnumerable<Package>> GetInstalledPackages()
9191
else
9292
{
9393
var nugetService = _choco.Container().GetInstance<INugetService>();
94-
var packages = await Task.Run(() => nugetService.list_run(chocoConfig));
94+
var packages = await Task.Run(() => nugetService.List(chocoConfig));
9595
return packages
9696
.Select(package => GetMappedPackage(_choco, package, _mapper, true))
9797
.ToArray();
@@ -107,7 +107,7 @@ public async Task<IReadOnlyList<OutdatedPackage>> GetOutdatedPackages(bool inclu
107107
return new List<OutdatedPackage>();
108108
}
109109

110-
var outdatedPackagesFile = _fileSystem.combine_paths(_localAppDataPath, "outdatedPackages.xml");
110+
var outdatedPackagesFile = _fileSystem.CombinePaths(_localAppDataPath, "outdatedPackages.xml");
111111

112112
var outdatedPackagesCacheDurationInMinutesSetting = _configService.GetEffectiveConfiguration().OutdatedPackagesCacheDurationInMinutes;
113113
int outdatedPackagesCacheDurationInMinutes = 0;
@@ -116,9 +116,9 @@ public async Task<IReadOnlyList<OutdatedPackage>> GetOutdatedPackages(bool inclu
116116
int.TryParse(outdatedPackagesCacheDurationInMinutesSetting, out outdatedPackagesCacheDurationInMinutes);
117117
}
118118

119-
if (_fileSystem.file_exists(outdatedPackagesFile) && (DateTime.Now - _fileSystem.get_file_modified_date(outdatedPackagesFile)).TotalMinutes < outdatedPackagesCacheDurationInMinutes)
119+
if (_fileSystem.FileExists(outdatedPackagesFile) && (DateTime.Now - _fileSystem.GetFileModifiedDate(outdatedPackagesFile)).TotalMinutes < outdatedPackagesCacheDurationInMinutes)
120120
{
121-
return _xmlService.deserialize<List<OutdatedPackage>>(outdatedPackagesFile);
121+
return _xmlService.Deserialize<List<OutdatedPackage>>(outdatedPackagesFile);
122122
}
123123
else
124124
{
@@ -140,7 +140,7 @@ public async Task<IReadOnlyList<OutdatedPackage>> GetOutdatedPackages(bool inclu
140140
if (chocoConfig.Sources != null)
141141
{
142142
var nugetService = choco.Container().GetInstance<INugetService>();
143-
var packages = await Task.Run(() => nugetService.upgrade_noop(chocoConfig, null));
143+
var packages = await Task.Run(() => nugetService.UpgradeDryRun(chocoConfig, null));
144144
var results = packages
145145
.Where(p => !p.Value.Inconclusive)
146146
.Select(p => new OutdatedPackage
@@ -154,12 +154,12 @@ public async Task<IReadOnlyList<OutdatedPackage>> GetOutdatedPackages(bool inclu
154154
// packages, when the serialized file has become old/stale, so we NEED the file to be re-written
155155
// when this check is done, so that it isn't always doing the check. Therefore, when we are
156156
// getting ready to serialize the list of outdated packages, if the file already exists, delete it.
157-
if (_fileSystem.file_exists(outdatedPackagesFile))
157+
if (_fileSystem.FileExists(outdatedPackagesFile))
158158
{
159-
_fileSystem.delete_file(outdatedPackagesFile);
159+
_fileSystem.DeleteFile(outdatedPackagesFile);
160160
}
161161

162-
_xmlService.serialize(results, outdatedPackagesFile);
162+
_xmlService.Serialize(results, outdatedPackagesFile);
163163
}
164164
catch (Exception ex)
165165
{
@@ -189,7 +189,7 @@ public async Task<PackageOperationResult> InstallPackage(
189189
choco.Set(
190190
config =>
191191
{
192-
config.CommandName = CommandNameType.install.ToString();
192+
config.CommandName = CommandNameType.Install.ToString();
193193
config.PackageNames = id;
194194
config.Features.UsePackageExitCodes = false;
195195

@@ -369,7 +369,7 @@ public async Task<PackageOperationResult> UninstallPackage(string id, string ver
369369
choco.Set(
370370
config =>
371371
{
372-
config.CommandName = CommandNameType.uninstall.ToString();
372+
config.CommandName = CommandNameType.Uninstall.ToString();
373373
config.PackageNames = id;
374374
config.Features.UsePackageExitCodes = false;
375375

@@ -392,7 +392,7 @@ public async Task<PackageOperationResult> UpdatePackage(string id, Uri source =
392392
choco.Set(
393393
config =>
394394
{
395-
config.CommandName = CommandNameType.upgrade.ToString();
395+
config.CommandName = CommandNameType.Upgrade.ToString();
396396
config.PackageNames = id;
397397
config.Features.UsePackageExitCodes = false;
398398
});
@@ -409,7 +409,7 @@ public async Task<PackageOperationResult> PinPackage(string id, string version)
409409
config =>
410410
{
411411
config.CommandName = "pin";
412-
config.PinCommand.Command = PinCommandType.add;
412+
config.PinCommand.Command = PinCommandType.Add;
413413
config.PinCommand.Name = id;
414414
config.Version = version;
415415
config.Sources = ApplicationParameters.PackagesLocation;
@@ -436,7 +436,7 @@ public async Task<PackageOperationResult> UnpinPackage(string id, string version
436436
config =>
437437
{
438438
config.CommandName = "pin";
439-
config.PinCommand.Command = PinCommandType.remove;
439+
config.PinCommand.Command = PinCommandType.Remove;
440440
config.PinCommand.Name = id;
441441
config.Version = version;
442442
config.Sources = ApplicationParameters.PackagesLocation;
@@ -474,7 +474,7 @@ public async Task SetFeature(ChocolateyFeature feature)
474474
config =>
475475
{
476476
config.CommandName = "feature";
477-
config.FeatureCommand.Command = feature.Enabled ? chocolatey.infrastructure.app.domain.FeatureCommandType.enable : chocolatey.infrastructure.app.domain.FeatureCommandType.disable;
477+
config.FeatureCommand.Command = feature.Enabled ? chocolatey.infrastructure.app.domain.FeatureCommandType.Enable : chocolatey.infrastructure.app.domain.FeatureCommandType.Disable;
478478
config.FeatureCommand.Name = feature.Name;
479479
});
480480

@@ -497,7 +497,7 @@ public async Task SetSetting(ChocolateySetting setting)
497497
config =>
498498
{
499499
config.CommandName = "config";
500-
config.ConfigCommand.Command = chocolatey.infrastructure.app.domain.ConfigCommandType.set;
500+
config.ConfigCommand.Command = chocolatey.infrastructure.app.domain.ConfigCommandType.Set;
501501
config.ConfigCommand.Name = setting.Key;
502502
config.ConfigCommand.ConfigValue = setting.Value;
503503
});
@@ -514,7 +514,7 @@ public async Task<ChocolateySource[]> GetSources()
514514
var config = await GetConfigFile();
515515
var allSources = config.Sources.Select(_mapper.Map<ChocolateySource>).ToArray();
516516

517-
var filteredSourceIds = _configSettingsService.source_list(_choco.GetConfiguration()).Select(s => s.Id).ToArray();
517+
var filteredSourceIds = _configSettingsService.ListSources(_choco.GetConfiguration()).Select(s => s.Id).ToArray();
518518

519519
var mappedSources = allSources.Where(s => filteredSourceIds.Contains(s.Id)).ToArray();
520520
return mappedSources;
@@ -528,7 +528,7 @@ public async Task AddSource(ChocolateySource source)
528528
config =>
529529
{
530530
config.CommandName = "source";
531-
config.SourceCommand.Command = SourceCommandType.add;
531+
config.SourceCommand.Command = SourceCommandType.Add;
532532
config.SourceCommand.Name = source.Id;
533533
config.Sources = source.Value;
534534
config.SourceCommand.Username = source.UserName;
@@ -560,7 +560,7 @@ public async Task DisableSource(string id)
560560
config =>
561561
{
562562
config.CommandName = "source";
563-
config.SourceCommand.Command = SourceCommandType.disable;
563+
config.SourceCommand.Command = SourceCommandType.Disable;
564564
config.SourceCommand.Name = id;
565565
});
566566

@@ -573,7 +573,7 @@ public async Task EnableSource(string id)
573573
config =>
574574
{
575575
config.CommandName = "source";
576-
config.SourceCommand.Command = SourceCommandType.enable;
576+
config.SourceCommand.Command = SourceCommandType.Enable;
577577
config.SourceCommand.Name = id;
578578
});
579579

@@ -611,7 +611,7 @@ public async Task<bool> RemoveSource(string id)
611611
config =>
612612
{
613613
config.CommandName = "source";
614-
config.SourceCommand.Command = SourceCommandType.remove;
614+
config.SourceCommand.Command = SourceCommandType.Remove;
615615
config.SourceCommand.Name = id;
616616
});
617617

@@ -646,7 +646,7 @@ private static Package GetMappedPackage(GetChocolatey choco, PackageResult packa
646646
}
647647

648648
var packageInfoService = choco.Container().GetInstance<IChocolateyPackageInformationService>();
649-
var packageInfo = packageInfoService.get_package_information(package.PackageMetadata);
649+
var packageInfo = packageInfoService.Get(package.PackageMetadata);
650650
mappedPackage.IsPinned = packageInfo.IsPinned;
651651
mappedPackage.IsInstalled = !string.IsNullOrWhiteSpace(package.InstallLocation) || forceInstalled;
652652

@@ -714,7 +714,7 @@ private async Task<ConfigFileSettings> GetConfigFile()
714714
var xmlService = _choco.Container().GetInstance<IXmlService>();
715715
var config =
716716
await Task.Run(
717-
() => xmlService.deserialize<ConfigFileSettings>(chocolatey.infrastructure.app.ApplicationParameters.GlobalConfigFileLocation));
717+
() => xmlService.Deserialize<ConfigFileSettings>(chocolatey.infrastructure.app.ApplicationParameters.GlobalConfigFileLocation));
718718
return config;
719719
}
720720
}

Source/ChocolateyGui.Common.Windows/Services/PackageArgumentsService.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public PackageArgumentsService(
4040

4141
public IEnumerable<string> DecryptPackageArgumentsFile(string id, string version)
4242
{
43-
var argumentsPath = _fileSystem.combine_paths(_chocolateyConfigurationProvider.ChocolateyInstall, ".chocolatey", "{0}.{1}".format_with(id, version));
44-
var argumentsFile = _fileSystem.combine_paths(argumentsPath, ".arguments");
43+
var argumentsPath = _fileSystem.CombinePaths(_chocolateyConfigurationProvider.ChocolateyInstall, ".chocolatey", "{0}.{1}".FormatWith(id, version));
44+
var argumentsFile = _fileSystem.CombinePaths(argumentsPath, ".arguments");
4545

4646
string arguments = string.Empty;
4747

4848
// Get the arguments decrypted in here and return them
4949
try
5050
{
51-
if (_fileSystem.file_exists(argumentsFile))
51+
if (_fileSystem.FileExists(argumentsFile))
5252
{
53-
arguments = _fileSystem.read_file(argumentsFile);
53+
arguments = _fileSystem.ReadFile(argumentsFile);
5454
}
5555
}
5656
catch (Exception ex)
@@ -69,25 +69,25 @@ public IEnumerable<string> DecryptPackageArgumentsFile(string id, string version
6969

7070
// The following code is borrowed from the Chocolatey codebase, should
7171
// be extracted to a separate location in choco executable so we can re-use it.
72-
var packageArgumentsUnencrypted = arguments.contains(" --") && arguments.to_string().Length > 4
72+
var packageArgumentsUnencrypted = arguments.Contains(" --") && arguments.ToStringSafe().Length > 4
7373
? arguments
74-
: _encryptionUtility.decrypt_string(arguments);
74+
: _encryptionUtility.DecryptString(arguments);
7575

7676
// Lets do a global check first to see if there are any sensitive arguments
7777
// before we filter out the values used later.
78-
var sensitiveArgs = ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted);
78+
var sensitiveArgs = ArgumentsUtility.SensitiveArgumentsProvided(packageArgumentsUnencrypted);
7979

8080
var packageArgumentsSplit =
8181
packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries);
8282

83-
foreach (var packageArgument in packageArgumentsSplit.or_empty_list_if_null())
83+
foreach (var packageArgument in packageArgumentsSplit.OrEmpty())
8484
{
85-
var isSensitiveArgument = sensitiveArgs && ArgumentsUtility.arguments_contain_sensitive_information(packageArgument);
85+
var isSensitiveArgument = sensitiveArgs && ArgumentsUtility.SensitiveArgumentsProvided(string.Concat("--", packageArgument));
8686

8787
var packageArgumentSplit =
8888
packageArgument.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
8989

90-
var optionName = packageArgumentSplit[0].to_string();
90+
var optionName = packageArgumentSplit[0].ToStringSafe();
9191
var optionValue = string.Empty;
9292

9393
if (packageArgumentSplit.Length == 2 && isSensitiveArgument)
@@ -96,14 +96,14 @@ public IEnumerable<string> DecryptPackageArgumentsFile(string id, string version
9696
}
9797
else if (packageArgumentSplit.Length == 2)
9898
{
99-
optionValue = packageArgumentSplit[1].to_string().remove_surrounding_quotes();
99+
optionValue = packageArgumentSplit[1].ToStringSafe().UnquoteSafe();
100100
if (optionValue.StartsWith("'"))
101101
{
102-
optionValue.remove_surrounding_quotes();
102+
optionValue.UnquoteSafe();
103103
}
104104
}
105105

106-
yield return "--{0}{1}".format_with(
106+
yield return "--{0}{1}".FormatWith(
107107
optionName,
108108
string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue);
109109
}

Source/ChocolateyGui.Common.Windows/ViewModels/AdvancedInstallViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private void OnSelectedVersionChanged(string stringVersion)
440440

441441
private void BrowseLogFile(object value)
442442
{
443-
var filter = "{0}|{1}|{2}".format_with(
443+
var filter = "{0}|{1}|{2}".FormatWith(
444444
L(nameof(Resources.FilePicker_LogFiles)) + "|*.log;*.klg",
445445
L(nameof(Resources.FilePicker_TextFiles)) + "|*.txt;*.text;*.plain",
446446
L(nameof(Resources.FilePicker_AllFiles)) + "|*.*");

Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ShellView(
6565

6666
// Certain things like Cef (our markdown browser engine) get unhappy when GUI is started from a different cwd.
6767
// If we're in a different one, reset it to our app files directory.
68-
if (_fileSystem.get_directory_name(Environment.CurrentDirectory) != Bootstrapper.ApplicationFilesPath)
68+
if (_fileSystem.GetDirectoryName(Environment.CurrentDirectory) != Bootstrapper.ApplicationFilesPath)
6969
{
7070
Environment.CurrentDirectory = Bootstrapper.ApplicationFilesPath;
7171
}

0 commit comments

Comments
 (0)