wolfssl/swig/runme.py

41 lines
1.0 KiB
Python
Raw Normal View History

2011-02-05 13:14:47 -06:00
# file: runme.py
import cyassl
print ""
print "Trying to connect to the echo server..."
2011-11-09 19:58:37 -06:00
cyassl.CyaSSL_Init()
#cyassl.CyaSSL_Debugging_ON()
2011-11-09 20:05:27 -06:00
ctx = cyassl.CyaSSL_CTX_new(cyassl.CyaTLSv1_client_method())
2011-11-09 19:58:37 -06:00
if ctx == None:
print "Couldn't get SSL CTX for TLSv1"
exit(-1)
2011-11-09 20:05:27 -06:00
ret = cyassl.CyaSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
2011-11-09 19:58:37 -06:00
if ret != cyassl.SSL_SUCCESS:
print "Couldn't do SSL_CTX_load_verify_locations "
print "error string = ", ret
exit(-1)
2011-02-05 13:14:47 -06:00
2011-11-09 20:05:27 -06:00
ssl = cyassl.CyaSSL_new(ctx)
ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
2011-02-05 13:14:47 -06:00
if ret != cyassl.SSL_SUCCESS:
print "Couldn't do SSL connect"
2011-11-09 20:05:27 -06:00
err = cyassl.CyaSSL_get_error(ssl, 0)
2011-02-05 13:14:47 -06:00
print "error string = ", cyassl.CyaSSL_error_string(err)
exit(-1)
print "...Connected"
2011-11-09 20:05:27 -06:00
written = cyassl.CyaSSL_write(ssl, "hello from python\r\n", 19)
2011-02-05 13:14:47 -06:00
if written > 0:
print "Wrote ", written, " bytes"
byteArray = cyassl.byteArray(100)
2011-11-09 20:05:27 -06:00
readBytes = cyassl.CyaSSL_read(ssl, byteArray, 100)
2011-02-05 13:14:47 -06:00
print "server reply: ", cyassl.cdata(byteArray, readBytes)