Example #1
0
    def VerifyChapPasswd(self, userpwd):
        """ Verify RADIUS ChapPasswd

        :param userpwd: plaintext password
        :type userpwd:  str
        :return:        is verify ok
        :rtype:         bool
        """

        if not self.authenticator:
            self.authenticator = self.CreateAuthenticator()

        if isinstance(userpwd, six.text_type):
            userpwd = userpwd.strip().encode('utf-8')

        chap_password = tools.DecodeOctets(self.get(3)[0])
        if len(chap_password) != 17:
            return False

        chapid = chap_password[0]
        if six.PY3:
            chapid = chr(chapid).encode('utf-8')
        password = chap_password[1:]

        challenge = self.authenticator
        if 'CHAP-Challenge' in self:
            challenge = self['CHAP-Challenge'][0]
        return password == md5_constructor(chapid + userpwd + challenge).digest()
Example #2
0
    def VerifyChapPasswd(self, userpwd):
        """ Verify RADIUS ChapPasswd

        :param userpwd: plaintext password
        :type userpwd:  str
        :return:        is verify ok
        :rtype:         bool
        """

        if not self.authenticator:
            self.authenticator = self.CreateAuthenticator()

        if isinstance(userpwd, six.text_type):
            userpwd = userpwd.strip().encode('utf-8')

        chap_password = tools.DecodeOctets(self.get(3)[0])
        if len(chap_password) != 17:
            return False

        chapid = chap_password[0]
        password = chap_password[1:]

        if type(chapid) == int:
            chapid = chr(chapid)

        challenge = self.authenticator
        if 'CHAP-Challenge' in self:
            challenge = self['CHAP-Challenge'][0]

        passwd_string = "%s%s%s" % (chapid, (userpwd if type(userpwd) == str
                                             else userpwd.decode('latin-1')),
                                    (challenge if type(userpwd) == str else
                                     challenge.decode('latin-1')))
        return password == md5_constructor(
            passwd_string.encode('latin-1')).digest()
Example #3
0
 def _DecodeValue(self, attr, value):
     if attr.has_tag:
         # Remove tag prefix if present
         tag, value = tools.DecodeTaggedAttr(attr.type, value)
     if attr.values.HasBackward(value):
         decoded_value = attr.values.GetBackward(value)
     elif attr.encrypt == 1 or attr.encrypt == 2:
         if self.auto_crypt:
             decoded_value = self._DecodeEncryptedValue(attr, value)
         else:
             decoded_value = tools.DecodeOctets(value)
     else:
         decoded_value = tools.DecodeAttr(attr.type, value)
     if attr.has_tag:
         return (tag, decoded_value)
     else:
         return decoded_value
Example #4
0
 def get_chappwd(self):
     try:
         return tools.DecodeOctets(self.get(3)[0])
     except:
         return None