Skip to content

Commit

Permalink
After discussion, with Jonas, We switched informational from WriteObj…
Browse files Browse the repository at this point in the history
…ect, but I wanted the rest in.

Removed duplicated Warning about no credentials found
  • Loading branch information
virot committed Dec 25, 2024
1 parent 61164d1 commit f690623
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Module/Cmdlets/Fido/ConnectYubikeyFIDO2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected override void ProcessRecord()
{
if (fido2Session.AuthenticatorInfo.GetOptionValue(AuthenticatorOptions.clientPin) == OptionValue.False)
{
WriteObject("Client PIN is not set.");
WriteWarning("Client PIN is not set.");
return;
}
else if (fido2Session.AuthenticatorInfo.ForcePinChange == true)
Expand Down
36 changes: 13 additions & 23 deletions Module/Cmdlets/Fido/GetYubikeyFIDO2Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,27 @@ protected override void ProcessRecord()

if (!RelyingParties.Any()) // Check if there are no relying parties
{
WriteObject("No credentials found on the YubiKey.");
WriteWarning("No credentials found on the YubiKey.");
return;
}

bool credentialsFound = false; // Track if any credentials are found

foreach (RelyingParty RelyingParty in RelyingParties)
else
{
var relayCredentials = fido2Session.EnumerateCredentialsForRelyingParty(RelyingParty);

if (relayCredentials.Any()) // Check if this relying party has credentials
foreach (RelyingParty RelyingParty in RelyingParties)
{
credentialsFound = true;
}
var relayCredentials = fido2Session.EnumerateCredentialsForRelyingParty(RelyingParty);

foreach (CredentialUserInfo user in relayCredentials)
{
Credentials credentials = new Credentials
foreach (CredentialUserInfo user in relayCredentials)
{
Site = RelyingParty.Id,
Name = user.User.Name,
DisplayName = user.User.DisplayName,
};
WriteObject(credentials);
Credentials credentials = new Credentials
{
Site = RelyingParty.Id,
Name = user.User.Name,
DisplayName = user.User.DisplayName,
};
WriteObject(credentials);
}
}
}

if (!credentialsFound)
{
WriteObject("No FIDO2 credentials found on the YubiKey.");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Module/Cmdlets/Fido/SetYubikeyFIDO2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected override void ProcessRecord()
// Code to set minimum PIN length here.

if (!fido2Session.TrySetPinConfig(MinimumPINLength, null, null))
{
{
throw new Exception("Failed to change the minimum PIN length.");
}
// Do it once more to force PIN change.
Expand Down
2 changes: 1 addition & 1 deletion Module/Cmdlets/Yubikey/ConnectYubikey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void ProcessRecord()
if (_yubikey is not null)
{
YubiKeyModule._yubikey = _yubikey;
WriteObject($"Connected to {PowershellYKText.FriendlyName(_yubikey)} with serial: {_yubikey.SerialNumber}.");
WriteInformation($"Connected to {PowershellYKText.FriendlyName(_yubikey)} with serial: {_yubikey.SerialNumber}.", new string[] { "YubiKey" });
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Module/Cmdlets/Yubikey/DisconnectYubikey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected override void BeginProcessing()
{
YubiKeyModule._yubikey = null;
YubiKeyModule.clearPassword();
WriteObject($"Disconnected from YubiKey.");
WriteInformation("Disconnected from YubiKey.", new string[] { "YubiKey" });
}
}
}

0 comments on commit f690623

Please sign in to comment.