Class ManagementSession

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ManagementSession
    extends com.yubico.yubikit.core.application.ApplicationSession<ManagementSession>
    Application to get information about and configure a YubiKey via the Management Application. https://developers.yubico.com/yubikey-manager/Config_Reference.html
    • Constructor Summary

      Constructors 
      Constructor Description
      ManagementSession​(com.yubico.yubikit.core.fido.FidoConnection connection)
      Establishes a new session with a YubiKeys Management application, over a FidoConnection.
      ManagementSession​(com.yubico.yubikit.core.otp.OtpConnection connection)
      Establishes a new session with a YubiKeys Management application, over an OtpConnection.
      ManagementSession​(com.yubico.yubikit.core.smartcard.SmartCardConnection connection)
      Establishes a new session with a YubiKeys Management application, over a SmartCardConnection.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      static void create​(com.yubico.yubikit.core.YubiKeyDevice device, com.yubico.yubikit.core.util.Callback<com.yubico.yubikit.core.util.Result<ManagementSession,​java.lang.Exception>> callback)
      Connects to a YubiKeyDevice and establishes a new session with a YubiKeys Management application.
      DeviceInfo getDeviceInfo()
      Get device information from the YubiKey.
      com.yubico.yubikit.core.Version getVersion()  
      void setMode​(com.yubico.yubikit.core.UsbInterface.Mode mode, byte chalrespTimeout, short autoejectTimeout)
      Write device configuration for YubiKey NEO and YubiKey 4.
      void updateDeviceConfig​(DeviceConfig config, boolean reboot, byte[] currentLockCode, byte[] newLockCode)
      Write device configuration to a YubiKey 5 or later.
      • Methods inherited from class com.yubico.yubikit.core.application.ApplicationSession

        require, supports
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FEATURE_MODE

        public static final com.yubico.yubikit.core.application.Feature<ManagementSession> FEATURE_MODE
        Support the SET_MODE command to change the USB mode of the YubiKey.
      • FEATURE_DEVICE_INFO

        public static final com.yubico.yubikit.core.application.Feature<ManagementSession> FEATURE_DEVICE_INFO
        Support for reading the DeviceInfo data from the YubiKey.
      • FEATURE_DEVICE_CONFIG

        public static final com.yubico.yubikit.core.application.Feature<ManagementSession> FEATURE_DEVICE_CONFIG
        Support for writing DeviceConfig data to the YubiKey.
    • Constructor Detail

      • ManagementSession

        public ManagementSession​(com.yubico.yubikit.core.smartcard.SmartCardConnection connection)
                          throws java.io.IOException,
                                 com.yubico.yubikit.core.application.ApplicationNotAvailableException
        Establishes a new session with a YubiKeys Management application, over a SmartCardConnection.
        Parameters:
        connection - connection with YubiKey
        Throws:
        java.io.IOException - in case of connection error
        com.yubico.yubikit.core.application.ApplicationNotAvailableException - in case the application is missing/disabled
      • ManagementSession

        public ManagementSession​(com.yubico.yubikit.core.otp.OtpConnection connection)
                          throws java.io.IOException,
                                 com.yubico.yubikit.core.application.ApplicationNotAvailableException
        Establishes a new session with a YubiKeys Management application, over an OtpConnection.
        Parameters:
        connection - connection with YubiKey
        Throws:
        java.io.IOException - in case of connection error
        com.yubico.yubikit.core.application.ApplicationNotAvailableException - in case the application is missing/disabled
      • ManagementSession

        public ManagementSession​(com.yubico.yubikit.core.fido.FidoConnection connection)
                          throws java.io.IOException
        Establishes a new session with a YubiKeys Management application, over a FidoConnection.
        Parameters:
        connection - a connection over the FIDO USB transport with a YubiKey
        Throws:
        java.io.IOException - in case of connection error
    • Method Detail

      • create

        public static void create​(com.yubico.yubikit.core.YubiKeyDevice device,
                                  com.yubico.yubikit.core.util.Callback<com.yubico.yubikit.core.util.Result<ManagementSession,​java.lang.Exception>> callback)
        Connects to a YubiKeyDevice and establishes a new session with a YubiKeys Management application.

        This method will use whichever connection type is available.

        Parameters:
        device - A YubiKey device to use
      • close

        public void close()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getVersion

        public com.yubico.yubikit.core.Version getVersion()
        Specified by:
        getVersion in class com.yubico.yubikit.core.application.ApplicationSession<ManagementSession>
      • getDeviceInfo

        public DeviceInfo getDeviceInfo()
                                 throws java.io.IOException,
                                        com.yubico.yubikit.core.application.CommandException
        Get device information from the YubiKey.

        This functionality requires support for FEATURE_DEVICE_INFO, available on YubiKey 4.1 or later.

        Returns:
        a DeviceInfo object
        Throws:
        java.io.IOException - in case of connection error
        com.yubico.yubikit.core.application.CommandException - in case of error response
      • updateDeviceConfig

        public void updateDeviceConfig​(DeviceConfig config,
                                       boolean reboot,
                                       @Nullable
                                       byte[] currentLockCode,
                                       @Nullable
                                       byte[] newLockCode)
                                throws java.io.IOException,
                                       com.yubico.yubikit.core.application.CommandException
        Write device configuration to a YubiKey 5 or later.

        This functionality requires support for FEATURE_DEVICE_CONFIG, available on YubiKey 5 or later.

        Parameters:
        config - the device configuration to write
        reboot - if true cause the YubiKey to immediately reboot, applying the new configuration
        currentLockCode - required if a configuration lock code is set
        newLockCode - changes or removes (if 16 byte all-zero) the configuration lock code
        Throws:
        java.io.IOException - in case of connection error
        com.yubico.yubikit.core.application.CommandException - in case of error response
      • setMode

        public void setMode​(com.yubico.yubikit.core.UsbInterface.Mode mode,
                            byte chalrespTimeout,
                            short autoejectTimeout)
                     throws java.io.IOException,
                            com.yubico.yubikit.core.application.CommandException
        Write device configuration for YubiKey NEO and YubiKey 4.

        This functionality requires support for FEATURE_MODE, available on YubiKey 3 and 4. If FEATURE_DEVICE_CONFIG is supported, the mode will be translated into a DeviceConfig and updateDeviceConfig(com.yubico.yubikit.management.DeviceConfig, boolean, byte[], byte[]) will instead be used.

        Parameters:
        mode - USB transport mode to set
        chalrespTimeout - timeout (seconds) for challenge-response requiring touch.
        autoejectTimeout - timeout (10x seconds) for auto-eject (only used for CCID-only mode).
        Throws:
        java.io.IOException - in case of connection error
        com.yubico.yubikit.core.smartcard.ApduException - in case of communication or not supported operation error
        com.yubico.yubikit.core.application.CommandException