[ 
https://issues.apache.org/jira/browse/SCM-945?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17564146#comment-17564146
 ] 

ASF GitHub Bot commented on SCM-945:
------------------------------------

kwin commented on code in PR #153:
URL: https://github.com/apache/maven-scm/pull/153#discussion_r916563521


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java:
##########
@@ -72,60 +64,56 @@ public void configure( Transport transport )
         }
     }
 
-    private static class SimpleSessionFactory extends JschConfigSessionFactory
-    {
-        @Override
-        protected void configure( OpenSshConfig.Host host, Session session )
-        {
-        }
-    }
-
-    private abstract static class PrivateKeySessionFactory extends 
SimpleSessionFactory
+    private static final class ScmProviderAwareSshdSessionFactory extends 
SshdSessionFactory
     {
         private final GitScmProviderRepository repo;
+        private final Logger logger;
 
-        GitScmProviderRepository getRepo()
-        {
-            return repo;
-        }
-
-        PrivateKeySessionFactory( GitScmProviderRepository repo )
+        ScmProviderAwareSshdSessionFactory( GitScmProviderRepository repo, 
Logger logger )
         {
             this.repo = repo;
-        }
-    }
-
-    private static class UnprotectedPrivateKeySessionFactory extends 
PrivateKeySessionFactory
-    {
-
-        UnprotectedPrivateKeySessionFactory( GitScmProviderRepository repo )
-        {
-            super( repo );
+            this.logger = logger;
         }
 
         @Override
-        protected JSch createDefaultJSch( FS fs ) throws JSchException
-        {
-            JSch defaultJSch = super.createDefaultJSch( fs );
-            defaultJSch.addIdentity( getRepo().getPrivateKey() );
-            return defaultJSch;
-        }
-    }
-
-    private static class ProtectedPrivateKeyFileSessionFactory extends 
PrivateKeySessionFactory
-    {
-
-        ProtectedPrivateKeyFileSessionFactory( GitScmProviderRepository repo )
+        protected List<Path> getDefaultIdentities( File sshDir )
         {
-            super( repo );
+            if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) )
+            {
+                logger.debug( "using private key: {}", repo.getPrivateKey() );
+                return Collections.singletonList( Paths.get( 
repo.getPrivateKey() ) );
+            }
+            else 
+            {
+                return super.getDefaultIdentities( sshDir );
+            }
         }
 
         @Override
-        protected JSch createDefaultJSch( FS fs ) throws JSchException
+        protected KeyPasswordProvider createKeyPasswordProvider( 
CredentialsProvider provider )
         {
-            JSch defaultJSch = super.createDefaultJSch( fs );
-            defaultJSch.addIdentity( getRepo().getPrivateKey(), 
getRepo().getPassphrase() );
-            return defaultJSch;
+            if ( repo.getPassphrase() != null )
+            {
+                return new IdentityPasswordProvider( provider )
+                {
+                    @Override
+                    public char[] getPassphrase( URIish uri, int attempt ) 
throws IOException

Review Comment:
   It is more lenient: 
https://gerrit.googlesource.com/jgit/+/refs/heads/stable-5.13/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java#36





> Support OpenSSH private keys with maven-scm-provider-jgit
> ---------------------------------------------------------
>
>                 Key: SCM-945
>                 URL: https://issues.apache.org/jira/browse/SCM-945
>             Project: Maven SCM
>          Issue Type: Bug
>          Components: maven-scm-provider-jgit
>    Affects Versions: 1.11.2
>            Reporter: Konrad Windszus
>            Priority: Major
>
> For SSH based authentication with private keys in the OpenSSH format the 
> following error is being emitted:  {{invalid privatekey: ...}}
> This is due to the use of JGit 4.5.4 
> (https://github.com/apache/maven-scm/blob/c5eb2c187568809e0dc0ea9ac83031f1dcb5ad1a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml#L53)
>  which used JSch which lacks support for those private keys. JGit 5.2 comes 
> with a new SSH implementation 
> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=520927) and should by that 
> also support OpenSSH private keys.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to