Skip to content

Commit 22b9dc0

Browse files
committed
Fix truncated legacy fingerprint lookup table
Legacy session-key renewal could throw IndexOutOfRangeException in FingerprintSubProcedure when a challenge selected the final lookup block. Data2Collection table 1 contained 4222 bytes although its 33 operations require 4224 bytes. Restore the missing final lookup word 0x4C28. The captured renewal challenge 5B15B4694FC38A775E6778F0770C6E7A3118200D now derives fingerprint 6AB5811DE6D28746 and can complete authentication instead of terminating the connection. Add a lookup-table size invariant and an exact regression test for the captured challenge. Bump the package, assembly, and file versions to 1.1.3 and document the fix in the package release notes.
1 parent d587055 commit 22b9dc0

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

Directory.Build.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<RepositoryType>git</RepositoryType>
1212
<PackageTags>siemens;s7</PackageTags>
1313

14-
<PackageVersion>1.1.2</PackageVersion>
15-
<AssemblyVersion>1.1.2</AssemblyVersion>
16-
<FileVersion>1.1.2</FileVersion>
17-
<Version>1.1.2</Version>
18-
<PackageReleaseNotes>Internal naming changes</PackageReleaseNotes>
14+
<PackageVersion>1.1.3</PackageVersion>
15+
<AssemblyVersion>1.1.3</AssemblyVersion>
16+
<FileVersion>1.1.3</FileVersion>
17+
<Version>1.1.3</Version>
18+
<PackageReleaseNotes>Fix legacy challenge fingerprint derivation for the final lookup-table block.</PackageReleaseNotes>
1919

2020
<PackageIcon>nuget-icon.png</PackageIcon>
2121
</PropertyGroup>

HarpoS7.Tests/Fingerprint/HarpoFingerprintTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ namespace HarpoS7.Tests.Fingerprint;
55

66
public class HarpoFingerprintTests
77
{
8+
[Test]
9+
public void LookupTablesCoverEveryComputedBlock()
10+
{
11+
for (var index = 0; index < FingerprintConsts.Data1Collection.Length; index++)
12+
{
13+
var operations = FingerprintConsts.Data1Collection[index].Length / 3;
14+
var requiredBytes = operations * 128;
15+
var availableBytes = FingerprintConsts.Data2Collection[index].Length * sizeof(ushort);
16+
Assert.That(
17+
availableBytes,
18+
Is.GreaterThanOrEqualTo(requiredBytes),
19+
$"Fingerprint table {index} is too short for its computed indices");
20+
}
21+
}
22+
23+
[Test]
24+
public void FingerprintChallengeHandlesCapturedLegacyRenewalEdgeCase()
25+
{
26+
Span<byte> fingerprint = stackalloc byte[FingerprintConsts.FingerprintLength];
27+
var challenge = Convert.FromHexString("5B15B4694FC38A775E6778F0770C6E7A3118200D");
28+
29+
HarpoFingerprint.FingerprintChallenge(fingerprint, challenge);
30+
31+
Assert.That(Convert.ToHexString(fingerprint), Is.EqualTo("6AB5811DE6D28746"));
32+
}
33+
834
public static IEnumerable<TestCaseData> FingerprintSubProcedureCases
935
{
1036
get
@@ -1003,4 +1029,4 @@ public void FingerprintChallenge()
10031029
var expectedFingerprint = new byte[8] { 0xe2, 0x87, 0xc1, 0xcb, 0x65, 0x9b, 0x9e, 0xdf }.AsSpan();
10041030
Assert.That(expectedFingerprint.SequenceEqual(fingerprint));
10051031
}
1006-
}
1032+
}

HarpoS7/Fingerprint/FingerprintConsts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public static class FingerprintConsts
524524
0xd7b1, 0xe73f, 0x7a90, 0xb821, 0xc54b, 0xabd6, 0x7552, 0x4a40, 0xf0d3, 0x2dbf, 0x1fc5, 0xcc99, 0x8111,
525525
0x4305, 0x7080, 0xe835, 0xbf4, 0x43f, 0x6a5f, 0x2ab3, 0xf854, 0x1f7f, 0x3491, 0xd376, 0xd0bb, 0x7bc7,
526526
0xed86, 0x7fbc, 0x2e5b, 0xc137, 0x8bcb, 0xe9ad, 0xb41c, 0xd4ce, 0x77d5, 0xc22f, 0x929f, 0xb6b2, 0xd74f,
527-
0xe11d, 0xf565, 0x823f, 0x518b, 0xa857, 0xbf08
527+
0xe11d, 0xf565, 0x823f, 0x518b, 0xa857, 0xbf08, 0x4c28
528528
},
529529
new ushort[]
530530
{
@@ -2710,4 +2710,4 @@ public static class FingerprintConsts
27102710
0xbc27, 0xf54d, 0x261
27112711
},
27122712
};
2713-
}
2713+
}

0 commit comments

Comments
 (0)