<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — Connection between Arduino client and Python server]]></title>
		<link>https://www.wolfssl.com/forums/topic1834-connection-between-arduino-client-and-python-server.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1834.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Connection between Arduino client and Python server.]]></description>
		<lastBuildDate>Thu, 30 Dec 2021 22:45:27 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Connection between Arduino client and Python server]]></title>
			<link>https://www.wolfssl.com/forums/post6434.html#p6434</link>
			<description><![CDATA[<p>Hi Mario,</p><p>Are you confident the python wolfSSL server is working correctly? You might try using our built-in C </p><div class="codebox"><pre><code>./examples/server/server -b -p 8090</code></pre></div><p>. I tried to setup the wolfssl-py here and looks like it is a bit outdated.</p><p>For the client side the call to wolfSSL_connect will trigger the EthernetSend with a client_hello TLS packet and the server should respond with a server_hello. You might consider enabling the client side debugging by building with </p><div class="codebox"><pre><code>DEBUG_WOLFSSL</code></pre></div><p> and calling </p><div class="codebox"><pre><code>wolfSSL_Debugging_ON();</code></pre></div><p> to see what is happening. You might also consider adding some debug statements in your ethernet send / recv functions. I did compare the client to our IDE/ARDUINO/sketches/wolfssl_client/wolfssl_client.ino.</p><p>Thanks,<br />David Garske, wolfSSL<br />Happy New Year!</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Thu, 30 Dec 2021 22:45:27 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6434.html#p6434</guid>
		</item>
		<item>
			<title><![CDATA[Connection between Arduino client and Python server]]></title>
			<link>https://www.wolfssl.com/forums/post6433.html#p6433</link>
			<description><![CDATA[<p>Hello everyone, we are having some troubles with secure communication between Arduino client and Python server. The client is stuck and waits for the connection and nothing happens, this happens precisely when the function </p><div class="codebox"><pre><code>wolfSSL_connect(ssl)</code></pre></div><p> is called. The following is the code:</p><p>Client:<br /></p><div class="codebox"><pre><code>#include &lt;WiFi.h&gt;
#include &quot;wolfssl.h&quot;
#include &quot;wolfssl/ssl.h&quot;

#define LIGHT_PIN 34
#define TEMP_PIN 35

const char* ssid = &quot;myssid&quot;;
const char* password= &quot;mypassword&quot;;
const uint16_t port = 8090;
const char* host = &quot;myip&quot;;

int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx);
int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx);

WiFiClient client;
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;

void setup() {
  Serial.begin(115200);

  /* Initialize WiFi */
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(&quot;...&quot;);
  }
  Serial.print(&quot;WiFi connected with IP: &quot;);
  Serial.println(WiFi.localIP());
  
  /* Initialize WolfSSL */
  WOLFSSL_METHOD* method;
  method = wolfTLSv1_2_client_method();
  if(method == NULL) {
    Serial.println(&quot;Unable to get method&quot;);
    return;
  }
  
  ctx = wolfSSL_CTX_new(method);
  if(ctx == NULL) {
    Serial.println(&quot;Unable to get ctx&quot;);
    return;
  }
  //wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
  wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, 0);
  wolfSSL_SetIOSend(ctx, EthernetSend);
  wolfSSL_SetIORecv(ctx, EthernetReceive);
}

