ValiMail/dane-discovery

View on GitHub
dane_discovery/identity.py

Summary

Maintainability
F
3 days
Test Coverage
B
86%

File identity.py has 338 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 4 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

    Function validate_certificate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_certificate(self, certificate):
            """Return True, None if the certificate is valid for the identity.
            
            This method returns two values, success and status.
    
    
    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_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 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

    Avoid too many return statements within this function.
    Open

            return True, "Format and authority CA signature verified."
    Severity: Major
    Found in dane_discovery/identity.py - About 30 mins to fix

      Function validate_pkix_cd has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_pkix_cd(self, cert_obj, credential):
              """Validate a certificate with certificate_usage 4.
              
              PKIX-CD expects selector 0 and matching type 0. This
              method will not validate configuration which differs 
      Severity: Minor
      Found in dane_discovery/identity.py - About 25 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

      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 258..263

      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 209..214

      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

      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 354..357

      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 359..362

      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 cert_usage == "DANE-EE":
                      valid, reason = self.validate_dane_ee(cert_obj, credential)
                      if valid:
                          return True, reason
                      else:
      Severity: Major
      Found in dane_discovery/identity.py and 1 other location - About 1 hr to fix
      dane_discovery/identity.py on lines 58..63

      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 45.

      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 cert_usage == "PKIX-CD":
                      valid, reason = self.validate_pkix_cd(cert_obj, credential)
                      if valid:
                          return True, reason
                      else:
      Severity: Major
      Found in dane_discovery/identity.py and 1 other location - About 1 hr to fix
      dane_discovery/identity.py on lines 64..69

      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 45.

      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

      There are no issues that match your filters.

      Category
      Status