mbedtls/programs
Gilles Peskine c83e56cc45 Test ssl_fork_server
Test ssl_fork_server with both TLS 1.2 and TLS 1.3.
Test against both OpenSSL and GnuTLS.

In the server, flush more often. Otherwise, when stdout is redirected to a
file, the server gets killed before it writes important information, such as
the logs that we expect in the test cases.

In the server, only write output for 10 seconds, not 100. That's enough time
to start concurrent clients if desired. 100 seconds causes ssl-opt to take a
very long time when the client actually listens to the whole input (which
`gnutls-cli` does, but not `openssl s_client`).

Clean up compile-time requirements in ssl_fork_server.c: any certificate-based
key exchange is ok, so don't insist on built-in RSA.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-25 18:05:17 +02:00
..
aes CMake: support "make programs" 2024-09-14 12:19:19 +02:00
cipher CMake: support "make programs" 2024-09-14 12:19:19 +02:00
fuzz CMake: support "make programs" 2024-09-14 12:19:19 +02:00
hash CMake: support "make programs" 2024-09-14 12:19:19 +02:00
pkey CMake: support "make programs" 2024-09-14 12:19:19 +02:00
psa CMake: support "make programs" 2024-09-14 12:19:19 +02:00
random CMake: support "make programs" 2024-09-14 12:19:19 +02:00
ssl Test ssl_fork_server 2024-09-25 18:05:17 +02:00
test CMake: support "make ssl-opt" to just build what ssl-opt.sh needs 2024-09-14 12:19:19 +02:00
util CMake: support "make programs" 2024-09-14 12:19:19 +02:00
x509 CMake: support "make programs" 2024-09-14 12:19:19 +02:00
.gitignore Revert "Autogenerated files for 3.6.0" 2024-03-27 17:36:15 +00:00
CMakeLists.txt Have make ssl-opt generate tls13-compat.sh 2024-09-24 19:09:57 +02:00
demo_common.sh
Makefile make: support "make ssl-opt" to just build what ssl-opt.sh needs 2024-09-14 13:06:15 +02:00
README.md
wince_main.c update headers 2023-11-02 19:47:20 +00:00

Mbed TLS sample programs

This subdirectory mostly contains sample programs that illustrate specific features of the library, as well as a few test and support programs.

Symmetric cryptography (AES) examples

  • aes/crypt_and_hash.c: file encryption and authentication, demonstrating the generic cipher interface and the generic hash interface.

Hash (digest) examples

Public-key cryptography examples

Generic public-key cryptography (pk) examples

  • 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.

  • pkey/key_app.c: loads a PEM or DER public key or private key file and dumps its content.

  • pkey/key_app_writer.c: loads a PEM or DER public key or private key file and writes it to a new PEM or DER file.

  • pkey/pk_encrypt.c, pkey/pk_decrypt.c: loads a PEM or DER public/private key file and uses the key to encrypt/decrypt a short string through the generic public-key interface.

  • pkey/pk_sign.c, pkey/pk_verify.c: loads a PEM or DER private/public key file and uses the key to sign/verify a short string.

ECDSA and RSA signature examples

Diffie-Hellman key exchange examples

  • pkey/dh_client.c, pkey/dh_server.c: secure channel demonstrators (client, server). This pair of programs illustrates how to set up a secure channel using RSA for authentication and Diffie-Hellman to generate a shared AES session key.

  • pkey/ecdh_curve25519.c: demonstration of a elliptic curve Diffie-Hellman (ECDH) key agreement.

Bignum (mpi) usage examples

Random number generator (RNG) examples

  • random/gen_entropy.c: shows how to use the default entropy sources to generate random data.
    Note: most applications should only use the entropy generator to seed a cryptographic pseudorandom generator, as illustrated by random/gen_random_ctr_drbg.c.

  • random/gen_random_ctr_drbg.c: shows how to use the default entropy sources to seed a pseudorandom generator, and how to use the resulting random generator to generate random data.

SSL/TLS examples

SSL/TLS sample applications

  • ssl/dtls_client.c: a simple DTLS client program, which sends one datagram to the server and reads one datagram in response.

  • 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.

  • 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.

  • ssl/ssl_client1.c: a simple HTTPS client that sends a fixed request and displays the response.

  • 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.

  • ssl/ssl_mail_client.c: a simple SMTP-over-TLS or SMTP-STARTTLS client. This client sends an email with fixed content.

  • 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.

  • ssl/ssl_server.c: a simple HTTPS server that sends a fixed response. It serves a single client at a time.

SSL/TLS feature demonstrators

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.

  • 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.

  • ssl/ssl_server2.c: an HTTPS server that sends a fixed response, with options to select TLS protocol features and Mbed TLS library features.

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.

Test utilities

Development utilities

  • 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.

  • util/strerror.c: prints the error description corresponding to an integer status returned by an Mbed TLS function.

X.509 certificate examples

  • x509/cert_app.c: connects to a TLS server and verifies its certificate chain.

  • x509/cert_req.c: generates a certificate signing request (CSR) for a private key.

  • x509/cert_write.c: signs a certificate signing request, or self-signs a certificate.

  • x509/crl_app.c: loads and dumps a certificate revocation list (CRL).

  • x509/req_app.c: loads and dumps a certificate signing request (CSR).