When multiple YubiKeys are connected (via USB, NFC, or both), the module provides APIs to list, identify, and target a specific device.
Listing devices
YubiKitManager.listDeviceRecords() returns a list of DesktopDeviceRecord objects, each containing the device, its DeviceInfo, and a DesktopDeviceSelector that can be used to target that device. Both USB and NFC devices are included.
YubiKitManager mgr = new YubiKitManager();
List<DesktopDeviceRecord> devices = mgr.listDeviceRecords();
for (DesktopDeviceRecord record : devices) {
System.out.println("Serial: " + record.getInfo().getSerialNumber());
System.out.println("Transport: " + record.getDevice().getTransport());
System.out.println("Selector: " + record.getSelector());
}
Device selection
Devices are identified by a DesktopDeviceSelector, which supports two modes:
-
Serial number (preferred) — stable across unplug/replug and process restarts.
-
Fingerprint (fallback) — derived from the OS-assigned device path (USB) or PC/SC terminal name (NFC); used when serial is unavailable (e.g. Security Key models). Not guaranteed stable across unplug/replug.
// Select by serial number
DesktopDeviceSelector selector = DesktopDeviceSelector.forSerial(36852057);
// Select by fingerprint (USB device)
DesktopDeviceSelector selector = DesktopDeviceSelector.forFingerprint("DevSrvsID:4294980754");
// Select by fingerprint (NFC reader)
DesktopDeviceSelector selector = DesktopDeviceSelector.forFingerprint("HID Global OMNIKEY 5022 CL 00");
Opening a connection on a selected device
DesktopDeviceSelector sel = devices.get(0).getSelector();
try (SmartCardConnection conn = mgr.openConnection(sel, SmartCardConnection.class)) {
// run operations on the selected device
}
Convenience methods
-
getDeviceBySerial(int serial) — find a device by serial number.
-
getDeviceBySelector(DesktopDeviceSelector selector) — find a device by selector.
-
requireSingleDevice() — returns the single connected device, or throws if zero or more than one are connected.