Skip to content

Commit bf00c88

Browse files
author
Brett Hazen
committed
Relax OpenSSL version to look at build date as well
1 parent 0e5f0e5 commit bf00c88

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

riak/security.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,52 @@
2020
import httplib
2121
import socket
2222
import select
23+
import string
24+
import datetime
2325
from riak import RiakError
2426
try:
2527
from cStringIO import StringIO
2628
except ImportError:
2729
from StringIO import StringIO
2830

2931
OPENSSL_VERSION_101G = 268439679
32+
OPENSSL_VERSION_101 = 1000*1000*1 + 1000*0 + 1
33+
OPENSSL_VERSION_NUM_POS = 1
34+
OPENSSL_VERSION_DAY_POS = 4
35+
OPENSSL_VERSION_MON_POS = 3
36+
OPENSSL_VERSION_YEAR_POS = 7
37+
ssldate = datetime.date(2014, 4, 1)
3038
sslver = OpenSSL.SSL.OPENSSL_VERSION_NUMBER
3139
# Be sure to use at least OpenSSL 1.0.1g
3240
if (sslver < OPENSSL_VERSION_101G):
41+
too_old = False
42+
# Check the build date on older versions
3343
verstring = OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION)
34-
raise RuntimeError("Found {0} version, but expected at least "
35-
"OpenSSL 1.0.1g".format(verstring))
44+
versions = string.split(verstring)
45+
# Convert version string to integer
46+
verdots = string.split(versions[OPENSSL_VERSION_NUM_POS], '.')
47+
if len(verdots) == 3:
48+
verint = 1000 * 1000 * verdots[0] + 1000 * verdots[1] + \
49+
verdots[2].translate(None, "abcdefghijklmnopqrstuvwxyz")
50+
# Is this at least 1.0.1 built after April 2014 (hopefully patched)
51+
if verint < OPENSSL_VERSION_101:
52+
too_old = True
53+
else:
54+
builtstr = OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_BUILT_ON)
55+
timestamp = string.split(builtstr)
56+
import calendar
57+
calmap = {v: k for k,v in enumerate(calendar.month_abbr)}
58+
day = int(timestamp[OPENSSL_VERSION_DAY_POS])
59+
mon = calmap[timestamp[OPENSSL_VERSION_MON_POS]]
60+
year = int(timestamp[OPENSSL_VERSION_YEAR_POS])
61+
build = datetime.date(year, mon, day)
62+
if build < ssldate:
63+
too_old = True
64+
else:
65+
too_old = True
66+
if too_old:
67+
raise RuntimeError("Found {0} version, but expected at least "
68+
"OpenSSL 1.0.1g".format(verstring))
3669

3770

3871
class SecurityError(RiakError):

0 commit comments

Comments
 (0)