Rutger Semp
Rutger Semp

Reputation: 43

SSL error on Raspberry Pi

I recently purchased a Raspberry Pi to run some Python scripts, but when I ported it the function I wrote to send emails through Windows Live suddenly started handing out an SSL error after successful handshake, specifically:

error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

After extensive searching around, I found many people with the same error, but all in vastly different situations. The most relevant thing I could find was that it seemed to be an issue with a specific version of OpenSSL, but I could find nothing about the version running on my Pi (1.0.1e).

The function (which works perfectly fine on Win7):

def wlive(adr_to, adr_fro, adr_pass, adr_subj, adr_file):

    saveout = smtplib.stderr
    logger = open('wlive.log', 'w')
    smtplib.stderr = logger

    msg = MIMEMultipart()
    msg['Subject'] = adr_subj
    msg['From'] = adr_fro
    msg['To'] = adr_to


    if adr_file != None:
    # subtype recognition based on extension
        filext = os.path.splitext(adr_file)[1]
        if filext == '.png':
            subt = 'png'
        else:
            subt = 'jpeg'

        fp = open(adr_file, 'rb')
        img = MIMEImage(fp.read(), subt)
        fp.close()
        msg.attach(img)


    try: 
        server = smtplib.SMTP('smtp.live.com', 587)
        server.set_debuglevel(1)
        server.ehlo()
        server.starttls()
        server.login(adr_fro, adr_pass)
        server.sendmail(adr_fro, adr_to, msg.as_string())
        server.quit()
        return True

    except Exception, e:
        print 'wlive exception:\n\n', str(e)
        return False

    smtplib.stderr = saveout
    logger.close()

I'm running the fully updated and upgraded Raspbian "Wheezy" image, and Python 2.7.3

Upvotes: 1

Views: 2490

Answers (1)

mmateoo
mmateoo

Reputation: 101

I encountered this problem yesterday. First thing to try is to change the account from which you want to send an email to some other provider: try gmail, for instance. In my case it started working instantly.

If it's also the case for you (Microsoft's fault?), try another thing with windows live account (similar to the one suggested in the comment):
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof

then type:
ehlo
auth login
In my case nothing happened. No answer, only read timeout. This time try:
openssl s_client -connect smtp.live.com:587 -starttls smtp -crlf -ign_eof -no_tls1_2
Then:
ehlo
auth login
I got an answer immediately. If it's still your case, there's a little problem. I haven't found any way to specify such a parameter (which versions of tls to prevent from being used). What I found is that in python 3.3 you can give an additional context argument instarttls and you should be able to define some cipher parameters in this context. List of options can be found here.
I must admit that it was easier for me to just use the gmail account than to get python 3.3 (on rpi you've got 3.2 with no possibility of specifying the context), not being even sure if it will help. However, I hope that this information helps you somehow.

Upvotes: 1

Related Questions