Пример #1
0
    def test_parse_fingerprint(self):
        fingerprint = CertParser.parse_fingerprint(
            "Certificate fingerprints:\n"
            "\t MD5: any-md5\n"
            "\t SHA1: any-sha1\n"
            "\t SHA256: any-sha256\n"
            "Signature algorithm name: any-signature\n"
            "Version: any-version"
        )

        self.assertEqual(
            CertFingerprint(
                md5="any-md5",
                sha1="any-sha1",
                sha256="any-sha256",
                signature="any-signature",
                version="any-version"
            ),
            fingerprint
        )
Пример #2
0
    def test_init(self, mock_file_parser, mock_get_localzone, mock_popen):
        file = any_file()
        mock_parser_instance = any_file_parser(file=file)
        mock_file_parser.return_value = mock_parser_instance
        mock_popen.return_value = any_popen(
            response=b"Owner: CN=OwnerName, OU=OwnerUnit, O=OwnerOrganization, L=OwnerCity, ST=OwnerState, C=OwnerCountry\n" \
                     b"Issuer: CN=IssuerName, OU=IssuerUnit, O=IssuerOrganization, L=IssuerCity, ST=IssuerState, C=IssuerCountry\n" \
                     b"Serial number: 558e7595\n" \
                     b"Valid from: Sat Jun 27 12:06:13 CEST 2015 until: Tue Feb 26 11:06:13 CET 2515\n" \
                     b"Certificate fingerprints:\n" \
                     b"\t MD5: 90:22:EF:0C:DB:C3:78:87:7B:C3:A3:6C:5A:68:E6:45\n" \
                     b"\t SHA1: 5A:C0:6C:32:63:7F:5D:BE:CA:F9:38:38:4C:FA:FF:ED:20:52:43:B6\n" \
                     b"\t SHA256: E5:15:CC:BC:5E:BF:B2:9D:A6:13:03:63:CF:19:33:FA:CE:AF:DC:ED:5D:2F:F5:98:7C:CE:37:13:64:4A:CF:77\n" \
                     b"Signature algorithm name: SHA1withRSA\n" \
                     b"Subject Public Key Algorithm: 1024-bit RSA key\n" \
                     b"Version: 3"
        )
        mock_get_localzone.return_value.localize.side_effect = ValueError()

        cert = self.sut.parse("any-file-path", "any-file-name")

        assert_file_parser_called_once_with(mock_parser_instance, filepath="any-file-path", filename="any-file-name")
        assert_popen_called_once_with(mock_popen, "keytool -printcert -file any-file-path")
        assert_file_equal(self, expected=file, actual=cert)
        self.assertEqual("558e7595", cert.get_serial_number())
        self.assertEqual(
            CertValidity(valid_from="Sat Jun 27 12:06:13 CEST 2015", valid_to="Tue Feb 26 11:06:13 CET 2515"),
            cert.get_validity()
        )
        self.assertEqual(
            CertFingerprint(
                md5="90:22:EF:0C:DB:C3:78:87:7B:C3:A3:6C:5A:68:E6:45",
                sha1="5A:C0:6C:32:63:7F:5D:BE:CA:F9:38:38:4C:FA:FF:ED:20:52:43:B6",
                sha256="E5:15:CC:BC:5E:BF:B2:9D:A6:13:03:63:CF:19:33:FA:CE:AF:DC:ED:5D:2F:F5:98:7C:CE:37:13:64:4A:CF:77",
                signature="SHA1withRSA",
                version="3"
            ),
            cert.get_fingerprint()
        )
        self.assertEqual(
            CertParticipant(
                name="OwnerName",
                email="",
                unit="OwnerUnit",
                organization="OwnerOrganization",
                city="OwnerCity",
                state="OwnerState",
                country="OwnerCountry",
                domain=""
            ),
            cert.get_owner()
        )
        self.assertEqual(
            CertParticipant(
                name="IssuerName",
                email="",
                unit="IssuerUnit",
                organization="IssuerOrganization",
                city="IssuerCity",
                state="IssuerState",
                country="IssuerCountry",
                domain=""
            ),
            cert.get_issuer()
        )
