def verifyMsChapV2(self, userpwd): ms_chap_response = self['MS-CHAP2-Response'][0] authenticator_challenge = self['MS-CHAP-Challenge'][0] if len(ms_chap_response) != 50: raise Exception("Invalid MSCHAPV2-Response attribute length") # if isinstance(userpwd, six.text_type): # userpwd = userpwd.strip().encode('utf-8') nt_response = ms_chap_response[26:50] peer_challenge = ms_chap_response[2:18] _user_name = self.get(1)[0] nt_resp = mschap.generate_nt_response_mschap2( authenticator_challenge, peer_challenge, _user_name, userpwd, ) if nt_resp == nt_response: auth_resp = mschap.generate_authenticator_response( userpwd, nt_response, peer_challenge, authenticator_challenge, _user_name) self.ext_attrs['MS-CHAP2-Success'] = auth_resp self.ext_attrs['MS-MPPE-Encryption-Policy'] = '\x00\x00\x00\x01' self.ext_attrs['MS-MPPE-Encryption-Type'] = '\x00\x00\x00\x06' nt_pwd_hash = mschap.nt_password_hash(userpwd) mppeSendKey, mppeRecvKey = mppe.mppe_chap2_gen_keys( userpwd, peer_challenge) self.ext_attrs['MS-MPPE-Send-Key'] = mppeSendKey self.ext_attrs['MS-MPPE-Recv-Key'] = mppeRecvKey return True else: return False
def verifyMsChapV2(self,userpwd): ms_chap_response = self['MS-CHAP2-Response'][0] authenticator_challenge = self['MS-CHAP-Challenge'][0] if len(ms_chap_response)!=50: raise Exception("Invalid MSCHAPV2-Response attribute length") # if isinstance(userpwd, six.text_type): # userpwd = userpwd.strip().encode('utf-8') nt_response = ms_chap_response[26:50] peer_challenge = ms_chap_response[2:18] _user_name = self.get(1)[0] nt_resp = mschap.generate_nt_response_mschap2( authenticator_challenge, peer_challenge, _user_name, userpwd, ) if nt_resp == nt_response: auth_resp = mschap.generate_authenticator_response( userpwd, nt_response, peer_challenge, authenticator_challenge, _user_name ) self.ext_attrs['MS-CHAP2-Success'] = auth_resp self.ext_attrs['MS-MPPE-Encryption-Policy'] = '\x00\x00\x00\x01' self.ext_attrs['MS-MPPE-Encryption-Type'] = '\x00\x00\x00\x06' nt_pwd_hash = mschap.nt_password_hash(userpwd) mppeSendKey,mppeRecvKey = mppe.mppe_chap2_gen_keys(userpwd,peer_challenge) self.ext_attrs['MS-MPPE-Send-Key'] = mppeSendKey self.ext_attrs['MS-MPPE-Recv-Key'] = mppeRecvKey return True else: return False
def verifyMsChapV1(self, userpwd): ms_chap_response = self['MS-CHAP-Response'][0] authenticator_challenge = self['MS-CHAP-Challenge'][0] if len(ms_chap_response) != 50: raise Exception("Invalid MSCHAPV1-Response attribute length") flag = ms_chap_response[1] lm_password = None nt_password = None if flag == 0: lm_password = ms_chap_response[2:26] else: nt_password = ms_chap_response[26:50] resp = None auth_ok = False if nt_password: resp = mschap.generate_nt_response_mschap(authenticator_challenge, userpwd) auth_ok = (resp == nt_password) elif lm_password: resp = mschap.generate_lm_response_mschap(authenticator_challenge, userpwd) auth_ok = (resp == lm_password) if not auth_ok: return False nt_hash = mschap.nt_password_hash(userpwd) lm_hash = mschap.lm_password_hash(userpwd) _key = (nt_hash + lm_hash).ljust(32, '0') mppekey = mppe.radius_encrypt_keys(_key, self.secret, self.authenticator, mppe.create_salt()) self.ext_attrs['MS-CHAP-MPPE-Keys'] = mppekey return True
def verifyMsChapV1(self,userpwd): ms_chap_response = self['MS-CHAP-Response'][0] authenticator_challenge = self['MS-CHAP-Challenge'][0] if len(ms_chap_response)!=50: raise Exception("Invalid MSCHAPV1-Response attribute length") flag = ms_chap_response[1] lm_password = None nt_password = None if flag == 0: lm_password = ms_chap_response[2:26] else: nt_password = ms_chap_response[26:50] resp = None auth_ok = False if nt_password: resp = mschap.generate_nt_response_mschap(authenticator_challenge,userpwd) auth_ok = (resp == nt_password) elif lm_password: resp = mschap.generate_lm_response_mschap(authenticator_challenge,userpwd) auth_ok = (resp == lm_password) if not auth_ok:return False nt_hash = mschap.nt_password_hash(userpwd) lm_hash = mschap.lm_password_hash(userpwd) _key = (nt_hash + lm_hash).ljust(32,'0') mppekey = mppe.radius_encrypt_keys(_key,self.secret,self.authenticator,mppe.create_salt()) self.ext_attrs['MS-CHAP-MPPE-Keys'] = mppekey return True