Exemplo n.º 1
0
    def check_sapcar_archive(self, filename, version):
        """Test SAP CAR archive file"""

        with open(data_filename(filename), "rb") as fd:
            sapcar_archive = SAPCARArchive(fd, mode="r")

            self.assertEqual(filename, basename(sapcar_archive.filename))
            self.assertEqual(version, sapcar_archive.version)
            self.assertEqual(1, len(sapcar_archive.files))
            self.assertEqual(1, len(sapcar_archive.files_names))
            self.assertListEqual([self.test_filename], sapcar_archive.files_names)
            self.assertListEqual([self.test_filename], sapcar_archive.files.keys())

            af = sapcar_archive.open(self.test_filename)
            self.assertEqual(self.test_string, af.read())
            af.close()

            ff = sapcar_archive.files[self.test_filename]
            self.assertEqual(len(self.test_string), ff.size)
            self.assertEqual(self.test_filename, ff.filename)
            self.assertEqual(self.test_timestamp, ff.timestamp)
            self.assertEqual(self.test_timestamp_raw, ff.timestamp_raw)
            self.assertEqual(self.test_permissions, ff.permissions)
            self.assertEqual(self.test_perm_mode, ff.perm_mode)
            self.assertEqual(version, ff.version)
            self.assertTrue(ff.is_file())
            self.assertFalse(ff.is_directory())

            self.assertTrue(ff.check_checksum())
            self.assertEqual(ff.calculate_checksum(self.test_string), ff.checksum)

            af = ff.open()
            self.assertEqual(self.test_string, af.read())
            af.close()
Exemplo n.º 2
0
    def check_sapcar_archive(self, filename, version):
        """Test SAP CAR archive file version 201"""

        with open(data_filename(filename), "rb") as fd:
            sapcar_archive = SAPCARArchive(fd, mode="r")

            self.assertEqual(filename, basename(sapcar_archive.filename))
            self.assertEqual(version, sapcar_archive.version)
            self.assertEqual(1, len(sapcar_archive.files))
            self.assertEqual(1, len(sapcar_archive.files_names))
            self.assertListEqual([self.test_filename], sapcar_archive.files_names)
            self.assertListEqual([self.test_filename], sapcar_archive.files.keys())

            af = sapcar_archive.open(self.test_filename)
            self.assertEqual(self.test_string, af.read())
            af.close()

            ff = sapcar_archive.files[self.test_filename]
            self.assertEqual(len(self.test_string), ff.size)
            self.assertEqual(self.test_filename, ff.filename)
            self.assertEqual(self.test_timestamp, ff.timestamp)
            self.assertEqual(self.test_permissions, ff.permissions)

            self.assertTrue(ff.check_checksum())
            self.assertEqual(ff.calculate_checksum(self.test_string), ff.checksum)

            af = ff.open()
            self.assertEqual(self.test_string, af.read())
            af.close()
Exemplo n.º 3
0
    def test_pse_v2_lps_off_pbes1_3des_sha1_decrypt(self):
        """Test decryption of a v2 PBES1 encrypted PSE with LPS off"""

        with open(data_filename("pse_v2_lps_off_pbes1_3des_sha1.pse"), "rb") as fd:
            s = fd.read()

        pse = SAPPSEFile(s)
        self.assertRaisesRegexp(ValueError, "Invalid PIN supplied", pse.decrypt, "Some Invalid PIN")
        pse.decrypt(self.decrypt_pin)
Exemplo n.º 4
0
    def test_pse_v2_lps_off_pbes1_3des_sha1_decrypt(self):
        """Test decryption of a v2 PBES1 encrypted PSE with LPS off"""

        with open(data_filename("pse_v2_lps_off_pbes1_3des_sha1.pse"), "rb") as fd:
            s = fd.read()

        pse = SAPPSEFile(s)
        self.assertRaisesRegexp(ValueError, "Invalid PIN supplied", pse.decrypt, "Some Invalid PIN")
        pse.decrypt(self.decrypt_pin)
