wolfssl/swig/runme.py

44 lines
1.1 KiB
Python
Raw Normal View History

2011-02-05 13:14:47 -06:00
# file: runme.py
2015-01-08 15:47:41 -06:00
import wolfssl
2011-02-05 13:14:47 -06:00
print ""
print "Trying to connect to the example server -d..."
2011-02-05 13:14:47 -06:00
2015-01-08 15:47:41 -06:00
wolfssl.wolfSSL_Init()
#wolfssl.wolfSSL_Debugging_ON()
ctx = wolfssl.wolfSSL_CTX_new(wolfssl.wolfTLSv1_2_client_method())
2011-11-09 19:58:37 -06:00
if ctx == None:
print "Couldn't get SSL CTX for TLSv1.2"
2011-11-09 19:58:37 -06:00
exit(-1)
2015-01-08 15:47:41 -06:00
ret = wolfssl.wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
if ret != wolfssl.SSL_SUCCESS:
2011-11-09 19:58:37 -06:00
print "Couldn't do SSL_CTX_load_verify_locations "
2015-01-08 15:47:41 -06:00
print "error string = ", ret
2011-11-09 19:58:37 -06:00
exit(-1)
2011-02-05 13:14:47 -06:00
2015-01-08 15:47:41 -06:00
ssl = wolfssl.wolfSSL_new(ctx)
ret = wolfssl.wolfSSL_swig_connect(ssl, "localhost", 11111)
2011-02-05 13:14:47 -06:00
2015-01-08 15:47:41 -06:00
if ret != wolfssl.SSL_SUCCESS:
2011-02-05 13:14:47 -06:00
print "Couldn't do SSL connect"
2015-01-08 15:47:41 -06:00
err = wolfssl.wolfSSL_get_error(ssl, 0)
if ret == -2:
print "tcp error, is example server running?"
else:
print "error string = ", wolfssl.wolfSSL_error_string(err)
2011-02-05 13:14:47 -06:00
exit(-1)
print "...Connected"
2015-01-08 15:47:41 -06:00
written = wolfssl.wolfSSL_write(ssl, "hello from python\r\n", 19)
2011-02-05 13:14:47 -06:00
if written > 0:
print "Wrote ", written, " bytes"
2015-01-08 15:47:41 -06:00
byteArray = wolfssl.byteArray(100)
readBytes = wolfssl.wolfSSL_read(ssl, byteArray, 100)
2011-02-05 13:14:47 -06:00
2015-01-08 15:47:41 -06:00
print "server reply: ", wolfssl.cdata(byteArray, readBytes)
2011-02-05 13:14:47 -06:00