ValiMail/dane-discovery

View on GitHub
dane_discovery/pki.py

Summary

Maintainability
C
1 day
Test Coverage
A
96%

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

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

    Avoid too many return statements within this function.
    Open

            return (False, msg)
    Severity: Major
    Found in dane_discovery/pki.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return {x509_ext.oid._name: x509_ext.value}
      Severity: Major
      Found in dane_discovery/pki.py - About 30 mins to fix

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

            def clean_up_certificate(cls, certificate):
                """This method returns a clean PEM-encoded certificate.
                
                This is useful for removing the human-readable certificate
                metadata that sometimes ends up in certificates produced 
        Severity: Minor
        Found in dane_discovery/pki.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

        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

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

                try:
                    # Next, we try as raw public key
                    der = cls.certificate_association_to_der(certificate)
                    cls.build_public_key_object_from_der(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 242..247

        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

        There are no issues that match your filters.

        Category
        Status