-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signature algorithm selection should match the behaviour of OpenSSH
- Loading branch information
Showing
3 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ public boolean start(Session session) throws Exception { | |
} | ||
} | ||
|
||
@SuppressWarnings("fallthrough") | ||
private boolean _start(Session session, List<Identity> identities, List<String> pkmethods, | ||
List<String> not_available_pks) throws Exception { | ||
if (session.auth_failures >= session.max_auth_tries) { | ||
|
@@ -124,17 +125,40 @@ private boolean _start(Session session, List<Identity> identities, List<String> | |
boolean use_pk_auth_query = session.getConfig("enable_pubkey_auth_query").equals("yes"); | ||
boolean try_other_pkmethods = | ||
session.getConfig("try_additional_pubkey_algorithms").equals("yes"); | ||
boolean use_openssh_rsa_pubkey_order = | ||
session.getConfig("use_openssh_rsa_pubkey_order").equals("yes"); | ||
|
||
String[] server_sig_algs = session.getServerSigAlgs(); | ||
boolean has_server_sig_algs = server_sig_algs != null && server_sig_algs.length > 0; | ||
|
||
List<String> rsamethods = new ArrayList<>(); | ||
List<String> nonrsamethods = new ArrayList<>(); | ||
for (String pkmethod : pkmethods) { | ||
if (pkmethod.equals("ssh-rsa") || pkmethod.equals("rsa-sha2-256") | ||
|| pkmethod.equals("rsa-sha2-512") || pkmethod.equals("[email protected]") | ||
|| pkmethod.equals("[email protected]") || pkmethod.equals("[email protected]") | ||
|| pkmethod.equals("[email protected]")) { | ||
rsamethods.add(pkmethod); | ||
} else { | ||
nonrsamethods.add(pkmethod); | ||
switch (pkmethod) { | ||
case "ssh-rsa": | ||
if (!has_server_sig_algs && use_openssh_rsa_pubkey_order) { | ||
// "Servers that accept rsa-sha2-* signatures for client authentication | ||
// SHOULD implement the extension negotiation mechanism defined in | ||
// [RFC8308], including especially the "server-sig-algs" extension." | ||
// | ||
// OpenSSH 8.0 and newer implementations will only attempt the "ssh-rsa" signature | ||
// algorithm. To match this behaviour Jsch will force the first attempt, irrespective of | ||
// the clients PubkeyAcceptedKeyTypes order, to the "ssh-rsa" signature algorithm. Any | ||
// subsequent retries will respect the order as defined by the client. | ||
rsamethods.add(0, pkmethod); | ||
break; | ||
} | ||
case "rsa-sha2-256": | ||
case "rsa-sha2-512": | ||
case "[email protected]": | ||
case "[email protected]": | ||
case "[email protected]": | ||
case "[email protected]": | ||
rsamethods.add(pkmethod); | ||
break; | ||
default: | ||
nonrsamethods.add(pkmethod); | ||
break; | ||
} | ||
} | ||
|
||
|