Commit 383e4c82 authored by Szilárd Pfeiffer's avatar Szilárd Pfeiffer
Browse files

Merge branch 'code-coverage'

parents 3c941533 0d452ddc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,6 +5,6 @@ source = cryptolyzer
exclude_lines =
    pragma: no cover
    raise NotImplementedError
fail_under = 92
fail_under = 100
include = cryptolyzer/*
show_missing = True
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ class ProtocolHandlerBase(object):
        plugin_root_dir_parts = __file__.split(os.path.sep)[:-2]  # remove common/analyzer.py
        plugin_module_dir_parts = set()
        for path in glob.iglob(os.path.sep.join(plugin_root_dir_parts + ['*', 'analyzer.py'])):
            if plugin_root_dir_parts[-3:] == ['cryptolyzer', 'common', 'analyzer.py']:
            if path == __file__:
                continue

            plugin_path_parts = path.split(os.path.sep)[-3:-1]  # split plugin dirs
+16 −11
Original line number Diff line number Diff line
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from cryptography.hazmat.backends import default_backend as cryptography_default_backend  # pylint: disable=import-error
import cryptography.exceptions  # pylint: disable=import-error
import cryptography.hazmat.primitives.asymmetric.ec as cryptography_ec  # pylint: disable=import-error
import cryptography.hazmat.primitives.asymmetric.dh as cryptography_dh  # pylint: disable=import-error
import cryptography.hazmat.primitives.asymmetric.x25519 as cryptography_x25519  # pylint: disable=import-error
from cryptography.hazmat.backends import default_backend as cryptography_default_backend
import cryptography.exceptions
import cryptography.hazmat.primitives.asymmetric.ec as cryptography_ec
import cryptography.hazmat.primitives.asymmetric.dh as cryptography_dh
import cryptography.hazmat.primitives.asymmetric.x25519 as cryptography_x25519

from cryptoparser.common.base import Vector, VectorParamNumeric, Serializable
from cryptoparser.common.parse import ParserBinary
from cryptoparser.tls.extension import TlsNamedCurve, TlsNamedCurveFactory
from cryptoparser.tls.subprotocol import TlsECCurveType

from cryptolyzer.common.exception import ResponseError, ResponseErrorType


class TlsDHParamVector(Vector):  # pylint: disable=too-many-ancestors
    @classmethod
@@ -53,18 +55,21 @@ def parse_ecdh_params(param_bytes):
    if named_curve == TlsNamedCurve.X25519:
        try:
            public_key = cryptography_x25519.X25519PublicKey.from_public_bytes(bytes(parser['point']))
        except cryptography.exceptions.UnsupportedAlgorithm:
        except cryptography.exceptions.UnsupportedAlgorithm:  # pragma: no cover
            raise NotImplementedError(named_curve)
    else:
        try:
            cryptography_curve = getattr(cryptography_ec, named_curve.name)()
        except AttributeError:
        except AttributeError:  # pragma: no cover
            raise NotImplementedError(named_curve)

        try:
            public_key = cryptography_ec.EllipticCurvePublicKey.from_encoded_point(
                cryptography_curve,
                bytes(parser['point'])
            )
        except ValueError:
            raise ResponseError(ResponseErrorType.UNPARSABLE_RESPONSE)

    return parser['named_curve'], public_key

+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ class NetworkError(IOError):
class ResponseErrorType(enum.IntEnum):
    PLAIN_TEXT_RESPONSE = 1
    UNPARSABLE_RESPONSE = 2
    UNSUPPORTED_SECURITY = 3


class ResponseError(ValueError):
+3 −3
Original line number Diff line number Diff line
@@ -221,11 +221,11 @@ class PublicKeyX509(PublicKey):

    @property
    def subject(self):
        return [attribute for attribute in self._certificate.subject]
        return list(self._certificate.subject)

    @property
    def issuer(self):
        return [attribute for attribute in self._certificate.issuer]
        return list(self._certificate.issuer)

    @property
    def common_names(self):
@@ -264,7 +264,7 @@ class PublicKeyX509(PublicKey):
                        cryptography_x509.oid.NameOID.COMMON_NAME
                    )
                    for relative_name in attributes:
                        crl_distribution_points.append(relative_name)
                        crl_distribution_points.append(relative_name.value)

            return crl_distribution_points

Loading