]> source.dussan.org Git - jgit.git/commitdiff
[sshd] Correct signature for RSA keys from an SSH agent 62/194362/1
authorThomas Wolf <thomas.wolf@paranor.ch>
Thu, 23 Jun 2022 10:14:37 +0000 (12:14 +0200)
committerThomas Wolf <thomas.wolf@paranor.ch>
Thu, 23 Jun 2022 10:14:37 +0000 (12:14 +0200)
Ensure that there is always a list of signature factories in public key
authentication. For keys loaded directly, Apache MINA sshd will use the
(always set) list from the SSH session by default, but for keys from an
SSH agent it won't and instead consider the list set locally on the
UserAuthPublicKey instance. Only that one is null by default, and then
Apache MINA sshd just uses the key type as signature type. Which for
RSA keys from an agent is the "ssh-rsa" signature, i.e., the deprecated
SHA1 signature.

Fix this by explicitly propagating the list from the session to the
UserAuthPublicKey instance if not set already.

Upstream issue is SSHD-1272.[1]

[1] https://issues.apache.org/jira/browse/SSHD-1272

Bug: 580073
Change-Id: Id7a783f19d06c9e7c8494b1fbf7465d392ffc366
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitPublicKeyAuthentication.java

index 96da0cccdd86f581efe2292a5e017f6dcea30aa3..e1036c628332fc63742f811193089e375749af3d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018, 2021 Thomas Wolf <thomas.wolf@paranor.ch> and others
+ * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -99,13 +99,18 @@ public class JGitPublicKeyAuthentication extends UserAuthPublicKey {
                                        log.debug(PUBKEY_ACCEPTED_ALGORITHMS + ' ' + signatures);
                                }
                                setSignatureFactoriesNames(signatures);
-                       } else {
-                               log.warn(format(SshdText.get().configNoKnownAlgorithms,
-                                               PUBKEY_ACCEPTED_ALGORITHMS, pubkeyAlgos));
+                               super.init(session, service);
+                               return;
                        }
+                       log.warn(format(SshdText.get().configNoKnownAlgorithms,
+                                       PUBKEY_ACCEPTED_ALGORITHMS, pubkeyAlgos));
+               }
+               // TODO: remove this once we're on an sshd version that has SSHD-1272
+               // fixed
+               List<NamedFactory<Signature>> localFactories = getSignatureFactories();
+               if (localFactories == null || localFactories.isEmpty()) {
+                       setSignatureFactoriesNames(session.getSignatureFactoriesNames());
                }
-               // If we don't set signature factories here, the default ones from the
-               // session will be used.
                super.init(session, service);
        }