import ssl fails

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Nico
Posts: 10
Joined: Wed Oct 28, 2015 6:56 am

import ssl fails

Post by Nico » Sun Nov 15, 2015 8:05 pm

Hi,

I'm using unix micropython, with head revision from master and I'm failing with import ssl :

Code: Select all

$ ./unix/micropython
MicroPython v1.5-138-g3862ef9 on 2015-11-14; darwin version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'ssl'
I can't find any ssl module in microypthon-libs so I guessed is was built-in.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: import ssl fails

Post by platforma » Sun Nov 15, 2015 9:51 pm


pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: import ssl fails

Post by pfalcon » Mon Nov 16, 2015 11:19 am

"ussl" module isn't yet enabled by default in unix build, as we'd like to collect more feedback from people first (feedback from MacOS users in particular is welcome). As usual, information on how to enable that module can be found in README.md, (e.g. as shown at https://github.com/micropython/micropython )
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Nico
Posts: 10
Joined: Wed Oct 28, 2015 6:56 am

Re: import ssl fails

Post by Nico » Mon Nov 16, 2015 8:49 pm

Sorry, I missed that documentation. Now I've followed the instruction. I've done:

Code: Select all

$ git submodule update --init
plus enabled SSL (MICROPY_PY_USSL=1)
When running $ make deplibs I get:

Code: Select all

cd ../lib/axtls; make all CC="clang" LD="ld"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C crypto
In file included from aes.c:38:
In file included from ../ssl/os_port.h:40:
./os_int.h:59:10: fatal error: 'endian.h' file not found
#include <endian.h>
According to here, I've added this in the makefile :

Code: Select all

INC += -I/usr/include/machine in the Makefile. 
Using this configuration, make goes further but I get another error :

Code: Select all

$ make deplibs
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
cd ../lib/libffi; git clean -d -x -f
Removing Makefile.in
Removing aclocal.m4
Removing autom4te.cache/
Removing build_dir/
Removing compile
Removing config.guess
Removing config.sub
Removing configure
Removing depcomp
Removing fficonfig.h.in
Removing include/Makefile.in
Removing install-sh
Removing ltmain.sh
Removing m4/libtool.m4
Removing m4/ltoptions.m4
Removing m4/ltsugar.m4
Removing m4/ltversion.m4
Removing m4/lt~obsolete.m4
Removing man/Makefile.in
Removing mdate-sh
Removing missing
Removing testsuite/Makefile.in
cd ../lib/libffi; ./autogen.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: /opt/local/bin/aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: /opt/local/bin/glibtoolize --copy --force
glibtoolize: putting auxiliary files in '.'.
glibtoolize: copying file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: copying file 'm4/libtool.m4'
glibtoolize: copying file 'm4/ltoptions.m4'
glibtoolize: copying file 'm4/ltsugar.m4'
glibtoolize: copying file 'm4/ltversion.m4'
glibtoolize: copying file 'm4/lt~obsolete.m4'
autoreconf: running: /opt/local/bin/autoconf --force
autoreconf: running: /opt/local/bin/autoheader --force
autoreconf: running: /opt/local/bin/automake --add-missing --copy --force-missing
configure.ac:31: installing './compile'
configure.ac:8: installing './config.guess'
configure.ac:8: installing './config.sub'
configure.ac:19: installing './install-sh'
configure.ac:19: installing './missing'
Makefile.am: installing './depcomp'
Makefile.am:18: installing './mdate-sh'
autoreconf: Leaving directory `.'
mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
	../configure  --prefix=$PWD/out CC="clang" CXX="g++" LD="ld"; \
	make install-exec-recursive; make -C include install-data-am
checking build system type... x86_64-apple-darwin15.0.0
checking host system type... x86_64-apple-darwin15.0.0
checking target system type... x86_64-apple-darwin15.0.0
checking for gsed... sed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ../install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/Users/nico/Dev/micropython/micropython/lib/libffi/build_dir':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** No rule to make target `install-exec-recursive'.  Stop.
make: *** include: No such file or directory.  Stop.
make: *** [libffi] Error 2

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: import ssl fails

Post by pfalcon » Mon Nov 16, 2015 9:26 pm

Nico wrote:Sorry, I missed that documentation. Now I've followed the instruction. I've done:

Code: Select all

$ git submodule update --init
plus enabled SSL (MICROPY_PY_USSL=1)
When running $ make deplibs I get:

Code: Select all

cd ../lib/axtls; make all CC="clang" LD="ld"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C crypto
In file included from aes.c:38:
In file included from ../ssl/os_port.h:40:
./os_int.h:59:10: fatal error: 'endian.h' file not found
#include <endian.h>
According to here, I've added this in the makefile :

Code: Select all

INC += -I/usr/include/machine in the Makefile. 
We use patched axtls, so feel free to submit patch for it which #include <machine/endian.h> on MacOSX.
Using this configuration, make goes further but I get another error :

Code: Select all

$ make deplibs
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
cd ../lib/libffi; git clean -d -x -f
Removing Makefile.in
Removing aclocal.m4
Removing autom4te.cache/
Removing build_dir/
Removing compile
Removing config.guess
Removing config.sub
Removing configure
Removing depcomp
Removing fficonfig.h.in
Removing include/Makefile.in
Removing install-sh
Removing ltmain.sh
Removing m4/libtool.m4
Removing m4/ltoptions.m4
Removing m4/ltsugar.m4
Removing m4/ltversion.m4
Removing m4/lt~obsolete.m4
Removing man/Makefile.in
Removing mdate-sh
Removing missing
Removing testsuite/Makefile.in
cd ../lib/libffi; ./autogen.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: /opt/local/bin/aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: /opt/local/bin/glibtoolize --copy --force
glibtoolize: putting auxiliary files in '.'.
glibtoolize: copying file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: copying file 'm4/libtool.m4'
glibtoolize: copying file 'm4/ltoptions.m4'
glibtoolize: copying file 'm4/ltsugar.m4'
glibtoolize: copying file 'm4/ltversion.m4'
glibtoolize: copying file 'm4/lt~obsolete.m4'
autoreconf: running: /opt/local/bin/autoconf --force
autoreconf: running: /opt/local/bin/autoheader --force
autoreconf: running: /opt/local/bin/automake --add-missing --copy --force-missing
configure.ac:31: installing './compile'
configure.ac:8: installing './config.guess'
configure.ac:8: installing './config.sub'
configure.ac:19: installing './install-sh'
configure.ac:19: installing './missing'
Makefile.am: installing './depcomp'
Makefile.am:18: installing './mdate-sh'
autoreconf: Leaving directory `.'
mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
	../configure  --prefix=$PWD/out CC="clang" CXX="g++" LD="ld"; \
	make install-exec-recursive; make -C include install-data-am
[]
make[1]: *** No rule to make target `install-exec-recursive'.  Stop.
make: *** include: No such file or directory.  Stop.
make: *** [libffi] Error 2
Ok, feel free to just use "make axtls" instead of "make deplibs" for your case.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Nico
Posts: 10
Joined: Wed Oct 28, 2015 6:56 am

Re: import ssl fails

Post by Nico » Mon Nov 16, 2015 9:53 pm

Running "make axtls gives":

Code: Select all

$ make axtls
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
cd ../lib/axtls; cp config/upyconfig config/.config
cd ../lib/axtls; make oldconfig -B
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C config/scripts/config conf
cp ../../scripts/config/zconf.tab.h_shipped zconf.tab.h
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -I. -c ../../scripts/config/conf.c -o conf.o
cp ../../scripts/config/zconf.tab.c_shipped zconf.tab.c
cp ../../scripts/config/lex.zconf.c_shipped lex.zconf.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -I../../scripts/config -I. -c zconf.tab.c -o zconf.tab.o
In file included from zconf.tab.c:2123:
lex.zconf.c:2969:16: warning: 'static' function 'input' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
    static int input  (void)
               ^
1 warning generated.
gcc  conf.o zconf.tab.o -o conf
#
# using defaults found in config/.config
#
*
* axTLS Configuration
*
Platform
> 1. Linux (CONFIG_PLATFORM_LINUX)
  2. Cygwin (CONFIG_PLATFORM_CYGWIN)
  3. Win32 (CONFIG_PLATFORM_WIN32)
choice[1-3]: 1
*
* General Configuration
*
axTLS installation prefix (PREFIX) [/usr/local] /usr/local
Build axTLS with Debugging symbols (CONFIG_DEBUG) [N/y/?] n
  Strip unwanted sections from elf binaries (CONFIG_STRIP_UNWANTED_SECTIONS) [N/y/?] n
Any extra CFLAGS options for the compiler? (CONFIG_EXTRA_CFLAGS_OPTIONS) []
Any extra LDFLAGS options for the compiler? (CONFIG_EXTRA_LDFLAGS_OPTIONS) []
*
* SSL Library
*
Mode
  1. Server only - no verification (CONFIG_SSL_SERVER_ONLY)
  2. Server only - with verification (CONFIG_SSL_CERT_VERIFICATION)
  3. Client/Server enabled with diagnostics (CONFIG_SSL_FULL_MODE)
> 4. Skeleton mode - the smallest server mode (CONFIG_SSL_SKELETON_MODE)
choice[1-4]: 4
Client enabled (CONFIG_SSL_ENABLE_CLIENT) [Y/n/?] y
Diagnostic messages (CONFIG_SSL_DIAGNOSTICS) [N/y/?] n
Protocol Preference
> 1. Low (CONFIG_SSL_PROT_LOW)
  2. Medium (CONFIG_SSL_PROT_MEDIUM)
  3. High (CONFIG_SSL_PROT_HIGH)
choice[1-3]: 1
Enable AES cipher (CONFIG_SSL_AES) [Y/n/?] y
Generate X.509 Certificate (CONFIG_SSL_GENERATE_X509_CERT) [N/y/?] n
Enable v23 Handshake (CONFIG_SSL_ENABLE_V23_HANDSHAKE) [N/y/?] n
Maximum number of chained certificates (CONFIG_SSL_MAX_CERTS) [3] 3
Enable SSL_CTX mutexing (CONFIG_SSL_CTX_MUTEXING) [N/y/?] n
Use /dev/urandom (CONFIG_USE_DEV_URANDOM) [N/y/?] n
Enable openssl API compatibility (CONFIG_OPENSSL_COMPATIBLE) [N/y/?] n
Enable axtlswrap (CONFIG_AXTLSWRAP) [N/y/?] n
Enable HTTP/HTTPS Web Server (CONFIG_AXHTTPD) [N/y/?] n
*
* Language Bindings
*
Create language bindings (CONFIG_BINDINGS) [N/y/?] n
*
* Samples
*
Create Samples (CONFIG_SAMPLES) [N/y/?] n
cd ../lib/axtls; make clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C test clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C c clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C csharp clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C vbnet clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C java clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C perl clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C lua clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C csharp clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C vbnet clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C java clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C perl clean
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C lua clean
cd ../lib/axtls; make all CC="clang" LD="ld"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C crypto
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o aes.o aes.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o bigint.o bigint.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o crypto_misc.o crypto_misc.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o hmac.o hmac.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o md5.o md5.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o rc4.o rc4.c
clang -I../lib/netutils -I. -I.. -Ibuild -I/usr/include/machine -I../lib/mp-readline -Wall -Werror -Wpointer-arith -Wuninitialized -ansi -std=gnu99 -DUNIX -DMICROPY_PY_USSL=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config -DMICROPY_USE_READLINE=1 -DMICROPY_PY_TIME=1 -DMICROPY_PY_TERMIOS=1 -DMICROPY_PY_SOCKET=1 -I/opt/local/lib/libffi-3.2.1/include  -DMICROPY_PY_FFI=1 -Os   -I/config -I/ssl -I/crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables   -I../config -I../ssl -I../crypto -Wall -Wstrict-prototypes -Wshadow -g -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables     -c -o rsa.o rsa.c
In file included from rsa.c:36:
/usr/include/stdio.h:77:9: error: unknown type name '__darwin_off_t'
typedef __darwin_off_t          fpos_t;
        ^
In file included from rsa.c:36:
In file included from /usr/include/stdio.h:411:
/usr/include/sys/_types/_off_t.h:30:9: error: unknown type name '__darwin_off_t'
typedef __darwin_off_t          off_t;
        ^
2 errors generated.
make[2]: *** [rsa.o] Error 1
make[1]: *** [target] Error 2
make: *** [axtls] Error 2
I tried to google the error message, but I didn't find something evident.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: import ssl fails

Post by pfalcon » Mon Nov 16, 2015 10:33 pm

Well, this is very weird, including stdio.h of course shouldn't lead to such error on any system (anything required by it should be pulled in by itself). But well, you have your entire /usr/include , grep thru it, try to see what defines __darwin_off_t, try to include it manually before stdio.h, but ultimately, you should figure why it's not included automagically, while it should.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: import ssl fails

Post by pfalcon » Mon Nov 16, 2015 10:40 pm

And generally, your logs look strange. Do you use GNU make? Do you run it with -j1?
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

cabalist
Posts: 7
Joined: Thu Jun 02, 2016 7:37 pm

Re: import ssl fails

Post by cabalist » Thu Jun 02, 2016 7:42 pm

We are having the same issue at the Pycon sprint.

Link to the issue (with a solution) here:
https://github.com/micropython/micropython/issues/2143

Post Reply