Skip to content

Commit

Permalink
JSch: Fix NPE if unsupported cipher specified
Browse files Browse the repository at this point in the history
More specifically, fail gracefully rather than throw a
NullPointerException if a cipher algorithm supported by the SSH server
but not the SSH client was specified using the Ciphers OpenSSH config
file keyword.

Fixes #441
  • Loading branch information
dcommander committed Jan 21, 2025
1 parent 5a2da44 commit 0ee702a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ in the system settings.
23. The Windows TurboVNC Viewer now sends Alt-F4 keystrokes to the VNC server
if keyboard grabbing is enabled.

24. Fixed an issue whereby the TurboVNC Viewer's built-in SSH client threw a
NullPointerException if a cipher algorithm supported by the SSH server but not
by the SSH client was specified using the `Ciphers` OpenSSH config file
keyword.


3.0.3
=====
Expand Down
10 changes: 9 additions & 1 deletion java/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
Copyright (c) 2018, 2023-2024 D. R. Commander. All rights reserved.
Copyright (c) 2018, 2023-2025 D. R. Commander. All rights reserved.
Copyright (c) 2020-2021 Jeremy Norris. All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -1155,6 +1155,8 @@ private void updateKeys(KeyExchange kex) throws Exception{
String method;

method=guess[KeyExchange.PROPOSAL_ENC_ALGS_STOC];
if(getConfig(method)==null)
throw new JSchException("Unsupported cipher "+method);
c=Class.forName(getConfig(method));
s2ccipher=(Cipher)(c.getDeclaredConstructor().newInstance());
while(s2ccipher.getBlockSize()>Es2c.length){
Expand All @@ -1173,6 +1175,8 @@ private void updateKeys(KeyExchange kex) throws Exception{
s2ccipher_size=s2ccipher.getIVSize();

method=guess[KeyExchange.PROPOSAL_MAC_ALGS_STOC];
if(getConfig(method)==null)
throw new JSchException("Unsupported cipher "+method);
c=Class.forName(getConfig(method));
s2cmac=(MAC)(c.getDeclaredConstructor().newInstance());
MACs2c = expandKey(buf, K, H, MACs2c, hash, s2cmac.getBlockSize());
Expand All @@ -1182,6 +1186,8 @@ private void updateKeys(KeyExchange kex) throws Exception{
s2cmac_result2=new byte[s2cmac.getBlockSize()];

method=guess[KeyExchange.PROPOSAL_ENC_ALGS_CTOS];
if(getConfig(method)==null)
throw new JSchException("Unsupported cipher "+method);
c=Class.forName(getConfig(method));
c2scipher=(Cipher)(c.getDeclaredConstructor().newInstance());
while(c2scipher.getBlockSize()>Ec2s.length){
Expand All @@ -1200,6 +1206,8 @@ private void updateKeys(KeyExchange kex) throws Exception{
c2scipher_size=c2scipher.getIVSize();

method=guess[KeyExchange.PROPOSAL_MAC_ALGS_CTOS];
if(getConfig(method)==null)
throw new JSchException("Unsupported cipher "+method);
c=Class.forName(getConfig(method));
c2smac=(MAC)(c.getDeclaredConstructor().newInstance());
MACc2s = expandKey(buf, K, H, MACc2s, hash, c2smac.getBlockSize());
Expand Down

0 comments on commit 0ee702a

Please sign in to comment.