runme.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # file: runme.py
  2. import wolfssl
  3. print ""
  4. print "Trying to connect to the example server -d..."
  5. wolfssl.wolfSSL_Init()
  6. #wolfssl.wolfSSL_Debugging_ON()
  7. ctx = wolfssl.wolfSSL_CTX_new(wolfssl.wolfTLSv1_2_client_method())
  8. if ctx == None:
  9. print "Couldn't get SSL CTX for TLSv1.2"
  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. if ret == -2:
  22. print "tcp error, is example server running?"
  23. else:
  24. print "error string = ", wolfssl.wolfSSL_error_string(err)
  25. exit(-1)
  26. print "...Connected"
  27. written = wolfssl.wolfSSL_write(ssl, "hello from python\r\n", 19)
  28. if written > 0:
  29. print "Wrote ", written, " bytes"
  30. byteArray = wolfssl.byteArray(100)
  31. readBytes = wolfssl.wolfSSL_read(ssl, byteArray, 100)
  32. print "server reply: ", wolfssl.cdata(byteArray, readBytes)