ussl.wrap_socket results in OSError: [Errno -1] ERR_MEM



  • Hi all,
    I'm stuck on a problem which does not occur in python on PC:

    import ussl, socket
    s=socket.socket()
    s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    s.bind(('0.0.0.0',443))
    s.listen(16)
    conn, addr = s.accept()
    

    gives the follwowing output with curl:

    daniel@trias:~$ curl -v -k https://192.168.4.1
    * Expire in 0 ms for 6 (transfer 0x55aafe83ff30)
    *   Trying 192.168.4.1...
    * TCP_NODELAY set
    * Expire in 200 ms for 4 (transfer 0x55aafe83ff30)
    * Connected to 192.168.4.1 (192.168.4.1) port 443 (#0)
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *   CAfile: /home/daniel/anaconda3/ssl/cacert.pem
      CApath: none
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    

    That looks good. However, if I continue to wrap the connection into ssl, the handshake is done, but after that the error is given:

    sslconn = ussl.wrap_socket(conn, server_side = True, keyfile = '/flash/cert/device.key', certfile = '/flash/cert/device.crt')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno -1] ERR_MEM
    
    

    curl continues:

    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
    * ALPN, server did not agree to a protocol
    * Server certificate:
    *  subject: C=AU; ST=Some-State; O=Internet Widgits Pty Ltd; CN=192.168.4.1
    *  start date: Oct 10 12:24:08 2019 GMT
    *  expire date: Dec 14 12:24:08 2038 GMT
    *  issuer: C=AU; ST=Some-State; O=Internet Widgits Pty Ltd
    *  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
    > GET / HTTP/1.1
    > Host: 192.168.4.1
    > User-Agent: curl/7.64.0
    > Accept: */*
    

    Someone else seems to have no issues with this when he modified microWebSrv accordingly:
    microWebSrv - HTTPS and WSS support #55
    So it seems to be WiPy related.

    Here some additional info and input for easy reconstruction:

    >>> os.uname()
    (sysname='WiPy', nodename='WiPy', release='1.20.1.r1', version='3138a13d on 2019-10-08', machine='WiPy with ESP32')
    

    device.crt:

    -----BEGIN CERTIFICATE-----
    MIIDJzCCAg8CFC+R6gilkabtpc5uGukrYlG/J0hLMA0GCSqGSIb3DQEBCwUAMEUx
    CzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRl
    cm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTkxMDEwMTIyNDA4WhcNMzgxMjE0MTIy
    NDA4WjBbMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UE
    CgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRQwEgYDVQQDDAsxOTIuMTY4LjQu
    MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMP/YDQnq1Jqrku782rY
    rV+UVun1STrjlt7bWb3cZn1ehzLcnjcP9VpIlVlNu6uTZhiJTKBDNXHrHzWpuYYX
    XWrel3/96sXZsFCVZqCegIG/4ZYunCzvJNDG3WSP5NjHHhI0z6600JCPeu8X3ha4
    6OMzz13em+BYQ6AMstN7zYhovQmePZ6TZ7ZxLEeCsOwf5z2Enu02OceWjsDl+Db0
    1lkSx6ExhhuG9YOHtP8l7GqpX/TVCoRNBv0lgUX+TuKfmbMbfsNvB2xW5e8KvJUp
    xPgBIDzz9V4ygrM1AeSeiqDeuNB0nnLceYUNGu5CLcRdv0He6PMIWc7gHEnRydI+
    vBECAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAHtoAWF9wsQ/S3qsbu6dRYDY4Ta3l
    ONlwigyDz2KCluLJ9mO6/ViIVu6PHWSSH63P6iDuENDw5rk5BG5SrQwfOlwH7agd
    cTOGJLMWtx2sUUe1YFMawSi8wlndp1tDZ3A7xISri5DACj3LQYC7mKUoiMNEyg0r
    FLxIrvKHDCXQOcvBgl99MfKQQgdbEmnlM8qmKRK9w4jEueySW4h0Iy4S0r4r8XbI
    K0v1WpezqnACw2KX3frPtiGyepSSQhIxk6FVewCw9jiAQwu0E6EBt9hmxJSrA8s3
    wIWim08N218isZPbfRUy0lemhxybg+TQPx1maJ3FIh/aPRfoCSwLKIwwQw==
    -----END CERTIFICATE-----
    

    device.key:

    -----BEGIN RSA PRIVATE KEY-----
    MIIEpgIBAAKCAQEAw/9gNCerUmquS7vzatitX5RW6fVJOuOW3ttZvdxmfV6HMtye
    Nw/1WkiVWU27q5NmGIlMoEM1cesfNam5hhddat6Xf/3qxdmwUJVmoJ6Agb/hli6c
    LO8k0MbdZI/k2MceEjTPrrTQkI967xfeFrjo4zPPXd6b4FhDoAyy03vNiGi9CZ49
    npNntnEsR4Kw7B/nPYSe7TY5x5aOwOX4NvTWWRLHoTGGG4b1g4e0/yXsaqlf9NUK
    hE0G/SWBRf5O4p+Zsxt+w28HbFbl7wq8lSnE+AEgPPP1XjKCszUB5J6KoN640HSe
    ctx5hQ0a7kItxF2/Qd7o8whZzuAcSdHJ0j68EQIDAQABAoIBAQCuCYwRg9AbJOOU
    GFbzX2fD4WKz6LyX8BO93CT59EWFuXRv83sCBcel3aHQZLfqiL41t2U1QbipaVCT
    RBybNxAan4EDhCL+gGiRhbhVk6kkjY/w3X6MX+XfBVb9vtBEtbq8C+0Gg0RXuTA+
    MoFgx9z0MsNF5S+grH+QFPaN1/cP0fL+dMe944pzUT+51oJy8R+47+vA0h1Hr7kW
    JSrCcqLBQ3X5sV+RGTX4pgKkMZWcqopXuigD7nFOAynq6rJWRuwzW6xEHykPOVch
    58mgAKYTKH7FPVErQbidWL/0DLEWbAh1GJl+iXP5f9buCPbGVkKf7A/IElYRSnDg
    HX7hWiipAoGBAOwXdEcXWMg7OHKXoKdyNlttavPZV77XPwDaQIDLL8xybDab+32A
    reSmyY5GdQ672wJY8qqmJghIn3DaQO+732MA1p4C1iMucLoF258n/p3MH6ZtF9xp
    vqtUS5TGVfuYG2uwdG7tGedGgq4hmBCiCMw1xdrBtc6Hh6SQCQMcHwFTAoGBANSG
    Z7Lk07NchHAM7CUUFZP38JzvisProW3VDsbF9BX/tzUH0XTR9MZ9+BcalASETTIK
    DXgP9OkPSI54wiA/wios47i2e1wY77CHYTI1Z5ZUA/TEcrqcFrRd8mLG5bTYBCPL
    iuURRu2ybA1HRq6ooZO+q8rcGlvAsAI0zqqmfmyLAoGBALMqjXSR9C9oOctE5IeO
    dk/l9n991kgew1JbTw4upGSMBTFgKHey2sSmClmtgJIg3/ClHeuBUWWB73XOO+9y
    7PEOJtEdJ/LlAGk7ntLmoCSSTwaWzb/Yg/kzbHRIG+JmKZENBR9VUg4ghXWuSt98
    iB6pRDBiRx2n3rl1EVHJ2oG/AoGBAJayg3+noLHTTZnCoAQevLpCmpw9gzEvuTUP
    Wb37Cfw7aiaxV4W1hxLkqfGACCs3wSFVXX2gGvLTwog7+rMxYrXTRNpqkwiYKgYL
    yRD4K26+PlvmnM/T9ImLAF+oV6OndTAImYGagaf014eG3gjlTEVec6SR9CLRfDzk
    QxNgoc7HAoGBANv9gV8Taq1f9U8I1svI7ITYuB+zLU4A9r/vnHmSP/s0mAYVeu+C
    S/e1ErBRe5TNmp3ME1J4PmY9cww0KrLWmLFRHQI97jskN+bxTNE4Em/JcQ3EZAZg
    ZvXBYQ7kPQD3poBlXZ/DXERWnrDTuK7ZXdOOab0JlF/kiwJSi3hzrnMG
    -----END RSA PRIVATE KEY-----
    

Log in to reply
 

Pycom on Twitter