Skip to content

Commit ca87212

Browse files
authored
Merge pull request #128 from rlm2002/styleFormattingUpdates
Updated whitespace and removed duplicate entry in wolf Object echoserver
2 parents 6a2a9d2 + 1d14183 commit ca87212

File tree

1 file changed

+48
-61
lines changed

1 file changed

+48
-61
lines changed

wolfSSL/src/chapter11.md

+48-61
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The downloaded ZIP file has the following structure:
2929

3030
```text
3131
/finished_src
32+
/certs (Certificate files)
3233
/echoclient (Completed echoclient code)
3334
/echoserver (Completed echoserver code)
3435
/include (Modified unp.h)
@@ -215,7 +216,7 @@ gcc -o echoserver ../lib/*.c tcpserv04.c -I ../include -lm -lwolfssl
215216

216217
## Headers
217218

218-
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:
219220

220221
```c
221222
#include <wolfssl/ssl.h>
@@ -266,63 +267,63 @@ Putting these things together (library initialization, protocol selection, and C
266267
EchoClient:
267268
268269
```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) !=
281-
SSL_SUCCESS) {
282-
fprintf(stderr, "Error loading ../certs/ca-cert.pem, please check
283-
the file.\n");
284-
exit(EXIT_FAILURE);
285-
}
270+
WOLFSSL_CTX* ctx;
271+
272+
wolfSSL_Init();/* Initialize wolfSSL */
273+
274+
/* Create the WOLFSSL_CTX */
275+
if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
276+
fprintf(stderr, "wolfSSL_CTX_new error.\n");
277+
exit(EXIT_FAILURE);
278+
}
279+
280+
/* Load CA certificates into WOLFSSL_CTX */
281+
if (wolfSSL_CTX_load_verify_locations(ctx,"../certs/ca-cert.pem",0) !=
282+
SSL_SUCCESS) {
283+
fprintf(stderr, "Error loading ../certs/ca-cert.pem, please check"
284+
"the file.\n");
285+
exit(EXIT_FAILURE);
286+
}
286287
```
287288

288289
EchoServer:
289290

290291
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:
291292

292293
```c
293-
WOLFSSL_CTX* ctx;
294+
WOLFSSL_CTX* ctx;
294295

295-
wolfSSL_Init(); /* Initialize wolfSSL */
296+
wolfSSL_Init(); /* Initialize wolfSSL */
296297

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+
}
302303

303-
/* Load CA certificates into WOLFSSL_CTX */
304-
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", 0) !=
305-
SSL_SUCCESS) {
306-
fprintf(stderr, "Error loading ../certs/ca-cert.pem, "
307-
"please check the file.\n");
308-
exit(EXIT_FAILURE);
309-
}
304+
/* Load CA certificates into WOLFSSL_CTX */
305+
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", 0) !=
306+
SSL_SUCCESS) {
307+
fprintf(stderr, "Error loading ../certs/ca-cert.pem, "
308+
"please check the file.\n");
309+
exit(EXIT_FAILURE);
310+
}
310311

311312
/* Load server certificates into WOLFSSL_CTX */
312-
if (wolfSSL_CTX_use_certificate_file(ctx,"../certs/server-cert.pem",
313-
SSL_FILETYPE_PEM) != SSL_SUCCESS){
314-
fprintf(stderr, "Error loading ../certs/server-cert.pem, please
315-
check the file.\n");
316-
exit(EXIT_FAILURE);
317-
}
318-
319-
/* Load keys */
320-
if (wolfSSL_CTX_use_PrivateKey_file(ctx,"../certs/server-key.pem",
321-
SSL_FILETYPE_PEM) != SSL_SUCCESS){
322-
fprintf(stderr, "Error loading ../certs/server-key.pem, please check
323-
the file.\n");
324-
exit(EXIT_FAILURE);
325-
}
313+
if (wolfSSL_CTX_use_certificate_file(ctx,"../certs/server-cert.pem",
314+
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
315+
fprintf(stderr, "Error loading ../certs/server-cert.pem, please"
316+
"check the file.\n");
317+
exit(EXIT_FAILURE);
318+
}
319+
320+
/* Load keys */
321+
if (wolfSSL_CTX_use_PrivateKey_file(ctx,"../certs/server-key.pem",
322+
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
323+
fprintf(stderr, "Error loading ../certs/server-key.pem, please check"
324+
"the file.\n");
325+
exit(EXIT_FAILURE);
326+
}
326327
```
327328

328329
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.
@@ -377,21 +378,7 @@ if ( (ssl = wolfSSL_new(ctx)) == NULL) {
377378
wolfSSL_set_fd(ssl, connfd);
378379
```
379380

380-
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.
395382

396383
## Sending/Receiving Data
397384

0 commit comments

Comments
 (0)