Esempio n. 1
0
    def test_fprint(self):
        """
        Test fingerprints
        :return:
        """
        positive_samples = [
            'mod01.txt', 'mod02.txt', 'mod03.txt', 'mod08.txt', 'mod09.txt',
            'key04.pgp', 'cert04.pem', 'cert05.pem', 'ssh06.pub',
            'pubkey03.pem'
        ]
        self.assertGreaterEqual(len(self.inputs), 19,
                                'Some inputs are missing')

        fprinter = RocaFingerprinter()
        for fname, data in self.inputs:
            ret = drop_none(flatten(fprinter.process_file(data, fname)))
            self.assertGreaterEqual(len(ret), 1,
                                    'At least one result expected')

            if fname.endswith('.txt'):
                self.assertEqual(
                    len(ret), 1,
                    'Hex mod input epxected result count is 1, not %s' %
                    len(ret))
                self.assertEqual('mod-hex', ret[0].type,
                                 'File type detection failed')

            for sub in ret:
                self.assertIsNone(
                    sub.error,
                    'Unexpected error with file %s : %s' % (fname, sub.error))
                self.assertEqual(fname, sub.fname, 'Filename mismatch')
                self.assertIsNotNone(sub.n, 'Modulus is empty')
                self.assertGreaterEqual(len(sub.n), 10, 'Modulus is too short')

                if fname in positive_samples:
                    self.assertTrue(
                        sub.marked,
                        'False negative detection on fingerprinted modulus: %s'
                        % fname)
                else:
                    self.assertFalse(
                        sub.marked,
                        'False positive detection on non-fingerprinted modulus %s'
                        % fname)
Esempio n. 2
0
    def fprint_subtest(self, fprinter):
        """
        Basic fingerprinter test
        :param fprinter:
        :return:
        """
        self.assertGreaterEqual(len(self.inputs), 19,
                                'Some inputs are missing')

        for fname, data in self.inputs:
            ret = drop_none(flatten(fprinter.process_file(data, fname)))
            self.assertGreaterEqual(len(ret), 1,
                                    'At least one result expected')

            if fname.endswith('.txt'):
                self.assertEqual(
                    len(ret), 1,
                    'Hex mod input epxected result count is 1, not %s' %
                    len(ret))
                self.assertEqual('mod-hex', ret[0].type,
                                 'File type detection failed')

            for sub in ret:
                self.assertIsNone(
                    sub.error,
                    'Unexpected error with file %s : %s' % (fname, sub.error))
                self.assertEqual(fname, sub.fname, 'Filename mismatch')
                self.assertIsNotNone(sub.n, 'Modulus is empty')
                self.assertGreaterEqual(len(sub.n), 10, 'Modulus is too short')

                if fname in self.positive_samples:
                    self.assertTrue(
                        sub.marked,
                        'False negative detection on fingerprinted modulus: %s'
                        % fname)
                else:
                    self.assertFalse(
                        sub.marked,
                        'False positive detection on non-fingerprinted modulus %s'
                        % fname)