ValiMail/dane-discovery

View on GitHub

Showing 31 of 31 total issues

File dane.py has 466 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""DANE class definition."""
import binascii
import hashlib
import re
import requests
Severity: Minor
Found in dane_discovery/dane.py - About 7 hrs to fix

    Function get_all_certificates has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_all_certificates(self, filters=[]):
            """Return a dictionary of all EE certificates for this identity.
    
            This method uses available methods for validating certificates retrieved
            from TLSA records associated with the identity's DNS name. 
    Severity: Minor
    Found in dane_discovery/identity.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File identity.py has 303 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    """Identity abstraction."""
    import pprint
    
    from cryptography.hazmat.primitives import serialization
    
    
    Severity: Minor
    Found in dane_discovery/identity.py - About 3 hrs to fix

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if strict:
                  try:
                      target["tlsa_parsed"]["dnssec"] = self.dnssec
                      DANE.authenticate_tlsa(self.dnsname, target["tlsa_parsed"], self.resolver_override, self.dns_timeout)
                  except ValueError as err:
      Severity: Major
      Found in dane_discovery/identity.py and 1 other location - About 3 hrs to fix
      dane_discovery/identity.py on lines 217..222

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 63.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if strict:
                  try:
                      target["tlsa_parsed"]["dnssec"] = self.dnssec
                      DANE.authenticate_tlsa(self.dnsname, target["tlsa_parsed"], self.resolver_override, self.dns_timeout)
                  except ValueError as err:
      Severity: Major
      Found in dane_discovery/identity.py and 1 other location - About 3 hrs to fix
      dane_discovery/identity.py on lines 168..173

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 63.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      File pki.py has 295 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """PKI- and Certificate-oriented utilities here."""
      import binascii
      
      from cryptography import x509
      from cryptography.hazmat.primitives import serialization
      Severity: Minor
      Found in dane_discovery/pki.py - About 3 hrs to fix

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        def write_individual_certs(certs, out_path):
            prepped = [(os.path.join(out_path, "{}.crt.pem".format(name)), contents) 
                       for name, contents in certs.items()]
            for item in prepped:
                write_file(*item)
        Severity: Major
        Found in dane_discovery/scripts/dane_discovery_get_certificates.py and 1 other location - About 2 hrs to fix
        dane_discovery/scripts/dane_discovery_get_ca_certificates.py on lines 50..54

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 58.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        def write_individual_certs(certs, out_path):
            prepped = [(os.path.join(out_path, "{}.crt.pem".format(name)), contents) 
                       for name, contents in certs.items()]
            for item in prepped:
                write_file(*item)
        Severity: Major
        Found in dane_discovery/scripts/dane_discovery_get_ca_certificates.py and 1 other location - About 2 hrs to fix
        dane_discovery/scripts/dane_discovery_get_certificates.py on lines 44..48

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 58.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if (tlsa["certificate_usage"] == 1 and "PKIX-EE" in filters):
                        if not self.dnssec:
                            continue
                        retval["{}-{}".format(id_name, cert_hash)] = cert_pem
        Severity: Major
        Found in dane_discovery/identity.py and 1 other location - About 2 hrs to fix
        dane_discovery/identity.py on lines 313..316

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 56.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if (tlsa["certificate_usage"] == 3 and "DANE-EE" in filters):
                        if not self.dnssec:
                            continue
                        retval["{}-{}".format(id_name, cert_hash)] = cert_pem
        Severity: Major
        Found in dane_discovery/identity.py and 1 other location - About 2 hrs to fix
        dane_discovery/identity.py on lines 318..321

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 56.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        def write_cert_bundle(certs, out_path):
            just_certs = [y for _, y in certs.items()]
            contents = b"\n".join(just_certs)
            write_file(out_path, contents)
        Severity: Major
        Found in dane_discovery/scripts/dane_discovery_get_certificates.py and 1 other location - About 1 hr to fix
        dane_discovery/scripts/dane_discovery_get_ca_certificates.py on lines 57..60

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 46.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        def write_cert_bundle(certs, out_path):
            just_certs = [y for _, y in certs.items()]
            contents = b"\n".join(just_certs)
            write_file(out_path, contents)
        dane_discovery/scripts/dane_discovery_get_certificates.py on lines 51..54

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 46.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function get_first_entity_certificate_by_type has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_first_entity_certificate_by_type(self, cert_type, strict=True):
                """Return the first certificate of ``cert_type`` for the identity.
                
                Supported certificate types:
                    PKIX-EE: Corresponds with ``certificate_usage`` ``1``.
        Severity: Minor
        Found in dane_discovery/identity.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function get_first_entity_certificate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_first_entity_certificate(self, strict=True):
                """Return the first entity certificate for the identity.
        
                Keyword args:
                    strict (bool): Raise TLSAError if certificate was not retrieved
        Severity: Minor
        Found in dane_discovery/identity.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function validate_certificate_chain has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_certificate_chain(cls, entity_certificate, ca_certificates):
                """Return True if PKI trust chain is established from entity to CA.
                
                This method attempts cryptographic validation of ``entity_certificate`` 
                against the list of ``ca_certificates``. This method only checks 
        Severity: Minor
        Found in dane_discovery/pki.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function report has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def report(self):
                """Return a report for the identity.
        
                Prints the query context (DNSSEC, etc) as well as information about
                the TLSA records stored at the identity's name.
        Severity: Minor
        Found in dane_discovery/identity.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function authenticate_tlsa has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def authenticate_tlsa(cls, dns_name, record, nsaddr=None, dns_timeout=5):
                """Return None if the identity is authenticated, or raise ValueError.
        
                This method authenticates a TLSA record as follows:
        
        
        Severity: Minor
        Found in dane_discovery/dane.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function verify_certificate_signature has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def verify_certificate_signature(cls, certificate, ca_certificate):
                """Return True if certificate was signed by ca_certificate.
        
                Args:
                    entity_certificate (str): entity certificate in DER or PEM format.
        Severity: Minor
        Found in dane_discovery/pki.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function get_ca_certificates_for_identity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_ca_certificates_for_identity(cls, identity_name, certificate, max_levels=100, nsaddr=None, dns_timeout=5):
                """Return the CA certificates for verifying identity_name.
                
                Returns the PEM representation of the CA certificates
                used for verifying any DANE PKIX-CD certificate 
        Severity: Minor
        Found in dane_discovery/dane.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                try:
                    # First, we try to parse as x509
                    der = cls.certificate_association_to_der(certificate)
                    cls.build_x509_object(der)
                    return
        Severity: Minor
        Found in dane_discovery/pki.py and 1 other location - About 50 mins to fix
        dane_discovery/pki.py on lines 249..254

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 36.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Severity
        Category
        Status
        Source
        Language