31 import java.net.InetAddress; |
31 import java.net.InetAddress; |
32 import java.net.PasswordAuthentication; |
32 import java.net.PasswordAuthentication; |
33 import java.net.UnknownHostException; |
33 import java.net.UnknownHostException; |
34 import java.net.URL; |
34 import java.net.URL; |
35 import java.security.GeneralSecurityException; |
35 import java.security.GeneralSecurityException; |
|
36 import java.util.Base64; |
36 |
37 |
37 import sun.net.www.HeaderParser; |
38 import sun.net.www.HeaderParser; |
38 import sun.net.www.protocol.http.AuthenticationInfo; |
39 import sun.net.www.protocol.http.AuthenticationInfo; |
39 import sun.net.www.protocol.http.AuthScheme; |
40 import sun.net.www.protocol.http.AuthScheme; |
40 import sun.net.www.protocol.http.HttpURLConnection; |
41 import sun.net.www.protocol.http.HttpURLConnection; |
228 } |
229 } |
229 } |
230 } |
230 |
231 |
231 private String buildType1Msg () { |
232 private String buildType1Msg () { |
232 byte[] msg = client.type1(); |
233 byte[] msg = client.type1(); |
233 String result = "NTLM " + (new B64Encoder()).encode (msg); |
234 String result = "NTLM " + Base64.getEncoder().encodeToString(msg); |
234 return result; |
235 return result; |
235 } |
236 } |
236 |
237 |
237 private String buildType3Msg (String challenge) throws GeneralSecurityException, |
238 private String buildType3Msg (String challenge) throws GeneralSecurityException, |
238 IOException { |
239 IOException { |
239 /* First decode the type2 message to get the server nonce */ |
240 /* First decode the type2 message to get the server nonce */ |
240 /* nonce is located at type2[24] for 8 bytes */ |
241 /* nonce is located at type2[24] for 8 bytes */ |
241 |
242 |
242 byte[] type2 = (new sun.misc.BASE64Decoder()).decodeBuffer (challenge); |
243 byte[] type2 = Base64.getDecoder().decode(challenge); |
243 byte[] nonce = new byte[8]; |
244 byte[] nonce = new byte[8]; |
244 new java.util.Random().nextBytes(nonce); |
245 new java.util.Random().nextBytes(nonce); |
245 byte[] msg = client.type3(type2, nonce); |
246 byte[] msg = client.type3(type2, nonce); |
246 String result = "NTLM " + (new B64Encoder()).encode (msg); |
247 String result = "NTLM " + Base64.getEncoder().encodeToString(msg); |
247 return result; |
248 return result; |
248 } |
249 } |
249 } |
250 } |
250 |
251 |
251 class B64Encoder extends sun.misc.BASE64Encoder { |
|
252 /* to force it to to the entire encoding in one line */ |
|
253 protected int bytesPerLine () { |
|
254 return 1024; |
|
255 } |
|
256 } |
|