<?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 — STM32F4 HAL, FreeRTOS, LWIP and WolfSSL]]></title>
		<link>https://www.wolfssl.com/forums/topic1005-stm32f4-hal-freertos-lwip-and-wolfssl.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1005.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in STM32F4 HAL, FreeRTOS, LWIP and WolfSSL.]]></description>
		<lastBuildDate>Fri, 02 Jun 2017 22:55:14 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: STM32F4 HAL, FreeRTOS, LWIP and WolfSSL]]></title>
			<link>https://www.wolfssl.com/forums/post3292.html#p3292</link>
			<description><![CDATA[<p>Hi Jeff,<br /></p><div class="quotebox"><blockquote><p>1. Unable to verify host cert.</p></blockquote></div><p>To verify the host you need at a minimum a copy of the Host&#039;s ROOT CA. You can easily load this in PEM or DER format without a file system. Just use:</p><div class="codebox"><pre><code>wolfSSL_CTX_load_verify_buffer(ssl_object, cert_buffer, sizeof(cert_buffer), SSL_FILETYPE_PEM);</code></pre></div><p>Then format your cert like this:<br /></p><div class="codebox"><pre><code>const unsigned char cert_buffer[] = { &quot;\n\
-----BEGIN CERTIFICATE-----\n\
MIICVzCCAd2gAwIBAgIBKDAKBggqhkjOPQQDAzBBMRMwEQYKCZImiZPyLGQBGRYD\n\
bWlsMRgwFgYKCZImiZPyLGQBGRYIVHlwZTFQS0kxEDAOBgNVBAsTB1BLSUNBMDEw\n\
HhcNMTcwNDE0MTgxMjM3WhcNMjIwNDE0MTgxMjM3WjA3MRUwEwYDVQQFEwxBMDAw\n\
MTAwMDAwMTExHjAcBgNVBAMTFTIuMTYuODQwLjEuMTAxLjIuMS4xNzB2MBAGByqG\n\
SM49AgEGBSuBBAAiA2IABDLKAVvq5fRxDwtVNWczivw7dPECc0I6d6V/+poMFGTC\n\
OhJ+1jubn6VwWGqE5oGm22vJ2CjXC8yTwt+HJ/NVN/oylXGRRAjH0kghGzBP7Zr8\n\
S85cmtn3lP7ygUx7WGNK5qOBsjCBrzATBgNVHSMEDDAKgAhx+thUesQIQzARBgNV\n\
HQ4ECgQI8oFMe1hjSuYwDgYDVR0PAQH/BAQDAgeAMBYGA1UdIAQPMA0wCwYJYIZI\n\
AWUCAQsGMCsGA1UdEQQkMCKgIAYIKwYBBQUHCASgFDASBghghkgBZQIBEQQGoAAQ\n\
AAARMDAGA1UdHwQpMCcwJaAjoCGGH2h0dHBzOi8vUHJpbWFyeVBERS9wa2kvMTAw\n\
MTI3MzkwCgYIKoZIzj0EAwMDaAAwZQIxANMDtwbS4vD+zrge2vuTLwt0cy0J6j9P\n\
LldPMuKrAxRMVQ0fTgDMlxjGyV7onb0NxAIwXW2qCXjEvZBzgOx+IQnCHOjxDLp2\n\
/bDPlrF8llEDzjYvTLmN0cUZ5bwcOQygi3Xo\n\
-----END CERTIFICATE-----\n\n&quot;
};</code></pre></div><br /><br /><br /><div class="quotebox"><blockquote><p>2. Failure in the Encrypt() function</p></blockquote></div><p>Yes my first thought here was that you have no encryption configured IE no aes, no 3des, no camellia... etc. The MQTT user_settings example is quite sophisticated but intended to try and present all the available options for customizing our library. You have resolved this already based on the above.</p><p>Finally I see you are calling wolfSSL_write() which will call wolfSSL_connect() if the handshake has not completed already, however the downside to doing this is that you will not be able to debug if something goes wrong in the handshake.</p><p>I would recommend trying this BEFORE calling wolfSSL_write():</p><div class="codebox"><pre><code>return_value = wolfSSL_connect(xWolfSSL_Object);

if (return_value != SSL_SUCCESS) {
    printf(&quot;Handshake failed with error code: %d\n&quot;, return_value);
}</code></pre></div><p>Is there an error code returned? If so what is the value? If it is -300 or less it is a TLS error and the definition can be found in &lt;wolf-root&gt;/wolfssl/error-ssl.h otherwise if it is in the -200 to 0 range the definition is crypto related and can be found in &lt;wolf-root&gt;/wolfssl/wolfcrypt/error-crypt.h</p><br /><p>Regards,</p><p>Kaleb</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Fri, 02 Jun 2017 22:55:14 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post3292.html#p3292</guid>
		</item>
		<item>
			<title><![CDATA[Re: STM32F4 HAL, FreeRTOS, LWIP and WolfSSL]]></title>
			<link>https://www.wolfssl.com/forums/post3284.html#p3284</link>
			<description><![CDATA[<p>Made a small amount of progress.&nbsp; HAVE_AES was not defined, preventing loading the cipher.&nbsp; This was not defined because it was specifically undefined because NO_AES_DECRYPT was defined.&nbsp; This was defined because HAVE_AESGCM was defined, and this was done in user_settings.h.&nbsp; I reused the user_settings.h from I believe the MQTT demo, so I&#039;m not sure why that was done.&nbsp; The offending section is below with the offending line commented out.</p><div class="codebox"><pre><code>/* AES */
#undef NO_AES
#if 1
    #define HAVE_AESGCM
    #ifdef HAVE_AESGCM
        // #define NO_AES_DECRYPT
        #define HAVE_AESGCM_DECRYPT
    #endif

    /* GCM Method: GCM_SMALL, GCM_WORD32 or GCM_TABLE */
    #undef  GCM_SMALL
    #define GCM_SMALL
#else
    #define NO_AES
#endif</code></pre></div><p>This gets me past this error, but I still do not get communications.&nbsp; The code enters CBIOSend via SendBuffered() at the end of SendFinished() and never returns.&nbsp; So now I&#039;m trying to figure out why this is happening.&nbsp; This may require WireShark.</p>]]></description>
			<author><![CDATA[null@example.com (jwormsley)]]></author>
			<pubDate>Thu, 01 Jun 2017 14:40:02 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post3284.html#p3284</guid>
		</item>
		<item>
			<title><![CDATA[STM32F4 HAL, FreeRTOS, LWIP and WolfSSL]]></title>
			<link>https://www.wolfssl.com/forums/post3282.html#p3282</link>
			<description><![CDATA[<p>I&#039;m trying to build a simple client application using the above processor and packages.&nbsp; I have the ethernet driver functioning with the LWIP stack, and can make connections and exchange data with straight TCP connections.&nbsp; I have WolfSSL building, and almost running, with what I think is two last issues which I need help figuring out.&nbsp; When I try to connect via a TLS 1.2 connection to my host, I have the following problems.</p><p>1. Unable to verify host cert.</p><p>I believe this is because I don&#039;t have the proper PEM file (actually hardcoded since the demo doesn&#039;t have a filesystem) loaded.&nbsp; I was able to work around this by using wolfSSL_CTX_set_verify to set a callback that allows overriding this failure.&nbsp; I found this in the MQTT demo app.&nbsp; I don&#039;t think this is an issue, since it worked for the MQTT demo and allowed data exchange.</p><p>2. Failure in the Encrypt() function</p><p>The connection proceeds through wolfSSL_write into SendData, wolfSSL_negotiate, wolfSSL_connect, SendFinished, BuildMessage and into Encrypt.&nbsp; Once there, one of the first things Encrypt does is check if the encrypt ciphers are set up.</p><div class="codebox"><pre><code>    switch (ssl-&gt;encrypt.state) {
        case CIPHER_STATE_BEGIN:
        {
            if (ssl-&gt;encrypt.setup == 0) {
                WOLFSSL_MSG(&quot;Encrypt ciphers not setup&quot;);
                return ENCRYPT_ERROR;
            }</code></pre></div><p>For some reason, they are not set up on my system, and I cannot figure out why, or where they were supposed to be set up.</p><p>The debug output, from the point where I override the cert failure up to this point is below.</p><div class="codebox"><pre><code>Verified Peer&#039;s cert
wolfSSL Entering ERR_error_string
TLS Verify Callback: PreVerify 0, Error -188 (ASN no signer error to confirm failure)
  Subject&#039;s domain name is wrs2test.hmps-apps.net
  Allowing cert anyways
Verify callback overriding error!
wolfSSL Leaving DoCertificate, return 0
wolfSSL Leaving DoHandShakeMsgType(), return 0
wolfSSL Leaving DoHandShakeMsg(), return 0
received record layer msg
wolfSSL Entering DoHandShakeMsg()
wolfSSL Entering DoHandShakeMsgType
No KeyExchange required
processing server hello done
wolfSSL Leaving DoHandShakeMsgType(), return 0
wolfSSL Leaving DoHandShakeMsg(), return 0
connect state: HELLO_AGAIN
connect state: HELLO_AGAIN_REPLY
connect state: FIRST_REPLY_DONE
connect state: FIRST_REPLY_FIRST
wolfSSL Entering SendClientKeyExchange
wolfSSL Entering RsaEnc
wolfSSL Leaving RsaEnc, return 0
growing output buffer

Shrinking output buffer

wolfSSL Leaving SendClientKeyExchange, return 0
sent: client key exchange
connect state: FIRST_REPLY_SECOND
connect state: FIRST_REPLY_THIRD
growing output buffer

Shrinking output buffer

sent: change cipher spec
connect state: FIRST_REPLY_FOURTH
growing output buffer

wolfSSL Entering BuildMessage
Encrypt ciphers not setup</code></pre></div><p>I&#039;m using the user_settings.h file attached.&nbsp; I&#039;m sure I must be missing something here, or not setting something up properly, but have been beating my head against the wall for two days trying to figure it out.</p><p>Minus my cert and not public server info, the following is the code I&#039;m running.&nbsp; Hopefully someone can see where I&#039;ve messed up from this.</p><div class="codebox"><pre><code>int ssl_init_done = 0;

/* Define a structure to hold the WolfSSL context. */
WOLFSSL_CTX* xWolfSSL_Context;
WOLFSSL* xWolfSSL_Object = NULL;

static int tls_verify_cb(int preverify, WOLFSSL_X509_STORE_CTX* store)
{
    char buffer[80];

    printf(&quot;TLS Verify Callback: PreVerify %d, Error %d (%s)\r\n&quot;, preverify,
        store-&gt;error, wolfSSL_ERR_error_string(store-&gt;error, buffer));
    printf(&quot;  Subject&#039;s domain name is %s\r\n&quot;, store-&gt;domain);

    /* Allowing to continue */
    /* Should check certificate and return 0 if not okay */
    printf(&quot;  Allowing cert anyways\r\n&quot;);

    return 1;
}

void test_secure(void)
{
  struct hostent *server;
  int socket_fd;
  struct sockaddr_in ra;

  int recv_data;
  char data_buffer[1024];

  int Step = 0;

  while (Step &gt;= 0)
  {
    switch (Step)
    {
      case 0 :
        printf(&quot;Initializing WolfSSL if needed\r\n&quot;);
        if (ssl_init_done == 0)
        {
          wolfSSL_Init();
          ssl_init_done = 1;
        }
        break;
      case 1 :
        printf(&quot;Creating WolfSSL context if needed\r\n&quot;);
        /* Attempt to create a context that uses the TLS V1.2 client protocol. */
        if (ssl_init_done == 1)
        {
          xWolfSSL_Context = wolfSSL_CTX_new( wolfTLSv1_2_client_method() );

          if( xWolfSSL_Context == NULL )
          {
            printf(&quot;Failed to create WolfSSL context\r\n&quot;);
            Step = -1;
          }
          else
          {
            ssl_init_done = 2;

            wolfSSL_CTX_set_verify(xWolfSSL_Context, SSL_VERIFY_PEER, tls_verify_cb);

          }
        }
        break;
      case 2 :
        printf(&quot;Loading WolfSSL CA Certificate\r\n&quot;);
        if (ssl_init_done == 2)
        {
          int rc = SSL_FAILURE;

          /* Load CA certificate file */
          rc = wolfSSL_CTX_load_verify_buffer(xWolfSSL_Context, cert, strlen(cert), SSL_FILETYPE_PEM);

          if (rc != SSL_SUCCESS)
          {
            printf(&quot;Failed to load CA Certificate\r\n&quot;);
            Step = -1;
          }
          else
            ssl_init_done = 3;
        }
        break;
      case 3 :
        printf(&quot;Create the socket\r\n&quot;);
        socket_fd = socket(PF_INET, SOCK_STREAM, 0);
        if ( socket_fd &lt; 0 )
        {
          printf(&quot;Socket call failed\r\n&quot;);
          Step = -1;
        }
        break;
      case 4 :
        {
          /* gethostbyname: get the server&#039;s DNS entry */
          printf(&quot;Gethostbyname: get the %s server&#039;s DNS entry\r\n&quot;, HMPS_TEST_SECURE_HOST);
          server = gethostbyname(HMPS_TEST_SECURE_HOST);
          if (server == NULL)
          {
            printf(&quot;ERROR, no such host as %s\r\n&quot;, HMPS_TEST_SECURE_HOST);
            Step = -1;
          }
          else
            printf(&quot;Host %s resolved to IP address %s\r\n&quot;,server-&gt;h_name,inet_ntoa(*server-&gt;h_addr_list[0]));

        }
        break;
      case 5 :
        printf(&quot;Connecting to server.\r\n&quot;);

        memset(&amp;ra, 0, sizeof(struct sockaddr_in));
        ra.sin_family = AF_INET;
        memcpy((char *)&amp;ra.sin_addr.s_addr, (char *)server-&gt;h_addr, server-&gt;h_length);
        ra.sin_port = htons(HMPS_TEST_SECURE_PORT);
        if(connect(socket_fd,(struct sockaddr const*)&amp;ra,sizeof(struct sockaddr_in)) &lt; 0)
        {
          printf(&quot;Connect failed \n&quot;);
          Step = -1;
        }
        else
          printf(&quot;Connected to IP address %s\r\n&quot;,inet_ntoa(ra.sin_addr.s_addr));
        break;
      case 6 :
        printf(&quot;Creating WolfSSL Object\r\n&quot;);
        // The connect was successful.  Create a WolfSSL object to associate with
        // this connection.  The context created during initialisation is passed as
        // the function parameter.
        if( xWolfSSL_Object == NULL )
          xWolfSSL_Object = wolfSSL_new( xWolfSSL_Context );

        if( xWolfSSL_Object == NULL )
        {
          printf(&quot;Failed to create WolfSSL Object\n&quot;);
          Step = -1;
        }
        break;
      case 7:
        printf(&quot;Associating WolfSSL Object to socket\r\n&quot;);
        // Associate the created WolfSSL object with the connected socket.
        wolfSSL_set_fd( xWolfSSL_Object, socket_fd );
        break;
      case 8 :
        {
          char buf[1024];
          int n;

          sprintf(buf,HMPS_TEST_SECURE_MSG);

          /* send the message line to the server */
          printf(&quot;Send the message %s to the server\r\n&quot;, HMPS_TEST_SECURE_MSG);

wolfSSL_Debugging_ON();
          n = wolfSSL_write( xWolfSSL_Object, buf, strlen(buf));
wolfSSL_Debugging_OFF();
          if (n != strlen(buf))
          {
            printf(&quot;ERROR writing to socket\r\n&quot;);
            Step = -1;
          }
        }
        break;
      case 9 :
        printf(&quot;Receive data\r\n&quot;);
        recv_data = wolfSSL_read( xWolfSSL_Object, data_buffer,sizeof(data_buffer));
        if(recv_data &lt; 0)
        {
          printf(&quot;Receive failed\r\n&quot;);
          Step = -1;
        }
        else
        {
          data_buffer[recv_data] = 0x00; // Force terminating NULL
          printf(&quot;Received data: %s\r\n&quot;, data_buffer);
        }
        break;
      case 10 :
        Step = -1;
        break;
    }
    if (Step &gt;= 0)
      Step ++;
  }

  if( xWolfSSL_Object != NULL )
  {
    printf(&quot;Clean up WolfSSL\r\n&quot;);

    // WolfSSL objects should be deleted when they are no longer required.
    wolfSSL_free( xWolfSSL_Object );
    xWolfSSL_Object = NULL;

    // The WolfSSL context should be deleted if it is no longer required.  However,
    // because most deeply embedded applications will keep the context for the lifetime
    // of the application, and only ever be restarted when the system is rebooted, it
    // might be that the context is never explicitly freed.
    // wolfSSL_CTX_free( xWolfSSL_Context );

    // The library itself should be shut down cleanly if it too is no longer
    // required.  Again, because most deeply embedded applications will require the
    // library for the lifetime of the application, and only ever be restarted when
    // the system is rebooted, it might be that the library is never explicitly closed.
    // wolfSSL_Cleanup();
  }
  close(socket_fd);

  printf(&quot;Test complete\r\n&quot;);
}</code></pre></div><p>Thanks in advance for any insight,<br />&nbsp; Jeff.</p>]]></description>
			<author><![CDATA[null@example.com (jwormsley)]]></author>
			<pubDate>Thu, 01 Jun 2017 12:54:32 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post3282.html#p3282</guid>
		</item>
	</channel>
</rss>
