authMethod = "Negotiate";
authorization = challenge.substring(10).trim();
}
}
if (authMethod == null) return null;
NtlmMessage message = null;
if (authorization != null) {
try {
message = new Type2Message(Base64.decode(authorization));
} catch (IOException ioe) {
ioe.printStackTrace();
return null;
}
}
// reconnect();
int flags = NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM | NtlmFlags.NTLMSSP_REQUEST_TARGET | NtlmFlags.NTLMSSP_NEGOTIATE_OEM | NtlmFlags.NTLMSSP_NEGOTIATE_UNICODE;
if (message == null) {
message = new Type1Message(flags, null, null);
} else {
credentials = credentials.substring(authMethod.length()+1); // strip off the "NTLM " or "Negotiate "
credentials = new String(Base64.decode(credentials)); // decode the base64
String domain = credentials.substring(0, credentials.indexOf("\\"));
String user = credentials.substring(domain.length()+1, credentials.indexOf(":"));
String password = credentials.substring(domain.length()+user.length()+2);
Type2Message type2 = (Type2Message) message;
flags ^= NtlmFlags.NTLMSSP_NEGOTIATE_OEM;
message = new Type3Message(type2, password, domain, user, null, flags);
}
return authMethod + " " + Base64.encode(message.toByteArray());
}