Пример #3
0
    def test_apk_as_dict(self):
        apk = APK(
            filename="any-apk-file-name",
            size=10,
            md5hash="any-apk-file-md5",
            sha1hash="any-apk-file-sha1",
            sha256hash="any-apk-file-sha256",
            sha512hash="any-apk-file-sha512",
            app_name="any-app-name",
            cert=Cert(
                filename="any-cert-file-name",
                size=20,
                md5hash="any-cert-file-md5",
                sha1hash="any-cert-file-sha1",
                sha256hash="any-cert-file-sha256",
                sha512hash="any-cert-file-sha512",
                serial_number="any-cert-serial-number",
                validity=CertValidity(
                    valid_from="any-cert-validity-from",
                    valid_to="any-cert-validity-to"
                ),
                fingerprint=CertFingerprint(
                    md5="any-cert-fingerprint-md5",
                    sha1="any-cert-fingerprint-sha1",
                    sha256="any-cert-fingerprint-sha256",
                    signature="any-cert-fingerprint-signature",
                    version="any-cert-fingerprint-version"
                ),
                owner=CertParticipant(
                    name="any-cert-owner-name",
                    email="any-cert-owner-email",
                    unit="any-cert-owner-unit",
                    organization="any-cert-owner-organization",
                    city="any-cert-owner-city",
                    state="any-cert-owner-state",
                    country="any-cert-owner-country",
                    domain="any-cert-owner-domain"
                ),
                issuer=CertParticipant(
                    name="any-cert-issuer-name",
                    email="any-cert-issuer-email",
                    unit="any-cert-issuer-unit",
                    organization="any-cert-issuer-organization",
                    city="any-cert-issuer-city",
                    state="any-cert-issuer-state",
                    country="any-cert-issuer-country",
                    domain="any-cert-issuer-domain"
                )
            ),
            manifest=AndroidManifest(
                filename="any-manifest-file-name",
                size=30,
                md5hash="any-manifest-file-md5",
                sha1hash="any-manifest-file-sha1",
                sha256hash="any-manifest-file-sha256",
                sha512hash="any-manifest-file-sha512",
                package_name="any-package-name",
                version=AppVersion(code=1, name="any-version-name"),
                sdk=AppSdk(min_version="10", target_version="15", max_version="20"),
                permissions=[],
                activities=[],
                services=[],
                receivers=[]
            ),
            dex_files=[
                Dex(
                    filename="any-dex-file-name",
                    size=40,
                    md5hash="any-dex-file-md5",
                    sha1hash="any-dex-file-sha1",
                    sha256hash="any-dex-file-sha256",
                    sha512hash="any-dex-file-sha512",
                    strings=[],
                    urls=[],
                    shell_commands=[],
                    custom_signatures=[]
                )
            ],
            other_files=[
                any_file(
                    filename="any-resource-file-name",
                    size=50,
                    md5="any-resource-file-md5",
                    sha1="any-resource-file-sha1",
                    sha256="any-resource-file-sha256",
                    sha512="any-resource-file-sha512"
                )
            ]
        )

        result = apk.as_dict()

        self.assertEqual(
            {
                "file": "any-apk-file-name",
                "size": 10,
                "md5": "any-apk-file-md5",
                "sha1": "any-apk-file-sha1",
                "sha256": "any-apk-file-sha256",
                "sha512": "any-apk-file-sha512",
                "name": "any-app-name",
                "cert": {
                    "file": "any-cert-file-name",
                    "size": 20,
                    "md5": "any-cert-file-md5",
                    "sha1": "any-cert-file-sha1",
                    "sha256": "any-cert-file-sha256",
                    "sha512": "any-cert-file-sha512",
                    "serial_number": "any-cert-serial-number",
                    "validity": {
                        "from": "any-cert-validity-from",
                        "until": "any-cert-validity-to"
                    },
                    "fingerprint": {
                        "md5": "any-cert-fingerprint-md5",
                        "sha1": "any-cert-fingerprint-sha1",
                        "sha256": "any-cert-fingerprint-sha256",
                        "signature": "any-cert-fingerprint-signature",
                        "version": "any-cert-fingerprint-version"
                    },
                    "owner": {
                        "name": "any-cert-owner-name",
                        "email": "any-cert-owner-email",
                        "unit": "any-cert-owner-unit",
                        "organization": "any-cert-owner-organization",
                        "city": "any-cert-owner-city",
                        "state": "any-cert-owner-state",
                        "country": "any-cert-owner-country",
                        "domain": "any-cert-owner-domain"
                    },
                    "issuer": {
                        "name": "any-cert-issuer-name",
                        "email": "any-cert-issuer-email",
                        "unit": "any-cert-issuer-unit",
                        "organization": "any-cert-issuer-organization",
                        "city": "any-cert-issuer-city",
                        "state": "any-cert-issuer-state",
                        "country": "any-cert-issuer-country",
                        "domain": "any-cert-issuer-domain"
                    }
                },
                "manifest": {
                    "file": "any-manifest-file-name",
                    "size": 30,
                    "md5": "any-manifest-file-md5",
                    "sha1": "any-manifest-file-sha1",
                    "sha256": "any-manifest-file-sha256",
                    "sha512": "any-manifest-file-sha512",
                    "package": "any-package-name",
                    "version": {
                        "code": 1,
                        "name": "any-version-name"
                    },
                    "sdk": {
                        "min": "10",
                        "target": "15",
                        "max": "20"
                    },
                    "permissions": []
                },
                "dex": [
                    {
                        "file": "any-dex-file-name",
                        "size": 40,
                        "md5": "any-dex-file-md5",
                        "sha1": "any-dex-file-sha1",
                        "sha256": "any-dex-file-sha256",
                        "sha512": "any-dex-file-sha512",
                        "strings": [],
                        "urls": [],
                        "shell_commands": []
                    }
                ],
                "other": [
                    {
                        "file": "any-resource-file-name",
                        "size": 50,
                        "md5": "any-resource-file-md5",
                        "sha1": "any-resource-file-sha1",
                        "sha256": "any-resource-file-sha256",
                        "sha512": "any-resource-file-sha512",
                    }
                ]
            },
            result
        )
