[issue25446] smtplib.py AUTH LOGIN code messed up sending login and password data since 3.5

2015-10-20 Thread Oliver Merkel

New submission from Oliver Merkel:

class SMTP:
def auth_login(self, challenge=None):

The self.docmd should use cmd "AUTH" with parameter "LOGIN" + encoded login like

(code, resp) = self.docmd("AUTH", "LOGIN " +
encode_base64(self.user.encode('ascii'), eol=''))

with

def auth(self, mechanism, authobject, *, initial_response_ok=True):

that should not send a "AUTH" in self.docmd in case the mechanism is 'LOGIN' and

if initial_response is not None:

meaning

if mechanism == 'LOGIN':
(code, resp) = self.docmd(response)
else:
(code, resp) = self.docmd("AUTH", mechanism + " " + response)

---

Could someone kindly review, evtly come up with better suggestion?

In short:
$ diff /c/Python35/Lib/smtplib-old.py /c/Python35/Lib/smtplib.py
630c630,633
< (code, resp) = self.docmd("AUTH", mechanism + " " + response)
---
> if mechanism == 'LOGIN':
> (code, resp) = self.docmd(response)
> else:
> (code, resp) = self.docmd("AUTH", mechanism + " " + response)
660c663
< (code, resp) = self.docmd(
---
> (code, resp) = self.docmd("AUTH", "LOGIN " +

--
components: email
messages: 253225
nosy: barry, merkel, r.david.murray
priority: normal
severity: normal
status: open
title: smtplib.py AUTH LOGIN code messed up sending login and password data 
since 3.5
type: behavior
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue25446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25446] smtplib.py AUTH LOGIN code messed up sending login and password data since 3.5

2015-10-20 Thread Oliver Merkel

Oliver Merkel added the comment:

Let us assume you want to establish a smtp session with AUTH LOGIN as the 
supported authentication type. Sample code to send mail: Typical preparation 
steps like

with SMTP( mailserver, 587 ) as smtp:
  # smtp.set_debuglevel(1)
  smtp.ehlo()
  smtp.starttls()
  smtp.ehlo()
  smtp.login( account, password )

If you try to login (last line in sample code above) at the smtp server then 
the smtp server will expect a command to be send like

AUTH LOGIN 

Now switching from sample code to our smtplib.py:

Since the "AUTH LOGIN" is missing in original Python35/Lib/smtplib.py in line...

660c663
< (code, resp) = self.docmd(
---
> (code, resp) = self.docmd("AUTH", "LOGIN " +

... the smtp server will answer that the library is sending an unknown command 
here. That is why I added... "AUTH", "LOGIN " + ...at this line.

Line 660 in class SMTP: def auth_login is called before it reaches line 630 in 
class SMTP: def auth

In case of authentication type AUTH LOGIN in line 630 you must not call with 
"AUTH", mechanism + " " +

So the following changes have to be applied at least for AUTH LOGIN mechanism

630c630,633
< (code, resp) = self.docmd("AUTH", mechanism + " " + response)
---
> if mechanism == 'LOGIN':
> (code, resp) = self.docmd(response)
> else:
> (code, resp) = self.docmd("AUTH", mechanism + " " + response)

The first change affecting line 660 described above will will imply that the 
you remove the AUTH mechanism in line 630. For mechanism LOGIN the base64 
encoded password will be needed to be sent in 660...

See possible fix in the diff above.

To ease understanding the fix I will apply a running version of my local 
Lib/smtplib.py (instead of just providing the diff lines). Feel free to 
directly use the file.

--
Added file: http://bugs.python.org/file40828/smtplib.py

___
Python tracker 
<http://bugs.python.org/issue25446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25446] smtplib.py AUTH LOGIN code messed up sending login and password data since 3.5

2015-10-20 Thread Oliver Merkel

Oliver Merkel added the comment:

Sample session log output showing the error with smtp.set_debuglevel(1):

send: 'ehlo \r\n'
reply: b'250- Hello [myIP4address]\r\n'
reply: b'250-SIZE 53248000\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-DSN\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250-STARTTLS\r\n'
reply: b'250-AUTH GSSAPI NTLM\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-BINARYMIME\r\n'
reply: b'250 CHUNKING\r\n'
reply: retcode (250); Msg: b' Hello [myIP4address]\
nSIZE 53248000\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\nSTARTTLS\nAUTH GSSAPI NTLM
\n8BITMIME\nBINARYMIME\nCHUNKING'
send: 'STARTTLS\r\n'
reply: b'220 2.0.0 SMTP server ready\r\n'
reply: retcode (220); Msg: b'2.0.0 SMTP server ready'
send: 'ehlo [mymachinename]\r\n'
reply: b'250- Hello [myIP4address]\r\n'
reply: b'250-SIZE 53248000\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-DSN\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250-AUTH GSSAPI NTLM LOGIN\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-BINARYMIME\r\n'
reply: b'250 CHUNKING\r\n'
reply: retcode (250); Msg: b' Hello [myIP4address]\
nSIZE 53248000\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\nAUTH GSSAPI NTLM LOGIN\n8B
ITMIME\nBINARYMIME\nCHUNKING'
send: '==\r\n'
reply: b'500 5.3.3 Unrecognized command\r\n'
reply: retcode (500); Msg: b'5.3.3 Unrecognized command'
send: 'QUIT\r\n'
reply: b'221 2.0.0 Service closing transmission channel\r\n'
reply: retcode (221); Msg: b'2.0.0 Service closing transmission channel'
Traceback (most recent call last):
  File "sendtestmail.py", line 172, in 
announcement.sendMail(password)
  File "sendtestmail.py", line 97, in sendMail
smtp.login( self.getShortAddressList()[0], password )
  File "c:\Python35\lib\smtplib.py", line 730, in login
raise last_exception
  File "c:\Python35\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
  File "c:\Python35\lib\smtplib.py", line 627, in auth
initial_response = (authobject() if initial_response_ok else None)
  File "c:\Python35\lib\smtplib.py", line 664, in auth_login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (500, b'5.3.3 Unrecognized command')

due to missing AUTH LOGIN here as previously described...

--

___
Python tracker 
<http://bugs.python.org/issue25446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25446] smtplib.py AUTH LOGIN code messed up sending login and password data since 3.5

2015-10-20 Thread Oliver Merkel

Oliver Merkel added the comment:

Change proposal attached as a unified diff / patch file.

--
keywords: +patch
Added file: http://bugs.python.org/file40829/smtplib-patch.issue25446.patch

___
Python tracker 
<http://bugs.python.org/issue25446>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com