Skip to content

encrypt_cisco_type7 drops the salt argument when salt value is 0 #741

@mathieu-mp

Description

@mathieu-mp

Environment

  • Python version: 3.9.22
  • netutils version: 1.15.1

Expected Behavior

encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) shall make use of the salt when their value is 0.

Observed Behavior

encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) drops the salt when their value is 0, and randomizes a new salt between 0 and 15.

Steps to Reproduce

>>> encrypt_cisco_type7("cisco", 0)
'121A0C041104'
>>> encrypt_cisco_type7("cisco", 0)
'13061E010803'
>>> encrypt_cisco_type7("cisco", 0)
'05080F1C2243'
>>> encrypt_cisco_type7("cisco", 0)
'1511021F0725'
>>> encrypt_cisco_type7("cisco", 0)
'00071A150754'

There is a 1 on 16 chance that the salt ends up being 0.

Root cause

In netutils.password.encrypt_cisco_type7(...), the code tests for a falsy salt value and not strictly for a None value.

    if not salt:
        salt = random.randint(0, 15)  # noqa: S311

Should be:

    if salt is None:
        salt = random.randint(0, 15)  # noqa: S311

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions