コード例 #1
0
    def generate(self, uri):
        """
        Returns a newly-generated PwdHash password for the received 'uri'.-
        """
        from pwdhash_vault.md5 import HmacMd5

        #
        # get the master password of this generator from the hashed list
        #
        passwd = [unichr(self._reversible_hash(c)) for c in self.hashed_pwd]
        passwd = ''.join(passwd)
        #
        # extract the domain from the received URI
        #
        realm = self._extract_domain(uri)
        #
        # the lenght of the generated password
        #
        size = len(passwd) + len(self.password_prefix)
        #
        # whether to include non-alphanumeric characters in the
        # generated password
        #
        non_alpha = len(re.findall(r'\W', passwd)) != 0
        #
        # generate the password
        #
        pwd_hash = HmacMd5.b64_hmac_md5(passwd, realm)
        del passwd

        return self._apply_constraints(pwd_hash, size, non_alpha)
コード例 #2
0
    def test_binl2b64(self):
        params = []
        expected = []

        params.append([[-379130694, 866638437, 433126637, 553295998]])
        expected.append('uuxm6WXapzPt/NAZfqD6IA')

        for i, p in enumerate(params):
            self.assertEqual(HmacMd5._binl2b64(*p), expected[i])
コード例 #3
0
 def test_core_md5(self):
     chrsz = 8
     lst = [
         1397117766, 909522486, 909522486, 909522486, 909522486, 909522486,
         909522486, 909522486, 909522486, 909522486, 909522486, 909522486,
         909522486, 909522486, 909522486, 909522486, 1735356263, 1663985004,
         28015
     ]
     expected = [-1906562005, 1347505609, -2070658591, 639279188]
     result = HmacMd5._core_md5(lst, 512 + 10 * chrsz)
     self.assertEqual(result, expected)
コード例 #4
0
    def test_core_hmac_md5(self):
        params = []
        expected = []

        params.append([u"^čufti^", "google.com"])
        expected.append([-1150369439, 320447430, 2092528897, -2140662759])

        params.append([u"pepe", "google.com"])
        expected.append([233115305, 81019179, -227315827, -927036398])

        for i, p in enumerate(params):
            self.assertEqual(HmacMd5._core_hmac_md5(*p), expected[i])
コード例 #5
0
    def test_md5_ff(self):
        params = []
        expected = []

        params.append([
            1732584193, -271733879, -1732584194, 271733878, 1397117766, 7,
            -680876936
        ])
        expected.append(1212779038)

        params.append([
            271733878, 1212779038, -271733879, -1732584194, 909522486, 12,
            -389564586
        ])
        expected.append(173550240)

        params.append([
            -1732584194, 173550240, 1212779038, -271733879, 909522486, 17,
            606105819
        ])
        expected.append(680127582)

        for i, p in enumerate(params):
            self.assertEqual(HmacMd5._md5_ff(*p), expected[i])
コード例 #6
0
 def test_str2binl(self):
     string = "pepe"
     expected = [1701864816]
     self.assertEqual(HmacMd5._str2binl(string, 8), expected)
コード例 #7
0
 def test_bit_rol(self):
     params = [[716240829, 7], [137109738, 12], [-522252520, 17]]
     expected = [1484512917, -1039228798, 506577342]
     for i, p in enumerate(params):
         self.assertEqual(HmacMd5._bit_rol(*p), expected[i])
コード例 #8
0
 def test_safe_add(self):
     params = [[668467704, 2130783302], [-1526234400, -1971324652]]
     expected = [-1495716290, 797408244]
     for i, p in enumerate(params):
         self.assertEqual(HmacMd5._safe_add(*p), expected[i])