Skip to content

Commit ec842bb

Browse files
committed
misc: minor work
remove unnecessary overload remove comment
1 parent e426906 commit ec842bb

File tree

5 files changed

+12
-151
lines changed

5 files changed

+12
-151
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ public byte SlotNumber
127127
/// <exception cref="ArgumentException">
128128
/// The algorithm specified is not a supported asymmetric algorithm.
129129
/// </exception>
130-
[Obsolete("Replaced by PublicKeyParameters.KeyType")]
131130
public PivAlgorithm Algorithm
132-
// the algorithm is not returned by the generate key pair, so this is useless, its already known by the caller
133131
{
134132
get => _algorithm;
135133
set
@@ -161,7 +159,6 @@ public PivAlgorithm Algorithm
161159
/// <param name="algorithm">
162160
/// The algorithm (and key size) of the key pair generated.
163161
/// </param>
164-
[Obsolete("Use other constructor")]
165162
public GenerateKeyPairResponse(
166163
ResponseApdu responseApdu,
167164
byte slotNumber,
@@ -211,9 +208,7 @@ public GenerateKeyPairResponse(
211208
/// <exception cref="InvalidOperationException">
212209
/// Thrown when <see cref="YubiKeyResponse.Status"/> is not <see cref="ResponseStatus.Success"/>.
213210
/// </exception>
214-
public PivPublicKey GetData() => // To change this to return IPublicKeyPArameters would be a brekaing change. But is it necessary? Can we still use
215-
// the pivpublickey inside the piv app? yes we can, but we dont need the caller to know we are converting in the bg
216-
// but in some times the caller is receiving a pivpublickey..
211+
public PivPublicKey GetData() =>
217212
Status switch
218213
{
219214
#pragma warning disable CS0618 // Type or member is obsolete

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

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -158,140 +158,6 @@ public byte[] Sign(byte slotNumber, ReadOnlyMemory<byte> dataToSign)
158158
ExceptionMessages.IncorrectDigestLength));
159159
}
160160

161-
/// <summary>
162-
/// Create a digital signature using the key in the given slot.
163-
/// </summary>
164-
/// <remarks>
165-
/// The caller supplies the data to sign in the form of a formatted
166-
/// message digest.
167-
/// <para>
168-
/// This method returns the digital signature created, if it can build
169-
/// one. Otherwise it will throw an exception.
170-
/// </para>
171-
/// <para>
172-
/// If the slot specified is not one that can sign, or it does not
173-
/// contain a key, this method will throw an exception. If the input data
174-
/// is not the correct length, the method will throw an exception.
175-
/// </para>
176-
/// <para>
177-
/// If the key is ECC P-256, then the formatted digest is simply the
178-
/// message digest itself, but it must be exactly 32 bytes. If the input
179-
/// is not exactly 32 bytes, the method will throw an exception. If the
180-
/// input data is shorter than 32 bytes, prepend pad bytes of 00 until
181-
/// the length is exactly 32 bytes. You will almost certainly want to use
182-
/// SHA-256 as the digest algorithm. The signature will be the BER
183-
/// encoding of
184-
/// <code>
185-
/// SEQUENCE {
186-
/// r INTEGER,
187-
/// s INTEGER }
188-
/// </code>
189-
/// </para>
190-
/// <para>
191-
/// If the key is ECC P-384, then the formatted digest is simply the
192-
/// message digest itself, but it must be exactly 48 bytes. If the input
193-
/// is not exactly 48 bytes, the method will throw an exception. If the
194-
/// input data is shorter than 48 bytes, prepend pad bytes of 00 until
195-
/// the length is exactly 48 bytes. You will almost certainly want to use
196-
/// SHA-384 as the digest algorithm. The signature will be the BER
197-
/// encoding of
198-
/// <code>
199-
/// SEQUENCE {
200-
/// r INTEGER,
201-
/// s INTEGER }
202-
/// </code>
203-
/// </para>
204-
/// <para>
205-
/// If the key is RSA 1024/2048/3072/4096, then the input must be exactly 128/256/384/512 bytes,
206-
/// otherwise the method will throw an exception. You can use the
207-
/// <see cref="Cryptography.RsaFormat"/> class to format the data. That
208-
/// class will be able to format the digest into either PKCS #1 v1.5 or a
209-
/// subset of PKCS #1 PSS. However, if that class does not support the
210-
/// exact format you want, you will have to write your own formatting
211-
/// code and guarantee the input to this method is exactly 128/256/384/512 bytes
212-
/// (prepend pad bytes of 00 until the length is exactly 128/256/384/512 if needed).
213-
/// The signature will be a 128/256/384/512-byte block.
214-
/// </para>
215-
/// <para>
216-
/// Signing might require the PIN and/or touch, depending on the PIN and
217-
/// touch policies specified at the time the key was generated or
218-
/// imported.
219-
/// </para>
220-
/// <para>
221-
/// If a PIN is required, this method will call the necessary
222-
/// routines to verify the PIN. See <see cref="VerifyPin()"/> for more
223-
/// information on PIN verification. If the user cancels, this method
224-
/// will throw an exception.
225-
/// </para>
226-
/// <para>
227-
/// If touch is required, the YubiKey itself will flash its touch signal
228-
/// and wait. If the YubiKey is not touched before the touch timeout, the
229-
/// YubiKey will return with an error, and this method will throw an
230-
/// exception (<c>OperationCanceledException</c>). Note that this method
231-
/// will not make another effort to sign if the YubiKey is not touched,
232-
/// it will simply throw the exception.
233-
/// </para>
234-
/// <para>
235-
/// Note that on YubiKeys prior to version 5.3, it is not possible to know
236-
/// programmatically what the PIN or touch policies are without actually
237-
/// trying to sign. Also, it is not possible to know programmatically if
238-
/// an authentication failure is due to PIN or touch. This means that on
239-
/// older YubiKeys, this method will try to sign without the PIN, and if
240-
/// it does not work because of authentication failure, it will not know
241-
/// if the failure was due to PIN or touch. Hence, it will try to verify
242-
/// the PIN then try to sign again. This all means that on older
243-
/// YubiKeys, it is possible a YubiKey slot was originally configured
244-
/// with a PIN policy of "never" and a touch policy of "always", and this
245-
/// method will call for the PIN anyway. This happens if the user does
246-
/// not touch the YubiKey before the timeout. See the User's Manual entry
247-
/// on <xref href="UsersManualPivKeepingTrack">keeping track</xref> of
248-
/// slot contents.
249-
/// </para>
250-
/// </remarks>
251-
/// <param name="slotNumber">
252-
/// The slot containing the key to use.
253-
/// </param>
254-
/// <param name="dataToSign">
255-
/// The formatted message digest.
256-
/// </param>
257-
/// <param name="keyType">The algorithm to use.</param>
258-
/// <returns>
259-
/// The resulting signature.
260-
/// </returns>
261-
/// <exception cref="ArgumentException">
262-
/// The slot number given was not valid, or the data to sign was an
263-
/// invalid length.
264-
/// </exception>
265-
/// <exception cref="InvalidOperationException">
266-
/// There was no key in the slot specified or the data did not match the
267-
/// key (e.g. the data to sign was 32 bytes long but the key was ECC
268-
/// P-384).
269-
/// </exception>
270-
/// <exception cref="OperationCanceledException">
271-
/// Either the PIN was required and the user canceled collection or touch
272-
/// was required and the user did not touch within the timeout period.
273-
/// </exception>
274-
/// <exception cref="SecurityException">
275-
/// The remaining retries count indicates the PIN is blocked.
276-
/// </exception>
277-
/// <exception cref="NotSupportedException">
278-
/// If the specified <see cref="PivAlgorithm"/> is not supported by the provided <see cref="IYubiKeyDevice"/>.
279-
/// </exception>
280-
public byte[] Sign(byte slotNumber, ReadOnlyMemory<byte> dataToSign, KeyType keyType)
281-
{
282-
var pivAlgorithm = keyType.GetPivAlgorithm();
283-
YubiKey.ThrowIfUnsupportedAlgorithm(pivAlgorithm);
284-
285-
var signCommand = new AuthenticateSignCommand(dataToSign, slotNumber, pivAlgorithm);
286-
return PerformPrivateKeyOperation(
287-
slotNumber,
288-
signCommand,
289-
signCommand.Algorithm,
290-
string.Format(
291-
CultureInfo.CurrentCulture,
292-
ExceptionMessages.IncorrectDigestLength));
293-
}
294-
295161
/// <summary>
296162
/// Decrypt the given data using the key in the given slot.
297163
/// </summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void Decrypt_2048_Succeeds(PivPinPolicy pinPolicy, StandardTestDevice tes
102102
[InlineData(KeyType.RSA2048, 0x95, RsaFormat.Sha256, 2, StandardTestDevice.Fw5)]
103103
[InlineData(KeyType.RSA2048, 0x95, RsaFormat.Sha384, 2, StandardTestDevice.Fw5)]
104104
[InlineData(KeyType.RSA2048, 0x95, RsaFormat.Sha512, 2, StandardTestDevice.Fw5)]
105-
[Obsolete] // FIx later
105+
[Obsolete] // TODO Fix later
106106
public void EncryptCSharp_Decrypt_Correct(KeyType keyType, byte slotNumber, int digestAlgorithm, int paddingScheme, StandardTestDevice testDeviceType)
107107
{
108108
var rsaPadding = RSAEncryptionPadding.Pkcs1;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public void PinAlways_Sign_Succeeds(StandardTestDevice testDeviceType)
4646
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
4747
};
4848

49-
byte[] signature1 = pivSession.Sign(slotNumber, dataToSign, KeyType.P256);
49+
byte[] signature1 = pivSession.Sign(slotNumber, dataToSign);
5050
Assert.Equal(0x30, signature1[0]);
5151

52-
byte[] signature2 = pivSession.Sign(slotNumber, dataToSign, KeyType.P256);
52+
byte[] signature2 = pivSession.Sign(slotNumber, dataToSign);
5353
bool isSame = signature1.SequenceEqual(signature2);
5454
Assert.False(isSame);
5555
}
@@ -80,10 +80,10 @@ public void Slot9C_Default_Sign_Succeeds(StandardTestDevice testDeviceType)
8080
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
8181
};
8282

