[Patches] [ python-Patches-500311 ] Work around for buggy https servers

noreply@sourceforge.net noreply@sourceforge.net
Wed, 17 Apr 2002 07:16:20 -0700


Patches item #500311, was opened at 2002-01-07 09:49
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=500311&group_id=5470

Category: Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Michel Van den Bergh (vdbergh)
Assigned to: Martin v. Löwis (loewis)
Summary: Work around for buggy https servers

Initial Comment:
Python 2.2. Tested on RH 7.1.

This a workaround for, 

http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=494762

The problem is that some https servers close an ssl
connection without properly resetting it first. In the
above bug description it is suggested that this
only occurs for IIS but apparently some  (modified)
Apache servers also suffer from it (see
telemeter.telenet.be).

One of the suggested workarounds is to modify
httplib.py so as to ignore the combination of
err[0]==SSL_ERROR_SYSCALL and 
err[1]=="EOF occurred in violation of protocol".
However I think one should never compare error strings
since in principle they may depend on language etc...

So I decided to modify _socket.c slightly so that
it becomes possible to return error codes which
are not in in ssl.h.

When an ssl-connection is closed without reset I now
return the error code SSL_ERROR_EOF. Then I ignore
this (apparently benign) error in httplib.py.

In addition I fixed what I think was an error in
PySSL_SetError(SSL *ssl, int ret) in socketmodule.c.

Originally there was:

	case SSL_ERROR_SSL:
	{
		unsigned long e = ERR_get_error();
		if (e == 0) {
			/* an EOF was observed that violates the protocol */
			errstr = "EOF occurred in violation of protocol";

etc... 
but if I understand the documentation for
SSL_get_error then the test should be: e==0 && ret==0.
A similar error occurs a few lines later.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-04-17 16:16

Message:
Logged In: YES 
user_id=21627

jribbens: Even when running the test from 494762, i.e.

import os,urllib2
os.environ["http_proxy"]=''
f = urllib2.urlopen("https://wwws.task.com.br/i.htm")
print f.read()

This gives an empty response for me...

----------------------------------------------------------------------

Comment By: Jon Ribbens (jribbens)
Date: 2002-04-16 19:00

Message:
Logged In: YES 
user_id=76089

py23ssl.txt works fine for me when applied to latest CVS, 
and fixes the problem.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-03-11 07:34

Message:
Logged In: YES 
user_id=21627

Unfortunately, your patch appears to be incorrect.
Performing the script in #494762, I get an empty string as
the result, whereas the content of the resource is 'HTTPS Test'

In case you want to experiment with the CVS version I'll
attach a patch for that.

----------------------------------------------------------------------

Comment By: Michel Van den Bergh (vdbergh)
Date: 2002-01-09 11:25

Message:
Logged In: YES 
user_id=10252

Due to some problems with sourceforge and incompetence on my
part I submitted this several times.
Please see patch 500311. 

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=500311&group_id=5470