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
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
3232 protected override void BeginProcessing ( )
3333 {
34- // Connect to FIDO2 if not already authenticated
35- if ( YubiKeyModule . _fido2PIN is null )
34+ // Connect to a YubiKey if not already connected
35+ if ( YubiKeyModule . _yubikey is null )
3636 {
37- WriteDebug ( "No FIDO2 session has been authenticated , calling Connect-YubikeyFIDO2 " ) ;
38- var myPowersShellInstance = PowerShell . Create ( RunspaceMode . CurrentRunspace ) . AddCommand ( "Connect-YubikeyFIDO2 " ) ;
37+ WriteDebug ( "No YubiKey selected , calling Connect-Yubikey... " ) ;
38+ var myPowersShellInstance = PowerShell . Create ( RunspaceMode . CurrentRunspace ) . AddCommand ( "Connect-Yubikey " ) ;
3939 if ( this . MyInvocation . BoundParameters . ContainsKey ( "InformationAction" ) )
4040 {
4141 myPowersShellInstance = myPowersShellInstance . AddParameter ( "InformationAction" , this . MyInvocation . BoundParameters [ "InformationAction" ] ) ;
4242 }
4343 myPowersShellInstance . Invoke ( ) ;
44- if ( YubiKeyModule . _fido2PIN is null )
45- {
46- throw new Exception ( "Connect-YubikeyFIDO2 failed to connect FIDO2 application." ) ;
47- }
44+ WriteDebug ( $ "Successfully connected") ;
4845 }
4946
5047 // Check if running as Administrator
@@ -57,19 +54,39 @@ protected override void BeginProcessing()
5754 // Process the main cmdlet logic
5855 protected override void ProcessRecord ( )
5956 {
57+ // Create a FIDO2 session with the YubiKey
6058 using ( var fido2Session = new Fido2Session ( ( YubiKeyDevice ) YubiKeyModule . _yubikey ! ) )
6159 {
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 )
60+ // Check if enterprise attestation is supported
61+ if ( ! fido2Session . AuthenticatorInfo . Options ! . Any ( v => v . Key . Contains ( AuthenticatorOptions . ep ) ) )
6662 {
6763 throw new Exception ( "Enterprise attestation not supported by this YubiKey." ) ;
6864 }
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." ) )
65+
66+ // Check if enterprise attestation is already enabled
67+ if ( fido2Session . AuthenticatorInfo . GetOptionValue ( AuthenticatorOptions . ep ) == OptionValue . True )
68+ {
69+ WriteWarning ( "Enterprise attestation is already enabled on this YubiKey." ) ;
70+ return ;
71+ }
72+
73+ // Check if PIN is required (only when alwaysUv is enabled but clientPin is not set)
74+ bool alwaysUv = fido2Session . AuthenticatorInfo . GetOptionValue ( AuthenticatorOptions . alwaysUv ) == OptionValue . True ;
75+ bool clientPin = fido2Session . AuthenticatorInfo . GetOptionValue ( AuthenticatorOptions . clientPin ) == OptionValue . True ;
76+
77+ if ( alwaysUv && ! clientPin )
78+ {
79+ throw new Exception ( "Enabling Enterprise Attestation requires a PIN to be set when alwaysUv is enabled." ) ;
80+ }
81+
82+ // Set up key collector only if PIN authentication is needed
83+ if ( clientPin )
7084 {
71- fido2Session . TryEnableEnterpriseAttestation ( ) ;
85+ fido2Session . KeyCollector = YubiKeyModule . _KeyCollector . YKKeyCollectorDelegate ;
7286 }
87+
88+ // Enable enterprise attestation if supported by the YubiKey
89+ fido2Session . TryEnableEnterpriseAttestation ( ) ;
7390 }
7491 }
7592 }
0 commit comments