11/// <summary>
2- /// Enables enterprise attestation the YubiKey FIDO2 applet.
2+ /// Enables enterprise attestation on the YubiKey FIDO2 applet.
33/// Enterprise attestation (EA) allows the YubiKey to provide detailed device information
44/// during FIDO2 authentication, which can be useful for enterprise deployments.
55/// Requires a YubiKey capable of Enterprise Attestation and administrator privileges on Windows.
6- /// Note: Enterprise attestation cannot be disabled without resetting the FIDO2 applet.
6+ /// Note: Enterprise attestation is only disabled when resetting the FIDO2 applet.
77///
88/// .EXAMPLE
99/// Enable-YubiKeyFIDO2EnterpriseAttestation
1010/// Enables enterprise attestation on the connected YubiKey
1111///
1212/// .EXAMPLE
13- /// Enable-YubiKeyFIDO2EnterpriseAttestation -Confirm:$false
14- /// Enables enterprise attestation without confirmation prompt
13+ /// Enable-YubiKeyFIDO2EnterpriseAttestation -InformationAction Continue
14+ /// Enables enterprise attestation and displays informational messages
1515/// </summary>
1616
1717// Imports
2525
2626namespace powershellYK . Cmdlets . Fido
2727{
28- [ Cmdlet ( VerbsLifecycle . Enable , "YubiKeyFIDO2EnterpriseAttestation" , SupportsShouldProcess = true , ConfirmImpact = ConfirmImpact . High ) ]
28+ [ Cmdlet ( VerbsLifecycle . Enable , "YubiKeyFIDO2EnterpriseAttestation" ) ]
2929 public class EnableYubikeyFIDO2CmdletEnterpriseAttestation : PSCmdlet
3030 {
3131 // Initialize processing and verify requirements
@@ -34,7 +34,7 @@ protected override void BeginProcessing()
3434 // Connect to FIDO2 if not already authenticated
3535 if ( YubiKeyModule . _fido2PIN is null )
3636 {
37- WriteDebug ( "No FIDO2 session has been authenticated, calling Connect-YubikeyFIDO2" ) ;
37+ WriteDebug ( "No FIDO2 session has been authenticated, calling Connect-YubikeyFIDO2... " ) ;
3838 var myPowersShellInstance = PowerShell . Create ( RunspaceMode . CurrentRunspace ) . AddCommand ( "Connect-YubikeyFIDO2" ) ;
3939 if ( this . MyInvocation . BoundParameters . ContainsKey ( "InformationAction" ) )
4040 {
@@ -43,7 +43,7 @@ protected override void BeginProcessing()
4343 myPowersShellInstance . Invoke ( ) ;
4444 if ( YubiKeyModule . _fido2PIN is null )
4545 {
46- throw new Exception ( "Connect-YubikeyFIDO2 failed to connect FIDO2 application. " ) ;
46+ throw new Exception ( "Connect-YubikeyFIDO2 failed to connect to the FIDO2 applet! " ) ;
4747 }
4848 }
4949
@@ -57,19 +57,28 @@ protected override void BeginProcessing()
5757 // Process the main cmdlet logic
5858 protected override void ProcessRecord ( )
5959 {
60+ // Create a FIDO2 session with the YubiKey
6061 using ( var fido2Session = new Fido2Session ( ( YubiKeyDevice ) YubiKeyModule . _yubikey ! ) )
6162 {
62- // Set up key collector for PIN operations
63- fido2Session . KeyCollector = YubiKeyModule . _KeyCollector . YKKeyCollectorDelegate ;
64- fido2Session . AuthenticatorInfo . Options ! . Any ( v => v . Key . Contains ( AuthenticatorOptions . ep ) ) ;
65- if ( ! ( fido2Session . AuthenticatorInfo . Options ! . Any ( v => v . Key . Contains ( AuthenticatorOptions . ep ) ) ) || fido2Session . AuthenticatorInfo . GetOptionValue ( AuthenticatorOptions . ep ) == OptionValue . False )
63+ // Check if enterprise attestation is supported
64+ if ( ! fido2Session . AuthenticatorInfo . Options ! . Any ( v => v . Key . Contains ( AuthenticatorOptions . ep ) ) )
6665 {
6766 throw new Exception ( "Enterprise attestation not supported by this YubiKey." ) ;
6867 }
69- if ( ShouldProcess ( "Enterprise attestion cannot be disabled without resetting the FIDO2 applet." , "Enterprise attestion cannot be disabled without resetting the FIDO2 applet." , "Disable not possible." ) )
68+
69+ // Check if enterprise attestation is already enabled
70+ if ( fido2Session . AuthenticatorInfo . GetOptionValue ( AuthenticatorOptions . ep ) == OptionValue . True )
7071 {
71- fido2Session . TryEnableEnterpriseAttestation ( ) ;
72+ WriteInformation ( "Enterprise attestation is already enabled on this YubiKey." , new string [ ] { "FIDO2" , "Info" } ) ;
73+ return ;
7274 }
75+
76+ // Set up key collector for PIN operations (required by SDK)
77+ fido2Session . KeyCollector = YubiKeyModule . _KeyCollector . YKKeyCollectorDelegate ;
78+
79+ // Enable enterprise attestation if supported by the YubiKey
80+ fido2Session . TryEnableEnterpriseAttestation ( ) ;
81+ WriteInformation ( "Enterprise attestation has been successfully enabled on this YubiKey." , new string [ ] { "FIDO2" , "Info" } ) ;
7382 }
7483 }
7584 }
0 commit comments