hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1787400 - in /httpcomponents/httpclient/branches/pull-66/httpclient/src: main/java/org/apache/http/impl/auth/NTLMEngineImpl.java test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
Date Fri, 17 Mar 2017 14:36:01 GMT
Author: kwright
Date: Fri Mar 17 14:36:00 2017
New Revision: 1787400

URL: http://svn.apache.org/viewvc?rev=1787400&view=rev
Log:
Make compatible with 4.5.x conventions

Modified:
    httpcomponents/httpclient/branches/pull-66/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/branches/pull-66/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java

Modified: httpcomponents/httpclient/branches/pull-66/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/pull-66/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java?rev=1787400&r1=1787399&r2=1787400&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/pull-66/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
(original)
+++ httpcomponents/httpclient/branches/pull-66/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
Fri Mar 17 14:36:00 2017
@@ -1088,6 +1088,28 @@ final class NTLMEngineImpl implements NT
         }
     }
 
+    /** Strip dot suffix from a name */
+    private static String stripDotSuffix(final String value) {
+        if (value == null) {
+            return null;
+        }
+        final int index = value.indexOf(".");
+        if (index != -1) {
+            return value.substring(0, index);
+        }
+        return value;
+    }
+
+    /** Convert host to standard form */
+    private static String convertHost(final String host) {
+        return stripDotSuffix(host);
+    }
+
+    /** Convert domain to standard form */
+    private static String convertDomain(final String domain) {
+        return stripDotSuffix(domain);
+    }
+
     /** NTLM message generation, base class */
     static class NTLMMessage {
         /** The current response */
@@ -1273,10 +1295,11 @@ final class NTLMEngineImpl implements NT
         Type1Message(final String domain, final String host, final Integer flags) throws
NTLMEngineException {
             super();
             this.flags = ((flags == null)?getDefaultFlags():flags);
-            // All host name manipulations now take place in the credentials
-            final String unqualifiedHost = host;
-            // All domain name manipulations now take place in the credentials
-            final String unqualifiedDomain = domain;
+
+            // Strip off domain name from the host!
+            final String unqualifiedHost = convertHost(host);
+            // Use only the base domain name!
+            final String unqualifiedDomain = convertDomain(domain);
 
             hostBytes = unqualifiedHost != null ?
                     unqualifiedHost.getBytes(UNICODE_LITTLE_UNMARKED) : null;
@@ -1544,11 +1567,10 @@ final class NTLMEngineImpl implements NT
             this.type1Message = type1Message;
             this.type2Message = type2Message;
 
-            // All host name manipulations now take place in the credentials
-            final String unqualifiedHost = host;
-            // All domain name manipulations now take place in the credentials
-            final String unqualifiedDomain = domain;
-
+            // Strip off domain name from the host!
+            final String unqualifiedHost = convertHost(host);
+            // Use only the base domain name!
+            final String unqualifiedDomain = convertDomain(domain);
 
             byte[] responseTargetInformation = targetInformation;
             if (peerServerCertificate != null) {

Modified: httpcomponents/httpclient/branches/pull-66/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/pull-66/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java?rev=1787400&r1=1787399&r2=1787400&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/pull-66/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
(original)
+++ httpcomponents/httpclient/branches/pull-66/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
Fri Mar 17 14:36:00 2017
@@ -31,6 +31,10 @@ import org.junit.Assert;
 import org.junit.Test;
 import java.util.Random;
 
+import java.io.ByteArrayInputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.Certificate;
+
 public class TestNTLMEngineImpl {
 
     @Test
@@ -262,6 +266,34 @@ public class TestNTLMEngineImpl {
             bytes2);
     }
 
+    private static String cannedCert =
+        "-----BEGIN CERTIFICATE-----\n"+
+        "MIIDIDCCAgigAwIBAgIEOqKaWTANBgkqhkiG9w0BAQsFADBSMQswCQYDVQQGEwJVUzEQMA4GA1UEBxMH\n"+
+        "TXkgQ2l0eTEYMBYGA1UEChMPTXkgT3JnYW5pemF0aW9uMRcwFQYDVQQDEw5NeSBBcHBsaWNhdGlvbjAe\n"+
+        "Fw0xNzAzMTcxNDAyMzRaFw0yNzAzMTUxNDAyMzRaMFIxCzAJBgNVBAYTAlVTMRAwDgYDVQQHEwdNeSBD\n"+
+        "aXR5MRgwFgYDVQQKEw9NeSBPcmdhbml6YXRpb24xFzAVBgNVBAMTDk15IEFwcGxpY2F0aW9uMIIBIjAN\n"+
+        "BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArc+mbViBaHeRSt82KrJ5IF+62b/Qob95Lca4DJIislTY\n"+
+        "vLPIo0R1faBV8BkEeUQwo01srkf3RaGLCHNZnFal4KEzbtiUy6W+n08G5E9w9YG+WSwW2dmjvEI7k2a2\n"+
+        "xqlaM4NdMKL4ONPXcxfZsMDqxDgpdkaNPKpZ10NDq6rmBTkQw/OSG0z1KLtwLkF1ZQ/3mXdjVzvP83V2\n"+
+        "g17AqBazb0Z1YHsVKmkGjPqnq3niJH/6Oke4N+5k/1cE5lSJcQNGP0nqeGdJfvqQZ+gk6gH/sOngZL9X\n"+
+        "hPVkpseAwHa+xuPneDSjibLgLmMt3XGDK6jGfjdp5FWqFvAD5E3LHbW9gwIDAQABMA0GCSqGSIb3DQEB\n"+
+        "CwUAA4IBAQCpUXUHhl5LyMSO5Q0OktEc9AaFjZtVfknpPde6Zeh35Pqd2354ErvJSBWgzFAphda0oh2s\n"+
+        "OIAFkM6LJQEnVDTbXDXN+YY8e3gb9ryfh85hkhC0XI9qp17WPSkmw8XgDfvRd6YQgKm1AnLxjOCwG2jg\n"+
+        "i09iZBIWkW3ZeRAMvWPHHjvq44iZB5ZrEl0apgumS6MxpUzKOr5Pcq0jxJDw2UCj5YloFMNl+UINv2vV\n"+
+        "aL/DR6ivc61dOfN1E/VNBGkkCk/AogNyucGiFMCq9hd25Y9EbkBBqObYTH1XMX+ufsJh+6hG7KDQ1e/F\n"+
+        "nRrlhKwM2uRe+aSH0D6/erjDBT7tXvwn\n"+
+        "-----END CERTIFICATE-----";
+
+    @Test
+    public void testType3MessageWithCert() throws Exception {
+        final ByteArrayInputStream fis = new ByteArrayInputStream(cannedCert.getBytes(Consts.ASCII));
+
+        final CertificateFactory cf = CertificateFactory.getInstance("X.509");
+
+        final Certificate cert = cf.generateCertificate(fis);
+        //System.out.println(cert.toString());
+    }
+
     @Test
     public void testRC4() throws Exception {
         checkArraysMatch(toBytes("e37f97f2544f4d7e"),



Mime
View raw message