Skip to content

Commit 92c041c

Browse files
Move password helper names to be namespaced with vendor information. Assign new name to old name to not break semver. (networktocode#286)
1 parent 8a878c8 commit 92c041c

File tree

6 files changed

+109
-91
lines changed

6 files changed

+109
-91
lines changed

docs/dev/attribution.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ Influencers
1313

1414
In many instances variables and function names were reused, but the code was built from scratch to avoid any potential licensing issues. Functions that were known to be rewritten and their known origin.
1515

16-
| Function | Origin |
17-
| ---------------- | ------- |
18-
| asn_to_int | NAPALM |
19-
| is_ip | IPCal |
20-
| ip_to_bin | IPCal |
21-
| get_usable_range | IPCal |
22-
| encrypt_type7 | unknown |
23-
| decrypt_type7 | unknown |
24-
| vlan_to_list | Ansible |
25-
| sanitize_config | NAPALM |
16+
| Function | Origin |
17+
| ------------------- | ------- |
18+
| asn_to_int | NAPALM |
19+
| is_ip | IPCal |
20+
| ip_to_bin | IPCal |
21+
| get_usable_range | IPCal |
22+
| encrypt_cisco_type7 | unknown |
23+
| decrypt_cisco_type7 | unknown |
24+
| vlan_to_list | Ansible |
25+
| sanitize_config | NAPALM |
2626

2727
Relevant PR's
2828

docs/user/include_jinja_list.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@
5252
| mac_to_int | netutils.mac.mac_to_int |
5353
| mac_type | netutils.mac.mac_type |
5454
| get_upgrade_path | netutils.os_version.get_upgrade_path |
55+
| compare_cisco_type5 | netutils.password.compare_cisco_type5 |
56+
| compare_cisco_type7 | netutils.password.compare_cisco_type7 |
57+
| compare_cisco_type9 | netutils.password.compare_cisco_type9 |
5558
| compare_type5 | netutils.password.compare_type5 |
5659
| compare_type7 | netutils.password.compare_type7 |
57-
| compare_type9 | netutils.password.compare_type9 |
58-
| decrypt_juniper | netutils.password.decrypt_juniper |
60+
| decrypt_cisco_type7 | netutils.password.decrypt_cisco_type7 |
61+
| decrypt_juniper_type9 | netutils.password.decrypt_juniper_type9 |
5962
| decrypt_type7 | netutils.password.decrypt_type7 |
60-
| encrypt_juniper | netutils.password.encrypt_juniper |
63+
| encrypt_cisco_type5 | netutils.password.encrypt_cisco_type5 |
64+
| encrypt_cisco_type7 | netutils.password.encrypt_cisco_type7 |
65+
| encrypt_cisco_type9 | netutils.password.encrypt_cisco_type9 |
66+
| encrypt_juniper_type9 | netutils.password.encrypt_juniper_type9 |
6167
| encrypt_type5 | netutils.password.encrypt_type5 |
6268
| encrypt_type7 | netutils.password.encrypt_type7 |
63-
| encrypt_type9 | netutils.password.encrypt_type9 |
6469
| get_hash_salt | netutils.password.get_hash_salt |
6570
| tcp_ping | netutils.ping.tcp_ping |
6671
| longest_prefix_match | netutils.route.longest_prefix_match |

docs/user/lib_use_cases.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ The following function will help in deploying list of VLANs and match the config
5454
You may want to compare a known password with a given encrypted password. This can help in verifying if the passwords are as expected for compliance reasons.
5555

5656
```python
57-
>>> from netutils.password import compare_type5
57+
>>> from netutils.password import compare_cisco_type5
5858
>>>
59-
>>> compare_type5("cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
59+
>>> compare_cisco_type5("cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
6060
True
6161
>>>
62-
>>> compare_type5("not_cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
62+
>>> compare_cisco_type5("not_cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
6363
False
6464
>>>
6565
```

netutils/password.py

+42-34
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def decorated(*args: t.Any, **kwargs: t.Any) -> t.Any:
112112
return decorated
113113

114114

115-
def compare_type5(
115+
def compare_cisco_type5(
116116
unencrypted_password: str, encrypted_password: str, return_original: bool = False
117117
) -> t.Union[str, bool]:
118118
"""Given an encrypted and unencrypted password of Cisco Type 5 password, compare if they are a match.
@@ -126,22 +126,22 @@ def compare_type5(
126126
Whether or not the password is as compared to.
127127
128128
Examples:
129-
>>> from netutils.password import compare_type5
130-
>>> compare_type5("cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
129+
>>> from netutils.password import compare_cisco_type5
130+
>>> compare_cisco_type5("cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
131131
True
132-
>>> compare_type5("not_cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
132+
>>> compare_cisco_type5("not_cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
133133
False
134134
>>>
135135
"""
136136
salt = get_hash_salt(encrypted_password)
137-
if encrypt_type5(unencrypted_password, salt) == encrypted_password:
137+
if encrypt_cisco_type5(unencrypted_password, salt) == encrypted_password:
138138
if return_original is True:
139139
return encrypted_password
140140
return True
141141
return False
142142

143143

144-
def compare_type7(
144+
def compare_cisco_type7(
145145
unencrypted_password: str, encrypted_password: str, return_original: bool = False
146146
) -> t.Union[str, bool]:
147147
"""Given an encrypted and unencrypted password of Cisco Type 7 password, compare if they are a match.
@@ -155,24 +155,24 @@ def compare_type7(
155155
Whether or not the password is as compared to.
156156
157157
Examples:
158-
>>> from netutils.password import compare_type7
159-
>>> compare_type7("cisco","121A0C041104")
158+
>>> from netutils.password import compare_cisco_type7
159+
>>> compare_cisco_type7("cisco","121A0C041104")
160160
True
161-
>>> compare_type7("not_cisco","121A0C041104")
161+
>>> compare_cisco_type7("not_cisco","121A0C041104")
162162
False
163163
>>>
164164
"""
165-
if decrypt_type7(encrypted_password) == unencrypted_password:
165+
if decrypt_cisco_type7(encrypted_password) == unencrypted_password:
166166
if return_original is True:
167167
return encrypted_password
168168
return True
169169
return False
170170

171171

172-
def compare_type9(
172+
def compare_cisco_type9(
173173
unencrypted_password: str, encrypted_password: str, return_original: bool = False
174174
) -> t.Union[str, bool]:
175-
"""Given an encrypted and unencrypted password of Cisco Type 7 password, compare if they are a match.
175+
"""Given an encrypted and unencrypted password of Cisco Type 9 password, compare if they are a match.
176176
177177
Args:
178178
unencrypted_password: A password that has not been encrypted, and will be compared against.
@@ -183,22 +183,22 @@ def compare_type9(
183183
Whether or not the password is as compared to.
184184
185185
Examples:
186-
>>> from netutils.password import compare_type9
187-
>>> compare_type9("cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
186+
>>> from netutils.password import compare_cisco_type9
187+
>>> compare_cisco_type9("cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
188188
True
189-
>>> compare_type9("not_cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
189+
>>> compare_cisco_type9("not_cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
190190
False
191191
>>>
192192
"""
193193
salt = get_hash_salt(encrypted_password)
194-
if encrypt_type9(unencrypted_password, salt) == encrypted_password:
194+
if encrypt_cisco_type9(unencrypted_password, salt) == encrypted_password:
195195
if return_original is True:
196196
return encrypted_password
197197
return True
198198
return False
199199

200200

201-
def decrypt_type7(encrypted_password: str) -> str:
201+
def decrypt_cisco_type7(encrypted_password: str) -> str:
202202
"""Given an unencrypted password of Cisco Type 7 password decrypt it.
203203
204204
Args:
@@ -208,8 +208,8 @@ def decrypt_type7(encrypted_password: str) -> str:
208208
The unencrypted_password password.
209209
210210
Examples:
211-
>>> from netutils.password import decrypt_type7
212-
>>> decrypt_type7("121A0C041104")
211+
>>> from netutils.password import decrypt_cisco_type7
212+
>>> decrypt_cisco_type7("121A0C041104")
213213
'cisco'
214214
>>>
215215
"""
@@ -229,7 +229,7 @@ def decrypt_type7(encrypted_password: str) -> str:
229229

230230

231231
@_fail_on_mac
232-
def encrypt_type5(unencrypted_password: str, salt: t.Optional[str] = None, salt_len: int = 4) -> str:
232+
def encrypt_cisco_type5(unencrypted_password: str, salt: t.Optional[str] = None, salt_len: int = 4) -> str:
233233
"""Given an unencrypted password of Cisco Type 5 password, encrypt it.
234234
235235
Args:
@@ -241,8 +241,8 @@ def encrypt_type5(unencrypted_password: str, salt: t.Optional[str] = None, salt_
241241
The encrypted password.
242242
243243
Examples:
244-
>>> from netutils.password import encrypt_type5
245-
>>> encrypt_type5("cisco") # doctest: +SKIP
244+
>>> from netutils.password import encrypt_cisco_type5
245+
>>> encrypt_cisco_type5("cisco") # doctest: +SKIP
246246
'$1$MHkb$v2MFmDkQX66TTxLkFF50K/'
247247
>>>
248248
"""
@@ -253,7 +253,7 @@ def encrypt_type5(unencrypted_password: str, salt: t.Optional[str] = None, salt_
253253
return crypt.crypt(unencrypted_password, f"$1${salt}$")
254254

255255

256-
def encrypt_type7(unencrypted_password: str, salt: t.Optional[int] = None) -> str:
256+
def encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None) -> str:
257257
"""Given an unencrypted password of Cisco Type 7 password, encypt it.
258258
259259
Args:
@@ -264,8 +264,8 @@ def encrypt_type7(unencrypted_password: str, salt: t.Optional[int] = None) -> st
264264
The encrypted password.
265265
266266
Examples:
267-
>>> from netutils.password import encrypt_type7
268-
>>> encrypt_type7("cisco", 11)
267+
>>> from netutils.password import encrypt_cisco_type7
268+
>>> encrypt_cisco_type7("cisco", 11)
269269
'110A1016141D'
270270
>>>
271271
"""
@@ -290,7 +290,7 @@ def encrypt_type7(unencrypted_password: str, salt: t.Optional[int] = None) -> st
290290
return encrypted_password
291291

292292

293-
def encrypt_type9(unencrypted_password: str, salt: t.Optional[str] = None) -> str:
293+
def encrypt_cisco_type9(unencrypted_password: str, salt: t.Optional[str] = None) -> str:
294294
"""Given an unencrypted password of Cisco Type 9 password, encrypt it.
295295
296296
Note: This uses the built-in Python `scrypt` function to generate the password
@@ -306,8 +306,8 @@ def encrypt_type9(unencrypted_password: str, salt: t.Optional[str] = None) -> st
306306
The encrypted password.
307307
308308
Examples:
309-
>>> from netutils.password import encrypt_type9
310-
>>> encrypt_type9("123456", "cvWdfQlRRDKq/U")
309+
>>> from netutils.password import encrypt_cisco_type9
310+
>>> encrypt_cisco_type9("123456", "cvWdfQlRRDKq/U")
311311
'$9$cvWdfQlRRDKq/U$VFTPha5VHTCbSgSUAo.nPoh50ZiXOw1zmljEjXkaq1g'
312312
313313
Raises:
@@ -364,7 +364,7 @@ def get_hash_salt(encrypted_password: str) -> str:
364364
return split_password[2]
365365

366366

367-
def decrypt_juniper(encrypted_password: str) -> str:
367+
def decrypt_juniper_type9(encrypted_password: str) -> str:
368368
"""Given an encrypted Junos $9$ type password, decrypt it.
369369
370370
Args:
@@ -374,8 +374,8 @@ def decrypt_juniper(encrypted_password: str) -> str:
374374
The unencrypted_password password.
375375
376376
Examples:
377-
>>> from netutils.password import decrypt_juniper
378-
>>> decrypt_juniper("$9$7YdwgGDkTz6oJz69A1INdb")
377+
>>> from netutils.password import decrypt_juniper_type9
378+
>>> decrypt_juniper_type9("$9$7YdwgGDkTz6oJz69A1INdb")
379379
'juniper'
380380
>>>
381381
"""
@@ -409,7 +409,7 @@ def decrypt_juniper(encrypted_password: str) -> str:
409409
return decrypted_password
410410

411411

412-
def encrypt_juniper(unencrypted_password: str, salt: t.Optional[int] = None) -> str:
412+
def encrypt_juniper_type9(unencrypted_password: str, salt: t.Optional[int] = None) -> str:
413413
"""Given an unencrypted password, encrypt to Juniper $9$ type password.
414414
415415
Args:
@@ -420,8 +420,8 @@ def encrypt_juniper(unencrypted_password: str, salt: t.Optional[int] = None) ->
420420
The encrypted password.
421421
422422
Examples:
423-
>>> from netutils.password import encrypt_juniper
424-
>>> encrypt_juniper("juniper", 35) # doctest: +SKIP
423+
>>> from netutils.password import encrypt_juniper_type9
424+
>>> encrypt_juniper_type9("juniper", 35) # doctest: +SKIP
425425
'$9$7YdwgGDkTz6oJz69A1INdb'
426426
>>>
427427
"""
@@ -454,3 +454,11 @@ def encrypt_juniper(unencrypted_password: str, salt: t.Optional[int] = None) ->
454454
encrypted_password += new_character
455455

456456
return encrypted_password
457+
458+
459+
# Provide until transition to 2.0
460+
compare_type5 = compare_cisco_type5
461+
compare_type7 = compare_cisco_type7
462+
decrypt_type7 = decrypt_cisco_type7
463+
encrypt_type5 = encrypt_cisco_type5
464+
encrypt_type7 = encrypt_cisco_type7

netutils/utils.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@
5454
"get_oui": "mac.get_oui",
5555
"compare_type5": "password.compare_type5",
5656
"compare_type7": "password.compare_type7",
57-
"compare_type9": "password.compare_type9",
57+
"compare_cisco_type5": "password.compare_cisco_type5",
58+
"compare_cisco_type7": "password.compare_cisco_type7",
59+
"compare_cisco_type9": "password.compare_cisco_type9",
5860
"decrypt_type7": "password.decrypt_type7",
61+
"decrypt_cisco_type7": "password.decrypt_cisco_type7",
62+
"decrypt_juniper_type9": "password.decrypt_juniper_type9",
5963
"encrypt_type5": "password.encrypt_type5",
6064
"encrypt_type7": "password.encrypt_type7",
61-
"encrypt_type9": "password.encrypt_type9",
65+
"encrypt_cisco_type5": "password.encrypt_cisco_type5",
66+
"encrypt_cisco_type7": "password.encrypt_cisco_type7",
67+
"encrypt_cisco_type9": "password.encrypt_cisco_type9",
68+
"encrypt_juniper_type9": "password.encrypt_juniper_type9",
6269
"get_hash_salt": "password.get_hash_salt",
63-
"encrypt_juniper": "password.encrypt_juniper",
64-
"decrypt_juniper": "password.decrypt_juniper",
6570
"tcp_ping": "ping.tcp_ping",
6671
"longest_prefix_match": "route.longest_prefix_match",
6772
"vlanlist_to_config": "vlan.vlanlist_to_config",

0 commit comments

Comments
 (0)