[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-04-14 Thread Simonas Kazlauskas

Simonas Kazlauskas simo...@kazlauskas.me added the comment:

Exactly same thing happens with `XOAUTH` mechanism too, so this bug report 
should be made more general. (Py3.2.2)

--
nosy: +nagisa

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-04-03 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

I made some time to work on this today.  Attached is a new patch.  I've 
incorporated the tests from the existing patches (though I'm doing the 
infrastructure a bit differently).  PLAIN seems to be a specific case of the 
general authenticate, so I just have a generalized test.

My fix is slightly different.  I'm changing the _Authenticate class to except 
either bytes or string as input.  String because that's more natural in 
Python3, bytes because there might be auth mechanisms that require bytes (since 
implementations can define 'X' auth mechanisms).

The authentication callback always gets passed the data as bytes, for the same 
reasons of generality.  So I'd be OK with the idea that the authentication 
handler always has to return bytes...which would require a different fix in 
login_cram_md5.

My login_cram_md5 test passes, so I *think* the fix I made there is OK.  
However, I'm getting a traceback from SSL about the socket being shut down, 
which seems to arise from an imaplib.abort resulting from an unexpected 'b''' 
value.  I'm out of time for working in this right now, so I'm uploading the 
patch to see if anyone else has time to figure it out.  I'll come back to it as 
some point but I don't know when.

--
assignee: docs@python - r.david.murray
components:  -Documentation
nosy:  -docs@python
stage:  - patch review
versions:  -Python 3.1
Added file: http://bugs.python.org/file25109/imaplib_authenticate.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-02-04 Thread Johannes Bauer

Johannes Bauer dfnsonfsdu...@gmx.de added the comment:

Issue also affects Python3.1. Hunk succeeds against 3.1 imaplib.py and works 
for me.

--
nosy: +joebauer
versions: +Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-03 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

In Python 2.6 PLAIN authentication works, in Python 3.1 not.

Lib/test/test_imaplib.py does not test IMAP4.authenticate() or 
IMAP4.login_cram_md5() functions, only IMAP4.login().

I would still like to go back to imaplib._Authenticator.encode() function. The 
function is below.

# inp = authobject(response)
def encode(self, inp):
oup = ''
while inp:
if len(inp)  48:
t = inp[:48]
inp = inp[48:]
else:
t = inp
inp = ''
e = binascii.b2a_base64(t)
if e:
oup = oup + e[:-1]
return oup

binascii.b2a_base64() takes bytes, so inp must therefore be bytes, and returns 
bytes (Python 3). Then str + bytes (out + e[:-1]) fails.

The fix would then be changing 
oup = oup + e[:-1]
to
oup = oup + e[:-1].decode()

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-03 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

I tried to fix the problem and the correct fix is to change
oup = ''
to
oup = b''

in imaplib._Authenticator.encode() function, and not what I suggested in my 
previous post.

After changing that PLAIN authentication works.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-03 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Would you be interested in providing a patch that includes tests?  I think 
Antoine set up a test framework for testing the login as part of issue 4471.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-03 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

Here's a patch with test.

I am not an IMAP guru, so please verify my patch.

--
keywords: +patch
Added file: http://bugs.python.org/file24132/issue13700.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-03 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

Here's another patch that should fix the CRAM-MD5 authentication. My previous 
patch is required with this one. The patch includes a test.

--
Added file: http://bugs.python.org/file24134/cram_md5.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread Erno Tukia

New submission from Erno Tukia erno.tu...@iki.fi:

 import imaplib
 imap = imaplib.IMAP4_SSL(imap.example.com)

 authcb = lambda resp: {0}\x00{0}\x00{1}.format(username,password)
 imap.authenticate(PLAIN, authcb)
Traceback (most recent call last):
  File pyshell#3, line 1, in module
imap.authenticate(PLAIN, authcb)
  File /usr/lib/python3.1/imaplib.py, line 361, in authenticate
typ, dat = self._simple_command('AUTHENTICATE', mech)
  File /usr/lib/python3.1/imaplib.py, line 1075, in _simple_command
return self._command_complete(name, self._command(name, *args))
  File /usr/lib/python3.1/imaplib.py, line 889, in _command
literal = literator(self.continuation_response)
  File /usr/lib/python3.1/imaplib.py, line 1238, in process
return self.encode(ret)
  File /usr/lib/python3.1/imaplib.py, line 1257, in encode
e = binascii.b2a_base64(t)
TypeError: must be bytes or buffer, not str

... and ...

 authcb = lambda resp: 
 {0}\x00{0}\x00{1}.format(username,password).encode()
 imap.authenticate(PLAIN, authcb)
Traceback (most recent call last):
  File pyshell#8, line 1, in module
imap.authenticate(PLAIN, authcb)
  File /usr/lib/python3.1/imaplib.py, line 361, in authenticate
typ, dat = self._simple_command('AUTHENTICATE', mech)
  File /usr/lib/python3.1/imaplib.py, line 1075, in _simple_command
return self._command_complete(name, self._command(name, *args))
  File /usr/lib/python3.1/imaplib.py, line 889, in _command
literal = literator(self.continuation_response)
  File /usr/lib/python3.1/imaplib.py, line 1238, in process
return self.encode(ret)
  File /usr/lib/python3.1/imaplib.py, line 1259, in encode
oup = oup + e[:-1]
TypeError: Can't convert 'bytes' object to str implicitly

--
components: Library (Lib)
messages: 150489
nosy: etukia
priority: normal
severity: normal
status: open
title: imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

The first argument to authenticate must be bytes.  This is not well documented. 
 It might also be a bug, since I'm not sure anyone has done a thorough audit of 
what should be bytes and what should be string in imaplib.

3.1 no longer gets bug fixes, so I'm removing it from versions.  Likewise I 
remove 3.4 since that applies only to changes that will *not* be put in 3.3 for 
some reason.

--
assignee:  - docs@python
components: +Documentation
nosy: +docs@python, r.david.murray
versions:  -Python 3.1, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

The same problems exists even if I use bPLAIN as the first argument in 
authenticate().

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Gah, I was looking at the wrong source code when I wrote that.  A string first 
argument is indeed valid.  I'm not sure where the problem is coming from since 
the internal CRAM_MD5 returns a string and that seems to work...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread Erno Tukia

Erno Tukia erno.tu...@iki.fi added the comment:

File /usr/lib/python3.1/imaplib.py, line 1257, in encode
e = binascii.b2a_base64(t)

imaplib._Authenticator.encode() calls binascii.b2a_base64() function. In Python 
2.6 that function returns a string, and in Python 3.1 it returns bytes. What is 
returned from b2a_base64() function is later in the encode() function 
concatenated with a string, with bytes that is not possible.

Should binascii.b2a_base64() return a string (2.6) or bytes (3.1)?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13700] imaplib.IMAP4.authenticate authobject fails with PLAIN mechanism

2012-01-02 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Bytes definitely.  We hashed that out a while ago.

My point is that CRAM_MD5 login calls authenticate, and its authenticator 
returns a string, just like your example does.  So it ought to be going through 
the same code path.  I haven't followed the logic in detail, though, so there 
must be some difference...I'm pretty sure the MD5 login has a test now (but not 
100% sure...)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13700
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com