You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/06/09 19:03:04 UTC

[maven-wagon] branch WAGON-491 created (now 9434e6f)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch WAGON-491
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git.


      at 9434e6f  [WAGON-491] Add ability to set certificate via byte[] and not only via file

This branch includes the following new commits:

     new 9434e6f  [WAGON-491] Add ability to set certificate via byte[] and not only via file

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-wagon] 01/01: [WAGON-491] Add ability to set certificate via byte[] and not only via file

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch WAGON-491
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 9434e6f7a2048921883a3f564be475daf2816532
Author: Laurent GraniƩ <la...@gmail.com>
AuthorDate: Sun Jun 9 21:01:59 2019 +0200

    [WAGON-491] Add ability to set certificate via byte[] and not only via file
---
 .../wagon/authentication/AuthenticationInfo.java   | 35 ++++++++++++++++++----
 .../providers/ssh/jsch/AbstractJschWagon.java      | 14 +++++++++
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java b/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
index 6e92717..60d5708 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
@@ -43,7 +43,7 @@ public class AuthenticationInfo
     private String password;
 
     /**
-     * Passphrase of the user's private key file
+     * Passphrase of the user's private key
      */
     private String passphrase;
 
@@ -53,11 +53,16 @@ public class AuthenticationInfo
     private String privateKey;
 
     /**
-     * Get the passphrase of the private key file. The passphrase is used only
+     * The private key file content (if key is in a package like JAR, WAR, ...)
+     */
+    private byte[] privateKeyContent;
+
+    /**
+     * Get the passphrase of the private key. The passphrase is used only
      * when host/protocol supports authentication via exchange of
      * private/public keys and private key was used for authentication.
      *
-     * @return passphrase of the private key file
+     * @return passphrase of the private key
      */
     public String getPassphrase()
     {
@@ -65,9 +70,9 @@ public class AuthenticationInfo
     }
 
     /**
-     * Set the passphrase of the private key file.
+     * Set the passphrase of the private key.
      *
-     * @param passphrase passphrase of the private key file
+     * @param passphrase passphrase of the private key
      */
     public void setPassphrase( final String passphrase )
     {
@@ -95,6 +100,26 @@ public class AuthenticationInfo
     }
 
     /**
+     * Get the private key content.
+     *
+     * @return private key content
+     */
+    public byte[] getPrivateKeyContent()
+    {
+        return privateKeyContent;
+    }
+
+    /**
+     * Set private key content.
+     *
+     * @param privateKeyContent private key content
+     */
+    public void setPrivateKeyContent( final byte[] privateKeyContent )
+    {
+        this.privateKeyContent = privateKeyContent;
+    }
+
+    /**
      * Get the user's password which is used when connecting to the repository.
      *
      * @return password of user
diff --git a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
index 7e87d2d..cc00ba7 100644
--- a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
+++ b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Properties;
 
@@ -148,6 +149,19 @@ public abstract class AbstractJschWagon
                 throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
             }
         }
+        else if ( authenticationInfo.getPrivateKeyContent() != null )
+        {
+            fireSessionDebug( "Using private key content" );
+            try
+            {
+                sch.addIdentity( null, authenticationInfo.getPrivateKeyContent(), null,
+                                 authenticationInfo.getPassphrase().getBytes( StandardCharsets.UTF_8 ) );
+            }
+            catch ( JSchException e )
+            {
+                throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
+            }
+        }
         else
         {
             try