I've embedded my embedded python application into marmalade C++ for cross-platform use (Android, iOS, Windows phone 8, BlackBerry 10). I'm having trouble connecting to websites over HTTPS (HTTP sockets work)
A hunch
- I had to write a custom random function since it's supposed to be cross platform, using /dev/random is out of the question ( posix issues too probably )
- With the marmalade api there is a built in cross-platform random function that I've had good results with when using it to generate iv bits for AES encryption.
If anyone could shed some light on how much randomness is required for ssl, in bits or if it actually checks for degree of entropy????
test_ssl.py [Traceback]
test_random (test_ssl.BasicTests) ...
RAND_status is 0 (insufficient randomness)
ok
test_refcycle (test_ssl.BasicTests) ... ERROR
test_sslwrap_simple (test_ssl.BasicTests) ... ok
======================================================================
ERROR: test_refcycle (test_ssl.BasicTests)
----------------------------------------------------------------------
----------------------------------------------------------------------
Ran 8 tests in 2.000s
test.test_support.TestFailed: Traceback (most recent call last):
File "./test_ssl.py", line 149, in test_refcycle
ss = ssl.wrap_socket(s)
File "/pythonHome/Lib/ssl.py", line 344, in wrap_socket
ciphers=ciphers)
File "/pythonHome/Lib/ssl.py", line 108, in __init__
socket.getpeername(self)
File "/pythonHome/Lib/socket.py", line 226, in meth
return getattr(self._sock,name)(*args)
error: [Errno 0] Error
Next I tested the obvious:
test_random.py [Traceback]
test_jumpahead (test_random.MersenneTwister_TestBasicOps) ... FAIL
======================================================================
FAIL: test_jumpahead (test_random.MersenneTwister_TestBasicOps)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./test_random.py", line 58, in test_jumpahead
self.assertRaises(TypeError, self.gen.jumpahead, "ick") # wrong type
AssertionError: TypeError not raised
----------------------------------------------------------------------
Ran 60 tests in 34.000s
FAILED (failures=1)
test.test_support.TestFailed: Traceback (most recent call last):
File "./test_random.py", line 58, in test_jumpahead
self.assertRaises(TypeError, self.gen.jumpahead, "ick") # wrong type
AssertionError: TypeError not raised
From what i've read the 'test_jumpahead' function is used for when you need entropy in parallel processes.. even though I patched the random function, this is the only issue it comes up with.
C++ custom random function
PyObject* s3eRand(PyObject* self, PyObject* pArgs)
{
char* str2;
Py_ssize_t count;
if (!PyArg_ParseTuple(pArgs, "s#", &str2, &count)) return NULL;
IwRandSeed((int32)s3eTimerGetMs());
char str[5];
sprintf(str,"%d",IwRandMinMax(0, 255));
return Py_BuildValue("s",str);
}
static PyMethodDef PYs3eRandomMethods[] = {
{ "s3eUrandom", s3eRand, METH_VARARGS, "randomintiger" },
{ NULL, NULL, 0, NULL }
};
os.py [modification]
import s3ePY
...
...
if not _exists("urandom"):
def urandom(n):
"""urandom(n) -> str
Return a string of n random bytes suitable for cryptographic use.
_urandomfd = open("raw:///dev/urandom", O_RDONLY) doesnt work
"""
#from s3ePY import s3eUrandom
bs=b""
while n - len(bs) >= 1:
bs+=chr(int(s3ePY.s3eUrandom()))
return bs