@@ -267,7 +267,7 @@ public PivPinOnlyMode TryRecoverPinOnlyMode()
267
267
// If we can authenticate the mgmt key, then set ADMIN DATA and
268
268
// PRINTED.
269
269
var userKeyCollector = KeyCollector ;
270
- using var specialKeyCollector = new SpecialKeyCollector ( ) ;
270
+ using var specialKeyCollector = new SpecialKeyCollector ( DefaultManagementKeyAlgorithm ) ;
271
271
272
272
try
273
273
{
@@ -349,7 +349,7 @@ private PivPinOnlyMode TryAuthenticatePinOnly(bool trustAdminData)
349
349
}
350
350
351
351
var userKeyCollector = KeyCollector ;
352
- using var specialKeyCollector = new SpecialKeyCollector ( ) ;
352
+ using var specialKeyCollector = new SpecialKeyCollector ( DefaultManagementKeyAlgorithm ) ;
353
353
354
354
try
355
355
{
@@ -513,7 +513,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
513
513
514
514
/// <summary>
515
515
/// Set the YubiKey's PIV application to be PIN-only with a PIN-derived
516
- /// and/or PIN-Protected Triple-DES management key. This sets the
516
+ /// and/or PIN-Protected management key (Firmware 5.7.x and later: AES-192. Firmware 5.6.x and earlier: TDES.) . This sets the
517
517
/// YubiKey to either
518
518
/// <code>
519
519
/// PivPinOnlyMode.PinProtected
@@ -544,7 +544,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
544
544
/// </para>
545
545
/// <para>
546
546
/// Note also that this will make sure that the management key algorithm
547
- /// will be Triple-DES , even if the current management key is a different
547
+ /// will be default management key algorithm (Firmware 5.7.x and later: AES-192. Firmware 5.6.x and earlier: TDES.) , even if the current management key is a different
548
548
/// algorithm. This behavior matches how this method operated in previous
549
549
/// versions of the SDK.
550
550
/// </para>
@@ -554,7 +554,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
554
554
/// </param>
555
555
/// <exception cref="InvalidOperationException">
556
556
/// There is no <c>KeyCollector</c> loaded, one of the keys provided was
557
- /// not a valid Triple-DES key , the data stored on the YubiKey is
557
+ /// not of a valid key algorithm type (Firmware 5.7.x and later: AES-192. Firmware 5.6.x and earlier: TDES.) , the data stored on the YubiKey is
558
558
/// incompatible with PIN-only, or the YubiKey had some other error, such
559
559
/// as unreliable connection.
560
560
/// </exception>
@@ -566,7 +566,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
566
566
/// authenticated, or the remaining retries count indicates the PIN is
567
567
/// blocked.
568
568
/// </exception>
569
- public void SetPinOnlyMode ( PivPinOnlyMode pinOnlyMode ) => SetPinOnlyMode ( pinOnlyMode , PivAlgorithm . TripleDes ) ;
569
+ public void SetPinOnlyMode ( PivPinOnlyMode pinOnlyMode ) => SetPinOnlyMode ( pinOnlyMode , DefaultManagementKeyAlgorithm ) ;
570
570
571
571
/// <summary>
572
572
/// Set the YubiKey's PIV application to be PIN-only with a PIN-derived
@@ -604,13 +604,13 @@ private PivPinOnlyMode GetPinDerivedStatus(
604
604
/// The management key derived and/or stored in PRINTED will be for the
605
605
/// specified algorithm. For all YubiKeys, <c>TripleDes</c> is a valid
606
606
/// algorithm. For YubiKeys 5.4.2 and later, it is possible to set the
607
- /// management key to an AES key. Before setting the
608
- /// <c>mgmtKeyAlgorithm</c> arg to an AES algorithm, make sure it is
607
+ /// management key to an AES key. For YubiKeys 5.7 and later, AES192 is the default.
608
+ /// Before setting the <c>mgmtKeyAlgorithm</c> arg to an AES algorithm, make sure it is
609
609
/// allowed on the YubiKey. You can use the <c>HasFeature</c> call. For
610
610
/// example,
611
611
/// <code language="csharp">
612
612
/// PivAlgorithm mgmtKeyAlgorithm = yubiKey.HasFeature(YubiKeyFeature.PivAesManagementKey) ?
613
- /// PivAlgorithm.Aes128 : PivAlgorithm.TripleDes;
613
+ /// PivAlgorithm.Aes192 : PivAlgorithm.TripleDes;
614
614
/// pivSession.SetPinOnlyMode(PivPinOnlyMode.PinProtected, mgmtKeyAlgorithm);
615
615
/// </code>
616
616
/// If the algorithm is not supported by the YubiKey, this method will
@@ -641,16 +641,11 @@ private PivPinOnlyMode GetPinDerivedStatus(
641
641
/// currently set to PIN-only (and neither PinProtected nor PinDerived is
642
642
/// Unavailable), this method will remove the contents of the storage
643
643
/// locations ADMIN DATA and PRINTED, and reset the management key to the
644
- /// default:
645
- /// <code>
646
- /// Triple-DES
647
- /// 0x01 02 03 04 05 06 07 08
648
- /// 01 02 03 04 05 06 07 08
649
- /// 01 02 03 04 05 06 07 08
650
- /// </code>
644
+ /// default management key.
651
645
/// In this case, the <c>mgmtKeyAlgorithm</c> arg will be ignored, the
652
646
/// management key's algorithm after removing PIN-only status will be
653
- /// Triple-DES. The touch policy of the management key will also be set
647
+ /// the default management key algorithm (Firmware 5.7.x and later: AES-192. Firmware 5.6.x and earlier: TDES.).
648
+ /// The touch policy of the management key will also be set
654
649
/// to the default (Never). Note that the management key must be
655
650
/// authenticated and the PIN verified in order to perform this task.
656
651
/// This method will authenticate the management key using the PIN-only
@@ -732,7 +727,7 @@ private PivPinOnlyMode GetPinDerivedStatus(
732
727
/// </param>
733
728
/// <exception cref="InvalidOperationException">
734
729
/// There is no <c>KeyCollector</c> loaded, one of the keys provided was
735
- /// not a valid Triple-DES key , the data stored on the YubiKey is
730
+ /// not of a valid key algorithm type (Firmware 5.7.x and later: AES-192. Firmware 5.6.x and earlier: TDES.) , the data stored on the YubiKey is
736
731
/// incompatible with PIN-only, or the YubiKey had some other error, such
737
732
/// as unreliable connection.
738
733
/// </exception>
@@ -751,7 +746,7 @@ public void SetPinOnlyMode(PivPinOnlyMode pinOnlyMode, PivAlgorithm mgmtKeyAlgor
751
746
pinOnlyMode . ToString ( ) , mgmtKeyAlgorithm . ToString ( ) ) ;
752
747
753
748
var userKeyCollector = KeyCollector ;
754
- using var specialKeyCollector = new SpecialKeyCollector ( ) ;
749
+ using var specialKeyCollector = new SpecialKeyCollector ( DefaultManagementKeyAlgorithm ) ;
755
750
756
751
try
757
752
{
@@ -777,7 +772,7 @@ private void SetPinOnlyMode(ReadOnlyMemory<byte> pin, PivPinOnlyMode pinOnlyMode
777
772
}
778
773
779
774
var userKeyCollector = KeyCollector ;
780
- using var specialKeyCollector = new SpecialKeyCollector ( ) ;
775
+ using var specialKeyCollector = new SpecialKeyCollector ( DefaultManagementKeyAlgorithm ) ;
781
776
782
777
try
783
778
{
@@ -835,7 +830,7 @@ private void SetPinOnlyMode(
835
830
// Or some other reason.
836
831
var newPinOnlyMode = PivPinOnlyMode . None ;
837
832
var currentPinOnlyMode = GetPrintedPinProtectedStatus ( specialKeyCollector , userKeyCollector ) ;
838
-
833
+
839
834
var pinOnlyCheck = CheckPinOnlyStatus (
840
835
currentPinOnlyMode , pinOnlyMode , PivPinOnlyMode . PinProtected , PivPinOnlyMode . PinProtectedUnavailable ,
841
836
newAlgorithm , ref newPinOnlyMode ) ;
@@ -1028,11 +1023,12 @@ private void ClearPinOnly(PivPinOnlyMode currentMode, SpecialKeyCollector specia
1028
1023
PutEmptyData ( AdminDataDataTag ) ;
1029
1024
}
1030
1025
1026
+ var managementKeyAlgorithm = DefaultManagementKeyAlgorithm ;
1031
1027
specialKeyCollector . SetKeyData (
1032
1028
SpecialKeyCollector . SetKeyDataDefault , ReadOnlyMemory < byte > . Empty , isNewKey : true ,
1033
- PivAlgorithm . TripleDes ) ;
1029
+ managementKeyAlgorithm ) ;
1034
1030
1035
- specialKeyCollector . ChangeManagementKey ( this , PivAlgorithm . TripleDes ) ;
1031
+ specialKeyCollector . ChangeManagementKey ( this , managementKeyAlgorithm ) ;
1036
1032
}
1037
1033
1038
1034
private void PutEmptyData ( int dataTag )
@@ -1087,7 +1083,7 @@ private void SetYubiKeyPinDerived(
1087
1083
// because this method will update the current key with the new key.
1088
1084
specialKeyCollector . ChangeManagementKey ( this , mgmtKeyAlgorithm ) ;
1089
1085
_ = BlockPinOrPuk ( PivSlot . Puk ) ;
1090
-
1086
+
1091
1087
adminData . SetSalt ( saltBytes ) ;
1092
1088
adminData . PukBlocked = true ;
1093
1089
}
@@ -1150,7 +1146,7 @@ private bool TryGetChangePinMode(ReadOnlyMemory<byte> pin, out PivPinOnlyMode mo
1150
1146
mode = PivPinOnlyMode . None ;
1151
1147
1152
1148
var userKeyCollectorFunc = KeyCollector ;
1153
- using var specialKeyCollector = new SpecialKeyCollector ( ) ;
1149
+ using var specialKeyCollector = new SpecialKeyCollector ( DefaultManagementKeyAlgorithm ) ;
1154
1150
1155
1151
bool isValid = TryReadObject ( out AdminData adminData ) ;
1156
1152
@@ -1179,17 +1175,18 @@ private bool TryGetChangePinMode(ReadOnlyMemory<byte> pin, out PivPinOnlyMode mo
1179
1175
1180
1176
_ = specialKeyCollector . DeriveKeyData ( salt , ManagementKeyAlgorithm , isNewKey : false ) ;
1181
1177
1178
+ var managementKeyAlgorithm = DefaultManagementKeyAlgorithm ;
1182
1179
specialKeyCollector . SetKeyData (
1183
1180
SpecialKeyCollector . SetKeyDataDefault , ReadOnlyMemory < byte > . Empty , isNewKey : true ,
1184
- PivAlgorithm . TripleDes ) ;
1181
+ managementKeyAlgorithm ) ;
1185
1182
1186
1183
// If this fails, then the mgmt key is not PIN-derived from the
1187
1184
// PIN and salt, so we'll say it is not PIN-derived.
1188
1185
if ( ! TryForcedChangeManagementKey (
1189
1186
specialKeyCollector . GetCurrentMgmtKey ( ) ,
1190
1187
specialKeyCollector . GetNewMgmtKey ( ) ,
1191
1188
PivTouchPolicy . Never ,
1192
- PivAlgorithm . TripleDes ) )
1189
+ managementKeyAlgorithm ) )
1193
1190
{
1194
1191
return true ;
1195
1192
}
@@ -1405,13 +1402,14 @@ private sealed class SpecialKeyCollector : IDisposable
1405
1402
private readonly MgmtKeyHolder _currentKey ;
1406
1403
private readonly Memory < byte > _defaultKey ;
1407
1404
private readonly MgmtKeyHolder _newKey ;
1405
+ private readonly PivAlgorithm _defaultManagementKeyAlgorithm ;
1408
1406
private readonly byte [ ] _pinData = new byte [ MaxPinLength ] ;
1409
1407
private readonly Memory < byte > _pinMemory ;
1410
1408
1411
1409
private bool _disposed ;
1412
1410
private int _pinLength ;
1413
1411
1414
- public SpecialKeyCollector ( )
1412
+ public SpecialKeyCollector ( PivAlgorithm defaultManagemenyKeyAlgorithm )
1415
1413
{
1416
1414
_defaultKey = new Memory < byte > (
1417
1415
new byte [ ]
@@ -1425,7 +1423,8 @@ public SpecialKeyCollector()
1425
1423
_newKey = new MgmtKeyHolder ( ) ;
1426
1424
1427
1425
// Make sure the current key is init to the default.
1428
- _currentKey . SetKeyData ( _defaultKey , PivAlgorithm . TripleDes ) ;
1426
+ _defaultManagementKeyAlgorithm = defaultManagemenyKeyAlgorithm ;
1427
+ _currentKey . SetKeyData ( _defaultKey , _defaultManagementKeyAlgorithm ) ;
1429
1428
1430
1429
PinCollected = false ;
1431
1430
_pinMemory = new Memory < byte > ( _pinData ) ;
@@ -1494,7 +1493,7 @@ public void SetKeyData(int setFlag, ReadOnlyMemory<byte> keyData, bool isNewKey,
1494
1493
return ;
1495
1494
}
1496
1495
1497
- destinationKeyHolder . SetKeyData ( _defaultKey , PivAlgorithm . TripleDes ) ;
1496
+ destinationKeyHolder . SetKeyData ( _defaultKey , _defaultManagementKeyAlgorithm ) ;
1498
1497
}
1499
1498
1500
1499
// Derive the mgmt key from the PIN in this object, along with the
0 commit comments