]> source.dussan.org Git - jgit.git/commitdiff
SSH signing: don't require a session in PasswordProviderWrapper 25/1202325/3
authorThomas Wolf <twolf@apache.org>
Sun, 6 Oct 2024 15:10:38 +0000 (17:10 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 22 Oct 2024 11:16:52 +0000 (13:16 +0200)
To read passphrase-protected private keys SSH signing will need to use a
PasswordProviderWrapper without SSH session.

Change-Id: I3ecac6c099f3ed1565fb4f0d56d55aee16edb9fc
Signed-off-by: Thomas Wolf <twolf@apache.org>
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/PasswordProviderWrapper.java

index 2cd066984275613d0f52e08927d57747baad3d03..900c9fba2454fab0d7a1dbdf38cd5874d553135e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
+ * Copyright (C) 2018, 2024 Thomas Wolf <twolf@apache.org> 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
@@ -47,6 +47,8 @@ public class PasswordProviderWrapper implements FilePasswordProvider {
 
        private final Supplier<KeyPasswordProvider> factory;
 
+       private PerSessionState noSessionState;
+
        /**
         * Creates a new {@link PasswordProviderWrapper}.
         *
@@ -59,13 +61,18 @@ public class PasswordProviderWrapper implements FilePasswordProvider {
        }
 
        private PerSessionState getState(SessionContext context) {
-               PerSessionState state = context.getAttribute(STATE);
+               PerSessionState state = context != null ? context.getAttribute(STATE)
+                               : noSessionState;
                if (state == null) {
                        state = new PerSessionState();
                        state.delegate = factory.get();
                        state.delegate.setAttempts(
                                        PASSWORD_PROMPTS.getRequiredDefault().intValue());
-                       context.setAttribute(STATE, state);
+                       if (context != null) {
+                               context.setAttribute(STATE, state);
+                       } else {
+                               noSessionState = state;
+                       }
                }
                return state;
        }