This PR adds the ability to salt decrypt encrypted attributes. Therefore the pyrad.packet.Packet class got a new function following the example of pyrad.packet.Packet.SaltCrypt. In addition to that the internal _DecodeValue function got changed and now directly decrypts the attribute whenever a user tries to access an attribute value and the attribute has encrypt=2.
Motivation and Context
I just stumbled over an issue working with encrypted integer attributes which is basically reproducible by following code snippet.
Traceback (most recent call last):
File "[...]/demo.py", line 9, in <module>
print(pkg['Encrypted-Attribute'])
File "[...]/lib/python3.9/site-packages/pyrad/packet.py", line 343, in __getitem__
res.append(self._DecodeValue(attr, v))
File "[...]/lib/python3.9/site-packages/pyrad/packet.py", line 247, in _DecodeValue
return tools.DecodeAttr(attr.type, value)
File "[...]/lib/python3.9/site-packages/pyrad/tools.py", line 216, in DecodeAttr
return DecodeInteger(value)
File "[...]/lib/python3.9/site-packages/pyrad/tools.py", line 172, in DecodeInteger
return (struct.unpack(format, num))[0]
struct.error: unpack requires a buffer of 4 bytes
How has this been tested?
A added a new unit tests for testing encrypted attributes:
[x] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
(What changes is that values now get decrypted automatically, no API change but a behaviour change)
Checklist:
[x] My code follows the code style of this project.
[x] My change requires a change to the documentation.
Description
This PR adds the ability to salt decrypt encrypted attributes. Therefore the
pyrad.packet.Packet
class got a new function following the example ofpyrad.packet.Packet.SaltCrypt
. In addition to that the internal_DecodeValue
function got changed and now directly decrypts the attribute whenever a user tries to access an attribute value and the attribute hasencrypt=2
.Motivation and Context
I just stumbled over an issue working with encrypted integer attributes which is basically reproducible by following code snippet.
Output:
How has this been tested?
A added a new unit tests for testing encrypted attributes:
Types of changes
Checklist: