From 29b59b74048d2b6426a96f46f2a26af4547199d5 Mon Sep 17 00:00:00 2001 From: Matvey Mukha Date: Fri, 19 Oct 2018 22:00:51 +0200 Subject: [PATCH] Add Secalot hardware token support. --- .../keychain/securitytoken/OpenPgpCapabilities.java | 4 ++-- .../keychain/securitytoken/SecurityTokenInfo.java | 8 +++++--- .../keychain/securitytoken/usb/UsbTransport.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java index e364b8b10..18f22e9b7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/OpenPgpCapabilities.java @@ -98,11 +98,11 @@ public abstract class OpenPgpCapabilities { } public int getPw1MaxLength() { - return getPwStatusBytes()[MAX_PW1_LENGTH_INDEX]; + return getPwStatusBytes()[MAX_PW1_LENGTH_INDEX] & 0xFF; } public int getPw3MaxLength() { - return getPwStatusBytes()[MAX_PW3_LENGTH_INDEX]; + return getPwStatusBytes()[MAX_PW3_LENGTH_INDEX] & 0xFF; } public int getPw1TriesLeft() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenInfo.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenInfo.java index ecdb885e5..77ab3d987 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenInfo.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenInfo.java @@ -117,7 +117,7 @@ public abstract class SecurityTokenInfo implements Parcelable { public enum TokenType { YUBIKEY_NEO, YUBIKEY_4, FIDESMO, NITROKEY_PRO, NITROKEY_STORAGE, NITROKEY_START_OLD, - NITROKEY_START_1_25_AND_NEWER, GNUK_OLD, GNUK_1_25_AND_NEWER, LEDGER_NANO_S, UNKNOWN + NITROKEY_START_1_25_AND_NEWER, GNUK_OLD, GNUK_1_25_AND_NEWER, LEDGER_NANO_S, SECALOT, UNKNOWN } public static final Set SUPPORTED_USB_TOKENS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( @@ -129,7 +129,8 @@ public abstract class SecurityTokenInfo implements Parcelable { TokenType.NITROKEY_START_1_25_AND_NEWER, TokenType.GNUK_OLD, TokenType.GNUK_1_25_AND_NEWER, - TokenType.LEDGER_NANO_S + TokenType.LEDGER_NANO_S, + TokenType.SECALOT ))); private static final Set SUPPORTED_USB_SETUP = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( @@ -138,7 +139,8 @@ public abstract class SecurityTokenInfo implements Parcelable { TokenType.NITROKEY_PRO, TokenType.NITROKEY_STORAGE, TokenType.NITROKEY_START_1_25_AND_NEWER, - TokenType.GNUK_1_25_AND_NEWER + TokenType.GNUK_1_25_AND_NEWER, + TokenType.SECALOT ))); public boolean isPutKeySupported() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/usb/UsbTransport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/usb/UsbTransport.java index 610106288..134985338 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/usb/UsbTransport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/usb/UsbTransport.java @@ -70,6 +70,9 @@ public class UsbTransport implements Transport { private static final int VENDOR_FSIJ = 9035; private static final int VENDOR_LEDGER = 11415; + private static final int VENDOR_SECALOT = 4617; + private static final int PRODUCT_SECALOT = 28672; + private final UsbDevice usbDevice; private final UsbManager usbManager; @@ -254,6 +257,13 @@ public class UsbTransport implements Transport { case VENDOR_LEDGER: { return TokenType.LEDGER_NANO_S; } + case VENDOR_SECALOT: { + switch (productId) { + case PRODUCT_SECALOT: + return TokenType.SECALOT; + } + break; + } } Timber.d("Unknown USB token. Vendor ID: %s, Product ID: %s", vendorId, productId);