runme.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # file: runme.py
  2. import wolfssl
  3. print ""
  4. print "Trying to connect to the echo server..."
  5. wolfssl.wolfSSL_Init()
  6. #wolfssl.wolfSSL_Debugging_ON()
  7. ctx = wolfssl.wolfSSL_CTX_new(wolfssl.wolfTLSv1_client_method())
  8. if ctx == None:
  9. print "Couldn't get SSL CTX for TLSv1"
  10. exit(-1)
  11. ret = wolfssl.wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", None)
  12. if ret != wolfssl.SSL_SUCCESS:
  13. print "Couldn't do SSL_CTX_load_verify_locations "
  14. print "error string = ", ret
  15. exit(-1)
  16. ssl = wolfssl.wolfSSL_new(ctx)
  17. ret = wolfssl.wolfSSL_swig_connect(ssl, "localhost", 11111)
  18. if ret != wolfssl.SSL_SUCCESS:
  19. print "Couldn't do SSL connect"
  20. err = wolfssl.wolfSSL_get_error(ssl, 0)
  21. print "error string = ", wolfssl.wolfSSL_error_string(err)
  22. exit(-1)
  23. print "...Connected"
  24. written = wolfssl.wolfSSL_write(ssl, "hello from python\r\n", 19)
  25. if written > 0:
  26. print "Wrote ", written, " bytes"
  27. byteArray = wolfssl.byteArray(100)
  28. readBytes = wolfssl.wolfSSL_read(ssl, byteArray, 100)
  29. print "server reply: ", wolfssl.cdata(byteArray, readBytes)