wolfssl/swig/runme.py

41 lines
1.0 KiB
Python
Raw Normal View History

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