Skip to content

Avoid BigInteger(int, byte[], int, int) for Android 12 and older - #379

Merged
kruton merged 1 commit into
connectbot:mainfrom
aluminique:android-bigint
Oct 26, 2026
Merged

kruton merged 1 commit into
connectbot:mainfrom
aluminique:android-bigint

Conversation

@aluminique

Copy link
Copy Markdown
Contributor

EcdsaSignatureAlgorithm.decodeEcPoint and EcdhKeyExchange.decodeEcPoint use BigInteger(int signum, byte[] magnitude, int off, int len). Android added that constructor only in API 33, so on Android 12 and older these calls throw NoSuchMethodError. ConnectBot (minSdk 24) dies right after login on servers with an ECDSA host key: OpenSSH sends its host keys (hostkeys-00@openssh.com), updateHostKeys verifies the ECDSA proof, and the Error is not caught by the catch (e: Exception) around it. Seen on Android 11:

java.lang.NoSuchMethodError: No direct method <init>(I[BII)V in class Ljava/math/BigInteger;
    at org.connectbot.sshlib.crypto.EcdsaSignatureAlgorithm.decodeEcPoint
    at org.connectbot.sshlib.crypto.EcdsaSignatureAlgorithm.verify
    at org.connectbot.sshlib.crypto.SignatureVerifier.verify
    at org.connectbot.sshlib.client.SshConnection.updateHostKeys

ecdh-sha2-nistp* key exchange takes the same path in EcdhKeyExchange.

The fix copies the coordinate bytes and uses BigInteger(int, byte[]). The length is checked just above, so the ranges are the same and the values are identical; behaviour on the JVM and on Android 13+ does not change. A JVM unit test cannot catch this, since the JVM has the constructor; checking against Android API signatures (e.g. animal-sniffer) could, if that is wanted as a follow-up.

Android added this constructor only in API 33. On Android 12 and older
the ECDSA and NIST ECDH point decoding throws NoSuchMethodError; since it
is an Error, updateHostKeys does not catch it and the app dies right
after login on servers with an ECDSA host key.

Copy the coordinate bytes and use BigInteger(int, byte[]). The length is
checked just before, so the ranges and values are the same.
@sonarqubecloud

Copy link
Copy Markdown

@kruton
kruton merged commit 739161c into connectbot:main Oct 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants