]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/swig/runme.py
Update WolfSSL library to the latest version.
[freertos] / FreeRTOS-Plus / Source / WolfSSL / swig / runme.py
1 # file: runme.py
2
3 import wolfssl
4
5 print ""
6 print "Trying to connect to the example server -d..."
7
8 wolfssl.wolfSSL_Init()
9 #wolfssl.wolfSSL_Debugging_ON()
10 ctx = wolfssl.wolfSSL_CTX_new(wolfssl.wolfTLSv1_2_client_method())
11 if ctx == None:
12     print "Couldn't get SSL CTX for TLSv1.2"
13     exit(-1)
14
15 ret = wolfssl.wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
16 if ret != wolfssl.SSL_SUCCESS:
17     print "Couldn't do SSL_CTX_load_verify_locations "
18     print "error string = ", ret
19     exit(-1)
20
21 ssl = wolfssl.wolfSSL_new(ctx)
22 ret = wolfssl.wolfSSL_swig_connect(ssl, "localhost", 11111)
23
24 if ret != wolfssl.SSL_SUCCESS:
25     print "Couldn't do SSL connect"
26     err    = wolfssl.wolfSSL_get_error(ssl, 0)
27     if ret == -2:
28         print "tcp error, is example server running?"
29     else:
30         print "error string = ", wolfssl.wolfSSL_error_string(err)
31     exit(-1)
32
33 print "...Connected"
34 written = wolfssl.wolfSSL_write(ssl, "hello from python\r\n", 19)
35
36 if written > 0:
37     print "Wrote ", written, " bytes"
38
39 byteArray = wolfssl.byteArray(100)
40 readBytes = wolfssl.wolfSSL_read(ssl, byteArray, 100)
41
42 print "server reply: ", wolfssl.cdata(byteArray, readBytes)
43