Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 1 | Mbed TLS sample programs |
| 2 | ======================== |
| 3 | |
| 4 | This subdirectory mostly contains sample programs that illustrate specific features of the library, as well as a few test and support programs. |
| 5 | |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 6 | ### Generic public-key cryptography (`pk`) examples |
| 7 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 8 | * [`pkey/gen_key.c`](pkey/gen_key.c): generates a key for any of the supported public-key algorithms (RSA or ECC) and writes it to a file that can be used by the other pk sample programs. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 9 | |
Gilles Peskine | 27a0460 | 2018-08-06 20:09:16 +0200 | [diff] [blame] | 10 | * [`pkey/pk_sign.c`](pkey/pk_sign.c), [`pkey/pk_verify.c`](pkey/pk_verify.c): loads a PEM or DER private/public key file and uses the key to sign/verify a short string. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 11 | |
| 12 | ### ECDSA and RSA signature examples |
| 13 | |
Gilles Peskine | 0b54419 | 2018-08-10 11:32:11 +0200 | [diff] [blame] | 14 | * [`pkey/rsa_sign_pss.c`](pkey/rsa_sign_pss.c), [`pkey/rsa_verify_pss.c`](pkey/rsa_verify_pss.c): loads an RSA private/public key and uses it to sign/verify a short string with the RSASSA-PSS algorithm. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 15 | |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 16 | ### SSL/TLS sample applications |
| 17 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 18 | * [`ssl/dtls_client.c`](ssl/dtls_client.c): a simple DTLS client program, which sends one datagram to the server and reads one datagram in response. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 19 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 20 | * [`ssl/dtls_server.c`](ssl/dtls_server.c): a simple DTLS server program, which expects one datagram from the client and writes one datagram in response. This program supports DTLS cookies for hello verification. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 21 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 22 | * [`ssl/mini_client.c`](ssl/mini_client.c): a minimalistic SSL client, which sends a short string and disconnects. This is primarily intended as a benchmark; for a better example of a typical TLS client, see `ssl/ssl_client1.c`. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 23 | |
| 24 | * [`ssl/ssl_client1.c`](ssl/ssl_client1.c): a simple HTTPS client that sends a fixed request and displays the response. |
| 25 | |
| 26 | * [`ssl/ssl_fork_server.c`](ssl/ssl_fork_server.c): a simple HTTPS server using one process per client to send a fixed response. This program requires a Unix/POSIX environment implementing the `fork` system call. |
| 27 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 28 | * [`ssl/ssl_mail_client.c`](ssl/ssl_mail_client.c): a simple SMTP-over-TLS or SMTP-STARTTLS client. This client sends an email with fixed content. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 29 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 30 | * [`ssl/ssl_pthread_server.c`](ssl/ssl_pthread_server.c): a simple HTTPS server using one thread per client to send a fixed response. This program requires the pthread library. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 31 | |
Gilles Peskine | aa22030 | 2018-08-06 20:19:50 +0200 | [diff] [blame] | 32 | * [`ssl/ssl_server.c`](ssl/ssl_server.c): a simple HTTPS server that sends a fixed response. It serves a single client at a time. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 33 | |
| 34 | ### SSL/TLS feature demonstrators |
| 35 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 36 | Note: unlike most of the other programs under the `programs/` directory, these two programs are not intended as a basis for writing an application. They combine most of the features supported by the library, and most applications require only a few features. To write a new application, we recommended that you start with `ssl_client1.c` or `ssl_server.c`, and then look inside `ssl/ssl_client2.c` or `ssl/ssl_server2.c` to see how to use the specific features that your application needs. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 37 | |
| 38 | * [`ssl/ssl_client2.c`](ssl/ssl_client2.c): an HTTPS client that sends a fixed request and displays the response, with options to select TLS protocol features and Mbed TLS library features. |
| 39 | |
| 40 | * [`ssl/ssl_server2.c`](ssl/ssl_server2.c): an HTTPS server that sends a fixed response, with options to select TLS protocol features and Mbed TLS library features. |
| 41 | |
Gilles Peskine | aa22030 | 2018-08-06 20:19:50 +0200 | [diff] [blame] | 42 | In addition to providing options for testing client-side features, the `ssl_client2` program has options that allow you to trigger certain behaviors in the server. For example, there are options to select ciphersuites, or to force a renegotiation. These options are useful for testing the corresponding features in a TLS server. Likewise, `ssl_server2` has options to activate certain behaviors that are useful for testing a TLS client. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 43 | |
| 44 | ## Test utilities |
| 45 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 46 | * [`test/selftest.c`](test/selftest.c): runs the self-test function in each library module. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 47 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 48 | * [`test/udp_proxy.c`](test/udp_proxy.c): a UDP proxy that can inject certain failures (delay, duplicate, drop). Useful for testing DTLS. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 49 | |
Harry Ramsey | f6fb2f0 | 2025-02-18 17:52:45 +0000 | [diff] [blame] | 50 | * [`test/zeroize.c`](../framework/tests/programs/zeroize.c): a test program for `mbedtls_platform_zeroize`, used by [`test_zeroize.gdb`](../framework/tests/programs/test_zeroize.gdb). |
Gilles Peskine | ffbdc61 | 2018-08-10 11:48:52 +0200 | [diff] [blame] | 51 | |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 52 | ## Development utilities |
| 53 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 54 | * [`util/pem2der.c`](util/pem2der.c): a PEM to DER converter. Mbed TLS can read PEM files directly, but this utility can be useful for interacting with other tools or with minimal Mbed TLS builds that lack PEM support. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 55 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 56 | * [`util/strerror.c`](util/strerror.c): prints the error description corresponding to an integer status returned by an Mbed TLS function. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 57 | |
| 58 | ## X.509 certificate examples |
| 59 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 60 | * [`x509/cert_app.c`](x509/cert_app.c): connects to a TLS server and verifies its certificate chain. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 61 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 62 | * [`x509/cert_req.c`](x509/cert_req.c): generates a certificate signing request (CSR) for a private key. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 63 | |
Gilles Peskine | 27a0460 | 2018-08-06 20:09:16 +0200 | [diff] [blame] | 64 | * [`x509/cert_write.c`](x509/cert_write.c): signs a certificate signing request, or self-signs a certificate. |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 65 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 66 | * [`x509/crl_app.c`](x509/crl_app.c): loads and dumps a certificate revocation list (CRL). |
Gilles Peskine | ceb7b12 | 2018-01-18 23:27:47 +0100 | [diff] [blame] | 67 | |
Gilles Peskine | 6b9cbb8 | 2018-07-30 20:06:19 +0200 | [diff] [blame] | 68 | * [`x509/req_app.c`](x509/req_app.c): loads and dumps a certificate signing request (CSR). |