Yann Leboulanger pushed to branch gajim_0.16 at gajim / gajim
Commits:
-
3dd35f5e
by Yann Leboulanger at 2017-11-28T10:47:56+01:00
2 changed files:
Changes:
| ... | ... | @@ -76,50 +76,8 @@ def base28(n): |
| 76 | 76 |
else:
|
| 77 | 77 |
return base28_chr[n]
|
| 78 | 78 |
|
| 79 |
-def add_entropy_sources_OpenSSL():
|
|
| 80 |
- # Other possibly variable data. This are very low quality sources of
|
|
| 81 |
- # entropy, but some of them are installation dependent and can be hard
|
|
| 82 |
- # to guess for the attacker.
|
|
| 83 |
- # Data available on all platforms Unix, Windows
|
|
| 84 |
- sources = [sys.argv, sys.builtin_module_names,
|
|
| 85 |
- sys.copyright, sys.getfilesystemencoding(), sys.hexversion,
|
|
| 86 |
- sys.modules, sys.path, sys.version, sys.api_version,
|
|
| 87 |
- os.environ, os.getcwd(), os.getpid()]
|
|
| 88 |
- |
|
| 89 |
- for s in sources:
|
|
| 90 |
- OpenSSL.rand.add(str(s), 1)
|
|
| 91 |
- |
|
| 92 |
- # The /proc filesystem on POSIX systems contains many random variables:
|
|
| 93 |
- # memory statistics, interrupt counts, network packet counts
|
|
| 94 |
- if os.name == 'posix':
|
|
| 95 |
- dirs = ['/proc', '/proc/net', '/proc/self']
|
|
| 96 |
- for d in dirs:
|
|
| 97 |
- if os.access(d, os.R_OK):
|
|
| 98 |
- for filename in os.listdir(d):
|
|
| 99 |
- OpenSSL.rand.add(filename, 0)
|
|
| 100 |
- try:
|
|
| 101 |
- with open(d + os.sep + filename, "r") as fp:
|
|
| 102 |
- # Limit the ammount of read bytes, in case a memory
|
|
| 103 |
- # file was opened
|
|
| 104 |
- OpenSSL.rand.add(str(fp.read(5000)), 1)
|
|
| 105 |
- except IOError:
|
|
| 106 |
- # Ignore all read and access errors
|
|
| 107 |
- pass
|
|
| 108 |
- |
|
| 109 |
-PYOPENSSL_PRNG_PRESENT = False
|
|
| 110 |
-try:
|
|
| 111 |
- import OpenSSL.rand
|
|
| 112 |
- PYOPENSSL_PRNG_PRESENT = True
|
|
| 113 |
-except ImportError:
|
|
| 114 |
- # PyOpenSSL PRNG not available
|
|
| 115 |
- pass
|
|
| 116 |
- |
|
| 117 | 79 |
def random_bytes(bytes_):
|
| 118 |
- if PYOPENSSL_PRNG_PRESENT:
|
|
| 119 |
- OpenSSL.rand.add(os.urandom(bytes_), bytes_)
|
|
| 120 |
- return OpenSSL.rand.bytes(bytes_)
|
|
| 121 |
- else:
|
|
| 122 |
- return os.urandom(bytes_)
|
|
| 80 |
+ return os.urandom(bytes_)
|
|
| 123 | 81 |
|
| 124 | 82 |
def generate_nonce():
|
| 125 | 83 |
return random_bytes(8)
|
| ... | ... | @@ -296,20 +296,6 @@ gajimpaths = configpaths.gajimpaths |
| 296 | 296 |
pid_filename = gajimpaths['PID_FILE']
|
| 297 | 297 |
config_filename = gajimpaths['CONFIG_FILE']
|
| 298 | 298 |
|
| 299 |
-# Seed the OpenSSL pseudo random number generator from file and initialize
|
|
| 300 |
-RNG_SEED = gajimpaths['RNG_SEED']
|
|
| 301 |
-PYOPENSSL_PRNG_PRESENT = False
|
|
| 302 |
-try:
|
|
| 303 |
- import OpenSSL.rand
|
|
| 304 |
- from common import crypto
|
|
| 305 |
- PYOPENSSL_PRNG_PRESENT = True
|
|
| 306 |
- # Seed from file
|
|
| 307 |
- OpenSSL.rand.load_file(str(RNG_SEED))
|
|
| 308 |
- crypto.add_entropy_sources_OpenSSL()
|
|
| 309 |
- OpenSSL.rand.write_file(str(RNG_SEED))
|
|
| 310 |
-except ImportError:
|
|
| 311 |
- log.info("PyOpenSSL PRNG not available")
|
|
| 312 |
- |
|
| 313 | 299 |
import traceback
|
| 314 | 300 |
import errno
|
| 315 | 301 |
import dialogs
|
| ... | ... | @@ -456,9 +442,6 @@ except IOError, e2: |
| 456 | 442 |
del pid_dir
|
| 457 | 443 |
|
| 458 | 444 |
def on_exit():
|
| 459 |
- # Save the entropy from OpenSSL PRNG
|
|
| 460 |
- if PYOPENSSL_PRNG_PRESENT:
|
|
| 461 |
- OpenSSL.rand.write_file(str(RNG_SEED))
|
|
| 462 | 445 |
# delete pid file on normal exit
|
| 463 | 446 |
if os.path.exists(pid_filename):
|
| 464 | 447 |
os.remove(pid_filename)
|