You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first thing we will need to do is include the wolfSSL native API header in both the client and the server. In the `tcpcli01.c` file for the client and the tcpserv04.c file for the server add the following line near the top:
219
+
The first thing we will need to do is include the wolfSSL native API header in both the client and the server. In the `tcpcli01.c` file for the client and the `tcpserv04.c` file for the server add the following line near the top:
219
220
220
221
```c
221
222
#include<wolfssl/ssl.h>
@@ -266,63 +267,63 @@ Putting these things together (library initialization, protocol selection, and C
266
267
EchoClient:
267
268
268
269
```c
269
-
WOLFSSL_CTX* ctx;
270
-
271
-
wolfSSL_Init();/* Initialize wolfSSL */
272
-
273
-
/* Create the WOLFSSL_CTX */
274
-
if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL){
275
-
fprintf(stderr, "wolfSSL_CTX_new error.\n");
276
-
exit(EXIT_FAILURE);
277
-
}
278
-
279
-
/* Load CA certificates into WOLFSSL_CTX */
280
-
if (wolfSSL_CTX_load_verify_locations(ctx,"../certs/ca-cert.pem",0) !=
When loading certificates into the `WOLFSSL_CTX`, the server certificate and key file should be loaded in addition to the CA certificate. This will allow the server to send the client its certificate for identification verification:
291
292
292
293
```c
293
-
WOLFSSL_CTX* ctx;
294
+
WOLFSSL_CTX* ctx;
294
295
295
-
wolfSSL_Init(); /* Initialize wolfSSL */
296
+
wolfSSL_Init(); /* Initialize wolfSSL */
296
297
297
-
/* Create the WOLFSSL_CTX */
298
-
if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())) == NULL){
299
-
fprintf(stderr, "wolfSSL_CTX_new error.\n");
300
-
exit(EXIT_FAILURE);
301
-
}
298
+
/* Create the WOLFSSL_CTX */
299
+
if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())) == NULL){
300
+
fprintf(stderr, "wolfSSL_CTX_new error.\n");
301
+
exit(EXIT_FAILURE);
302
+
}
302
303
303
-
/* Load CA certificates into WOLFSSL_CTX */
304
-
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", 0) !=
The code shown above should be added to the beginning of `tcpcli01.c` and `tcpserv04.c`, after both the variable definitions and the check that the user has started the client with an IP address (client). A version of the finished code is included in the SSL tutorial ZIP file for reference.
A WOLFSSL object needs to be created after each TCP Connect and the socket file descriptor needs to be associated with the session.
381
-
382
-
Create a new WOLFSSL object using the [`wolfSSL_new()`](group__Setup.md#function-wolfssl_new) function. This function returns a pointer to the `WOLFSSL` object if successful or `NULL` in the case of failure. We can then associate the socket file descriptor (`sockfd`) with the new `WOLFSSL` object (`ssl`):
383
-
384
-
```c
385
-
/* Create WOLFSSL object */
386
-
WOLFSSL* ssl;
387
-
388
-
if( (ssl = wolfSSL_new(ctx)) == NULL) {
389
-
fprintf(stderr, "wolfSSL_new error.\n");
390
-
exit(EXIT_FAILURE);
391
-
}
392
-
393
-
wolfSSL_set_fd(ssl, sockfd);
394
-
```
381
+
Again, a WOLFSSL object needs to be created after each TCP Connect and the socket file descriptor needs to be associated with the session.
0 commit comments