提交 94082ec6 编写于 作者: M msheppar

8006568: HTTP protocol handler NLTM Authentication should use Base64 API

Reviewed-by: chegar, alanb
上级 cea188a3
...@@ -33,6 +33,7 @@ import java.net.PasswordAuthentication; ...@@ -33,6 +33,7 @@ import java.net.PasswordAuthentication;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.URL; import java.net.URL;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Base64;
import sun.net.www.HeaderParser; import sun.net.www.HeaderParser;
import sun.net.www.protocol.http.AuthenticationInfo; import sun.net.www.protocol.http.AuthenticationInfo;
...@@ -230,7 +231,7 @@ public class NTLMAuthentication extends AuthenticationInfo { ...@@ -230,7 +231,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
private String buildType1Msg () { private String buildType1Msg () {
byte[] msg = client.type1(); byte[] msg = client.type1();
String result = "NTLM " + (new B64Encoder()).encode (msg); String result = "NTLM " + Base64.getEncoder().encodeToString(msg);
return result; return result;
} }
...@@ -239,18 +240,12 @@ public class NTLMAuthentication extends AuthenticationInfo { ...@@ -239,18 +240,12 @@ public class NTLMAuthentication extends AuthenticationInfo {
/* First decode the type2 message to get the server nonce */ /* First decode the type2 message to get the server nonce */
/* nonce is located at type2[24] for 8 bytes */ /* 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]; byte[] nonce = new byte[8];
new java.util.Random().nextBytes(nonce); new java.util.Random().nextBytes(nonce);
byte[] msg = client.type3(type2, nonce); byte[] msg = client.type3(type2, nonce);
String result = "NTLM " + (new B64Encoder()).encode (msg); String result = "NTLM " + Base64.getEncoder().encodeToString(msg);
return result; return result;
} }
} }
class B64Encoder extends sun.misc.BASE64Encoder {
/* to force it to to the entire encoding in one line */
protected int bytesPerLine () {
return 1024;
}
}
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
package sun.net.www.protocol.http.ntlm; package sun.net.www.protocol.http.ntlm;
import java.io.IOException; import java.io.IOException;
import sun.misc.BASE64Encoder; import java.util.Base64;
import sun.misc.BASE64Decoder;
/* /*
* Hooks into Windows implementation of NTLM. * Hooks into Windows implementation of NTLM.
...@@ -77,11 +76,11 @@ public class NTLMAuthSequence { ...@@ -77,11 +76,11 @@ public class NTLMAuthSequence {
assert !status.sequenceComplete; assert !status.sequenceComplete;
if (token != null) if (token != null)
input = (new BASE64Decoder()).decodeBuffer(token); input = Base64.getDecoder().decode(token);
byte[] b = getNextToken (crdHandle, input, status); byte[] b = getNextToken (crdHandle, input, status);
if (b == null) if (b == null)
throw new IOException ("Internal authentication error"); throw new IOException ("Internal authentication error");
return (new B64Encoder()).encode (b); return Base64.getEncoder().encodeToString(b);
} }
public boolean isComplete() { public boolean isComplete() {
...@@ -95,8 +94,3 @@ public class NTLMAuthSequence { ...@@ -95,8 +94,3 @@ public class NTLMAuthSequence {
private native byte[] getNextToken (long crdHandle, byte[] lastToken, Status returned); private native byte[] getNextToken (long crdHandle, byte[] lastToken, Status returned);
} }
class B64Encoder extends BASE64Encoder {
protected int bytesPerLine () {
return 1024;
}
}
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.Base64;
import javax.net.ssl.*; import javax.net.ssl.*;
import javax.net.ServerSocketFactory; import javax.net.ServerSocketFactory;
import sun.net.www.*; import sun.net.www.*;
...@@ -295,10 +296,8 @@ public class ProxyTunnelServer extends Thread { ...@@ -295,10 +296,8 @@ public class ProxyTunnelServer extends Thread {
String recvdUserPlusPass = authInfo.substring(ind + 1).trim(); String recvdUserPlusPass = authInfo.substring(ind + 1).trim();
// extract encoded (username:passwd // extract encoded (username:passwd
if (userPlusPass.equals( if (userPlusPass.equals(
new String( new String(Base64.getDecoder().decode(recvdUserPlusPass))
(new sun.misc.BASE64Decoder()). )) {
decodeBuffer(recvdUserPlusPass)
))) {
matched = true; matched = true;
} }
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册