8006568: HTTP protocol handler NLTM Authentication should use Base64 API
authormsheppar
Sat, 19 Jan 2013 08:39:20 +0000
changeset 15276 bbddb82e66ce
parent 15275 6e5b8f8361eb
child 15277 245068ba31b3
8006568: HTTP protocol handler NLTM Authentication should use Base64 API Reviewed-by: chegar, alanb
jdk/src/solaris/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java
jdk/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java
jdk/test/sun/net/www/protocol/http/ProxyTunnelServer.java
--- a/jdk/src/solaris/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Fri Jan 18 18:48:44 2013 +0000
+++ b/jdk/src/solaris/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java	Sat Jan 19 08:39:20 2013 +0000
@@ -33,6 +33,7 @@
 import java.net.UnknownHostException;
 import java.net.URL;
 import java.security.GeneralSecurityException;
+import java.util.Base64;
 
 import sun.net.www.HeaderParser;
 import sun.net.www.protocol.http.AuthenticationInfo;
@@ -230,7 +231,7 @@
 
     private String buildType1Msg () {
         byte[] msg = client.type1();
-        String result = "NTLM " + (new B64Encoder()).encode (msg);
+        String result = "NTLM " + Base64.getEncoder().encodeToString(msg);
         return result;
     }
 
@@ -239,18 +240,12 @@
         /* First decode the type2 message to get the server nonce */
         /* nonce is located at type2[24] for 8 bytes */
 
-        byte[] type2 = (new sun.misc.BASE64Decoder()).decodeBuffer (challenge);
+        byte[] type2 = Base64.getDecoder().decode(challenge);
         byte[] nonce = new byte[8];
         new java.util.Random().nextBytes(nonce);
         byte[] msg = client.type3(type2, nonce);
-        String result = "NTLM " + (new B64Encoder()).encode (msg);
+        String result = "NTLM " + Base64.getEncoder().encodeToString(msg);
         return result;
     }
 }
 
-class B64Encoder extends sun.misc.BASE64Encoder {
-    /* to force it to to the entire encoding in one line */
-    protected int bytesPerLine () {
-        return 1024;
-    }
-}
--- a/jdk/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java	Fri Jan 18 18:48:44 2013 +0000
+++ b/jdk/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.java	Sat Jan 19 08:39:20 2013 +0000
@@ -26,8 +26,7 @@
 package sun.net.www.protocol.http.ntlm;
 
 import java.io.IOException;
-import sun.misc.BASE64Encoder;
-import sun.misc.BASE64Decoder;
+import java.util.Base64;
 
 /*
  * Hooks into Windows implementation of NTLM.
@@ -77,11 +76,11 @@
         assert !status.sequenceComplete;
 
         if (token != null)
-            input = (new BASE64Decoder()).decodeBuffer(token);
+            input = Base64.getDecoder().decode(token);
         byte[] b = getNextToken (crdHandle, input, status);
         if (b == null)
             throw new IOException ("Internal authentication error");
-        return (new B64Encoder()).encode (b);
+        return Base64.getEncoder().encodeToString(b);
     }
 
     public boolean isComplete() {
@@ -95,8 +94,3 @@
     private native byte[] getNextToken (long crdHandle, byte[] lastToken, Status returned);
 }
 
-class B64Encoder extends BASE64Encoder {
-    protected int bytesPerLine () {
-        return 1024;
-    }
-}
--- a/jdk/test/sun/net/www/protocol/http/ProxyTunnelServer.java	Fri Jan 18 18:48:44 2013 +0000
+++ b/jdk/test/sun/net/www/protocol/http/ProxyTunnelServer.java	Sat Jan 19 08:39:20 2013 +0000
@@ -31,6 +31,7 @@
 
 import java.io.*;
 import java.net.*;
+import java.util.Base64;
 import javax.net.ssl.*;
 import javax.net.ServerSocketFactory;
 import sun.net.www.*;
@@ -295,10 +296,8 @@
             String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
             // extract encoded (username:passwd
             if (userPlusPass.equals(
-                                new String(
-                                (new sun.misc.BASE64Decoder()).
-                                decodeBuffer(recvdUserPlusPass)
-                                ))) {
+                                new String(Base64.getDecoder().decode(recvdUserPlusPass))
+                                )) {
                 matched = true;
             }
         } catch (Exception e) {