Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 1 | ## This file contains a record of how some of the test data was |
| 2 | ## generated. The final build products are committed to the repository |
| 3 | ## as well to make sure that the test data is identical. You do not |
| 4 | ## need to use this makefile unless you're extending mbed TLS's tests. |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 5 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 6 | ## Many data files were generated prior to the existence of this |
| 7 | ## makefile, so the method of their generation was not recorded. |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 8 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 9 | ## Note that in addition to depending on the version of the data |
| 10 | ## generation tool, many of the build outputs are randomized, so |
| 11 | ## running this makefile twice would not produce the same results. |
| 12 | |
| 13 | ## Tools |
| 14 | OPENSSL ?= openssl |
| 15 | |
| 16 | ## Build the generated test data. Note that since the final outputs |
| 17 | ## are committed to the repository, this target should do nothing on a |
| 18 | ## fresh checkout. Furthermore, since the generation is randomized, |
| 19 | ## re-running the same targets may result in differing files. The goal |
| 20 | ## of this makefile is primarily to serve as a record of how the |
| 21 | ## targets were generated in the first place. |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 22 | default: all_final |
| 23 | |
| 24 | all_intermediate := # temporary files |
| 25 | all_final := # files used by tests |
| 26 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 27 | |
| 28 | |
| 29 | ################################################################ |
| 30 | #### Generate certificates from existing keys |
| 31 | ################################################################ |
| 32 | |
| 33 | test_ca_key_file_rsa = test-ca.key |
| 34 | test_ca_pwd_rsa = PolarSSLTest |
| 35 | test_ca_config_file = test-ca.opensslconf |
| 36 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 37 | test-ca.csr: $(test_ca_key_file_rsa) $(test_ca_config_file) |
| 38 | $(OPENSSL) req -new -config $(test_ca_config_file) -key $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=PolarSSL Test CA" -out $@ |
| 39 | all_intermediate += test-ca.csr |
| 40 | test-ca-sha1.crt: $(test_ca_key_file_rsa) $(test_ca_config_file) test-ca.csr |
| 41 | $(OPENSSL) req -x509 -config $(test_ca_config_file) -key $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -set_serial 0 -days 3653 -sha1 -in test-ca.csr -out $@ |
| 42 | all_final += test-ca-sha1.crt |
| 43 | test-ca-sha256.crt: $(test_ca_key_file_rsa) $(test_ca_config_file) test-ca.csr |
| 44 | $(OPENSSL) req -x509 -config $(test_ca_config_file) -key $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -set_serial 0 -days 3653 -sha256 -in test-ca.csr -out $@ |
| 45 | all_final += test-ca-sha256.crt |
| 46 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 47 | cli_crt_key_file_rsa = cli-rsa.key |
| 48 | cli_crt_extensions_file = cli.opensslconf |
| 49 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 50 | cli-rsa.csr: $(cli_crt_key_file_rsa) |
| 51 | $(OPENSSL) req -new -key $(cli_crt_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=PolarSSL Client 2" -out $@ |
| 52 | all_intermediate += cli-rsa.csr |
| 53 | cli-rsa-sha1.crt: $(cli_crt_key_file_rsa) test-ca-sha1.crt cli-rsa.csr |
| 54 | $(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa -CA test-ca-sha1.crt -CAkey $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -set_serial 4 -days 3653 -sha1 -in cli-rsa.csr -out $@ |
| 55 | all_final += cli-rsa-sha1.crt |
| 56 | cli-rsa-sha256.crt: $(cli_crt_key_file_rsa) test-ca-sha256.crt cli-rsa.csr |
| 57 | $(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa -CA test-ca-sha256.crt -CAkey $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -set_serial 4 -days 3653 -sha256 -in cli-rsa.csr -out $@ |
| 58 | all_final += cli-rsa-sha256.crt |
| 59 | |
Gilles Peskine | bc70a18 | 2017-05-09 15:59:24 +0200 | [diff] [blame] | 60 | server2-rsa.csr: server2.key |
| 61 | $(OPENSSL) req -new -key server2.key -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@ |
| 62 | all_intermediate += server2-rsa.csr |
| 63 | server2-sha256.crt: server2-rsa.csr |
| 64 | $(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa -CA test-ca-sha256.crt -CAkey $(test_ca_key_file_rsa) -passin "pass:$(test_ca_pwd_rsa)" -set_serial 4 -days 3653 -sha256 -in server2-rsa.csr -out $@ |
| 65 | all_final += server2-sha256.crt |
| 66 | |
Ron Eldor | b006518 | 2017-10-16 12:40:27 +0300 | [diff] [blame^] | 67 | rsa_pkcs1_2048_public.pem: server8.key |
| 68 | $(OPENSSL) rsa -in server8.key -outform PEM -RSAPublicKey_out -out $@ |
| 69 | all_final += rsa_pkcs8_2048_public.pem |
Gilles Peskine | bc70a18 | 2017-05-09 15:59:24 +0200 | [diff] [blame] | 70 | |
Ron Eldor | b006518 | 2017-10-16 12:40:27 +0300 | [diff] [blame^] | 71 | rsa_pkcs1_2048_public.der: rsa_pkcs1_2048_public.pem |
| 72 | $(OPENSSL) -RSAPublicKey_in -in rsa_pkcs1_2048_public.pem -outform DER -RSAPublicKey_out -out $@ |
| 73 | all_final += rsa_pkcs8_2048_public.der |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 74 | |
| 75 | ################################################################ |
| 76 | #### Meta targets |
| 77 | ################################################################ |
| 78 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 79 | all_final: $(all_final) |
| 80 | all: $(all_intermediate) $(all_final) |
| 81 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 82 | .PHONY: default all_final all |
| 83 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 84 | # These files should not be committed to the repository. |
| 85 | list_intermediate: |
| 86 | @printf '%s\n' $(all_intermediate) | sort |
| 87 | # These files should be committed to the repository so that the test data is |
| 88 | # available upon checkout without running a randomized process depending on |
| 89 | # third-party tools. |
| 90 | list_final: |
| 91 | @printf '%s\n' $(all_final) | sort |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 92 | .PHONY: list_intermediate list_final |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 93 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 94 | ## Remove intermediate files |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 95 | clean: |
| 96 | rm -f $(all_intermediate) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 97 | ## Remove all build products, even the ones that are committed |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 98 | neat: clean |
| 99 | rm -f $(all_final) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 100 | .PHONY: clean neat |