You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2013/02/05 01:09:14 UTC

git commit: renamed "Easy*" classes to "Relaxed*" to better match the solution

Updated Branches:
  refs/heads/master 74bce91c2 -> 631464234


renamed "Easy*" classes to "Relaxed*" to better match the solution

Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/63146423
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/63146423
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/63146423

Branch: refs/heads/master
Commit: 6314642342f7776047990bed425585241c10dd51
Parents: 74bce91
Author: Hervé Boutemy <hb...@apache.org>
Authored: Tue Feb 5 01:09:05 2013 +0100
Committer: Hervé Boutemy <hb...@apache.org>
Committed: Tue Feb 5 01:09:05 2013 +0100

----------------------------------------------------------------------
 .../shared/http4/AbstractHttpClientWagon.java      |   66 ++++----
 .../wagon/shared/http4/EasyX509TrustManager.java   |  129 --------------
 .../shared/http4/RelaxedX509TrustManager.java      |  131 +++++++++++++++
 3 files changed, 162 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/63146423/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
index 89276c6..0c2d199 100644
--- a/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/AbstractHttpClientWagon.java
@@ -152,7 +152,6 @@ public abstract class AbstractHttpClientWagon
             return length;
         }
 
-
         public InputStream getContent()
             throws IOException, IllegalStateException
         {
@@ -168,7 +167,6 @@ public abstract class AbstractHttpClientWagon
             return true;
         }
 
-
         public void writeTo( final OutputStream outstream )
             throws IOException
         {
@@ -179,7 +177,7 @@ public abstract class AbstractHttpClientWagon
             TransferEvent transferEvent =
                 new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
             transferEvent.setTimestamp( System.currentTimeMillis() );
-            InputStream instream = this.source != null
+            InputStream instream = ( this.source != null )
                 ? new FileInputStream( this.source )
                 : new ByteArrayInputStream( this.byteBuffer.array() );
             try
@@ -222,8 +220,6 @@ public abstract class AbstractHttpClientWagon
         {
             return true;
         }
-
-
     }
 
     protected static final int SC_NULL = -1;
@@ -240,8 +236,8 @@ public abstract class AbstractHttpClientWagon
     /**
      * @since 2.0
      */
-    protected ClientConnectionManager clientConnectionManager = new BasicClientConnectionManager(
-            createSchemeRegistry());
+    protected ClientConnectionManager clientConnectionManager =
+        new BasicClientConnectionManager( createSchemeRegistry() );
 
     /**
      * use http(s) connection pool mechanism.
@@ -261,35 +257,36 @@ public abstract class AbstractHttpClientWagon
     protected static boolean sslInsecure = Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.insecure", "false" ) );
 
     /**
-     * ssl hostname verifier is allow all by default. Disable this will use a browser compat hostname verifier
+     * if using sslInsecure, certificate date issues will be ignored
      * <b>disabled by default</b>
      *
      * @since 2.0
      */
-    protected static boolean sslAllowAll =
-        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
+    protected static boolean IGNORE_SSL_VALIDITY_DATES =
+        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.ignore.validity.dates", "false" ) );
 
     /**
-     * if using sslInsecure certificate date issues will be ignored
+     * If enabled, ssl hostname verifier does not check hostname. Disable this will use a browser compat hostname verifier
      * <b>disabled by default</b>
      *
      * @since 2.0
+     * @see BrowserCompatHostnameVerifier
      */
