mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Clarify ciphertext length calculation; remove Python 2 compatibility
This commit is contained in:
parent
66fa79741d
commit
b38eeaebc9
@ -302,8 +302,8 @@ class Secret(ChangeLoggedModel, CustomFieldModel):
|
|||||||
Device; Devices may have multiple Secrets associated with them. A name can optionally be defined along with the
|
Device; Devices may have multiple Secrets associated with them. A name can optionally be defined along with the
|
||||||
ciphertext; this string is stored as plain text in the database.
|
ciphertext; this string is stored as plain text in the database.
|
||||||
|
|
||||||
A Secret can be up to 65,536 bytes (64KB) in length. Each secret string will be padded with random data to a minimum
|
A Secret can be up to 65,535 bytes (64KB - 1B) in length. Each secret string will be padded with random data to
|
||||||
of 64 bytes during encryption in order to protect short strings from ciphertext analysis.
|
a minimum of 64 bytes during encryption in order to protect short strings from ciphertext analysis.
|
||||||
"""
|
"""
|
||||||
device = models.ForeignKey(
|
device = models.ForeignKey(
|
||||||
to='dcim.Device',
|
to='dcim.Device',
|
||||||
@ -320,7 +320,7 @@ class Secret(ChangeLoggedModel, CustomFieldModel):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
ciphertext = models.BinaryField(
|
ciphertext = models.BinaryField(
|
||||||
max_length=65568, # 16B IV + 2B pad length + {62-65550}B padded
|
max_length=65568, # 128-bit IV + 16-bit pad length + 65535B secret + 15B padding
|
||||||
editable=False
|
editable=False
|
||||||
)
|
)
|
||||||
hash = models.CharField(
|
hash = models.CharField(
|
||||||
@ -388,11 +388,7 @@ class Secret(ChangeLoggedModel, CustomFieldModel):
|
|||||||
else:
|
else:
|
||||||
pad_length = 0
|
pad_length = 0
|
||||||
|
|
||||||
# Python 2 compatibility
|
header = bytes([len(s) >> 8]) + bytes([len(s) % 256])
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
header = chr(len(s) >> 8) + chr(len(s) % 256)
|
|
||||||
else:
|
|
||||||
header = bytes([len(s) >> 8]) + bytes([len(s) % 256])
|
|
||||||
|
|
||||||
return header + s + os.urandom(pad_length)
|
return header + s + os.urandom(pad_length)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user