runme.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # file: runme.py
  2. import cyassl
  3. print ""
  4. print "Trying to connect to the echo server..."
  5. cyassl.CyaSSL_Init()
  6. #cyassl.CyaSSL_Debugging_ON()
  7. ctx = cyassl.CyaSSL_CTX_new(cyassl.CyaTLSv1_client_method())
  8. if ctx == None:
  9. print "Couldn't get SSL CTX for TLSv1"
  10. exit(-1)
  11. ret = cyassl.CyaSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
  12. if ret != cyassl.SSL_SUCCESS:
  13. print "Couldn't do SSL_CTX_load_verify_locations "
  14. print "error string = ", ret
  15. exit(-1)
  16. ssl = cyassl.CyaSSL_new(ctx)
  17. ret = cyassl.CyaSSL_swig_connect(ssl, "localhost", 11111)
  18. if ret != cyassl.SSL_SUCCESS:
  19. print "Couldn't do SSL connect"
  20. err = cyassl.CyaSSL_get_error(ssl, 0)
  21. print "error string = ", cyassl.CyaSSL_error_string(err)
  22. exit(-1)
  23. print "...Connected"
  24. written = cyassl.CyaSSL_write(ssl, "hello from python\r\n", 19)
  25. if written > 0:
  26. print "Wrote ", written, " bytes"
  27. byteArray = cyassl.byteArray(100)
  28. readBytes = cyassl.CyaSSL_read(ssl, byteArray, 100)
  29. print "server reply: ", cyassl.cdata(byteArray, readBytes)