Skip to content

Commit e339ff3

Browse files
committed
misc: address pr feedback
1 parent b708a98 commit e339ff3

File tree

4 files changed

+33
-59
lines changed

4 files changed

+33
-59
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private AuthenticateKeyAgreeCommand()
124124
/// <exception cref="ArgumentException">
125125
/// The correspondent public value is not the correct length.
126126
/// </exception>
127-
[Obsolete("Use the constructor with the algorithm parameter instead.")]
127+
[Obsolete("Use the constructor with the algorithm parameter instead.", false)]
128128
public AuthenticateKeyAgreeCommand(ReadOnlyMemory<byte> correspondentPublicKey, byte slotNumber)
129129
{
130130
DataTag = KeyAgreeTag;

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

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,36 @@ public X509Certificate2 GetAttestationCertificate()
201201
ExceptionMessages.NotSupportedByYubiKeyVersion));
202202
}
203203

204-
/// <summary>
204+
205+
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
206+
public void ReplaceAttestationKeyAndCertificate(PivPrivateKey privateKey, X509Certificate2 certificate)
207+
{
208+
byte[] certDer = CheckVersionKeyAndCertRequirements(privateKey.Algorithm.GetKeyType(), certificate);
209+
210+
var tlvWriter = new TlvWriter();
211+
using (tlvWriter.WriteNestedTlv(0x53))
212+
{
213+
tlvWriter.WriteValue(0x70, certDer);
214+
tlvWriter.WriteByte(0x71, 0);
215+
tlvWriter.WriteValue(0xfe, null);
216+
}
217+
byte[] encodedCert = tlvWriter.Encode();
218+
219+
ImportPrivateKey(PivSlot.Attestation, privateKey);
220+
221+
var command = new PutDataCommand(AttestationCertTag, encodedCert);
222+
var response = Connection.SendCommand(command);
223+
if (response.Status != ResponseStatus.Success)
224+
{
225+
throw new InvalidOperationException(
226+
string.Format(
227+
CultureInfo.CurrentCulture,
228+
ExceptionMessages.CommandResponseApduUnexpectedResult,
229+
response.StatusWord.ToString("X4", CultureInfo.InvariantCulture)));
230+
}
231+
}
232+
233+
/// <summary>
205234
/// Replace the attestation key and certificate.
206235
/// </summary>
207236
/// <remarks>
@@ -328,34 +357,6 @@ public X509Certificate2 GetAttestationCertificate()
328357
/// Mutual authentication was performed and the YubiKey was not
329358
/// authenticated.
330359
/// </exception>
331-
[Obsolete("Usage of PivEccPublic/PivEccPrivateKey is deprecated. Use IPublicKey, IPrivateKey instead", false)]
332-
public void ReplaceAttestationKeyAndCertificate(PivPrivateKey privateKey, X509Certificate2 certificate)
333-
{
334-
byte[] certDer = CheckVersionKeyAndCertRequirements(privateKey.Algorithm.GetKeyType(), certificate);
335-
336-
var tlvWriter = new TlvWriter();
337-
using (tlvWriter.WriteNestedTlv(0x53))
338-
{
339-
tlvWriter.WriteValue(0x70, certDer);
340-
tlvWriter.WriteByte(0x71, 0);
341-
tlvWriter.WriteValue(0xfe, null);
342-
}
343-
byte[] encodedCert = tlvWriter.Encode();
344-
345-
ImportPrivateKey(PivSlot.Attestation, privateKey);
346-
347-
var command = new PutDataCommand(AttestationCertTag, encodedCert);
348-
var response = Connection.SendCommand(command);
349-
if (response.Status != ResponseStatus.Success)
350-
{
351-
throw new InvalidOperationException(
352-
string.Format(
353-
CultureInfo.CurrentCulture,
354-
ExceptionMessages.CommandResponseApduUnexpectedResult,
355-
response.StatusWord.ToString("X4", CultureInfo.InvariantCulture)));
356-
}
357-
}
358-
359360
public void ReplaceAttestationKeyAndCertificate(IPrivateKey privateKey, X509Certificate2 certificate)
360361
{
361362
if (privateKey is null)

Yubico.YubiKey/src/Yubico/YubiKey/Scp/Scp11KeyParameters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public Scp11KeyParameters(
111111
[Obsolete("Obsolete, use constructor with ECPrivateKey instead", false)]
112112
public Scp11KeyParameters(
113113
KeyReference keyReference,
114-
ECPublicKey pkSdEcka,
114+
ECPublicKeyParameters pkSdEcka,
115115
KeyReference oceKeyReference,
116116
ECPrivateKeyParameters skOceEcka,
117117
IReadOnlyCollection<X509Certificate2> oceCertificates)
118-
: this(keyReference, pkSdEcka, oceKeyReference, skOceEcka as ECPrivateKey, oceCertificates)
118+
: this(keyReference, pkSdEcka as ECPublicKey, oceKeyReference, skOceEcka as ECPrivateKey, oceCertificates)
119119
{
120120

121121
}

Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/KeyConverter.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -387,33 +387,6 @@ public PivPublicKey GetPivPublicKey()
387387
// not return a reference.
388388
public PivPrivateKey GetPivPrivateKey()
389389
{
390-
// if (_pivPrivateKey.Algorithm == PivAlgorithm.EccEd25519) // This is the simple one
391-
// {
392-
// var testPrivateKey = TestKeys.GetPrivateKey(_pivPrivateKey.Algorithm);
393-
// var last32Bytes = testPrivateKey.KeyBytes.AsSpan()[^32..];
394-
// var pivPrivateKey = new PivEccPrivateKey(last32Bytes.ToArray(), PivAlgorithm.EccEd25519);
395-
// return pivPrivateKey;
396-
// }
397-
//
398-
// if (_pivPrivateKey.Algorithm == PivAlgorithm.EccX25519) // This is the simple one
399-
// {
400-
// var testPrivateKey = TestKeys.GetPrivateKey(_pivPrivateKey.Algorithm);
401-
// var last32Bytes = testPrivateKey.KeyBytes.AsSpan()[^32..];
402-
// var pivPrivateKey = new PivEccPrivateKey(last32Bytes.ToArray(), PivAlgorithm.EccEd25519);
403-
// return pivPrivateKey;
404-
// }
405-
//
406-
// if (_pivPrivateKey.Algorithm ==
407-
// PivAlgorithm
408-
// .EccEd25519) // This is good as well, but a bit too complex. However it could be used to replace keyconverter
409-
// {
410-
// var testPrivateKey = TestKeys.GetPrivateKey(_pivPrivateKey.Algorithm);
411-
// var parser = new PrivateKeyInfoParser();
412-
// var keyInfo = parser.ParsePrivateKey<EdPrivateKeyInfo>(testPrivateKey.KeyBytes);
413-
// var pivPrivateKey = new PivEccPrivateKey(keyInfo.PrivateKey, _pivPrivateKey.Algorithm);
414-
// return pivPrivateKey;
415-
// }
416-
417390
if (_pivPrivateKey.Algorithm != PivAlgorithm.None)
418391
{
419392
return PivPrivateKey.Create(_pivPrivateKey.EncodedPrivateKey, _pivPrivateKey.Algorithm);

0 commit comments

Comments
 (0)