From f5f203d5eaffa7496bcf8684050d9e83970a1bb1 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sun, 23 Mar 2008 23:51:39 -0700 Subject: [PATCH] [project @ robey@lag.net-20080324065139-nmvo5goh1izbd3gr] not all windows boxes have winrandom --- paramiko/osrandom.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/paramiko/osrandom.py b/paramiko/osrandom.py index 447d090..6c559e0 100644 --- a/paramiko/osrandom.py +++ b/paramiko/osrandom.py @@ -37,6 +37,13 @@ try: except ImportError: winrandom = None +# Lastly, try to get the plain "RandomPool" +# (sometimes windows doesn't even have winrandom!) +try: + from Crypto.Util.randpool import RandomPool +except ImportError: + RandomPool = None + ## ## Define RandomPool classes @@ -88,6 +95,15 @@ class DevUrandomPool(BaseOSRandomPool): return bytes +class FallbackRandomPool (BaseOSRandomPool): + def __init__(self): + self._wr = RandomPool() + self.randomize() + + def get_bytes(self, n): + return self._wr.get_bytes(n) + + ## ## Detect default random number source ## @@ -103,6 +119,11 @@ if osrandom_source is None and winrandom is not None: osrandom_source = "winrandom" DefaultRandomPoolClass = WinRandomPool +# Try final fallback +if osrandom_source is None and RandomPool is not None: + osrandom_source = "randompool" + DefaultRandomPoolClass = FallbackRandomPool + # Give up if osrandom_source is None: raise ImportError("Cannot find OS entropy source")