diff --git a/.cvsignore b/.cvsignore index 911988b..469e518 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1 +1 @@ -m2crypto-0.16.tar.gz +m2crypto-0.17.tar.gz diff --git a/m2crypto-0.17-Py_ssize_t.patch b/m2crypto-0.17-Py_ssize_t.patch new file mode 100644 index 0000000..14540bb --- /dev/null +++ b/m2crypto-0.17-Py_ssize_t.patch @@ -0,0 +1,750 @@ +diff -ur m2crypto/SWIG/_aes.i m2crypto-0.17beta1/SWIG/_aes.i +--- m2crypto/SWIG/_aes.i 2006-03-17 19:55:17.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_aes.i 2006-12-14 03:59:16.000000000 +0100 +@@ -43,7 +43,7 @@ + */ + PyObject *AES_set_key(AES_KEY *key, PyObject *value, int bits, int op) { + const void *vbuf; +- int vlen; ++ Py_ssize_t vlen; + + if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) + return NULL; +@@ -62,7 +62,7 @@ + */ + PyObject *AES_crypt(const AES_KEY *key, PyObject *in, int outlen, int op) { + const void *buf; +- int len; ++ Py_ssize_t len; + unsigned char *out; + + if (PyObject_AsReadBuffer(in, &buf, &len) == -1) +diff -ur m2crypto/SWIG/_asn1.i m2crypto-0.17beta1/SWIG/_asn1.i +--- m2crypto/SWIG/_asn1.i 2006-03-09 02:50:42.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_asn1.i 2006-12-14 04:23:49.000000000 +0100 +@@ -39,12 +39,18 @@ + + %typemap(in) (const void *, int) { + if (PyString_Check($input)) { ++ Py_ssize_t len; ++ + $1 = PyString_AsString($input); +- $2 = PyString_Size($input); ++ len = PyString_Size($input); ++ if (len > INT_MAX) { ++ PyErr_SetString(PyExc_ValueError, "object too large"); ++ return NULL; ++ } ++ $2 = len; + } else { +- $1 = NULL; +- $2 = 0; + PyErr_SetString(PyExc_TypeError, "expected string"); ++ return NULL; + } + } + +diff -ur m2crypto/SWIG/_bio.i m2crypto-0.17beta1/SWIG/_bio.i +--- m2crypto/SWIG/_bio.i 2006-03-08 20:56:46.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_bio.i 2006-12-14 00:53:48.000000000 +0100 +@@ -122,7 +122,7 @@ + const void *fbuf; + int flen, ret; + +- if (PyObject_AsReadBuffer(from, &fbuf, &flen) == -1) ++ if (m2_PyObject_AsReadBufferInt(from, &fbuf, &flen) == -1) + return -1; + + Py_BEGIN_ALLOW_THREADS +@@ -171,7 +171,7 @@ + + PyObject *bio_set_cipher(BIO *b, EVP_CIPHER *c, PyObject *key, PyObject *iv, int op) { + const void *kbuf, *ibuf; +- int klen, ilen; ++ Py_ssize_t klen, ilen; + + if ((PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) + || (PyObject_AsReadBuffer(iv, &ibuf, &ilen) == -1)) +diff -ur m2crypto/SWIG/_dh.i m2crypto-0.17beta1/SWIG/_dh.i +--- m2crypto/SWIG/_dh.i 2006-03-08 20:56:46.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_dh.i 2006-12-14 01:15:44.000000000 +0100 +@@ -85,7 +85,7 @@ + BIGNUM *pk; + PyObject *ret; + +- if (PyObject_AsReadBuffer(pubkey, &pkbuf, &pklen) == -1) ++ if (m2_PyObject_AsReadBufferInt(pubkey, &pkbuf, &pklen) == -1) + return NULL; + + if (!(pk = BN_mpi2bn((unsigned char *)pkbuf, pklen, NULL))) { +@@ -146,7 +146,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -165,7 +165,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +diff -ur m2crypto/SWIG/_dsa.i m2crypto-0.17beta1/SWIG/_dsa.i +--- m2crypto/SWIG/_dsa.i 2006-05-10 23:31:24.000000000 +0200 ++++ m2crypto-0.17beta1/SWIG/_dsa.i 2006-12-14 01:03:37.000000000 +0100 +@@ -102,7 +102,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -121,7 +121,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -140,7 +140,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -215,7 +215,7 @@ + PyObject *tuple; + DSA_SIG *sig; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(sig = DSA_do_sign(vbuf, vlen, dsa))) { +@@ -239,9 +239,9 @@ + DSA_SIG *sig; + int ret; + +- if ((PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +- || (PyObject_AsReadBuffer(r, &rbuf, &rlen) == -1) +- || (PyObject_AsReadBuffer(s, &sbuf, &slen) == -1)) ++ if ((m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(r, &rbuf, &rlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(s, &sbuf, &slen) == -1)) + return -1; + + if (!(sig = DSA_SIG_new())) { +@@ -272,7 +272,7 @@ + int siglen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(sigbuf = PyMem_Malloc(DSA_size(dsa)))) { +@@ -294,8 +294,9 @@ + void *sbuf; + int vlen, slen, ret; + +- if ((PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +- || (PyObject_AsReadBuffer(sig, (const void **)&sbuf, &slen) == -1)) ++ if ((m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(sig, (const void **)&sbuf, &slen) ++ == -1)) + return -1; + + if ((ret = DSA_verify(0, vbuf, vlen, sbuf, slen, dsa)) == -1) +diff -ur m2crypto/SWIG/_ec.i m2crypto-0.17beta1/SWIG/_ec.i +--- m2crypto/SWIG/_ec.i 2006-10-31 19:41:27.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_ec.i 2006-12-14 01:15:25.000000000 +0100 +@@ -159,7 +159,8 @@ + + unsigned char *src=NULL; + void *dst=NULL; +- int src_len=0,dst_len=0; ++ int src_len=0; ++ Py_ssize_t dst_len=0; + PyObject *pyo=NULL; + int ret=0; + +@@ -241,7 +242,7 @@ + PyObject *tuple; + ECDSA_SIG *sig; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(sig = ECDSA_do_sign(vbuf, vlen, key))) { +@@ -265,9 +266,9 @@ + ECDSA_SIG *sig; + int ret; + +- if ((PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +- || (PyObject_AsReadBuffer(r, &rbuf, &rlen) == -1) +- || (PyObject_AsReadBuffer(s, &sbuf, &slen) == -1)) ++ if ((m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(r, &rbuf, &rlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(s, &sbuf, &slen) == -1)) + return -1; + + if (!(sig = ECDSA_SIG_new())) { +@@ -299,7 +300,7 @@ + int siglen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(sigbuf = PyMem_Malloc(ECDSA_size(key)))) { +@@ -322,8 +323,9 @@ + void *sbuf; + int vlen, slen, ret; + +- if ((PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +- || (PyObject_AsReadBuffer(sig, (const void **)&sbuf, &slen) == -1)) ++ if ((m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) ++ || (m2_PyObject_AsReadBufferInt(sig, (const void **)&sbuf, &slen) ++ == -1)) + return -1; + + if ((ret = ECDSA_verify(0, vbuf, vlen, sbuf, slen, key)) == -1) +@@ -366,8 +368,7 @@ + + EC_KEY* ec_key_from_pubkey_der(PyObject *pubkey) { + const void *keypairbuf; +- int keypairbuflen; +- long tempLen; ++ Py_ssize_t keypairbuflen; + const unsigned char *tempBuf; + EC_KEY *keypair; + +@@ -377,8 +378,7 @@ + } + + tempBuf = (const unsigned char *)keypairbuf; +- tempLen = (long)keypairbuflen; +- if ((keypair = d2i_EC_PUBKEY( NULL, &tempBuf, tempLen )) == 0) ++ if ((keypair = d2i_EC_PUBKEY( NULL, &tempBuf, keypairbuflen)) == 0) + { + PyErr_SetString(_ec_err, ERR_reason_error_string(ERR_get_error())); + return NULL; +diff -ur m2crypto/SWIG/_evp.i m2crypto-0.17beta1/SWIG/_evp.i +--- m2crypto/SWIG/_evp.i 2006-12-06 06:30:34.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_evp.i 2006-12-14 01:25:53.000000000 +0100 +@@ -168,12 +168,12 @@ + + int digest_update(EVP_MD_CTX *ctx, PyObject *blob) { + const void *buf; +- int len; ++ Py_ssize_t len; + + if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) + return -1; + +- return EVP_DigestUpdate(ctx, buf, (unsigned int)len); ++ return EVP_DigestUpdate(ctx, buf, len); + } + + PyObject *digest_final(EVP_MD_CTX *ctx) { +@@ -211,7 +211,7 @@ + const void *kbuf; + int klen; + +- if (PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) ++ if (m2_PyObject_AsReadBufferInt(key, &kbuf, &klen) == -1) + return NULL; + + HMAC_Init(ctx, kbuf, klen, md); +@@ -221,12 +221,12 @@ + + PyObject *hmac_update(HMAC_CTX *ctx, PyObject *blob) { + const void *buf; +- int len; ++ Py_ssize_t len; + + if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) + return NULL; + +- HMAC_Update(ctx, buf, (unsigned int)len); ++ HMAC_Update(ctx, buf, len); + Py_INCREF(Py_None); + return Py_None; + } +@@ -249,10 +249,11 @@ + PyObject *hmac(PyObject *key, PyObject *data, const EVP_MD *md) { + const void *kbuf, *dbuf; + void *blob; +- int klen, dlen, blen; ++ int klen, blen; ++ Py_ssize_t dlen; + PyObject *ret; + +- if ((PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) ++ if ((m2_PyObject_AsReadBufferInt(key, &kbuf, &klen) == -1) + || (PyObject_AsReadBuffer(data, &dbuf, &dlen) == -1)) + return NULL; + +@@ -289,10 +290,11 @@ + int iter) { + unsigned char key[EVP_MAX_KEY_LENGTH]; + const void *dbuf, *sbuf; +- int dlen, slen, klen; ++ int dlen, klen; ++ Py_ssize_t slen; + PyObject *ret; + +- if ((PyObject_AsReadBuffer(data, &dbuf, &dlen) == -1) ++ if ((m2_PyObject_AsReadBufferInt(data, &dbuf, &dlen) == -1) + || (PyObject_AsReadBuffer(salt, &sbuf, &slen) == -1)) + return NULL; + +@@ -307,7 +309,7 @@ + PyObject *cipher_init(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + PyObject *key, PyObject *iv, int mode) { + const void *kbuf, *ibuf; +- int klen, ilen; ++ Py_ssize_t klen, ilen; + + if ((PyObject_AsReadBuffer(key, &kbuf, &klen) == -1) + || (PyObject_AsReadBuffer(iv, &ibuf, &ilen) == -1)) +@@ -324,7 +326,7 @@ + void *obuf; + PyObject *ret; + +- if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(blob, &buf, &len) == -1) + return NULL; + + if (!(obuf = PyMem_Malloc(len + EVP_CIPHER_CTX_block_size(ctx) - 1))) { +@@ -354,7 +356,7 @@ + + PyObject *sign_update(EVP_MD_CTX *ctx, PyObject *blob) { + const void *buf; +- int len; ++ Py_ssize_t len; + + if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) + return NULL; +@@ -377,7 +379,7 @@ + + int verify_update(EVP_MD_CTX *ctx, PyObject *blob) { + const void *buf; +- int len; ++ Py_ssize_t len; + + if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) + return -1; +@@ -390,7 +392,7 @@ + unsigned char *kbuf; + int len; + +- if (PyObject_AsReadBuffer(blob, (const void **)&kbuf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(blob, (const void **)&kbuf, &len) == -1) + return -1; + + return EVP_VerifyFinal(ctx, kbuf, len, pkey); +diff -ur m2crypto/SWIG/_lib.h m2crypto-0.17beta1/SWIG/_lib.h +--- m2crypto/SWIG/_lib.h 2005-06-09 19:32:28.000000000 +0200 ++++ m2crypto-0.17beta1/SWIG/_lib.h 2006-12-14 05:08:26.000000000 +0100 +@@ -10,6 +10,10 @@ + Blob *blob_copy(Blob *from, const char *errmsg); + void blob_free(Blob *blob); + ++static int m2_PyObject_AsReadBufferInt(PyObject *obj, const void **buffer, ++ int *buffer_len); ++static int m2_PyString_AsStringAndSizeInt(PyObject *obj, char **s, int *len); ++ + void gen_callback(int p, int n, void *arg); + int passphrase_callback(char *buf, int num, int v, void *userdata); + +diff -ur m2crypto/SWIG/_lib.i m2crypto-0.17beta1/SWIG/_lib.i +--- m2crypto/SWIG/_lib.i 2006-12-06 06:30:34.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_lib.i 2006-12-14 05:11:56.000000000 +0100 +@@ -44,6 +44,50 @@ + } + + ++/* Python helpers. */ ++ ++%} ++%ignore m2_PyObject_AsReadBufferInt; ++%ignore m2_PyString_AsStringAndSizeInt; ++%{ ++static int ++m2_PyObject_AsReadBufferInt(PyObject *obj, const void **buffer, ++ int *buffer_len) ++{ ++ int ret; ++ Py_ssize_t len; ++ ++ ret = PyObject_AsReadBuffer(obj, buffer, &len); ++ if (ret != 0) ++ return ret; ++ if (len > INT_MAX) { ++ PyErr_SetString(PyExc_ValueError, "object too large"); ++ return -1; ++ } ++ *buffer_len = len; ++ return 0; ++} ++ ++static int ++m2_PyString_AsStringAndSizeInt(PyObject *obj, char **s, int *len) ++{ ++ int ret; ++ Py_ssize_t len2; ++ ++ if (len == NULL) ++ return PyString_AsStringAndSize(obj, s, NULL); ++ ret = PyString_AsStringAndSize(obj, s, &len2); ++ if (ret != 0) ++ return ret; ++ if (len2 > INT_MAX) { ++ PyErr_SetString(PyExc_ValueError, "string too large"); ++ return -1; ++ } ++ *len = len2; ++ return 0; ++} ++ ++ + /* C callbacks invoked by OpenSSL; these in turn call back into + Python. */ + +@@ -215,7 +259,8 @@ + } + + int passphrase_callback(char *buf, int num, int v, void *arg) { +- int i, len; ++ int i; ++ Py_ssize_t len; + char *str; + PyObject *argv, *ret, *cbfunc; + +@@ -270,7 +315,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + return BN_mpi2bn(vbuf, vlen, NULL); +@@ -296,7 +341,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + return BN_bin2bn(vbuf, vlen, NULL); +@@ -305,7 +350,7 @@ + PyObject *bn_to_hex(BIGNUM *bn) { + char *hex; + PyObject *pyo; +- int len; ++ Py_ssize_t len; + + hex = BN_bn2hex(bn); + if (!hex) { +@@ -322,7 +367,7 @@ + + BIGNUM *hex_to_bn(PyObject *value) { + const void *vbuf; +- int vlen; ++ Py_ssize_t vlen; + BIGNUM *bn; + + if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +@@ -343,7 +388,7 @@ + + BIGNUM *dec_to_bn(PyObject *value) { + const void *vbuf; +- int vlen; ++ Py_ssize_t vlen; + BIGNUM *bn; + + if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) +@@ -367,17 +412,24 @@ + /* Various useful typemaps. */ + + %typemap(in) Blob * { ++ Py_ssize_t len; ++ + if (!PyString_Check($input)) { + PyErr_SetString(PyExc_TypeError, "expected PyString"); + return NULL; + } ++ len=PyString_Size($input); ++ if (len > INT_MAX) { ++ PyErr_SetString(PyExc_ValueError, "object too large"); ++ return -1; ++ } + $1=(Blob *)PyMem_Malloc(sizeof(Blob)); + if (!$1) { + PyErr_SetString(PyExc_MemoryError, "malloc Blob"); + return NULL; + } + $1->data=(unsigned char *)PyString_AsString($input); +- $1->len=PyString_Size($input); ++ $1->len=len; + } + + %typemap(out) Blob * { +diff -ur m2crypto/SWIG/_rand.i m2crypto-0.17beta1/SWIG/_rand.i +--- m2crypto/SWIG/_rand.i 2006-06-05 23:29:00.000000000 +0200 ++++ m2crypto-0.17beta1/SWIG/_rand.i 2006-12-14 03:36:39.000000000 +0100 +@@ -27,7 +27,7 @@ + const void *buf; + int len; + +- if (PyObject_AsReadBuffer(seed, &buf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(seed, &buf, &len) == -1) + return NULL; + + RAND_seed(buf, len); +@@ -39,7 +39,7 @@ + const void *buf; + int len; + +- if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(blob, &buf, &len) == -1) + return NULL; + + RAND_add(buf, len, entropy); +diff -ur m2crypto/SWIG/_rc4.i m2crypto-0.17beta1/SWIG/_rc4.i +--- m2crypto/SWIG/_rc4.i 2006-03-07 21:51:58.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_rc4.i 2006-12-14 03:39:44.000000000 +0100 +@@ -25,7 +25,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + RC4_set_key(key, vlen, vbuf); +@@ -36,7 +36,7 @@ + PyObject *rc4_update(RC4_KEY *key, PyObject *in) { + PyObject *ret; + const void *buf; +- int len; ++ Py_ssize_t len; + void *out; + + if (PyObject_AsReadBuffer(in, &buf, &len) == -1) +diff -ur m2crypto/SWIG/_rsa.i m2crypto-0.17beta1/SWIG/_rsa.i +--- m2crypto/SWIG/_rsa.i 2006-05-02 23:00:53.000000000 +0200 ++++ m2crypto-0.17beta1/SWIG/_rsa.i 2006-12-14 05:13:13.000000000 +0100 +@@ -105,7 +105,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -124,7 +124,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -143,7 +143,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_bin2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -162,7 +162,7 @@ + const void *vbuf; + int vlen; + +- if (PyObject_AsReadBuffer(value, &vbuf, &vlen) == -1) ++ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) + return NULL; + + if (!(bn = BN_bin2bn((unsigned char *)vbuf, vlen, NULL))) { +@@ -182,7 +182,7 @@ + int flen, tlen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(from, &fbuf, &flen) == -1) ++ if (m2_PyObject_AsReadBufferInt(from, &fbuf, &flen) == -1) + return NULL; + + if (!(tbuf = PyMem_Malloc(BN_num_bytes(rsa->n)))) { +@@ -207,7 +207,7 @@ + int flen, tlen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(from, &fbuf, &flen) == -1) ++ if (m2_PyObject_AsReadBufferInt(from, &fbuf, &flen) == -1) + return NULL; + + if (!(tbuf = PyMem_Malloc(BN_num_bytes(rsa->n)))) { +@@ -232,7 +232,7 @@ + int flen, tlen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(from, &fbuf, &flen) == -1) ++ if (m2_PyObject_AsReadBufferInt(from, &fbuf, &flen) == -1) + return NULL; + + if (!(tbuf = PyMem_Malloc(BN_num_bytes(rsa->n)))) { +@@ -257,7 +257,7 @@ + int flen, tlen; + PyObject *ret; + +- if (PyObject_AsReadBuffer(from, &fbuf, &flen) == -1) ++ if (m2_PyObject_AsReadBufferInt(from, &fbuf, &flen) == -1) + return NULL; + + if (!(tbuf = PyMem_Malloc(BN_num_bytes(rsa->n)))) { +@@ -285,7 +285,8 @@ + unsigned char * sign_buf = NULL; + PyObject *signature; + +- ret = PyString_AsStringAndSize(py_digest_string, &digest_string, &digest_len); ++ ret = m2_PyString_AsStringAndSizeInt(py_digest_string, &digest_string, ++ &digest_len); + if (ret == -1) { + /* PyString_AsStringAndSize raises the correct exceptions. */ + return NULL; +@@ -312,13 +313,15 @@ + char * verify_string = NULL; + int verify_len = 0; + int sign_len = 0; +- +- ret = PyString_AsStringAndSize(py_verify_string, &verify_string, &verify_len); ++ ++ ret = m2_PyString_AsStringAndSizeInt(py_verify_string, &verify_string, ++ &verify_len); + if (ret == -1) { + /* PyString_AsStringAndSize raises the correct exceptions. */ + return 0; + } +- ret = PyString_AsStringAndSize(py_sign_string, &sign_string, &sign_len); ++ ret = m2_PyString_AsStringAndSizeInt(py_sign_string, &sign_string, ++ &sign_len); + if (ret == -1) { + return 0; + } +diff -ur m2crypto/SWIG/_ssl.i m2crypto-0.17beta1/SWIG/_ssl.i +--- m2crypto/SWIG/_ssl.i 2006-04-01 00:11:55.000000000 +0200 ++++ m2crypto-0.17beta1/SWIG/_ssl.i 2006-12-14 03:49:17.000000000 +0100 +@@ -268,7 +268,7 @@ + const void *buf; + int len; + +- if (PyObject_AsReadBuffer(sid_ctx, &buf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(sid_ctx, &buf, &len) == -1) + return -1; + + return SSL_CTX_set_session_id_context(ctx, buf, len); +@@ -337,7 +337,7 @@ + const void *buf; + int len; + +- if (PyObject_AsReadBuffer(sid_ctx, &buf, &len) == -1) ++ if (m2_PyObject_AsReadBufferInt(sid_ctx, &buf, &len) == -1) + return -1; + + return SSL_set_session_id_context(ssl, buf, len); +@@ -550,7 +550,7 @@ + + gilstate = PyGILState_Ensure(); + +- if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) { ++ if (m2_PyObject_AsReadBufferInt(blob, &buf, &len) == -1) { + PyGILState_Release(gilstate); + return -1; + } +@@ -599,7 +599,7 @@ + + gilstate = PyGILState_Ensure(); + +- if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) { ++ if (m2_PyObject_AsReadBufferInt(blob, &buf, &len) == -1) { + PyGILState_Release(gilstate); + return -1; + } +diff -ur m2crypto/SWIG/_util.i m2crypto-0.17beta1/SWIG/_util.i +--- m2crypto/SWIG/_util.i 2006-03-07 21:51:58.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_util.i 2006-12-14 03:53:20.000000000 +0100 +@@ -17,12 +17,12 @@ + PyObject *obj; + const void *buf; + char *ret; +- int len; ++ Py_ssize_t len; + + if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) + return NULL; + +- ret = hex_to_string((unsigned char *)buf, (long)len); ++ ret = hex_to_string((unsigned char *)buf, len); + if (!ret) { + PyErr_SetString(_util_err, ERR_reason_error_string(ERR_get_error())); + return NULL; +@@ -36,12 +36,14 @@ + PyObject *obj; + const void *buf; + unsigned char *ret; +- int len; ++ Py_ssize_t len0; ++ long len; + +- if (PyObject_AsReadBuffer(blob, &buf, &len) == -1) ++ if (PyObject_AsReadBuffer(blob, &buf, &len0) == -1) + return NULL; + +- ret = string_to_hex((char *)buf, (long *)&len); ++ len = len0; ++ ret = string_to_hex((char *)buf, &len); + if (ret == NULL) { + PyErr_SetString(_util_err, ERR_reason_error_string(ERR_get_error())); + return NULL; +diff -ur m2crypto/SWIG/_x509.i m2crypto-0.17beta1/SWIG/_x509.i +--- m2crypto/SWIG/_x509.i 2006-12-06 06:30:34.000000000 +0100 ++++ m2crypto-0.17beta1/SWIG/_x509.i 2006-12-14 03:57:24.000000000 +0100 +@@ -510,10 +510,14 @@ + STACK * + make_stack_from_der_sequence(PyObject * pyEncodedString){ + STACK_OF(X509) *certs; +- int encoded_string_len; ++ Py_ssize_t encoded_string_len; + char *encoded_string; + + encoded_string_len = PyString_Size(pyEncodedString); ++ if (encoded_string_len > INT_MAX) { ++ PyErr_SetString(PyExc_ValueError, "object too large"); ++ return NULL; ++ } + encoded_string = PyString_AsString(pyEncodedString); + + certs = ASN1_seq_unpack((unsigned char *)encoded_string, encoded_string_len, (D2ITYPE)d2i_X509, (void(*)())X509_free ); diff --git a/m2crypto-0.17-timeouts.patch b/m2crypto-0.17-timeouts.patch new file mode 100644 index 0000000..f18b276 --- /dev/null +++ b/m2crypto-0.17-timeouts.patch @@ -0,0 +1,599 @@ +diff -ur m2crypto/M2Crypto/SSL/Connection.py m2crypto-0.16/M2Crypto/SSL/Connection.py +--- m2crypto/M2Crypto/SSL/Connection.py 2006-05-11 00:43:47.000000000 +0200 ++++ m2crypto-0.16/M2Crypto/SSL/Connection.py 2006-10-23 18:55:39.000000000 +0200 +@@ -36,9 +36,11 @@ + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self._fileno = self.socket.fileno() +- +- self.blocking = self.socket.gettimeout() +- ++ ++ self._timeout = self.socket.gettimeout() ++ if self._timeout is None: ++ self._timeout = -1.0 ++ + def __del__(self): + if getattr(self, 'sslbio', None): + self.m2_bio_free(self.sslbio) +@@ -122,7 +124,7 @@ + m2.ssl_set_accept_state(self.ssl) + + def accept_ssl(self): +- return m2.ssl_accept(self.ssl) ++ return m2.ssl_accept(self.ssl, self._timeout) + + def accept(self): + """Accept an SSL connection. The return value is a pair (ssl, addr) where +@@ -144,7 +146,7 @@ + m2.ssl_set_connect_state(self.ssl) + + def connect_ssl(self): +- return m2.ssl_connect(self.ssl) ++ return m2.ssl_connect(self.ssl, self._timeout) + + def connect(self, addr): + self.socket.connect(addr) +@@ -171,7 +173,7 @@ + return m2.ssl_pending(self.ssl) + + def _write_bio(self, data): +- return m2.ssl_write(self.ssl, data) ++ return m2.ssl_write(self.ssl, data, self._timeout) + + def _write_nbio(self, data): + return m2.ssl_write_nbio(self.ssl, data) +@@ -179,7 +181,7 @@ + def _read_bio(self, size=1024): + if size <= 0: + raise ValueError, 'size <= 0' +- return m2.ssl_read(self.ssl, size) ++ return m2.ssl_read(self.ssl, size, self._timeout) + + def _read_nbio(self, size=1024): + if size <= 0: +@@ -187,13 +189,13 @@ + return m2.ssl_read_nbio(self.ssl, size) + + def write(self, data): +- if self.blocking: ++ if self._timeout != 0.0: + return self._write_bio(data) + return self._write_nbio(data) + sendall = send = write + + def read(self, size=1024): +- if self.blocking: ++ if self._timeout != 0.0: + return self._read_bio(size) + return self._read_nbio(size) + recv = read +@@ -201,7 +203,17 @@ + def setblocking(self, mode): + """Set this connection's underlying socket to _mode_.""" + self.socket.setblocking(mode) +- self.blocking = mode ++ if mode: ++ self._timeout = -1.0 ++ else: ++ self._timeout = 0.0 ++ ++ def settimeout(self, timeout): ++ """Set this connection's underlying socket's timeout to _timeout_.""" ++ self.socket.settimeout(timeout) ++ self._timeout = timeout ++ if self._timeout is None: ++ self._timeout = -1.0 + + def fileno(self): + return self.socket.fileno() +@@ -280,15 +292,8 @@ + """Set the cipher suites for this connection.""" + return m2.ssl_set_cipher_list(self.ssl, cipher_list) + +- def makefile(self, mode='rb', bufsize='ignored'): +- r = 'r' in mode or '+' in mode +- w = 'w' in mode or 'a' in mode or '+' in mode +- b = 'b' in mode +- m2mode = ['', 'r'][r] + ['', 'w'][w] + ['', 'b'][b] +- # XXX Need to dup(). +- bio = BIO.BIO(self.sslbio, _close_cb=self.close) +- m2.bio_do_handshake(bio._ptr()) +- return BIO.IOBuffer(bio, m2mode, _pyfree=0) ++ def makefile(self, mode='rb', bufsize=-1): ++ return socket._fileobject(self, mode, bufsize) + + def getsockname(self): + return self.socket.getsockname() +diff -ur m2crypto/M2Crypto/SSL/__init__.py m2crypto-0.16/M2Crypto/SSL/__init__.py +--- m2crypto/M2Crypto/SSL/__init__.py 2006-03-20 20:26:28.000000000 +0100 ++++ m2crypto-0.16/M2Crypto/SSL/__init__.py 2006-10-23 19:53:10.000000000 +0200 +@@ -2,11 +2,14 @@ + + Copyright (c) 1999-2004 Ng Pheng Siong. All rights reserved.""" + ++import socket ++ + # M2Crypto + from M2Crypto import m2 + + class SSLError(Exception): pass +-m2.ssl_init(SSLError) ++class SSLTimeoutError(SSLError, socket.timeout): pass ++m2.ssl_init(SSLError, SSLTimeoutError) + + # M2Crypto.SSL + from Cipher import Cipher, Cipher_Stack +diff -ur m2crypto/SWIG/_ssl.i m2crypto-0.16/SWIG/_ssl.i +--- m2crypto/SWIG/_ssl.i 2006-04-01 00:11:55.000000000 +0200 ++++ m2crypto-0.16/SWIG/_ssl.i 2006-10-23 20:00:36.000000000 +0200 +@@ -8,10 +8,13 @@ + + %{ + #include ++#include + #include + #include + #include + #include ++#include ++#include + %} + + %apply Pointer NONNULL { SSL_CTX * }; +@@ -142,6 +145,11 @@ + %rename(ssl_session_get_timeout) SSL_SESSION_get_timeout; + extern long SSL_SESSION_get_timeout(CONST SSL_SESSION *); + ++extern PyObject *ssl_accept(SSL *ssl, double timeout = -1); ++extern PyObject *ssl_connect(SSL *ssl, double timeout = -1); ++extern PyObject *ssl_read(SSL *ssl, int num, double timeout = -1); ++extern int ssl_write(SSL *ssl, PyObject *blob, double timeout = -1); ++ + %constant int ssl_error_none = SSL_ERROR_NONE; + %constant int ssl_error_ssl = SSL_ERROR_SSL; + %constant int ssl_error_want_read = SSL_ERROR_WANT_READ; +@@ -192,14 +200,19 @@ + %constant int SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = SSL_MODE_ENABLE_PARTIAL_WRITE; + %constant int SSL_MODE_AUTO_RETRY = SSL_MODE_AUTO_RETRY; + ++%ignore ssl_handle_error; ++%ignore ssl_sleep_with_timeout; + %inline %{ + static PyObject *_ssl_err; ++static PyObject *_ssl_timeout_err; + +-void ssl_init(PyObject *ssl_err) { ++void ssl_init(PyObject *ssl_err, PyObject *ssl_timeout_err) { + SSL_library_init(); + SSL_load_error_strings(); + Py_INCREF(ssl_err); ++ Py_INCREF(ssl_timeout_err); + _ssl_err = ssl_err; ++ _ssl_timeout_err = ssl_timeout_err; + } + + void ssl_ctx_passphrase_callback(SSL_CTX *ctx, PyObject *pyfunc) { +@@ -353,36 +366,139 @@ + return ret; + } + +-PyObject *ssl_accept(SSL *ssl) { ++static void ssl_handle_error(int ssl_err, int ret) { ++ int err; ++ ++ switch (ssl_err) { ++ case SSL_ERROR_SSL: ++ PyErr_SetString(_ssl_err, ++ ERR_reason_error_string(ERR_get_error())); ++ break; ++ case SSL_ERROR_SYSCALL: ++ err = ERR_get_error(); ++ if (err) ++ PyErr_SetString(_ssl_err, ERR_reason_error_string(err)); ++ else if (ret == 0) ++ PyErr_SetString(_ssl_err, "unexpected eof"); ++ else if (ret == -1) ++ PyErr_SetFromErrno(_ssl_err); ++ else ++ assert(0); ++ break; ++ default: ++ PyErr_SetString(_ssl_err, "unexpected SSL error"); ++ } ++} ++ ++static int ssl_sleep_with_timeout(SSL *ssl, const struct timeval *start, ++ double timeout, int ssl_err) { ++ PyGILState_STATE gilstate; ++ struct pollfd fd; ++ struct timeval tv; ++ int ms; ++ ++ assert(timeout > 0); ++ again: ++ gettimeofday(&tv, NULL); ++ /* tv >= start */ ++ if ((timeout + start->tv_sec - tv.tv_sec) > INT_MAX / 1000) ++ ms = -1; ++ else { ++ int fract; ++ ++ ms = ((start->tv_sec + (int)timeout) - tv.tv_sec) * 1000; ++ fract = (start->tv_usec + (timeout - (int)timeout) * 1000000 ++ - tv.tv_usec + 999) / 1000; ++ if (ms > 0 && fract > INT_MAX - ms) ++ ms = -1; ++ else { ++ ms += fract; ++ if (ms <= 0) ++ goto timeout; ++ } ++ } ++ switch (ssl_err) { ++ case SSL_ERROR_WANT_READ: ++ fd.fd = SSL_get_rfd(ssl); ++ fd.events = POLLIN; ++ break; ++ ++ case SSL_ERROR_WANT_WRITE: ++ fd.fd = SSL_get_wfd(ssl); ++ fd.events = POLLOUT; ++ break; ++ ++ case SSL_ERROR_WANT_X509_LOOKUP: ++ return 0; /* FIXME: is this correct? */ ++ ++ default: ++ assert(0); ++ } ++ if (fd.fd == -1) { ++ gilstate = PyGILState_Ensure(); ++ PyErr_SetString(_ssl_err, "timeout on a non-FD SSL"); ++ PyGILState_Release(gilstate); ++ return -1; ++ } ++ switch (poll(&fd, 1, ms)) { ++ case 1: ++ return 0; ++ case 0: ++ goto timeout; ++ case -1: ++ if (errno == EINTR) ++ goto again; ++ gilstate = PyGILState_Ensure(); ++ PyErr_SetFromErrno(_ssl_err); ++ PyGILState_Release(gilstate); ++ return -1; ++ } ++ return 0; ++ ++ timeout: ++ gilstate = PyGILState_Ensure(); ++ PyErr_SetNone(_ssl_timeout_err); ++ PyGILState_Release(gilstate); ++ return -1; ++} ++ ++PyObject *ssl_accept(SSL *ssl, double timeout) { + PyObject *obj = NULL; +- int r, err; ++ int r, ssl_err; ++ struct timeval tv; + PyGILState_STATE gilstate; + ++ if (timeout > 0) ++ gettimeofday(&tv, NULL); ++ again: + r = SSL_accept(ssl); ++ ssl_err = SSL_get_error(ssl, r); + + gilstate = PyGILState_Ensure(); + +- switch (SSL_get_error(ssl, r)) { ++ switch (ssl_err) { + case SSL_ERROR_NONE: + case SSL_ERROR_ZERO_RETURN: + obj = PyInt_FromLong((long)1); + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: +- obj = PyInt_FromLong((long)0); +- break; +- case SSL_ERROR_SSL: +- PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error())); ++ if (timeout <= 0) { ++ obj = PyInt_FromLong((long)0); ++ break; ++ } ++ ++ PyGILState_Release(gilstate); ++ if (ssl_sleep_with_timeout(ssl, &tv, timeout, ssl_err) == 0) ++ goto again; ++ gilstate = PyGILState_Ensure(); ++ + obj = NULL; + break; ++ ++ case SSL_ERROR_SSL: + case SSL_ERROR_SYSCALL: +- err = ERR_get_error(); +- if (err) +- PyErr_SetString(_ssl_err, ERR_reason_error_string(err)); +- else if (r == 0) +- PyErr_SetString(_ssl_err, "unexpected eof"); +- else if (r == -1) +- PyErr_SetFromErrno(_ssl_err); ++ ssl_handle_error(ssl_err, r); + obj = NULL; + break; + } +@@ -392,36 +508,43 @@ + return obj; + } + +-PyObject *ssl_connect(SSL *ssl) { ++PyObject *ssl_connect(SSL *ssl, double timeout) { + PyObject *obj = NULL; +- int r, err; ++ int r, ssl_err; ++ struct timeval tv; + PyGILState_STATE gilstate; + ++ if (timeout > 0) ++ gettimeofday(&tv, NULL); ++ again: + r = SSL_connect(ssl); ++ ssl_err = SSL_get_error(ssl, r); + + gilstate = PyGILState_Ensure(); + +- switch (SSL_get_error(ssl, r)) { ++ switch (ssl_err) { + case SSL_ERROR_NONE: + case SSL_ERROR_ZERO_RETURN: + obj = PyInt_FromLong((long)1); + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: +- obj = PyInt_FromLong((long)0); +- break; +- case SSL_ERROR_SSL: +- PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error())); ++ if (timeout <= 0) { ++ obj = PyInt_FromLong((long)0); ++ break; ++ } ++ ++ PyGILState_Release(gilstate); ++ if (ssl_sleep_with_timeout(ssl, &tv, timeout, ssl_err) == 0) ++ goto again; ++ gilstate = PyGILState_Ensure(); ++ + obj = NULL; + break; ++ ++ case SSL_ERROR_SSL: + case SSL_ERROR_SYSCALL: +- err = ERR_get_error(); +- if (err) +- PyErr_SetString(_ssl_err, ERR_reason_error_string(err)); +- else if (r == 0) +- PyErr_SetString(_ssl_err, "unexpected eof"); +- else if (r == -1) +- PyErr_SetFromErrno(_ssl_err); ++ ssl_handle_error(ssl_err, r); + obj = NULL; + break; + } +@@ -435,10 +558,11 @@ + SSL_set_shutdown(ssl, mode); + } + +-PyObject *ssl_read(SSL *ssl, int num) { ++PyObject *ssl_read(SSL *ssl, int num, double timeout) { + PyObject *obj = NULL; + void *buf; +- int r, err; ++ int r; ++ struct timeval tv; + PyGILState_STATE gilstate; + + gilstate = PyGILState_Ensure(); +@@ -451,36 +575,48 @@ + + PyGILState_Release(gilstate); + ++ if (timeout > 0) ++ gettimeofday(&tv, NULL); ++ again: + r = SSL_read(ssl, buf, num); + + gilstate = PyGILState_Ensure(); + +- switch (SSL_get_error(ssl, r)) { +- case SSL_ERROR_NONE: +- case SSL_ERROR_ZERO_RETURN: +- buf = PyMem_Realloc(buf, r); +- obj = PyString_FromStringAndSize(buf, r); +- break; +- case SSL_ERROR_WANT_WRITE: +- case SSL_ERROR_WANT_READ: +- case SSL_ERROR_WANT_X509_LOOKUP: +- Py_INCREF(Py_None); +- obj = Py_None; +- break; +- case SSL_ERROR_SSL: +- PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error())); +- obj = NULL; +- break; +- case SSL_ERROR_SYSCALL: +- err = ERR_get_error(); +- if (err) +- PyErr_SetString(_ssl_err, ERR_reason_error_string(err)); +- else if (r == 0) +- PyErr_SetString(_ssl_err, "unexpected eof"); +- else if (r == -1) +- PyErr_SetFromErrno(_ssl_err); +- obj = NULL; +- break; ++ if (r >= 0) { ++ buf = PyMem_Realloc(buf, r); ++ obj = PyString_FromStringAndSize(buf, r); ++ } else { ++ int ssl_err; ++ ++ ssl_err = SSL_get_error(ssl, r); ++ switch (ssl_err) { ++ case SSL_ERROR_NONE: ++ case SSL_ERROR_ZERO_RETURN: ++ assert(0); ++ ++ case SSL_ERROR_WANT_WRITE: ++ case SSL_ERROR_WANT_READ: ++ case SSL_ERROR_WANT_X509_LOOKUP: ++ if (timeout <= 0) { ++ Py_INCREF(Py_None); ++ obj = Py_None; ++ break; ++ } ++ ++ PyGILState_Release(gilstate); ++ if (ssl_sleep_with_timeout(ssl, &tv, timeout, ssl_err) == 0) ++ goto again; ++ gilstate = PyGILState_Ensure(); ++ ++ obj = NULL; ++ break; ++ ++ case SSL_ERROR_SSL: ++ case SSL_ERROR_SYSCALL: ++ ssl_handle_error(ssl_err, r); ++ obj = NULL; ++ break; ++ } + } + PyMem_Free(buf); + +@@ -543,9 +679,10 @@ + return obj; + } + +-int ssl_write(SSL *ssl, PyObject *blob) { ++int ssl_write(SSL *ssl, PyObject *blob, double timeout) { + const void *buf; +- int len, r, err, ret; ++ int len, r, ssl_err, ret; ++ struct timeval tv; + PyGILState_STATE gilstate; + + gilstate = PyGILState_Ensure(); +@@ -556,12 +693,16 @@ + } + + PyGILState_Release(gilstate); +- ++ ++ if (timeout > 0) ++ gettimeofday(&tv, NULL); ++ again: + r = SSL_write(ssl, buf, len); ++ ssl_err = SSL_get_error(ssl, r); + + gilstate = PyGILState_Ensure(); + +- switch (SSL_get_error(ssl, r)) { ++ switch (ssl_err) { + case SSL_ERROR_NONE: + case SSL_ERROR_ZERO_RETURN: + ret = r; +@@ -569,20 +710,22 @@ + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_X509_LOOKUP: ++ if (timeout <= 0) { ++ ret = -1; ++ break; ++ } ++ ++ PyGILState_Release(gilstate); ++ if (ssl_sleep_with_timeout(ssl, &tv, timeout, ssl_err) == 0) ++ goto again; ++ gilstate = PyGILState_Ensure(); ++ + ret = -1; + break; ++ + case SSL_ERROR_SSL: +- PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error())); +- ret = -1; +- break; + case SSL_ERROR_SYSCALL: +- err = ERR_get_error(); +- if (err) +- PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error())); +- else if (r == 0) +- PyErr_SetString(_ssl_err, "unexpected eof"); +- else if (r == -1) +- PyErr_SetFromErrno(_ssl_err); ++ ssl_handle_error(ssl_err, r); + default: + ret = -1; + } +diff -ur m2crypto/tests/test_ssl.py m2crypto-0.16/tests/test_ssl.py +--- m2crypto/tests/test_ssl.py 2006-10-22 01:22:57.000000000 +0200 ++++ m2crypto-0.16/tests/test_ssl.py 2006-10-23 20:14:46.000000000 +0200 +@@ -631,6 +631,53 @@ + self.stop_server(pid) + self.failIf(string.find(data, 's_server -quiet -www') == -1) + ++ def test_timeout(self): ++ pid = self.start_server(self.args) ++ try: ++ ctx = SSL.Context() ++ s = SSL.Connection(ctx) ++ # Just a really small number so we can timeout ++ s.settimeout(0.000000000000000000000000000001) ++ self.assertRaises(SSL.SSLTimeoutError, s.connect, self.srv_addr) ++ s.close() ++ finally: ++ self.stop_server(pid) ++ ++ def test_makefile_timeout(self): ++ # httpslib uses makefile to read the response ++ pid = self.start_server(self.args) ++ try: ++ from M2Crypto import httpslib ++ c = httpslib.HTTPS(srv_host, srv_port) ++ c.putrequest('GET', '/') ++ c.putheader('Accept', 'text/html') ++ c.putheader('Accept', 'text/plain') ++ c.endheaders() ++ c._conn.sock.settimeout(100) ++ err, msg, headers = c.getreply() ++ assert err == 200, err ++ f = c.getfile() ++ data = f.read() ++ c.close() ++ finally: ++ self.stop_server(pid) ++ self.failIf(string.find(data, 's_server -quiet -www') == -1) ++ ++ def test_makefile_timeout_fires(self): ++ pid = self.start_server(self.args) ++ try: ++ from M2Crypto import httpslib ++ c = httpslib.HTTPS(srv_host, srv_port) ++ c.putrequest('GET', '/') ++ c.putheader('Accept', 'text/html') ++ c.putheader('Accept', 'text/plain') ++ c.endheaders() ++ c._conn.sock.settimeout(0.0000000001) ++ self.assertRaises(socket.timeout, c.getreply) ++ c.close() ++ finally: ++ self.stop_server(pid) ++ + def test_twisted_wrapper(self): + # + # LEAK ALERT! diff --git a/m2crypto.spec b/m2crypto.spec index a48e8e0..a547bb7 100644 --- a/m2crypto.spec +++ b/m2crypto.spec @@ -2,12 +2,11 @@ Summary: Support for using OpenSSL in python scripts Name: m2crypto -Version: 0.16 -Release: 8 +Version: 0.17 +Release: 1 Source0: http://wiki.osafoundation.org/pub/Projects/MeTooCrypto/m2crypto-%{version}.tar.gz -Patch0: m2crypto-0.16-m2urllib2.patch -Patch1: m2crypto-0.16-proxy-connect.patch -Patch2: m2crypto-0.16-timeouts.patch +Patch0: m2crypto-0.17-timeouts.patch +Patch1: m2crypto-0.17-Py_ssize_t.patch License: BSDish Group: System Environment/Libraries URL: http://wiki.osafoundation.org/bin/view/Projects/MeTooCrypto @@ -22,8 +21,7 @@ This package allows you to call OpenSSL functions from python scripts. %prep %setup -q %patch0 -p1 -%patch1 -p0 -b .proxy-connect -%patch2 -p1 +%patch1 -p1 -b .Py_ssize_t # Red Hat opensslconf.h #includes an architecture-specific file, but SWIG # doesn't follow the #include. @@ -73,6 +71,10 @@ rm -rf $RPM_BUILD_ROOT %{python_sitearch}/M2Crypto %changelog +* Wed Jan 17 2007 Miloslav Trmac - 0.17-1 +- Update to m2crypto-0.17 +- Update for Python 2.5 + * Thu Dec 7 2006 Miloslav Trmac - 0.16-8 - Rebuild with updated build tools to avoid DT_TEXTREL on s390x Resolves: #218578 diff --git a/sources b/sources index 4541898..5b26557 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -6fc06583a2be56fc2a46872a0540d78e m2crypto-0.16.tar.gz +c67b45c752fd5e8115cd6b14831c5a38 m2crypto-0.17.tar.gz