Пример #4
0
    def test_cert_as_dict(self):
        cert = Cert(
            filename="any-file-name",
            size=10,
            md5hash="any-file-md5",
            sha1hash="any-file-sha1",
            sha256hash="any-file-sha256",
            sha512hash="any-file-sha512",
            serial_number="any-serial-number",
            validity=CertValidity(
                valid_from="any-validity-from",
                valid_to="any-validity-to"
            ),
            fingerprint=CertFingerprint(
                md5="any-fingerprint-md5",
                sha1="any-fingerprint-sha1",
                sha256="any-fingerprint-sha256",
                signature="any-fingerprint-signature",
                version="any-fingerprint-version"
            ),
            owner=CertParticipant(
                name="any-owner-name",
                email="any-owner-email",
                unit="any-owner-unit",
                organization="any-owner-organization",
                city="any-owner-city",
                state="any-owner-state",
                country="any-owner-country",
                domain="any-owner-domain"
            ),
            issuer=CertParticipant(
                name="any-issuer-name",
                email="any-issuer-email",
                unit="any-issuer-unit",
                organization="any-issuer-organization",
                city="any-issuer-city",
                state="any-issuer-state",
                country="any-issuer-country",
                domain="any-issuer-domain"
            )
        )

        result = cert.as_dict()

        self.assertEqual(
            {
                "file": "any-file-name",
                "size": 10,
                "md5": "any-file-md5",
                "sha1": "any-file-sha1",
                "sha256": "any-file-sha256",
                "sha512": "any-file-sha512",
                "serial_number": "any-serial-number",
                "validity": {
                    "from": "any-validity-from",
                    "until": "any-validity-to"
                },
                "fingerprint": {
                    "md5": "any-fingerprint-md5",
                    "sha1": "any-fingerprint-sha1",
                    "sha256": "any-fingerprint-sha256",
                    "signature": "any-fingerprint-signature",
                    "version": "any-fingerprint-version"
                },
                "owner": {
                    "name": "any-owner-name",
                    "email": "any-owner-email",
                    "unit": "any-owner-unit",
                    "organization": "any-owner-organization",
                    "city": "any-owner-city",
                    "state": "any-owner-state",
                    "country": "any-owner-country",
                    "domain": "any-owner-domain"
                },
                "issuer": {
                    "name": "any-issuer-name",
                    "email": "any-issuer-email",
                    "unit": "any-issuer-unit",
                    "organization": "any-issuer-organization",
                    "city": "any-issuer-city",
                    "state": "any-issuer-state",
                    "country": "any-issuer-country",
                    "domain": "any-issuer-domain"
                }
            },
            result
        )