ssm/crypto.py

Summary

Maintainability
A
2 hrs
Test Coverage

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(['openssl', 'smime', '-decrypt',
                '-recip', certpath, '-inkey', keypath],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE,
               universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE,
               universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Consider possible security implications associated with Popen module.
Open

from subprocess import Popen, PIPE


# logging configuration
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

        p1 = Popen(['openssl', 'smime', '-sign', '-inkey',
                    keypath, '-signer', certpath, '-text'],
                   stdin=PIPE, stdout=PIPE, stderr=PIPE,
                   universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

        p1 = Popen(['openssl', 'smime', '-sign', '-inkey',
                    keypath, '-signer', certpath, '-text'],
                   stdin=PIPE, stdout=PIPE, stderr=PIPE,
                   universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(['openssl', 'smime', '-pk7out'], stdin=PIPE, stdout=PIPE,
               stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(['openssl', 'smime', '-encrypt', cipher, certpath],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

    p1 = Popen(['openssl', 'smime', '-pk7out'], stdin=PIPE, stdout=PIPE,
               stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p2 = Popen(['openssl', 'pkcs7', '-print_certs'], stdin=PIPE, stdout=PIPE,
               stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

    p1 = Popen(['openssl', 'smime', '-decrypt',
                '-recip', certpath, '-inkey', keypath],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

    p1 = Popen(['openssl', 'smime', '-verify', '-CApath', capath, '-noverify'],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

subprocess call - check for execution of untrusted input.
Open

    p1 = Popen(['openssl', 'smime', '-verify', '-CApath', capath, '-noverify'],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

    p1 = Popen(['openssl', 'smime', '-encrypt', cipher, certpath],
               stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Starting a process with a partial executable path
Open

    p2 = Popen(['openssl', 'pkcs7', '-print_certs'], stdin=PIPE, stdout=PIPE,
               stderr=PIPE, universal_newlines=True)
Severity: Info
Found in ssm/crypto.py by bandit

Cyclomatic complexity is too high in function verify. (9)
Open

def verify(signed_text, capath, check_crl):
    """Verify the signed message has been signed by the certificate.

    Verify the signed message has been signed by the certificate (attached to
    the supplied SMIME message) it claims to have, by one of the accepted CAs
Severity: Minor
Found in ssm/crypto.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function verify_cert. (7)
Open

def verify_cert(certstring, capath, check_crls=True):
    """Verify that the certificate is signed by a CA with a cert in capath.

    Note that I've had to compare strings in the output of openssl to check
    for verification, which may make this brittle.
Severity: Minor
Found in ssm/crypto.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

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

def verify(signed_text, capath, check_crl):
    """Verify the signed message has been signed by the certificate.

    Verify the signed message has been signed by the certificate (attached to
    the supplied SMIME message) it claims to have, by one of the accepted CAs
Severity: Minor
Found in ssm/crypto.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_cert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def verify_cert(certstring, capath, check_crls=True):
    """Verify that the certificate is signed by a CA with a cert in capath.

    Note that I've had to compare strings in the output of openssl to check
    for verification, which may make this brittle.
Severity: Minor
Found in ssm/crypto.py - About 35 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 certificate_public_key.strip() == private_public_key.strip()
Severity: Major
Found in ssm/crypto.py - About 30 mins to fix

    Expected 2 blank lines, found 1
    Open

    def _get_subject_components(subject_x509name):
    Severity: Minor
    Found in ssm/crypto.py by pep8

    Separate top-level function and class definitions with two blank lines.

    Method definitions inside a class are separated by a single blank
    line.
    
    Extra blank lines may be used (sparingly) to separate groups of
    related functions.  Blank lines may be omitted between a bunch of
    related one-liners (e.g. a set of dummy implementations).
    
    Use blank lines in functions, sparingly, to indicate logical
    sections.
    
    Okay: def a():\n    pass\n\n\ndef b():\n    pass
    Okay: def a():\n    pass\n\n\nasync def b():\n    pass
    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
    Okay: default = 1\nfoo = 1
    Okay: classify = 1\nfoo = 1
    
    E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef b(n):\n    pass
    E302: def a():\n    pass\n\nasync def b(n):\n    pass
    E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
    E303: def a():\n\n\n\n    pass
    E304: @decorator\n\ndef a():\n    pass
    E305: def a():\n    pass\na()
    E306: def a():\n    def b():\n        pass\n    def c():\n        pass

    Expected 2 blank lines, found 1
    Open

    def get_certificate_subject(certstring):
    Severity: Minor
    Found in ssm/crypto.py by pep8

    Separate top-level function and class definitions with two blank lines.

    Method definitions inside a class are separated by a single blank
    line.
    
    Extra blank lines may be used (sparingly) to separate groups of
    related functions.  Blank lines may be omitted between a bunch of
    related one-liners (e.g. a set of dummy implementations).
    
    Use blank lines in functions, sparingly, to indicate logical
    sections.
    
    Okay: def a():\n    pass\n\n\ndef b():\n    pass
    Okay: def a():\n    pass\n\n\nasync def b():\n    pass
    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
    Okay: default = 1\nfoo = 1
    Okay: classify = 1\nfoo = 1
    
    E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef b(n):\n    pass
    E302: def a():\n    pass\n\nasync def b(n):\n    pass
    E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
    E303: def a():\n\n\n\n    pass
    E304: @decorator\n\ndef a():\n    pass
    E305: def a():\n    pass\na()
    E306: def a():\n    def b():\n        pass\n    def c():\n        pass

    Line too long (88 > 79 characters)
    Open

            raise CryptoException('Message signing failed. Check cert and key permissions.')
    Severity: Minor
    Found in ssm/crypto.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Expected 2 blank lines, found 1
    Open

    def sign(text, certpath, keypath):
    Severity: Minor
    Found in ssm/crypto.py by pep8

    Separate top-level function and class definitions with two blank lines.

    Method definitions inside a class are separated by a single blank
    line.
    
    Extra blank lines may be used (sparingly) to separate groups of
    related functions.  Blank lines may be omitted between a bunch of
    related one-liners (e.g. a set of dummy implementations).
    
    Use blank lines in functions, sparingly, to indicate logical
    sections.
    
    Okay: def a():\n    pass\n\n\ndef b():\n    pass
    Okay: def a():\n    pass\n\n\nasync def b():\n    pass
    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
    Okay: default = 1\nfoo = 1
    Okay: classify = 1\nfoo = 1
    
    E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef b(n):\n    pass
    E302: def a():\n    pass\n\nasync def b(n):\n    pass
    E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
    E303: def a():\n\n\n\n    pass
    E304: @decorator\n\ndef a():\n    pass
    E305: def a():\n    pass\na()
    E306: def a():\n    def b():\n        pass\n    def c():\n        pass

    There are no issues that match your filters.

    Category
    Status