-    protected static boolean IGNORE_SSL_VALIDITY_DATES =
-        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.ignore.validity.dates", "false" ) );
+    protected static boolean sslAllowAll =
+        Boolean.valueOf( System.getProperty( "maven.wagon.http.ssl.allowall", "false" ) );
 
     private static SchemeRegistry createSchemeRegistry()
     {
         SchemeRegistry schemeRegistry = new SchemeRegistry();
-        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
+        schemeRegistry.register( new Scheme( "http", 80, PlainSocketFactory.getSocketFactory() ) );
         SSLSocketFactory sslSocketFactory;
         if ( sslInsecure )
         {
             try
             {
                 sslSocketFactory = new SSLSocketFactory(
-                    EasyX509TrustManager.createEasySSLContext(),
-                    sslAllowAll ? new EasyHostNameVerifier() : SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
+                    RelaxedX509TrustManager.createRelaxedSSLContext(),
+                    sslAllowAll ? new RelaxedHostNameVerifier() : SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
             }
             catch ( IOException e )
             {
@@ -302,9 +299,10 @@ public abstract class AbstractHttpClientWagon
                 HttpsURLConnection.getDefaultSSLSocketFactory(),
                 SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
         }
-        Scheme httpsScheme = new Scheme( "https", 443,
-            new ConfigurableSSLSocketFactoryDecorator( sslSocketFactory ));
-        schemeRegistry.register(httpsScheme);
+
+        Scheme httpsScheme = new Scheme( "https", 443, new ConfigurableSSLSocketFactoryDecorator( sslSocketFactory ) );
+        schemeRegistry.register( httpsScheme );
+
         return schemeRegistry;
     }
 
@@ -316,8 +314,8 @@ public abstract class AbstractHttpClientWagon
         }
         else
         {
-            PoolingClientConnectionManager poolingClientConnectionManager = new PoolingClientConnectionManager(
-                createSchemeRegistry());
+            PoolingClientConnectionManager poolingClientConnectionManager =
+                new PoolingClientConnectionManager( createSchemeRegistry() );
             int maxPerRoute =
                 Integer.parseInt( System.getProperty( "maven.wagon.httpconnectionManager.maxPerRoute", "20" ) );
             poolingClientConnectionManager.setDefaultMaxPerRoute( maxPerRoute );
@@ -334,7 +332,7 @@ public abstract class AbstractHttpClientWagon
      *
      * @since 2.0
      */
-    private static class EasyHostNameVerifier
+    private static class RelaxedHostNameVerifier
         implements X509HostnameVerifier
     {
         public void verify( String s, SSLSocket sslSocket )
@@ -546,13 +544,11 @@ public abstract class AbstractHttpClientWagon
 
         if ( authenticationInfo != null )
         {
-
             String username = authenticationInfo.getUserName();
             String password = authenticationInfo.getPassword();
             // preemptive for put
             if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
             {
-
                 AuthCache authCache = new BasicAuthCache();
                 BasicScheme basicAuth = new BasicScheme();
                 HttpHost targetHost =
@@ -591,7 +587,7 @@ public abstract class AbstractHttpClientWagon
             }
 
             int statusCode = response.getStatusLine().getStatusCode();
-            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
+            String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
             fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );
 
             // Check that we didn't run out of retries.
@@ -680,7 +676,7 @@ public abstract class AbstractHttpClientWagon
         try
         {
             statusCode = response.getStatusLine().getStatusCode();
-            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
+            String reasonPhrase = ", ReasonPhrase: " + response.getStatusLine().getReasonPhrase() + ".";
             switch ( statusCode )
             {
                 case HttpStatus.SC_OK:
@@ -696,10 +692,10 @@ public abstract class AbstractHttpClientWagon
                     throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
 
                 case HttpStatus.SC_UNAUTHORIZED:
-                    throw new AuthorizationException( "Not authorized" + reasonPhrase );
+                    throw new AuthorizationException( "Not authorized " + reasonPhrase );
 
                 case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
-                    throw new AuthorizationException( "Not authorized by proxy" + reasonPhrase );
+                    throw new AuthorizationException( "Not authorized by proxy " + reasonPhrase );
 
                 case HttpStatus.SC_NOT_FOUND:
                     return false;
@@ -922,32 +918,32 @@ public abstract class AbstractHttpClientWagon
             case SC_NULL:
             {
                 TransferFailedException e =
-                    new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
+                    new TransferFailedException( "Failed to transfer file: " + url + " " + reasonPhrase );
                 fireTransferError( resource, e, TransferEvent.REQUEST_GET );
                 throw e;
             }
 
             case HttpStatus.SC_FORBIDDEN:
                 fireSessionConnectionRefused();
-                throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );
+                throw new AuthorizationException( "Access denied to: " + url + " " + reasonPhrase );
 
             case HttpStatus.SC_UNAUTHORIZED:
                 fireSessionConnectionRefused();
-                throw new AuthorizationException( "Not authorized" + reasonPhrase );
+                throw new AuthorizationException( "Not authorized " + reasonPhrase );
 
             case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
                 fireSessionConnectionRefused();
-                throw new AuthorizationException( "Not authorized by proxy" + reasonPhrase );
+                throw new AuthorizationException( "Not authorized by proxy " + reasonPhrase );
 
             case HttpStatus.SC_NOT_FOUND:
-                throw new ResourceDoesNotExistException( "File: " + url + reasonPhrase );
+                throw new ResourceDoesNotExistException( "File: " + url + " " + reasonPhrase );
 
                 // add more entries here
             default:
             {
                 cleanupGetTransfer( resource );
                 TransferFailedException e = new TransferFailedException(
-                    "Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
+                    "Failed to transfer file: " + url + ". Return code is: " + statusCode + " " + reasonPhrase );
                 fireTransferError( resource, e, TransferEvent.REQUEST_GET );
                 throw e;
             }
@@ -1009,7 +1005,7 @@ public abstract class AbstractHttpClientWagon
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
 
             String msg =
-                "Error occurred while retrieving from remote repository:" + getRepository() + ": " + e.getMessage();
+                "Error occurred while retrieving from remote repository " + getRepository() + ": " + e.getMessage();
 
             throw new TransferFailedException( msg, e );
         }

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/63146423/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/EasyX509TrustManager.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/EasyX509TrustManager.java b/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/EasyX509TrustManager.java
deleted file mode 100644
index f2c394a..0000000
--- a/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/EasyX509TrustManager.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.apache.maven.wagon.shared.http4;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.net.ssl.X509TrustManager;
-import java.io.IOException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.CertificateNotYetValidException;
-import java.security.cert.X509Certificate;
-
-/**
- * @author Olivier Lamy
- * @since 2.0
- */
-public class EasyX509TrustManager
-    implements X509TrustManager
-{
-    private X509TrustManager standardTrustManager = null;
-
-
-    protected static SSLContext createEasySSLContext()
-        throws IOException
-    {
-        try
-        {
-            SSLContext context = SSLContext.getInstance( "SSL" );
-            context.init( null, new TrustManager[]{ new EasyX509TrustManager( null ) }, null );
-            return context;
-        }
-        catch ( Exception e )
-        {
-            IOException ioe = new IOException( e.getMessage() );
-            ioe.initCause( e );
-            throw ioe;
-        }
-    }
-
-    /**
-     * Constructor for EasyX509TrustManager.
-     */
-    public EasyX509TrustManager( KeyStore keystore )
-        throws NoSuchAlgorithmException, KeyStoreException
-    {
-        super();
-        TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
-        factory.init( keystore );
-        TrustManager[] trustmanagers = factory.getTrustManagers();
-        if ( trustmanagers.length == 0 )
-        {
-            throw new NoSuchAlgorithmException( "no trust manager found" );
-        }
-        this.standardTrustManager = (X509TrustManager) trustmanagers[0];
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[], String authType)
-     */
-    public void checkClientTrusted( X509Certificate[] certificates, String authType )
-        throws CertificateException
-    {
-        standardTrustManager.checkClientTrusted( certificates, authType );
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String authType)
-     */
-    public void checkServerTrusted( X509Certificate[] certificates, String authType )
-        throws CertificateException
-    {
-
-        if ( ( certificates != null ) && ( certificates.length == 1 ) )
-        {
-            try
-            {
-                certificates[0].checkValidity();
-            }
-            catch ( CertificateExpiredException e )
-            {
-                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
-                {
-                    throw e;
-                }
-            }
-            catch ( CertificateNotYetValidException e )
-            {
-                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
-                {
-                    throw e;
-                }
-            }
-        }
-        else
-        {
-            standardTrustManager.checkServerTrusted( certificates, authType );
-        }
-    }
-
-    /**
-     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
-     */
-    public X509Certificate[] getAcceptedIssuers()
-    {
-        return this.standardTrustManager.getAcceptedIssuers();
-    }
-}

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/63146423/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/RelaxedX509TrustManager.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/RelaxedX509TrustManager.java b/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/RelaxedX509TrustManager.java
new file mode 100644
index 0000000..82b07bf
--- /dev/null
+++ b/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http4/RelaxedX509TrustManager.java
@@ -0,0 +1,131 @@
+package org.apache.maven.wagon.shared.http4;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+
+/**
+ * Relaxed X509 certificate trust manager: can ignore invalid certificate date.
+ *
+ * @author Olivier Lamy
+ * @since 2.0
+ * @see AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES
+ */
+public class RelaxedX509TrustManager
+    implements X509TrustManager
+{
+    private X509TrustManager standardTrustManager = null;
+
+    protected static SSLContext createRelaxedSSLContext()
+        throws IOException
+    {
+        try
+        {
+            SSLContext context = SSLContext.getInstance( "SSL" );
+            context.init( null, new TrustManager[]{ new RelaxedX509TrustManager( null ) }, null );
+            return context;
+        }
+        catch ( Exception e )
+        {
+            IOException ioe = new IOException( e.getMessage() );
+            ioe.initCause( e );
+            throw ioe;
+        }
+    }
+
+    /**
+     * Constructor for EasyX509TrustManager.
+     */
+    public RelaxedX509TrustManager( KeyStore keystore )
+        throws NoSuchAlgorithmException, KeyStoreException
+    {
+        super();
+        TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
+        factory.init( keystore );
+        TrustManager[] trustmanagers = factory.getTrustManagers();
+        if ( trustmanagers.length == 0 )
+        {
+            throw new NoSuchAlgorithmException( "no trust manager found" );
+        }
+        this.standardTrustManager = (X509TrustManager) trustmanagers[0];
+    }
+
+    /**
+     * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[], String authType)
+     */
+    public void checkClientTrusted( X509Certificate[] certificates, String authType )
+        throws CertificateException
+    {
+        standardTrustManager.checkClientTrusted( certificates, authType );
+    }
+
+    /**
+     * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String authType)
+     */
+    public void checkServerTrusted( X509Certificate[] certificates, String authType )
+        throws CertificateException
+    {
+
+        if ( ( certificates != null ) && ( certificates.length == 1 ) )
+        {
+            try
+            {
+                certificates[0].checkValidity();
+            }
+            catch ( CertificateExpiredException e )
+            {
+                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
+                {
+                    throw e;
+                }
+            }
+            catch ( CertificateNotYetValidException e )
+            {
+                if ( !AbstractHttpClientWagon.IGNORE_SSL_VALIDITY_DATES )
+                {
+                    throw e;
+                }
+            }
+        }
+        else
+        {
+            standardTrustManager.checkServerTrusted( certificates, authType );
+        }
+    }
+
+    /**
+     * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
+     */
+    public X509Certificate[] getAcceptedIssuers()
+    {
+        return this.standardTrustManager.getAcceptedIssuers();
+    }
+}