Skip to content

Commit 8c52f4e

Browse files
committed
tests: misc Scp test changes
1 parent 3465c0a commit 8c52f4e

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Piv/Simple39KeyCollector.cs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System;
16+
1517
namespace Yubico.YubiKey.Piv
1618
{
1719
// This KeyCollector class can be used to provide the KeyCollector delegate
@@ -50,20 +52,17 @@ public Simple39KeyCollector(bool setKeyFlagOnChange = false)
5052

5153
public bool Simple39KeyCollectorDelegate(KeyEntryData keyEntryData)
5254
{
53-
if (keyEntryData.IsRetry && RetryFlag == 0)
55+
if (keyEntryData.IsRetry &&
56+
RetryFlag == 0 &&
57+
keyEntryData.RetriesRemaining is not null &&
58+
keyEntryData.RetriesRemaining == 1)
5459
{
55-
if (!(keyEntryData.RetriesRemaining is null))
56-
{
57-
if (keyEntryData.RetriesRemaining == 1)
58-
{
59-
return false;
60-
}
61-
}
60+
return false;
6261
}
6362

6463
bool isChange = false;
65-
byte[] currentValue;
66-
byte[]? newValue = null;
64+
Memory<byte> currentValue;
65+
Memory<byte>? newValue = null;
6766

6867
switch (keyEntryData.Request)
6968
{
@@ -125,52 +124,35 @@ public bool Simple39KeyCollectorDelegate(KeyEntryData keyEntryData)
125124
{
126125
if (KeyFlag != 0)
127126
{
128-
currentValue[0] = 0x39;
127+
currentValue.Span[0] = 0x39;
129128
}
130129

131-
keyEntryData.SubmitValue(currentValue);
130+
keyEntryData.SubmitValue(currentValue.Span);
132131
}
133132
else
134133
{
135134
if (KeyFlag != 0)
136135
{
137-
currentValue[0] = 0x39;
136+
currentValue.Span[0] = 0x39;
138137
}
139138
else
140139
{
141-
newValue[0] = 0x39;
140+
newValue.Value.Span[0] = 0x39;
142141
}
143142

144-
keyEntryData.SubmitValues(currentValue, newValue);
143+
keyEntryData.SubmitValues(currentValue.Span, newValue.Value.Span);
145144
}
146145

147146
if (_setKeyFlagOnChange && isChange)
148147
{
149-
if (KeyFlag == 0)
150-
{
151-
KeyFlag = 1;
152-
}
153-
else
154-
{
155-
KeyFlag = 1;
156-
}
148+
KeyFlag = 1;
157149
}
158150

159151
return true;
160152
}
161153

162-
public static byte[] CollectPin() =>
163-
new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36 };
164-
165-
public static byte[] CollectPuk() =>
166-
new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 };
167-
168-
public static byte[] CollectMgmtKey() =>
169-
new byte[]
170-
{
171-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
172-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
173-
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
174-
};
154+
public static Memory<byte> CollectPin() => PivSessionIntegrationTestBase.DefaultPin.ToArray();
155+
public static Memory<byte> CollectPuk() => PivSessionIntegrationTestBase.DefaultPuk.ToArray();
156+
public static Memory<byte> CollectMgmtKey() => PivSessionIntegrationTestBase.DefaultManagementKey.ToArray();
175157
}
176158
}

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Scp/Scp03Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private byte[] GetValidPin(
536536
byte[] pin;
537537
if (desiredDeviceType == StandardTestDevice.Fw5Fips)
538538
{
539-
ScpTestUtilities.SetFipsApprovedCredentials(testDevice, YubiKeyApplication.Piv, keyParams);
539+
ScpTestUtilities.SetFipsApprovedCredentials(testDevice, keyParams);
540540
pin = ScpTestUtilities.FipsPin;
541541
}
542542
else

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Scp/ScpTestUtilities.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ namespace Yubico.YubiKey.Scp
2020
{
2121
public static class ScpTestUtilities
2222
{
23-
public static byte[] FipsPin = {
23+
public static readonly byte[] FipsPin = {
2424
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88
2525
};
2626

27-
public static byte[] FipsPuk = {
27+
public static readonly byte[] FipsPuk = {
2828
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88
2929
};
3030

31-
public static byte[] FipsManagementKey = {
31+
public static readonly byte[] FipsManagementKey = {
3232
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
3333
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12,
3434
0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9A
@@ -47,18 +47,10 @@ public static void SetFipsApprovedCredentials(PivSession session)
4747

4848
public static void SetFipsApprovedCredentials(
4949
IYubiKeyDevice device,
50-
YubiKeyApplication application,
5150
ScpKeyParameters parameters)
5251
{
53-
if (application == YubiKeyApplication.Piv)
54-
{
55-
using var session = new PivSession(device, parameters);
56-
SetFipsApprovedCredentials(session);
57-
58-
return;
59-
}
60-
61-
throw new NotSupportedException();
52+
using var session = new PivSession(device, parameters);
53+
SetFipsApprovedCredentials(session);
6254
}
6355
}
6456
}

0 commit comments

Comments
 (0)