RANDOM.nextBytes(masterKey);
byte[] exchangedKey = new byte[16];
try {
Cipher rc4 = Cipher.getInstance("RC4");
rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(userSessionKey, "RC4"));
rc4.update(masterKey, 0, 16, exchangedKey, 0);
} catch (GeneralSecurityException gse) {
throw new RuntimeException("", gse);
}
setSessionKey(exchangedKey);
} else {
masterKey = userSessionKey;
setSessionKey(masterKey);
}
}
}
break;
case 2:
byte[] nt = getNTResponse(type2, password);
setLMResponse(nt);
setNTResponse(nt);
break;
case 3:
case 4:
case 5:
byte[] responseKeyNT = NtlmPasswordAuthentication.nTOWFv2(domain, user, password);
byte[] clientChallenge = new byte[8];
RANDOM.nextBytes(clientChallenge);
setLMResponse(getLMv2Response(type2, domain, user, password, clientChallenge));
byte[] clientChallenge2 = new byte[8];
RANDOM.nextBytes(clientChallenge2);
setNTResponse(getNTLMv2Response(type2, responseKeyNT, clientChallenge2));
if ((getFlags() & NTLMSSP_NEGOTIATE_SIGN) == NTLMSSP_NEGOTIATE_SIGN) {
masterKey = new byte[16];
RANDOM.nextBytes(masterKey);
HMACT64 hmac = new HMACT64(responseKeyNT);
hmac.update(ntResponse, 0, 16); // only first 16 bytes of ntResponse
byte[] userSessionKey = hmac.digest();
/* TODO: don't do this if NTLMSSP_NEGOTIATE_KEY_EXCH not set
*/
byte[] exchangedKey = new byte[16];
try {
Cipher rc4 = Cipher.getInstance("RC4");
rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(userSessionKey, "RC4"));
rc4.update(masterKey, 0, 16, exchangedKey, 0);
} catch (GeneralSecurityException gse) {
throw new RuntimeException("", gse);
}