Skip to content

Commit 3025188

Browse files
committed
tests, misc: fix test, mark as false obsolete
1 parent a555bdb commit 3025188

File tree

10 files changed

+18
-75
lines changed

10 files changed

+18
-75
lines changed

Yubico.YubiKey/src/Yubico/YubiKey/Piv/Commands/ImportAsymmetricKeyCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private ImportAsymmetricKeyCommand()
215215
/// <exception cref="ArgumentException">
216216
/// The <c>privateKey</c> argument does not contain a key.
217217
/// </exception>
218-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
218+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
219219
public ImportAsymmetricKeyCommand(
220220
PivPrivateKey privateKey,
221221
byte slotNumber,
@@ -274,7 +274,7 @@ public ImportAsymmetricKeyCommand(
274274
/// <exception cref="ArgumentException">
275275
/// The <c>privateKey</c> argument does not contain a key.
276276
/// </exception>
277-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
277+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
278278
public ImportAsymmetricKeyCommand(PivPrivateKey privateKey)
279279
{
280280
if (privateKey is null)

Yubico.YubiKey/src/Yubico/YubiKey/Piv/Converters/PivKeyDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static Curve25519PublicKey CreateCurve25519PublicKey(ReadOnlyMemory<byte>
9090
/// The created instance will be one of the following concrete types:
9191
/// <list type="bullet">
9292
/// <item><see cref="RSAPrivateKey"/></item>
93-
/// <item><see cref="ECPrivateKeyParameters"/></item>
93+
/// <item><see cref="ECPrivateKey"/></item>
9494
/// <item><see cref="Curve25519PrivateKey"/></item>
9595
/// </list>
9696
/// </remarks>

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivEccPublicKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private PivEccPublicKey()
8383
/// <exception cref="ArgumentException">
8484
/// The format of the public point is not supported.
8585
/// </exception>
86-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
86+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
8787
public PivEccPublicKey(ReadOnlySpan<byte> publicPoint, PivAlgorithm? algorithm = null)
8888
{
8989
if (!LoadEccPublicKey(publicPoint, algorithm))

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private void ParseResponseData(ReadOnlyMemory<byte> responseData)
314314
/// <summary>
315315
/// The public key associated with the private key in the given slot.
316316
/// </summary>
317-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
317+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
318318
public PivPublicKey PublicKey { get; private set; }
319319

320320
/// <summary>

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Attestation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public X509Certificate2 GetAttestationCertificate()
328328
/// Mutual authentication was performed and the YubiKey was not
329329
/// authenticated.
330330
/// </exception>
331-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
331+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
332332
public void ReplaceAttestationKeyAndCertificate(PivPrivateKey privateKey, X509Certificate2 certificate)
333333
{
334334
byte[] certDer = CheckVersionKeyAndCertRequirements(privateKey.Algorithm.GetKeyType(), certificate);

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.Crypto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public byte[] Decrypt(byte slotNumber, ReadOnlyMemory<byte> dataToDecrypt)
267267
ExceptionMessages.IncorrectCiphertextLength));
268268
}
269269

270-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
270+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
271271
public byte[] KeyAgree(byte slotNumber, PivPublicKey correspondentPublicKey)
272272
{
273273
if (correspondentPublicKey is null)

Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.KeyPairs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public sealed partial class PivSession : IDisposable
3232
private const int PivCompressionTag = 0x71;
3333
private const int PivLrcTag = 0xFE;
3434

35-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
35+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
3636
public PivPublicKey GenerateKeyPair(
3737
byte slotNumber,
3838
PivAlgorithm algorithm,
@@ -255,7 +255,7 @@ public IPublicKey GenerateKeyPair(
255255
/// <exception cref="NotSupportedException">
256256
/// If the specified <see cref="PivAlgorithm"/> is not supported by the provided <see cref="IYubiKeyDevice"/>.
257257
/// </exception>
258-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey, ECPublicKey or ECPrivateKeyParameters instead")]
258+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
259259
public void ImportPrivateKey(
260260
byte slotNumber,
261261
PivPrivateKey privateKey,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ public void ImportPrivateKey_with_PrivateKey_Succeeds_and_HasExpectedValues(
9292
[InlineData(KeyType.RSA2048, StandardTestDevice.Fw5)]
9393
[InlineData(KeyType.RSA3072, StandardTestDevice.Fw5)]
9494
[InlineData(KeyType.RSA4096, StandardTestDevice.Fw5)]
95-
[Obsolete("Replaced by IPrivateKey")] // TODO
9695
public void KeyAndCertImport(
9796
KeyType keyType,
9897
StandardTestDevice testDeviceType)
9998
{
100-
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
99+
var testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
101100
Assert.True(testDevice.EnabledUsbCapabilities.HasFlag(YubiKeyCapabilities.Piv));
102101

103102
using var pivSession = new PivSession(testDevice);
@@ -107,11 +106,12 @@ public void KeyAndCertImport(
107106
var collectorObj = new Simple39KeyCollector();
108107
pivSession.KeyCollector = collectorObj.Simple39KeyCollectorDelegate;
109108

110-
isValid = SampleKeyPairs.GetMatchingKeyAndCert(keyType, out var cert, out var privateKey);
111-
Assert.True(isValid);
109+
var testPrivateKey = TestKeys.GetTestPrivateKey(keyType);
110+
var testCert =TestKeys.GetTestCertificate(keyType);
111+
var privateKey = AsnPrivateKeyDecoder.CreatePrivateKey(testPrivateKey.EncodedKey);
112112

113-
pivSession.ImportPrivateKey(0x90, privateKey!);
114-
pivSession.ImportCertificate(0x90, cert!);
113+
pivSession.ImportPrivateKey(0x90, privateKey);
114+
pivSession.ImportCertificate(0x90, testCert.AsX509Certificate2()!);
115115
}
116116

117117
[SkippableTheory(typeof(NotSupportedException), typeof(DeviceNotFoundException))]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class KeyAgreeTests
3131
[InlineData(KeyType.ECP384, PivPinPolicy.Never, StandardTestDevice.Fw5)]
3232
[InlineData(KeyType.X25519, PivPinPolicy.Never, StandardTestDevice.Fw5)]
3333
[InlineData(KeyType.X25519, PivPinPolicy.Always, StandardTestDevice.Fw5)]
34-
public void KeyAgree_Succeeds(
34+
public void KeyAgree_SharedSecret_IsValid(
3535
KeyType keyType,
3636
PivPinPolicy pinPolicy,
3737
StandardTestDevice testDeviceType)

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

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace Yubico.YubiKey.Piv
2727
{
2828
public class SignTests
2929
{
30+
3031
[Trait(TraitTypes.Category, TestCategories.Simple)]
3132
[SkippableTheory(typeof(NotSupportedException), typeof(DeviceNotFoundException))]
3233
[InlineData(StandardTestDevice.Fw5)]
@@ -35,7 +36,7 @@ public void Sign_WithEd25519_RandomData_Succeeds(
3536
StandardTestDevice testDeviceType)
3637
{
3738
// Arrange
38-
var dataToSign = new byte[3062];
39+
var dataToSign = new byte[3062]; // APDU cannot be bigger than this
3940
Random.Shared.NextBytes(dataToSign);
4041

4142
// -> Generate a Ed25519 key
@@ -241,63 +242,6 @@ public void SignRsa_VerifyCSharp_Correct(
241242
}
242243
}
243244

244-
[SkippableTheory(typeof(DeviceNotFoundException))]
245-
[InlineData(StandardTestDevice.Fw5, KeyType.ECP256, 0x94)]
246-
[InlineData(StandardTestDevice.Fw5Fips, KeyType.ECP384, 0x95)]
247-
[Obsolete("Use the keyparameters method instead")]
248-
public void SignEcc_VerifyCSharp_CorrectObsolete(
249-
StandardTestDevice testDeviceType,
250-
KeyType keyType,
251-
byte slotNumber)
252-
{
253-
byte[] dataToSign = new byte[128];
254-
Random.Shared.NextBytes(dataToSign);
255-
256-
var hashAlgorithm = keyType switch
257-
{
258-
KeyType.ECP256 => HashAlgorithmName.SHA256,
259-
_ => HashAlgorithmName.SHA384,
260-
};
261-
262-
using HashAlgorithm digester = keyType switch
263-
{
264-
KeyType.ECP256 => CryptographyProviders.Sha256Creator(),
265-
_ => CryptographyProviders.Sha384Creator(),
266-
};
267-
268-
digester.TransformFinalBlock(dataToSign, 0, dataToSign.Length);
269-
270-
_ = SampleKeyPairs.GetKeysAndCertPem(keyType, false, out _, out var pubKeyPem, out var priKeyPem);
271-
var pubKey = new KeyConverter(pubKeyPem!.ToCharArray());
272-
var priKey = new KeyConverter(priKeyPem!.ToCharArray());
273-
274-
try
275-
{
276-
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
277-
Assert.True(testDevice.AvailableUsbCapabilities.HasFlag(YubiKeyCapabilities.Piv));
278-
279-
using var pivSession = new PivSession(testDevice);
280-
var collectorObj = new Simple39KeyCollector();
281-
pivSession.KeyCollector = collectorObj.Simple39KeyCollectorDelegate;
282-
283-
pivSession.ImportPrivateKey(slotNumber, priKey.GetPivPrivateKey());
284-
285-
byte[] signature = pivSession.Sign(slotNumber, digester.Hash);
286-
287-
bool isValid = ConvertEcdsaSignature(signature, digester.Hash!.Length, out byte[] rsSignature);
288-
Assert.True(isValid);
289-
290-
using ECDsa eccPublic = pubKey.GetEccObject();
291-
bool isVerified = eccPublic.VerifyData(dataToSign, rsSignature, hashAlgorithm);
292-
Assert.True(isVerified);
293-
}
294-
finally
295-
{
296-
priKey.Clear();
297-
}
298-
}
299-
300-
301245
[SkippableTheory(typeof(DeviceNotFoundException))]
302246
[InlineData(StandardTestDevice.Fw5, KeyType.ECP256, 0x94)]
303247
[InlineData(StandardTestDevice.Fw5Fips, KeyType.ECP384, 0x95)]
@@ -323,7 +267,6 @@ public void SignEcc_VerifyCSharp_Correct(
323267

324268
digester.TransformFinalBlock(dataToSign, 0, dataToSign.Length);
325269

326-
// _ = SampleKeyPairs.GetKeysAndCertPem(keyType, false, out _, out var pubKeyPem, out var priKeyPem);
327270
var (testPublicKey, testPrivateKey) = TestKeys.GetKeyPair(keyType);
328271
var privateKey = ECPrivateKey.CreateFromPkcs8(testPrivateKey.EncodedKey);
329272
try

0 commit comments

Comments
 (0)