Skip to content

Commit df0170a

Browse files
authored
Merge pull request #86 from Keyfactor/release-2.11
Release 2.11.4
2 parents f283030 + a1a0a9d commit df0170a

File tree

17 files changed

+332
-27
lines changed

17 files changed

+332
-27
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
v2.11.4
2+
- Bug Fix: Handle condition where a certificate store definition that contains an invalid value for `FileTransferProtocol`
3+
would return empty inventory. If no value is set or an invalid value is set, the default value of `Both` will be used
4+
and a warning status will be returned for the job.
5+
6+
> [!IMPORTANT]
7+
> Due to an issue in Keyfactor Command versions through 25.2.1, when adding multiple choice store properties to exiting
8+
> certificate store types, existing certificate stores receive incorrect initialization data for the new property.
9+
> If you have upgraded your store type from something prior to version 2.10.0, ensure that each existing certificate
10+
> store has a valid value for `FileTransferProtocol`. Valid values are `SCP`, `SFTP`, `Both`, otherwise inventory jobs **may report
11+
> empty certificate store inventories**. Extension version 2.11.4 compensates for this, but upgrading customers should
12+
> check their store’s configuration for proper `FileTransferProtocol` values.
13+
114
v2.11.3
215
- Change returned result of a Management-Create job for a store that already exists from 'Failure' to 'Warning'
316

README.md