83-
byte[] signature1 = pivSession.Sign(slotNumber, dataToSign, KeyType.P256);
83+
byte[] signature1 = pivSession.Sign(slotNumber, dataToSign);
8484
Assert.Equal(0x30, signature1[0]);
8585

86-
byte[] signature2 = pivSession.Sign(slotNumber, dataToSign, KeyType.P256);
86+
byte[] signature2 = pivSession.Sign(slotNumber, dataToSign);
8787
bool isSame = signature1.SequenceEqual(signature2);
8888
Assert.False(isSame);
8989
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Sign_WithEd25519_RandomData_Succeeds(
4444
var publicKeyParameters = pivSession.GenerateKeyPair(PivSlot.Retired12, KeyType.Ed25519);
4545

4646
// Act
47-
var signature = pivSession.Sign(PivSlot.Retired12, dataToSign, KeyType.Ed25519);
47+
var signature = pivSession.Sign(PivSlot.Retired12, dataToSign);
4848

4949
// -> Verify the signature
5050
var bouncyKeyParameters = GetBouncyKeyParameters(publicKeyParameters);
@@ -71,7 +71,7 @@ public void Sign_WithEd25519_RandomData_Succeeds(
7171
[InlineData(StandardTestDevice.Fw5Fips, KeyType.RSA4096)]
7272
[InlineData(StandardTestDevice.Fw5Fips, KeyType.P256)]
7373
[InlineData(StandardTestDevice.Fw5Fips, KeyType.P384)]
74-
public async Task Sign_with_RSAandECDsa_Succeeds(
74+
public async Task Sign_with_RSAandECDsa_Succeeds( // TODO Tests are flaky
7575
StandardTestDevice testDeviceType,
7676
KeyType keyType)
7777
{
@@ -107,7 +107,7 @@ public async Task Sign_with_RSAandECDsa_Succeeds(
107107
var collectorObj = new Simple39KeyCollector();
108108
pivSession.KeyCollector = collectorObj.Simple39KeyCollectorDelegate;
109109

110-
var signature2 = pivSession.Sign(slotNumber, dataToSign, keyType);
110+
var signature2 = pivSession.Sign(slotNumber, dataToSign);
111111
Assert.True(isValid);
112112
Assert.NotEmpty(signature2);
113113
}
@@ -230,7 +230,7 @@ public void SignRsa_VerifyCSharp_Correct(
230230
pivSession.KeyCollector = collectorObj.Simple39KeyCollectorDelegate;
231231

232232
pivSession.ImportPrivateKey(slotNumber, priKey.GetPivPrivateKey());
233-
byte[] signature = pivSession.Sign(slotNumber, formattedData, keyType);
233+
byte[] signature = pivSession.Sign(slotNumber, formattedData);
234234

235235
using RSA rsaPublic = pubKey.GetRsaObject();
236236
bool isVerified = rsaPublic.VerifyData(dataToSign, signature, hashAlgorithm, padding);
@@ -283,7 +283,7 @@ public void SignEcc_VerifyCSharp_CorrectObsolete(
283283

284284
pivSession.ImportPrivateKey(slotNumber, priKey.GetPivPrivateKey());
285285

286-
byte[] signature = pivSession.Sign(slotNumber, digester.Hash, keyType);
286+
byte[] signature = pivSession.Sign(slotNumber, digester.Hash);
287287

288288
bool isValid = ConvertEcdsaSignature(signature, digester.Hash!.Length, out byte[] rsSignature);
289289
Assert.True(isValid);
@@ -338,7 +338,7 @@ public void SignEcc_VerifyCSharp_Correct(
338338

339339
pivSession.ImportPrivateKey(slotNumber, privateKey);
340340

341-
byte[] signature = pivSession.Sign(slotNumber, digester.Hash, keyType);
341+
byte[] signature = pivSession.Sign(slotNumber, digester.Hash);
342342

343343
bool isValid = ConvertEcdsaSignature(signature, digester.Hash!.Length, out byte[] rsSignature);
344344
Assert.True(isValid);

0 commit comments

Comments
 (0)