Skip to content

Commit b610e83

Browse files
Merge pull request #213 from holtrop/wolfssl-manual-fixes-and-updates
Update and fix various wolfSSL user manual chapters
2 parents ec8a01b + 3a5b07e commit b610e83

File tree

8 files changed

+64
-77
lines changed

8 files changed

+64
-77
lines changed

wolfSSL/src/chapter02.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,8 @@ Enabling this option will turn on User Atomic Record Layer Processing callbacks.
24432443
24442444
Enable Public Key Callbacks
24452445
2446+
Eabling this option will turn on Public Key callbacks, allowing the application to register its own ECC sign/verify and RSA sign/verify and encrypt/decrypt callbacks.
2447+
24462448
### `--enable-sniffer`
24472449
24482450
Enable wolfSSL sniffer support.
@@ -2465,14 +2467,12 @@ Stream ciphers:
24652467
24662468
Enable AES-GCM support.
24672469
2468-
Eabling this option will turn on Public Key callbacks, allowing the application to register its own ECC sign/verify and RSA sign/verify and encrypt/decrypt callbacks.
2470+
Enabling AES-GCM will add these cipher suites to wolfSSL. wolfSSL offers four different implementations of AES-GCM balancing speed versus memory consumption. If available, wolfSSL will use 64-bit or 32-bit math. For embedded applications, there is a speedy 8-bit version that uses RAM-based lookup tables (8KB per session) which is speed comparable to the 64-bit version and a slower 8-bit version that doesn't take up any additional RAM. The --enable-aesgcm configure option may be modified with the options `=word32`, `=table`, or `=small`, i.e. `--enable-aesgcm=table`.
24692471
24702472
### `--enable-aesccm`
24712473
24722474
Enable AES-CCM support
24732475
2474-
Enabling AES-GCM will add these cipher suites to wolfSSL. wolfSSL offers four different implementations of AES-GCM balancing speed versus memory consumption. If available, wolfSSL will use 64-bit or 32-bit math. For embedded applications, there is a speedy 8-bit version that uses RAM-based lookup tables (8KB per session) which is speed comparable to the 64-bit version and a slower 8-bit version that doesn't take up any additional RAM. The --enable-aesgcm configure option may be modified with the options `=word32`, `=table`, or `=small`, i.e. `--enable-aesgcm=table`.
2475-
24762476
### `--disable-aescbc`
24772477
24782478
Used to with [`--disable-aescbc`](#--disable-aescbc) to compile out AES-CBC

wolfSSL/src/chapter03.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ This section will explain the basic steps needed to add wolfSSL to a client appl
496496
497497
```c
498498
/*after connecting to socket fd*/
499-
WOLF SSL* ssl;
499+
WOLFSSL* ssl;
500500
if ((ssl = wolfSSL_new(ctx)) == NULL) {
501501
fprintf(stderr, "wolfSSL_new error.\n");
502502
exit(EXIT_FAILURE);
@@ -558,7 +558,7 @@ calling:
558558
559559
This section will explain the basic steps needed to add wolfSSL to a server application using the wolfSSL native API. For a client explanation, please see [Changing a Client Application to Use wolfSSL](#changing-a-client-application-to-use-wolfssl). A more complete walk-through, with example code, is located in the [SSL Tutorial](chapter11.md#ssl-tutorial) chapter.
560560
561-
1. Follow the instructions above for a client, except change the client method call in step 5 to a server one, so:
561+
1. Follow the instructions above for a client, except change the client method call in step 2 to a server one, so:
562562
563563
```c
564564
wolfSSL_CTX_new(wolfTLSv1_client_method());

wolfSSL/src/chapter04.md

Lines changed: 24 additions & 55 deletions
Large diffs are not rendered by default.

wolfSSL/src/chapter06.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Additionally, each callback type requires its specific feature to be enabled (e.
120120
wolfSSL provides DH (Diffie-Hellman) callbacks for users who wish to have more control over DH key generation and key agreement operations during the SSL/TLS connection.
121121

122122
The user can optionally define 2 functions:
123+
123124
1. DH key generation callback
124125
2. DH key agreement callback
125126

@@ -138,6 +139,7 @@ typedef int (*CallbackDhAgree)(WOLFSSL* ssl, struct DhKey* key,
138139
```
139140
140141
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
142+
141143
* `wolfSSL_CTX_SetDhGenerateKeyPair()`
142144
* `wolfSSL_CTX_SetDhAgreeCb()`
143145
@@ -152,6 +154,7 @@ To use DH callbacks, wolfSSL needs to be compiled with `HAVE_DH` defined.
152154
wolfSSL provides Ed25519 callbacks for users who wish to have more control over Ed25519 sign/verify operations during the SSL/TLS connection.
153155
154156
The user can optionally define 2 functions:
157+
155158
1. Ed25519 sign callback
156159
2. Ed25519 verify callback
157160
@@ -172,10 +175,12 @@ typedef int (*CallbackEd25519Verify)(WOLFSSL* ssl,
172175
```
173176

174177
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
178+
175179
* `wolfSSL_CTX_SetEd25519SignCb()`
176180
* `wolfSSL_CTX_SetEd25519VerifyCb()`
177181

178182
The user can set a context per WOLFSSL object (session) with:
183+
179184
* `wolfSSL_SetEd25519SignCtx()`
180185
* `wolfSSL_SetEd25519VerifyCtx()`
181186

@@ -188,6 +193,7 @@ To use Ed25519 callbacks, wolfSSL needs to be compiled with `HAVE_PK_CALLBACKS`
188193
wolfSSL provides X25519 callbacks for users who wish to have more control over X25519 key generation and shared secret computation during the SSL/TLS connection.
189194

190195
The user can optionally define 2 functions:
196+
191197
1. X25519 key generation callback
192198
2. X25519 shared secret callback
193199

@@ -205,10 +211,12 @@ typedef int (*CallbackX25519SharedSecret)(WOLFSSL* ssl,
205211
```
206212
207213
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
214+
208215
* `wolfSSL_CTX_SetX25519KeyGenCb()`
209216
* `wolfSSL_CTX_SetX25519SharedSecretCb()`
210217
211218
The user can set a context per WOLFSSL object (session) with:
219+
212220
* `wolfSSL_SetX25519KeyGenCtx()`
213221
* `wolfSSL_SetX25519SharedSecretCtx()`
214222
@@ -221,6 +229,7 @@ To use X25519 callbacks, wolfSSL needs to be compiled with `HAVE_PK_CALLBACKS` a
221229
wolfSSL provides Ed448 callbacks for users who wish to have more control over Ed448 sign/verify operations during the SSL/TLS connection.
222230
223231
The user can optionally define 2 functions:
232+
224233
1. Ed448 sign callback
225234
2. Ed448 verify callback
226235
@@ -241,10 +250,12 @@ typedef int (*CallbackEd448Verify)(WOLFSSL* ssl,
241250
```
242251

243252
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
253+
244254
* `wolfSSL_CTX_SetEd448SignCb()`
245255
* `wolfSSL_CTX_SetEd448VerifyCb()`
246256

247257
The user can set a context per WOLFSSL object (session) with:
258+
248259
* `wolfSSL_SetEd448SignCtx()`
249260
* `wolfSSL_SetEd448VerifyCtx()`
250261

@@ -257,6 +268,7 @@ To use Ed448 callbacks, wolfSSL needs to be compiled with `HAVE_PK_CALLBACKS` an
257268
wolfSSL provides X448 callbacks for users who wish to have more control over X448 key generation and shared secret operations during the SSL/TLS connection.
258269

259270
The user can optionally define 2 functions:
271+
260272
1. X448 key generation callback
261273
2. X448 shared secret callback
262274

@@ -274,10 +286,12 @@ typedef int (*CallbackX448SharedSecret)(WOLFSSL* ssl,
274286
```
275287
276288
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
289+
277290
* `wolfSSL_CTX_SetX448KeyGenCb()`
278291
* `wolfSSL_CTX_SetX448SharedSecretCb()`
279292
280293
The user can set a context per WOLFSSL object (session) with:
294+
281295
* `wolfSSL_SetX448KeyGenCtx()`
282296
* `wolfSSL_SetX448SharedSecretCtx()`
283297
@@ -290,6 +304,7 @@ To use X448 callbacks, wolfSSL needs to be compiled with `HAVE_PK_CALLBACKS` and
290304
wolfSSL provides RSA PSS callbacks for users who wish to have more control over RSA PSS sign/verify operations during the SSL/TLS connection.
291305
292306
The user can optionally define 4 functions:
307+
293308
1. RSA PSS sign callback
294309
2. RSA PSS verify callback
295310
3. RSA PSS sign check callback
@@ -320,12 +335,14 @@ typedef int (*CallbackRsaPssSignCheck)(WOLFSSL* ssl,
320335
```
321336

322337
The user needs to write and register these functions per wolfSSL context (`WOLFSSL_CTX`) with:
338+
323339
* `wolfSSL_CTX_SetRsaPssSignCb()`
324340
* `wolfSSL_CTX_SetRsaPssVerifyCb()`
325341
* `wolfSSL_CTX_SetRsaSignCheckCb()`
326342
* `wolfSSL_CTX_SetRsaPssSignCheckCb()`
327343

328344
The user can set a context per WOLFSSL object (session) with:
345+
329346
* `wolfSSL_SetRsaPssSignCtx()`
330347
* `wolfSSL_SetRsaPssVerifyCtx()`
331348
* `wolfSSL_SetRsaSignCheckCtx()`
@@ -432,7 +449,7 @@ The high level steps use crypto callbacks are:
432449
433450
434451
#### 1. Compile wolfSSL with crypto callback support
435-
Support for crypto callbacks is enabled in wolfSSL via the `–enable-cryptocb` configure option, or `#define WOLF_CRYPTO_CB`.
452+
Support for crypto callbacks is enabled in wolfSSL via the `–-enable-cryptocb` configure option, or `#define WOLF_CRYPTO_CB`.
436453
437454
#### 2. Register your callback and unique devID with wolfCrypt
438455
@@ -467,6 +484,7 @@ wc_InitCmac_ex
467484
This will cause wolfCrypt to invoke the crypto callback in place of the default implementation. This is not an exhaustive API list. Please refer to the wolfCrypt API documentation to see if a particular algorithm supports crypto callbacks.
468485

469486
#### 4. (TLS only): associate the devId with a wolfSSL context
487+
470488
To enable use of a crypto callback when using TLS, you must supply the `devId` arguments on initialization of a `WOLFSSL_CTX` or `WOLFSSL` struct.
471489
```c
472490
wolfSSL_CTX_SetDevId(ctx, devId);

wolfSSL/src/chapter07.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX *ctx,
174174
175175
## Certificate Chain Verification
176176
177-
wolfSSL requires that only the top or “root” certificate in a chain to be loaded as a trusted certificate in order to verify a certificate chain. This means that if you have a certificate chain (A -\> B -\> C), where C is signed by B, and B is signed by A, wolfSSL only requires that certificate A be loaded as a trusted certificate in order to verify the entire chain (A-\>B-\>C).
177+
wolfSSL requires only the top or “root” certificate in a chain to be loaded as a trusted certificate in order to verify a certificate chain. This means that if you have a certificate chain (A -\> B -\> C), where C is signed by B, and B is signed by A, wolfSSL only requires that certificate A be loaded as a trusted certificate in order to verify the entire chain (A-\>B-\>C).
178178
179179
For example, if a server certificate chain looks like:
180180
@@ -192,7 +192,7 @@ Checking the domain name of the certificate is an important step that verifies t
192192
193193
## No File System and using Certificates
194194
195-
Normally a file system is used to load private keys, certificates, and CAs. Since wolfSSL is sometimes used in environments without a full file system an extension to use memory buffers instead is provided. To use the extension define the constant `NO_FILESYSTEM` and the following functions will be made available:
195+
Normally a file system is used to load private keys, certificates, and CAs. Since wolfSSL is sometimes used in environments without a full file system, an extension to use memory buffers instead is provided. To use the extension define the constant `NO_FILESYSTEM` and the following functions will be made available:
196196
197197
* [`int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,long sz, int format);`](group__CertsKeys.md#function-wolfssl_ctx_load_verify_buffer)
198198
* [`int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX* ctx, const unsigned char* in, long sz, int format);`](group__CertsKeys.md#function-wolfssl_ctx_use_certificate_buffer)
@@ -204,7 +204,7 @@ Use these functions exactly like their counterparts that are named `*_file` inst
204204
205205
### Test Certificate and Key Buffers
206206
207-
wolfSSL has come bundled with test certificate and key files in the past. Now it also comes bundled with test certificate and key buffers for use in environments with no filesystem available. These buffers are available in `certs_test.h` when defining one or more of `USE_CERT_BUFFERS_1024`, `USE_CERT_BUFFERS_2048`, or `USE_CERT_BUFFERS_256`.
207+
wolfSSL comes bundled with test certificate and key files. Additionally, it also comes bundled with test certificate and key buffers for use in environments with no filesystem available. These buffers are available in `certs_test.h` when defining one or more of `USE_CERT_BUFFERS_1024`, `USE_CERT_BUFFERS_2048`, or `USE_CERT_BUFFERS_256`.
208208
209209
## Serial Number Retrieval
210210
@@ -225,7 +225,7 @@ wolfSSL supports RSA key generation of varying lengths up to 4096 bits. Key gene
225225
int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng);
226226
```
227227
228-
Where `size` is the length in bits and `e` is the public exponent, using 65537 is usually a good choice for `e`. The following from `wolfcrypt/test/test.c` gives an example creating an RSA key of 1024 bits:
228+
Where `size` is the length in bits and `e` is the public exponent (using 65537 is usually a good choice for `e`). The following from `wolfcrypt/test/test.c` gives an example creating an RSA key of 1024 bits:
229229
230230
```c
231231
RsaKey genKey;

wolfSSL/src/chapter09.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ wolfSSL (formerly CyaSSL) is thread safe by design. Multiple threads can enter t
5252

5353
## Input and Output Buffers
5454

55-
wolfSSL now uses dynamic buffers for input and output. They default to 0 bytes and are controlled by the `RECORD_SIZE` define in `wolfssl/internal.h`. If an input record is received that is greater in size than the static buffer, then a dynamic buffer is temporarily used to handle the request and then freed. You can set the static buffer size up to the `MAX_RECORD_SIZE` which is 2^16 or 16,384.
55+
wolfSSL now uses dynamic buffers for input and output. They default to 0 bytes and are controlled by the `RECORD_SIZE` define in `wolfssl/internal.h`. If an input record is received that is greater in size than the static buffer, then a dynamic buffer is temporarily used to handle the request and then freed. You can set the static buffer size up to the `MAX_RECORD_SIZE` which is 2^14 or 16,384.
5656

5757
If you prefer the previous way that wolfSSL operated, with 16Kb static buffers that will never need dynamic memory, you can still get that option by defining `LARGE_STATIC_BUFFERS`.
5858

wolfSSL/src/chapter10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ For usage examples please see the camellia_test() function in `<wolfssl_root>/wo
263263

264264
**NOTE**: ARC4 is outdated and considered insecure. Please consider using a different stream cipher.
265265

266-
The most common stream cipher used on the Internet is ARC4. wolfCrypt supports it through the header `wolfssl/wolfcrypt/arc4.h`. Usage is simpler than block ciphers because there is no block size and the key length can be any length. The following is a typical usage of ARC4.
266+
wolfCrypt supports ARC4 through the header `wolfssl/wolfcrypt/arc4.h`. Usage is simpler than block ciphers because there is no block size and the key length can be any length. The following is a typical usage of ARC4.
267267

268268
```c
269269
Arc4 enc;

wolfSSL/src/chapter11.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ EchoServer:
256256
* [`wolfDTLSv1_2_server_method();`](ssl_8h.md#function-wolfdtlsv1_2_server_method) - DTLS 1.2
257257
* [`wolfDTLSv1_3_server_method();`](ssl_8h.md#function-wolfdtlsv1_3_server_method) - DTLS 1.3
258258

259-
We need to load our CA (Certificate Authority) certificate into the `WOLFSSL_CTX` so that the when the echoclient connects to the echoserver, it is able to verify the server’s identity. To load the CA certificates into the `WOLFSSL_CTX`, use [`wolfSSL_CTX_load_verify_locations()`](group__CertsKeys.md#function-wolfssl_ctx_load_verify_locations). This function requires three arguments: a `WOLFSSL_CTX` pointer, a certificate file, and a path value. The path value points to a directory which should contain CA certificates in PEM format. When looking up certificates, wolfSSL will look at the certificate file value before looking in the path location. In this case, we don’t need to specify a certificate path because we will specify one CA file - as such we use the value 0 for the path argument. The [`wolfSSL_CTX_load_verify_locations`](group__CertsKeys.md#function-wolfssl_ctx_load_verify_locations) function returns either `SSL_SUCCESS` or `SSL_FAILURE`:
259+
We need to load our CA (Certificate Authority) certificate into the `WOLFSSL_CTX` so that the when the echoclient connects to the echoserver, it is able to verify the server’s identity. To load the CA certificates into the `WOLFSSL_CTX`, use [`wolfSSL_CTX_load_verify_locations()`](group__CertsKeys.md#function-wolfssl_ctx_load_verify_locations). This function requires three arguments: a `WOLFSSL_CTX` pointer, a certificate file, and a path value. The path value points to a directory which should contain CA certificates in PEM format. When looking up certificates, wolfSSL will look at the certificate file value before looking in the path location. In this case, we don’t need to specify a certificate path because we will specify one CA file - as such we use NULL for the path argument. The [`wolfSSL_CTX_load_verify_locations`](group__CertsKeys.md#function-wolfssl_ctx_load_verify_locations) function returns either `SSL_SUCCESS` or `SSL_FAILURE`:
260260

261261
```c
262262
wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file, const char* path)
@@ -278,10 +278,10 @@ EchoClient:
278278
}
279279
280280
/* Load CA certificates into WOLFSSL_CTX */
281-
if (wolfSSL_CTX_load_verify_locations(ctx,"../certs/ca-cert.pem",0) !=
281+
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", NULL) !=
282282
SSL_SUCCESS) {
283-
fprintf(stderr, "Error loading ../certs/ca-cert.pem, please check"
284-
"the file.\n");
283+
fprintf(stderr, "Error loading ../certs/ca-cert.pem, "
284+
"please check the file.\n");
285285
exit(EXIT_FAILURE);
286286
}
287287
```
@@ -304,23 +304,23 @@ if ( (ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())) == NULL) {
304304
}
305305

306306
/* Load CA certificates into WOLFSSL_CTX */
307-
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", 0) !=
307+
if (wolfSSL_CTX_load_verify_locations(ctx, "../certs/ca-cert.pem", NULL) !=
308308
SSL_SUCCESS) {
309309
fprintf(stderr, "Error loading ../certs/ca-cert.pem, "
310310
"please check the file.\n");
311311
exit(EXIT_FAILURE);
312312
}
313313

314314
/* Load server certificates into WOLFSSL_CTX */
315-
if (wolfSSL_CTX_use_certificate_file(ctx,"../certs/server-cert.pem",
315+
if (wolfSSL_CTX_use_certificate_file(ctx, "../certs/server-cert.pem",
316316
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
317317
fprintf(stderr, "Error loading ../certs/server-cert.pem, please"
318318
"check the file.\n");
319319
exit(EXIT_FAILURE);
320320
}
321321

322322
/* Load keys */
323-
if (wolfSSL_CTX_use_PrivateKey_file(ctx,"../certs/server-key.pem",
323+
if (wolfSSL_CTX_use_PrivateKey_file(ctx, "../certs/server-key.pem",
324324
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
325325
fprintf(stderr, "Error loading ../certs/server-key.pem, please check"
326326
"the file.\n");
@@ -341,11 +341,11 @@ wolfSSL_Cleanup();
341341
342342
### EchoClient
343343
344-
A WOLFSSL object needs to be created after each TCP Connect and the socket file descriptor needs to be associated with the session. In the echoclient example, we will do this after the call to `Connect()`, shown below:
344+
A WOLFSSL object needs to be created after each TCP connect and the socket file descriptor needs to be associated with the session. In the echoclient example, we will do this after the call to `connect()`, shown below:
345345
346346
```c
347347
/* Connect to socket file descriptor */
348-
Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
348+
connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
349349
```
350350

351351
Directly after connecting, 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`):
@@ -497,7 +497,7 @@ while(cleanup != 1)
497497
}
498498
```
499499

500-
For the echoserver we need to disable the operating system from restarting calls which were being executed before the signal was handled after our handler has finished. By disabling these, the operating system will not restart calls to `accept()` after the signal has been handled. If we didn’t do this, we would have to wait for another client to connect and disconnect before the echoserver would clean up resources and exit. To define the signal handler and turn off `SA_RESTART`, first define act and oact structures in the echoserver’s `main()` function:
500+
For the echoserver we need to disable the operating system from restarting calls which were being executed before the signal was handled after our handler has finished. By disabling these, the operating system will not restart calls to `accept()` after the signal has been handled. If we didn’t do this, we would have to wait for another client to connect and disconnect before the echoserver would clean up resources and exit. To define the signal handler and turn off `SA_RESTART`, first define `act` and `oact` structures in the echoserver’s `main()` function:
501501

502502
```c
503503
struct sigaction act, oact;

0 commit comments

Comments
 (0)