void loop() {
  int err = 0;
  int input = 0;
  int total_input = 0;
  char msg[16];
  int msgSz = (int) strlen(msg);
  char errBuf[80];
  char reply[80];
  const char* cipherName;
  
  int lightLevel = analogRead(LIGHT_PIN);
  itoa(lightLevel, msg, 10);

  if(client.connect(host, port)) {
    Serial.print(&quot;Connected to &quot;);
    Serial.println(host);

    ssl = wolfSSL_new(ctx);
    if(ssl == NULL) {
      Serial.println(&quot;Unable to allocate SSL object&quot;);
      return;
    }

    Serial.println(&quot;Before connect&quot;);
    err = wolfSSL_connect(ssl);
    Serial.println(&quot;A&quot;);
    if(err != WOLFSSL_SUCCESS) {
      err = wolfSSL_get_error(ssl, 0);
      wolfSSL_ERR_error_string(err, errBuf);
      Serial.print(&quot;TLS Connect Error: &quot;);
      Serial.println(errBuf);
    }

    Serial.print(&quot;SSL version is &quot;);
    Serial.println(wolfSSL_get_version(ssl));
      
    cipherName = wolfSSL_get_cipher(ssl);
    Serial.print(&quot;SSL cipher suite is &quot;);
    Serial.println(cipherName);

    if((wolfSSL_write(ssl, msg, msgSz)) == msgSz) {
      Serial.print(&quot;Server response: &quot;);
      /* wait for data */
      while (!client.available()) {}
      
      /* read data */
      while (wolfSSL_pending(ssl)) {
        input = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
        total_input += input;
        if (input &lt; 0) {
          err = wolfSSL_get_error(ssl, 0);
          wolfSSL_ERR_error_string(err, errBuf);
          Serial.print(&quot;TLS Read Error: &quot;);
          Serial.println(errBuf);
          break;
        } else if (input &gt; 0) {
          reply[input] = &#039;\0&#039;;
          Serial.print(reply);
        } else {
          Serial.println();
        }
      }
    } else {
      err = wolfSSL_get_error(ssl, 0);
      wolfSSL_ERR_error_string(err, errBuf);
      Serial.print(&quot;TLS Write Error: &quot;);
      Serial.println(errBuf);
    }
      
    wolfSSL_shutdown(ssl);
    wolfSSL_free(ssl);

    client.stop();
    Serial.println(&quot;Connection complete.&quot;);
    } else {
      Serial.println(&quot;Trying to reconnect...&quot;);
    }
  delay(1000);
}

int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx) {
  int sent = 0;
  sent = client.write((byte*)msg, sz);
  return sent;
}


int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx) {
  int ret = 0;
  while(client.available() &gt; 0 &amp;&amp; ret &lt; sz) {
    reply[ret++] = client.read();
  }
  return ret;
}</code></pre></div><p>Server:<br /></p><div class="codebox"><pre><code>import sys
import socket
import argparse
import wolfssl


def get_method(index):
    return (
        wolfssl.PROTOCOL_SSLv3,
        wolfssl.PROTOCOL_TLSv1,
        wolfssl.PROTOCOL_TLSv1_1,
        wolfssl.PROTOCOL_TLSv1_2,
        wolfssl.PROTOCOL_SSLv23
    )[index]


def main():
    bind_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    bind_socket.bind((&#039;0.0.0.0&#039;, 8090))
    bind_socket.listen(0)

    print(&quot;Server listening on port&quot;, bind_socket.getsockname()[1])

    # enable debug, if native wolfSSL has been compiled with &#039;--enable-debug&#039;
    wolfssl.WolfSSL.enable_debug()
    context = wolfssl.SSLContext(get_method(3), server_side=True)
    context.load_cert_chain(&quot;./certs/server-cert.pem&quot;, &quot;./certs/server-key.pem&quot;)
    context.set_ciphers(&quot;&quot;)


    context.verify_mode = wolfssl.CERT_NONE


    while True:
        try:
            secure_socket = None
            new_socket, from_addr = bind_socket.accept()
            secure_socket = context.wrap_socket(new_socket)

            print(&quot;Connection received from&quot;, from_addr)
            print(&quot;\n&quot;, secure_socket.read(), &quot;\n&quot;)
            secure_socket.write(b&quot;I hear you fa shizzle!&quot;)

        except KeyboardInterrupt:
            print()
            break

        finally:
            if secure_socket:
                secure_socket.close()

    break

    bind_socket.close()


if __name__ == &#039;__main__&#039;:
    main()</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (mariorossi)]]></author>
			<pubDate>Thu, 30 Dec 2021 21:43:34 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post6433.html#p6433</guid>
		</item>
	</channel>
</rss>