Lines changed: 30 additions & 18 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Xunit;
2+
using Keyfactor.Extensions.Orchestrator.RemoteFile;
3+
4+
namespace RemoteFile.UnitTests;
5+
6+
public class ApplicationSettingsTests
7+
{
8+
[Fact]
9+
public void FileTransferProtocol_WhenPopulatedWithValidValue_ReturnsValue()
10+
{
11+
var path = Path.Combine(Directory.GetCurrentDirectory(), "fixtures", "config", "valid", "config.json");
12+
ApplicationSettings.Initialize(path);
13+
Assert.Equal(ApplicationSettings.FileTransferProtocolEnum.SCP, ApplicationSettings.FileTransferProtocol);
14+
}
15+
16+
[Fact]
17+
public void FileTransferProtocol_WhenAllThreePopulated_DefaultsToBoth()
18+
{
19+
var path = Path.Combine(Directory.GetCurrentDirectory(), "fixtures", "config", "file_transfer_protocol_all_three", "config.json");
20+
ApplicationSettings.Initialize(path);
21+
Assert.Equal(ApplicationSettings.FileTransferProtocolEnum.Both, ApplicationSettings.FileTransferProtocol);
22+
}
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Keyfactor.Extensions.Orchestrator.RemoteFile;
2+
using Xunit;
3+
4+
namespace RemoteFile.UnitTests;
5+
6+
public class PropertyUtilitiesTests
7+
{
8+
[Theory]
9+
[InlineData("SCP", ApplicationSettings.FileTransferProtocolEnum.SCP)]
10+
[InlineData("SFTP", ApplicationSettings.FileTransferProtocolEnum.SFTP)]
11+
[InlineData("Both", ApplicationSettings.FileTransferProtocolEnum.Both)]
12+
public void TryEnumParse_WhenProvidedAValidEnumString_MapsToExpectedEnumValue(string input,
13+
ApplicationSettings.FileTransferProtocolEnum expected)
14+
{
15+
var isValid = PropertyUtilities.TryEnumParse(input, out var isFlagCombination,
16+
out ApplicationSettings.FileTransferProtocolEnum result);
17+
18+
Assert.True(isValid);
19+
Assert.Equal(expected, result);
20+
Assert.False(isFlagCombination);
21+
}
22+
23+
[Fact]
24+
public void TryEnumParse_WhenProvidedAFlagCombination_SetsIsFlagCombination()
25+
{
26+
var input = "SCP,SFTP,Both";
27+
28+
var isValid = PropertyUtilities.TryEnumParse(input, out var isFlagCombination,
29+
out ApplicationSettings.FileTransferProtocolEnum result);
30+
31+
Assert.True(isValid);
32+
Assert.Equal((ApplicationSettings.FileTransferProtocolEnum) 3, result);
33+
Assert.True(isFlagCombination);
34+
}
35+
36+
[Fact]
37+
public void TryEnumParse_WhenProvidedAnInvalidMapping_MarksIsValidAsFalse()
38+
{
39+
var input = "randomstring";
40+
41+
var isValid = PropertyUtilities.TryEnumParse(input, out var isFlagCombination,
42+
out ApplicationSettings.FileTransferProtocolEnum result);
43+
44+
Assert.False(isValid);
45+
Assert.Equal(ApplicationSettings.FileTransferProtocolEnum.SCP, result);
46+
Assert.False(isFlagCombination);
47+
}
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
13+
<PackageReference Include="xunit" Version="2.4.1"/>
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="3.1.2">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\RemoteFile\RemoteFile.csproj" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<None Update="fixtures\config\valid\config.json">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</None>
32+
<None Update="fixtures\config\file_transfer_protocol_all_three\config.json">
33+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
34+
</None>
35+
<None Update="fixtures\config\valid_scp\config.json">
36+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37+
</None>
38+
</ItemGroup>
39+
40+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"UseSudo": "N",
3+
"DefaultSudoImpersonatedUser": "",
4+
"CreateStoreIfMissing": "N",
5+
"UseNegotiate": "N",
6+
"SeparateUploadFilePath": "",
7+
"FileTransferProtocol": "Both,SCP,SFTP",
8+
"DefaultLinuxPermissionsOnStoreCreation": "600",
9+
"DefaultOwnerOnStoreCreation": "",
10+
"SSHPort": ""
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"UseSudo": "N",
3+
"DefaultSudoImpersonatedUser": "",
4+
"CreateStoreIfMissing": "N",
5+
"UseNegotiate": "N",
6+
"SeparateUploadFilePath": "",
7+
"FileTransferProtocol": "SCP",
8+
"DefaultLinuxPermissionsOnStoreCreation": "600",
9+
"DefaultOwnerOnStoreCreation": "",
10+
"SSHPort": ""
11+
}

RemoteFile.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ VisualStudioVersion = 16.0.31702.278
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteFile", "RemoteFile\RemoteFile.csproj", "{A006BFAB-20F7-4F42-8B5F-591268ACE836}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{856DF77E-EB78-45EB-836F-50C3B017B4C2}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteFile.UnitTests", "RemoteFile.UnitTests\RemoteFile.UnitTests.csproj", "{2769EBA9-6C62-4409-B637-FFA86E23749E}"
11+
EndProject
812
Global
913
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1014
Debug|Any CPU = Debug|Any CPU
@@ -15,11 +19,18 @@ Global
1519
{A006BFAB-20F7-4F42-8B5F-591268ACE836}.Debug|Any CPU.Build.0 = Debug|Any CPU
1620
{A006BFAB-20F7-4F42-8B5F-591268ACE836}.Release|Any CPU.ActiveCfg = Release|Any CPU
1721
{A006BFAB-20F7-4F42-8B5F-591268ACE836}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{2769EBA9-6C62-4409-B637-FFA86E23749E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{2769EBA9-6C62-4409-B637-FFA86E23749E}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{2769EBA9-6C62-4409-B637-FFA86E23749E}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{2769EBA9-6C62-4409-B637-FFA86E23749E}.Release|Any CPU.Build.0 = Release|Any CPU
1826
EndGlobalSection
1927
GlobalSection(SolutionProperties) = preSolution
2028
HideSolutionNode = FALSE
2129
EndGlobalSection
2230
GlobalSection(ExtensibilityGlobals) = postSolution
2331
SolutionGuid = {8F3245C7-FCC9-4666-99E0-F8D63BBE8373}
2432
EndGlobalSection
33+
GlobalSection(NestedProjects) = preSolution
34+
{2769EBA9-6C62-4409-B637-FFA86E23749E} = {856DF77E-EB78-45EB-836F-50C3B017B4C2}
35+
EndGlobalSection
2536
EndGlobal

RemoteFile/ApplicationSettings.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Keyfactor.Extensions.Orchestrator.RemoteFile
1818
{
19-
class ApplicationSettings
19+
public class ApplicationSettings
2020
{
2121
public enum FileTransferProtocolEnum
2222
{
@@ -63,15 +63,27 @@ public static FileTransferProtocolEnum FileTransferProtocol
6363
{
6464
get
6565
{
66+
ILogger logger = LogHandler.GetClassLogger<ApplicationSettings>();
67+
6668
string protocolNames = string.Empty;
6769
foreach (string protocolName in Enum.GetNames(typeof(FileTransferProtocolEnum)))
6870
{
6971
protocolNames += protocolName + ", ";
7072
}
7173
protocolNames = protocolNames.Substring(0, protocolNames.Length - 2);
74+
string? protocolValue = configuration["FileTransferProtocol"];
7275

73-
if (!Enum.TryParse(configuration["FileTransferProtocol"], out FileTransferProtocolEnum protocol))
74-
throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {configuration["FileTransferProtocol"]}. If present, must be one of these values: {protocolNames}.");
76+
if (!PropertyUtilities.TryEnumParse(protocolValue, out bool isFlagCombination, out FileTransferProtocolEnum protocol))
77+
throw new RemoteFileException($"Invalid optional config.json FileTransferProtocol option of {protocolValue}. If present, must be one of these values: {protocolNames}.");
78+
79+
// Issue: If received a comma-delimited list ("SCP,SFTP,Both"), it's treating it as a flag combination (i.e. mapping it to 0+1+2=3)
80+
// If this happens, we want to default it to Both so it's resolved as a valid mapping.
81+
if (isFlagCombination)
82+
{
83+
logger.LogWarning($"FileTransferProtocol config value {protocolValue} mapped to a flag combination. Setting FileTransferProtocol explicitly to Both.");
84+
protocol = FileTransferProtocolEnum.Both;
85+
}
86+
7587
return protocol;
7688
}
7789
}

RemoteFile/ImplementedStoreTypes/PEM/PEMCertificateStoreSerializer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ private void LoadCustomProperties(string storeProperties)
200200
IncludesChain = properties.IncludesChain == null || string.IsNullOrEmpty(properties.IncludesChain.Value) ? false : bool.Parse(properties.IncludesChain.Value);
201201
SeparatePrivateKeyFilePath = properties.SeparatePrivateKeyFilePath == null || string.IsNullOrEmpty(properties.SeparatePrivateKeyFilePath.Value) ? String.Empty : properties.SeparatePrivateKeyFilePath.Value;
202202
IgnorePrivateKeyOnInventory = properties.IgnorePrivateKeyOnInventory == null || string.IsNullOrEmpty(properties.IgnorePrivateKeyOnInventory.Value) ? false : bool.Parse(properties.IgnorePrivateKeyOnInventory.Value);
203+
204+
logger.LogDebug("Custom Properties have been loaded:");
205+
logger.LogDebug($"IsTrustStore: {IsTrustStore}, IncludesChain: {IncludesChain}, SeparatePrivateKeyFilePath: {SeparatePrivateKeyFilePath}, IgnorePrivateKeyOnInventory: {IgnorePrivateKeyOnInventory}");
203206

204207
logger.MethodExit(LogLevel.Debug);
205208
}

0 commit comments

Comments
 (0)