Skip to content

Commit

Permalink
Use a better random generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Jan 15, 2013
1 parent ddfedb2 commit 38f74b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

2.1 - Unreleased
------------------

* Use a different random generator to improve the security of generated
packet ids and authenticators.


2.0 - May 15, 2011
------------------

Expand Down
9 changes: 6 additions & 3 deletions pyrad/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
CoAACK = 44
CoANAK = 45

# Use cryptographic-safe random generator as provided by the OS.
random_generator = random.SystemRandom()

# Current ID
CurrentID = random.randrange(1, 255)
CurrentID = random_generator.randrange(1, 255)


class PacketError(Exception):
Expand Down Expand Up @@ -208,7 +211,7 @@ def CreateAuthenticator():

data = []
for i in range(16):
data.append(random.randrange(0, 256))
data.append(random_generator.randrange(0, 256))
if six.PY3:
return bytes(data)
else:
Expand All @@ -223,7 +226,7 @@ def CreateID(self):
:rtype: integer
"""
return random.randrange(0, 256)
return random_generator.randrange(0, 256)

def ReplyPacket(self):
"""Create a ready-to-transmit authentication reply packet.
Expand Down

0 comments on commit 38f74b3

Please sign in to comment.