예제 #1
0
    def test_verifyHTTPDigest(self):
        expectations = (
            (u"zehcnasw", True),  # Correct
            ("wrong", False)  # Incorrect
        )
        record = (
            yield self.client.recordWithShortName(
                RecordType.user,
                u"wsanchez"
            )
        )

        realm = "host.example.com"
        nonce = "128446648710842461101646794502"
        algorithm = "md5"
        uri = "http://host.example.com"
        method = "GET"

        for password, answer in expectations:
            for qop, nc, cnonce in (
                ("", "", ""),
                ("auth", "00000001", "/rrD6TqPA3lHRmg+fw/vyU6oWoQgzK7h9yWrsCmv/lE="),
            ):
                response = calcResponse(
                    calcHA1(algorithm, u"wsanchez", realm, password, nonce, cnonce),
                    calcHA2(algorithm, method, uri, qop, None),
                    algorithm, nonce, nc, cnonce, qop)

                authenticated = (
                    yield record.verifyHTTPDigest(
                        u"wsanchez", realm, uri, nonce, cnonce, algorithm, nc, qop,
                        response, method
                    )
                )
                self.assertEquals(authenticated, answer)
 def test_MD5HashA1(self, _algorithm='md5', _hash=md5):
     """
     L{calcHA1} accepts the C{'md5'} algorithm and returns an MD5 hash of
     its parameters, excluding the nonce and cnonce.
     """
     nonce = 'abc123xyz'
     hashA1 = calcHA1(_algorithm, self.username, self.realm, self.password,
                      nonce, self.cnonce)
     a1 = '%s:%s:%s' % (self.username, self.realm, self.password)
     expected = _hash(a1).hexdigest()
     self.assertEqual(hashA1, expected)
 def test_MD5SessionHashA1(self):
     """
     L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
     of its parameters, including the nonce and cnonce.
     """
     nonce = 'xyz321abc'
     hashA1 = calcHA1('md5-sess', self.username, self.realm, self.password,
                      nonce, self.cnonce)
     a1 = '%s:%s:%s' % (self.username, self.realm, self.password)
     ha1 = md5(a1).digest()
     a1 = '%s:%s:%s' % (ha1, nonce, self.cnonce)
     expected = md5(a1).hexdigest()
     self.assertEqual(hashA1, expected)
    def getDigestResponse(self, challenge, ncount):
        """
        Calculate the response for the given challenge
        """
        nonce = challenge.get('nonce')
        algo = challenge.get('algorithm').lower()
        qop = challenge.get('qop')

        ha1 = calcHA1(
            algo, self.username, self.realm, self.password, nonce, self.cnonce)
        ha2 = calcHA2(algo, "GET", self.uri, qop, None)
        expected = calcResponse(ha1, ha2, algo, nonce, ncount, self.cnonce, qop)
        return expected
예제 #5
0
 def test_MD5SessionHashA1(self):
     """
     L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
     of its parameters, including the nonce and cnonce.
     """
     nonce = 'xyz321abc'
     hashA1 = calcHA1('md5-sess', self.username, self.realm, self.password,
                      nonce, self.cnonce)
     a1 = '%s:%s:%s' % (self.username, self.realm, self.password)
     ha1 = md5(a1).digest()
     a1 = '%s:%s:%s' % (ha1, nonce, self.cnonce)
     expected = md5(a1).hexdigest()
     self.assertEqual(hashA1, expected)
예제 #6
0
    def getDigestResponse(self, challenge, ncount):
        """
        Calculate the response for the given challenge
        """
        nonce = challenge.get('nonce')
        algo = challenge.get('algorithm').lower()
        qop = challenge.get('qop')

        ha1 = calcHA1(
            algo, self.username, self.realm, self.password, nonce, self.cnonce)
        ha2 = calcHA2(algo, "GET", self.uri, qop, None)
        expected = calcResponse(ha1, ha2, algo, nonce, ncount, self.cnonce, qop)
        return expected
예제 #7
0
 def test_MD5SessionHashA1(self):
     """
     L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
     of its parameters, including the nonce and cnonce.
     """
     nonce = b'xyz321abc'
     hashA1 = calcHA1(b'md5-sess', self.username, self.realm, self.password,
                      nonce, self.cnonce)
     a1 = self.username + b':' + self.realm + b':' + self.password
     ha1 = hexlify(md5(a1).digest())
     a1 = ha1 + b':' + nonce + b':' + self.cnonce
     expected = hexlify(md5(a1).digest())
     self.assertEqual(hashA1, expected)
예제 #8
0
 def test_MD5SessionHashA1(self):
     """
     L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
     of its parameters, including the nonce and cnonce.
     """
     nonce = b'xyz321abc'
     hashA1 = calcHA1(b'md5-sess', self.username, self.realm, self.password,
                      nonce, self.cnonce)
     a1 = self.username + b':' + self.realm + b':' + self.password
     ha1 = hexlify(md5(a1).digest())
     a1 = ha1 + b':' + nonce + b':' + self.cnonce
     expected = hexlify(md5(a1).digest())
     self.assertEqual(hashA1, expected)