]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/CyaSSL/swig/runme.py
Final commit before tagging - cosmetic changes only.
[freertos] / FreeRTOS-Plus / Source / CyaSSL / swig / runme.py
1 # file: runme.py
2
3 import cyassl 
4
5 print ""
6 print "Trying to connect to the echo server..."
7
8 cyassl.CyaSSL_Init()
9 #cyassl.CyaSSL_Debugging_ON()
10 ctx = cyassl.CyaSSL_CTX_new(cyassl.CyaTLSv1_client_method())
11 if ctx == None:
12     print "Couldn't get SSL CTX for TLSv1"
13     exit(-1)
14
15 ret = cyassl.CyaSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
16 if ret != cyassl.SSL_SUCCESS:
17     print "Couldn't do SSL_CTX_load_verify_locations "
18     print "error string = ", ret 
19     exit(-1)
20
21 ssl = cyassl.CyaSSL_new(ctx)
22 ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
23
24 if ret != cyassl.SSL_SUCCESS:
25     print "Couldn't do SSL connect"
26     err    = cyassl.CyaSSL_get_error(ssl, 0)
27     print "error string = ", cyassl.CyaSSL_error_string(err)
28     exit(-1)
29
30 print "...Connected"
31 written = cyassl.CyaSSL_write(ssl, "hello from python\r\n", 19)
32
33 if written > 0:
34     print "Wrote ", written, " bytes"
35
36 byteArray = cyassl.byteArray(100)
37 readBytes = cyassl.CyaSSL_read(ssl, byteArray, 100)
38
39 print "server reply: ", cyassl.cdata(byteArray, readBytes) 
40