From a1127bdf1a5049041dbfa1da8b5e472bffd50972 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 13 Jan 2017 02:37:42 +0100 Subject: [PATCH] support odd rsa moduli on security tokens --- .../keychain/securitytoken/SecurityTokenHelper.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenHelper.java index ceae990e4..0097ceaa3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/securitytoken/SecurityTokenHelper.java @@ -661,7 +661,8 @@ public class SecurityTokenHelper { byte[] data; - switch (mOpenPgpCapabilities.getFormatForKeyType(KeyType.SIGN).keyFormatType()) { + KeyFormat signKeyFormat = mOpenPgpCapabilities.getFormatForKeyType(KeyType.SIGN); + switch (signKeyFormat.keyFormatType()) { case RSAKeyFormatType: data = dsi; break; @@ -687,11 +688,12 @@ public class SecurityTokenHelper { byte[] signature = response.getData(); // Make sure the signature we received is actually the expected number of bytes long! - switch (mOpenPgpCapabilities.getFormatForKeyType(KeyType.SIGN).keyFormatType()) { + switch (signKeyFormat.keyFormatType()) { case RSAKeyFormatType: - if (signature.length != 128 && signature.length != 256 - && signature.length != 384 && signature.length != 512) { - throw new IOException("Bad signature length! Expected 128/256/384/512 bytes, got " + signature.length); + int modulusLength = ((RSAKeyFormat) signKeyFormat).getModulusLength(); + if (signature.length != (modulusLength / 8)) { + throw new IOException("Bad signature length! Expected " + (modulusLength / 8) + + " bytes, got " + signature.length); } break;