From a202d970651f5292c47e8bbf3505bea50d328081 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sun, 6 Oct 2024 17:10:38 +0200 Subject: [PATCH] SSH signing: don't require a session in PasswordProviderWrapper 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 --- .../transport/sshd/PasswordProviderWrapper.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/PasswordProviderWrapper.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/PasswordProviderWrapper.java index 2cd0669842..900c9fba24 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/PasswordProviderWrapper.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/PasswordProviderWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018, 2020 Thomas Wolf and others + * Copyright (C) 2018, 2024 Thomas Wolf 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 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; } -- 2.39.5