Skip to content

Commit

Permalink
Squash issues (#93)
Browse files Browse the repository at this point in the history
* Fix sky series friendly name and serial, #87
* Added debug to Get-YubikeyFIDO2Credentials
* Added CoseKey to Output but hidden for Fido2Info
* Add WriteWarning to allow for SDK failure to list entries with incompatible algorithms
  • Loading branch information
virot authored Dec 25, 2024
1 parent 748d4c4 commit dc44880
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
14 changes: 12 additions & 2 deletions Module/Cmdlets/Fido/GetYubikeyFIDO2Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,25 @@ protected override void ProcessRecord()
{
foreach (RelyingParty RelyingParty in RelyingParties)
{
var relayCredentials = fido2Session.EnumerateCredentialsForRelyingParty(RelyingParty);

WriteDebug($"Enumerating credentials for {RelyingParty.Id}.");
IReadOnlyList<CredentialUserInfo> relayCredentials;
try
{
relayCredentials = fido2Session.EnumerateCredentialsForRelyingParty(RelyingParty);
}
catch (NotSupportedException e)
{
WriteWarning($"Failed to enumerate credentials for {RelyingParty.Id}: {e.Message}, SDK might not support algorithm.");
continue;
}
foreach (CredentialUserInfo user in relayCredentials)
{
Credentials credentials = new Credentials
{
Site = RelyingParty.Id,
Name = user.User.Name,
DisplayName = user.User.DisplayName,
coseKey = user.CredentialPublicKey,
};
WriteObject(credentials);
}
Expand Down
11 changes: 9 additions & 2 deletions Module/Cmdlets/Yubikey/ConnectYubikey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void ProcessRecord()
if (yubikeys.Count() == 1)
{
_yubikey = (YubiKeyDevice)yubikeys.First();
WriteDebug($"Found only one device, using {_yubikey.SerialNumber}.");
WriteDebug($"Found only one device, using {_yubikey.SerialNumber.ToString() ?? "N/A"}.");
}
break;
case "Connect Yubikey with Serialnumber":
Expand All @@ -56,7 +56,14 @@ protected override void ProcessRecord()
if (_yubikey is not null)
{
YubiKeyModule._yubikey = _yubikey;
WriteInformation($"Connected to {PowershellYKText.FriendlyName(_yubikey)} with serial: {_yubikey.SerialNumber}.", new string[] { "YubiKey" });
if (_yubikey.SerialNumber is not null)
{
WriteInformation($"Connected to {PowershellYKText.FriendlyName(_yubikey)} with serial: {_yubikey.SerialNumber}.", new string[] { "YubiKey" });
}
else
{
WriteInformation($"Connected to {PowershellYKText.FriendlyName(_yubikey)} with serial: N/A.", new string[] { "YubiKey" });
}
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion Module/support/PowershellYKText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,20 @@ public static string FriendlyName(YubiKeyDevice yubiKeyDevice)
}
if (family == 5)
{
if (isSky)
{
switch (formFactor)
{
case FormFactor.UsbAKeychain:
return "Security Key A by Yubico";
case FormFactor.UsbCKeychain:
return "Security Key C by Yubico";
default:
return "Security Key by Yubico";
}
}
// YubiKey Bio
if (isBio)
else if (isBio)
{
if (isPIV) // Multi-Protocol Edition (AKA "MPE")
{
Expand Down
3 changes: 3 additions & 0 deletions Module/types/FIDO2-Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Yubico.YubiKey.Piv;
using System.Management.Automation;
using Yubico.YubiKey.Fido2;
using Yubico.YubiKey.Fido2.Cose;

namespace powershellYK.FIDO2
{
Expand All @@ -12,6 +13,8 @@ public class Credentials
public string? Name { get; set; }
public string? DisplayName { get; set; }
// public CredentialId? CredentialID { get; set; }
[Hidden]
public CoseKey? coseKey { get; set; }

}
}

0 comments on commit dc44880

Please sign in to comment.