Exemplo n.º 5
0
    def test_cred_v2_lps_off_dp_3des_decrypt(self):
        """Test decryption of a 3DES encrypted credential with LPS off using DP (Windows)"""

        with open(data_filename("cred_v2_lps_off_dp_3des"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt(self.decrypt_username)
        self.assertEqual(plain.option1, SAPCredv2_Cred_Plain.PROVIDER_MSCryptProtect)
Exemplo n.º 6
0
    def test_cred_v2_lps_off_3des_decrypt(self):
        """Test decryption of a 3DES encrypted credential with LPS off"""

        with open(data_filename("cred_v2_lps_off_3des"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt(self.decrypt_username)
        self.assertEqual(plain.pin.val, self.decrypt_pin)
Exemplo n.º 7
0
    def test_cred_v2_lps_on_int_aes256_decrypt(self):
        """Test decryption of a AES256 encrypted credential with LPS on, INT type"""

        with open(data_filename("cred_v2_lps_on_int_aes256"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt()
        self.assertEqual(plain.pin.val, self.decrypt_pin)
Exemplo n.º 8
0
    def test_cred_v2_lps_on_int_aes256_decrypt(self):
        """Test decryption of a AES256 encrypted credential with LPS on, INT type"""

        with open(data_filename("cred_v2_lps_on_int_aes256"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt()
        self.assertEqual(plain.pin.val, self.decrypt_pin)
Exemplo n.º 9
0
    def test_cred_v2_lps_off_3des_decrypt(self):
        """Test decryption of a 3DES encrypted credential with LPS off"""

        with open(data_filename("cred_v2_lps_off_3des"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt(self.decrypt_username)
        self.assertEqual(plain.pin.val, self.decrypt_pin)
Exemplo n.º 10
0
    def test_cred_v2_lps_off_dp_3des_decrypt(self):
        """Test decryption of a 3DES encrypted credential with LPS off using DP (Windows)"""

        with open(data_filename("cred_v2_lps_off_dp_3des"), "rb") as fd:
            s = fd.read()

        cred = SAPCredv2(s).creds[0].cred
        plain = cred.decrypt(self.decrypt_username)
        self.assertEqual(plain.option1,
                         SAPCredv2_Cred_Plain.PROVIDER_MSCryptProtect)
Exemplo n.º 11
0
    def test_pse_v4_lps_off_pbes1_3des_sha1(self):
        """Test parsing of a v4 PBES1 encrypted PSE with LPS off"""

        with open(data_filename("pse_v4_lps_off_pbes1_3des_sha1.pse"), "rb") as fd:
            s = fd.read()

        pse = SAPPSEFile(s)
        self.assertEqual(pse.version, 4)
        self.assertEqual(pse.enc_cont.algorithm_identifier.alg_id.val, PKCS12_ALGORITHM_PBE1_SHA_3DES_CBC)
        self.assertEqual(pse.enc_cont.algorithm_identifier.parameters.iterations, self.iterations)
        self.assertEqual(len(pse.enc_cont.algorithm_identifier.parameters.salt.val), 8)
Exemplo n.º 12
0
    def test_pse_v4_lps_off_pbes1_3des_sha1(self):
        """Test parsing of a v4 PBES1 encrypted PSE with LPS off"""

        with open(data_filename("pse_v4_lps_off_pbes1_3des_sha1.pse"), "rb") as fd:
            s = fd.read()

        pse = SAPPSEFile(s)
        self.assertEqual(pse.version, 4)
        self.assertEqual(pse.enc_cont.algorithm_identifier.alg_id.val, PKCS12_ALGORITHM_PBE1_SHA_3DES_CBC)
        self.assertEqual(pse.enc_cont.algorithm_identifier.parameters.iterations, self.iterations)
        self.assertEqual(len(pse.enc_cont.algorithm_identifier.parameters.salt.val), 8)
Exemplo n.º 13
0
    def test_sapcar_archive_file_200_to_201(self):
        """Test SAP CAR archive file object conversion from 2.00 to 2.01"""

        with open(data_filename("car200_test_string.sar"), "rb") as fd200:
            ar200 = SAPCARArchive(fd200, mode="r")
            ff200 = ar200.files[self.test_filename]
            ff201 = SAPCARArchiveFile.from_archive_file(ff200, SAPCAR_VERSION_201)

            self.assertEqual(ff200.size, ff201.size)
            self.assertEqual(ff200.filename, ff201.filename)
            self.assertEqual(ff200.timestamp, ff201.timestamp)
            self.assertEqual(ff200.permissions, ff201.permissions)
            self.assertEqual(ff200.checksum, ff201.checksum)

            af = ff201.open()
            self.assertEqual(self.test_string, af.read())
            af.close()
Exemplo n.º 14
0
    def test_sapcar_archive_file_200_to_201(self):
        """Test SAP CAR archive file object conversion from 2.00 to 2.01"""

        with open(data_filename("car200_test_string.sar"), "rb") as fd200:
            ar200 = SAPCARArchive(fd200, mode="r")
            ff200 = ar200.files[self.test_filename]
            ff201 = SAPCARArchiveFile.from_archive_file(
                ff200, SAPCAR_VERSION_201)

            self.assertEqual(ff200.size, ff201.size)
            self.assertEqual(ff200.filename, ff201.filename)
            self.assertEqual(ff200.timestamp, ff201.timestamp)
            self.assertEqual(ff200.permissions, ff201.permissions)
            self.assertEqual(ff200.checksum, ff201.checksum)

            af = ff201.open()
            self.assertEqual(self.test_string, af.read())
            af.close()
Exemplo n.º 15
0
    def test_cred_v2_lps_on_dp_aes256(self):
        """Test parsing of a AES256 encrypted credential with LPS on, DP type"""

        with open(data_filename("cred_v2_lps_on_dp_aes256"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.common_name)
        self.assertEqual(cred.pse_file_path, self.pse_path_win)
        self.assertEqual(cred.lps_type, 1)
        self.assertEqual(cred.cipher_format_version, 2)

        self.assertEqual(cred.version.val, 2)
        self.assertEqual(cred.oid.val, "2.5.4.3")
        self.assertEqual(cred.value.val, self.common_name)
        self.assertEqual(cred.pse_path, self.pse_path_win)
Exemplo n.º 16
0
    def test_cred_v2_lps_on_dp_aes256(self):
        """Test parsing of a AES256 encrypted credential with LPS on, DP type"""

        with open(data_filename("cred_v2_lps_on_dp_aes256"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.common_name)
        self.assertEqual(cred.pse_file_path, self.pse_path_win)
        self.assertEqual(cred.lps_type, 1)
        self.assertEqual(cred.cipher_format_version, 2)

        self.assertEqual(cred.version.val, 2)
        self.assertEqual(cred.oid.val, "2.5.4.3")
        self.assertEqual(cred.value.val, self.common_name)
        self.assertEqual(cred.pse_path, self.pse_path_win)
Exemplo n.º 17
0
    def test_cred_v2_lps_off_dp_3des(self):
        """Test parsing of a 3DES encrypted credential with LPS off using DP (Windows)"""

        with open(data_filename("cred_v2_lps_off_dp_3des"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.cert_name)
        self.assertEqual(cred.pse_file_path, self.pse_path_win)
        self.assertEqual(cred.lps_type, None)
        self.assertEqual(cred.cipher_format_version, 0)
        self.assertEqual(cred.cipher_algorithm, CIPHER_ALGORITHM_3DES)

        self.assertEqual(cred.cert_name, self.cert_name)
        self.assertEqual(cred.unknown1, "")
        self.assertEqual(cred.pse_path, self.pse_path_win)
        self.assertEqual(cred.unknown2, "")
Exemplo n.º 18
0
    def test_cred_v2_lps_off_aes256(self):
        """Test parsing of a AES256 encrypted credential with LPS off"""

        with open(data_filename("cred_v2_lps_off_aes256"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.cert_name)
        self.assertEqual(cred.pse_file_path, self.pse_path)
        self.assertEqual(cred.lps_type, None)
        self.assertEqual(cred.cipher_format_version, 1)
        self.assertEqual(cred.cipher_algorithm, CIPHER_ALGORITHM_AES256)

        self.assertEqual(cred.cert_name, self.cert_name)
        self.assertEqual(cred.unknown1, "")
        self.assertEqual(cred.pse_path, self.pse_path)
        self.assertEqual(cred.unknown2, "")
Exemplo n.º 19
0
    def test_cred_v2_lps_off_dp_3des(self):
        """Test parsing of a 3DES encrypted credential with LPS off using DP (Windows)"""

        with open(data_filename("cred_v2_lps_off_dp_3des"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.cert_name)
        self.assertEqual(cred.pse_file_path, self.pse_path_win)
        self.assertEqual(cred.lps_type, None)
        self.assertEqual(cred.cipher_format_version, 0)
        self.assertEqual(cred.cipher_algorithm, CIPHER_ALGORITHM_3DES)

        self.assertEqual(cred.cert_name, self.cert_name)
        self.assertEqual(cred.unknown1, "")
        self.assertEqual(cred.pse_path, self.pse_path_win)
        self.assertEqual(cred.unknown2, "")
Exemplo n.º 20
0
    def test_cred_v2_lps_off_aes256(self):
        """Test parsing of a AES256 encrypted credential with LPS off"""

        with open(data_filename("cred_v2_lps_off_aes256"), "rb") as fd:
            s = fd.read()

        creds = SAPCredv2(s).creds
        self.assertEqual(len(creds), 1)

        cred = creds[0].cred
        self.assertEqual(cred.common_name, self.cert_name)
        self.assertEqual(cred.pse_file_path, self.pse_path)
        self.assertEqual(cred.lps_type, None)
        self.assertEqual(cred.cipher_format_version, 1)
        self.assertEqual(cred.cipher_algorithm, CIPHER_ALGORITHM_AES256)

        self.assertEqual(cred.cert_name, self.cert_name)
        self.assertEqual(cred.unknown1, "")
        self.assertEqual(cred.pse_path, self.pse_path)
        self.assertEqual(cred.unknown2, "")
Exemplo n.º 21
0
    def test_sapcar_archive_201_to_200(self):
        """Test SAP CAR archive object conversion from 2.01 to 2.00"""

        with open(data_filename("car201_test_string.sar"), "rb") as fd:
            ar = SAPCARArchive(fd, mode="r")
            ff201 = ar.files[self.test_filename]

            ar.version = SAPCAR_VERSION_200
            ff200 = ar.files[self.test_filename]

            self.assertEqual(ff200.size, ff201.size)
            self.assertEqual(ff200.filename, ff201.filename)
            self.assertEqual(ff200.timestamp, ff201.timestamp)
            self.assertEqual(ff200.timestamp_raw, ff201.timestamp_raw)
            self.assertEqual(ff200.permissions, ff201.permissions)
            self.assertEqual(ff200.perm_mode, ff201.perm_mode)
            self.assertEqual(ff200.checksum, ff201.checksum)
            self.assertIs(ff200.is_file(), ff201.is_file())
            self.assertIs(ff200.is_directory(), ff201.is_directory())

            af = ff200.open()
            self.assertEqual(self.test_string, af.read())
            af.close()
Exemplo n.º 22
0
    def test_sapcar_archive_201_to_200(self):
        """Test SAP CAR archive object conversion from 2.01 to 2.00"""

        with open(data_filename("car201_test_string.sar"), "rb") as fd:
            ar = SAPCARArchive(fd, mode="r")
            ff201 = ar.files[self.test_filename]

            ar.version = SAPCAR_VERSION_200
            ff200 = ar.files[self.test_filename]

            self.assertEqual(ff200.size, ff201.size)
            self.assertEqual(ff200.filename, ff201.filename)
            self.assertEqual(ff200.timestamp, ff201.timestamp)
            self.assertEqual(ff200.timestamp_raw, ff201.timestamp_raw)
            self.assertEqual(ff200.permissions, ff201.permissions)
            self.assertEqual(ff200.perm_mode, ff201.perm_mode)
            self.assertEqual(ff200.checksum, ff201.checksum)
            self.assertIs(ff200.is_file(), ff201.is_file())
            self.assertIs(ff200.is_directory(), ff201.is_directory())

            af = ff200.open()
            self.assertEqual(self.test_string, af.read())
            af.close()