hw-security / de.cotech.hw

Package de.cotech.hw

Types

Name Summary

NfcIntentDispatchActivity

class NfcIntentDispatchActivity : Activity

A pseudo-activity used in the NFC dispatching process.

This class is optional, and shipped as an extra library (see below). If included, NFC security key discovery will work also while the App is not in the foreground. This is strictly optional, NFC dispatch will work with no limitations while the App is in the foreground.

This is an internal class used for discovering NFC security keys through the intent dispatch mechanism. It should never be used directly, but automatically supplements the discovery mechanism in SecurityKeyManager.

To include this class, add the following to build.gradle:

implementation 'de.cotech:hw-security-intent-nfc:1.0'

SecurityKeyInteractor

open class SecurityKeyInteractor

An interactor class to get information from and perform operations on a connected security key. This class is the main interface for communication with any connected security key. Instances are not obtained directly, but returned by SecurityKeyManager via a registered de.cotech.hw.SecurityKeyManager.SecurityKeyManagerCallback.

SecurityKeyManager

open class SecurityKeyManager

The SecurityKeyManager is a singleton class for high-level management operations of security keys.

To use security keys in your App, you must first initialize it using #init(Application). This is usually done in Application#onCreate.

Once initialized, this class will dispatch newly connected security keys to all currently registered listeners. Listeners can be registered and unregistered with #registerCallback(SecurityKeyManagerCallback) and #unregisterCallback(SecurityKeyManagerCallback), respectively. Listeners are called in reverse order of registration (last registered is called first), and have an opportunity to stop further propagation of the callback.

public void onCreate() {
      super.onCreate();
      SecurityKeyManager securityKeyManager = SecurityKeyManager.getInstance();
      securityKeyManager.init(this);
      securityKeyManager.registerCallback(new SecurityKeyManagerCallback() {
          public void onSecurityKeyDiscovered(SecurityKeyInteractor keyInteractor) {
              Toast.makeText(this, "Security key connected!", Toast.LENGTH_SHORT).show();
              return true;
          }
      });
  }

To receive callbacks in an Activity, register for a callback while the Activity is in its resumed state:

public void onResume() {
      super.onResume();
      SecurityKeyManager.getInstance().registerCallback(this);
  }
 
  public void onPause() {
      super.onPause();
      SecurityKeyManager.getInstance().unregisterCallback(this);
  }

In the default configuration, SecurityKeyManager will listen for OpenPGP-Card compatible security keys. This can be changed by passing a SecurityKeyManagerConfig during initialization. See [SecurityKeyManagerConfig.Builder#addAidPrefix(String)]() for details.

These two patterns can be combined, to implement some behavior while a specific Activity is in the foreground, and fall back to a default behavior while the App is open in any other Activity.

SecurityKeyManagerConfig

abstract class SecurityKeyManagerConfig

This class holds configuration options for SecurityKeyManager.

UsbIntentDispatchActivity

class UsbIntentDispatchActivity : Activity

A pseudo-activity used in the USB dispatching process.

This class is optional, and shipped as an extra library (see below). If included, the App will be registered for dispatching security keys connected via USB. Without this, the app will be unable to persist permission to access a USB security key. To avoid asking the user for permission every time a USB security key connects, it is recommended to include this class.

This is an internal class used for discovering NFC security keys through the intent dispatch mechanism. It should never be used directly, but automatically supplements the discovery mechanism in SecurityKeyManager.

To include this class, add the following to build.gradle:

implementation 'de.cotech:hw-security-intent-usb:1.0'