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 |
Manuel Pégourié-Gonnard | 29d60fb | 2017-06-05 10:20:32 +0200 | [diff] [blame^] | 15 | FAKETIME ?= faketime |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 16 | |
| 17 | ## Build the generated test data. Note that since the final outputs |
| 18 | ## are committed to the repository, this target should do nothing on a |
| 19 | ## fresh checkout. Furthermore, since the generation is randomized, |
| 20 | ## re-running the same targets may result in differing files. The goal |
| 21 | ## of this makefile is primarily to serve as a record of how the |
| 22 | ## targets were generated in the first place. |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 23 | default: all_final |
| 24 | |
| 25 | all_intermediate := # temporary files |
| 26 | all_final := # files used by tests |
| 27 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 28 | |
| 29 | |
| 30 | ################################################################ |
| 31 | #### Generate certificates from existing keys |
| 32 | ################################################################ |
| 33 | |
| 34 | test_ca_key_file_rsa = test-ca.key |
| 35 | test_ca_pwd_rsa = PolarSSLTest |
| 36 | test_ca_config_file = test-ca.opensslconf |
| 37 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 38 | test-ca.csr: $(test_ca_key_file_rsa) $(test_ca_config_file) |
| 39 | $(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 $@ |
| 40 | all_intermediate += test-ca.csr |
| 41 | test-ca-sha1.crt: $(test_ca_key_file_rsa) $(test_ca_config_file) test-ca.csr |
| 42 | $(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 $@ |
| 43 | all_final += test-ca-sha1.crt |
| 44 | test-ca-sha256.crt: $(test_ca_key_file_rsa) $(test_ca_config_file) test-ca.csr |
| 45 | $(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 $@ |
| 46 | all_final += test-ca-sha256.crt |
| 47 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 48 | cli_crt_key_file_rsa = cli-rsa.key |
| 49 | cli_crt_extensions_file = cli.opensslconf |
| 50 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 51 | cli-rsa.csr: $(cli_crt_key_file_rsa) |
| 52 | $(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 $@ |
| 53 | all_intermediate += cli-rsa.csr |
| 54 | cli-rsa-sha1.crt: $(cli_crt_key_file_rsa) test-ca-sha1.crt cli-rsa.csr |
| 55 | $(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 $@ |
| 56 | all_final += cli-rsa-sha1.crt |
| 57 | cli-rsa-sha256.crt: $(cli_crt_key_file_rsa) test-ca-sha256.crt cli-rsa.csr |
| 58 | $(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 $@ |
| 59 | all_final += cli-rsa-sha256.crt |
| 60 | |
Gilles Peskine | bc70a18 | 2017-05-09 15:59:24 +0200 | [diff] [blame] | 61 | server2-rsa.csr: server2.key |
| 62 | $(OPENSSL) req -new -key server2.key -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@ |
| 63 | all_intermediate += server2-rsa.csr |
| 64 | server2-sha256.crt: server2-rsa.csr |
| 65 | $(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 $@ |
| 66 | all_final += server2-sha256.crt |
| 67 | |
Manuel Pégourié-Gonnard | 29d60fb | 2017-06-05 10:20:32 +0200 | [diff] [blame^] | 68 | test_ca_int_rsa1 = test-int-ca.crt |
| 69 | |
| 70 | server7.csr: server7.key |
| 71 | $(OPENSSL) req -new -key server7.key -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@ |
| 72 | all_intermediate += server7.csr |
| 73 | server7-expired.crt: server7.csr $(test_ca_int_rsa1) |
| 74 | $(FAKETIME) -f -3653d $(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa -CA $(test_ca_int_rsa1) -CAkey test-int-ca.key -set_serial 16 -days 3653 -sha256 -in server7.csr | cat - $(test_ca_int_rsa1) > $@ |
| 75 | all_final += server7-expired.crt |
| 76 | server7-future.crt: server7.csr $(test_ca_int_rsa1) |
| 77 | $(FAKETIME) -f +3653d $(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa -CA $(test_ca_int_rsa1) -CAkey test-int-ca.key -set_serial 16 -days 3653 -sha256 -in server7.csr | cat - $(test_ca_int_rsa1) > $@ |
| 78 | all_final += server7-future.crt |
| 79 | |
Gilles Peskine | bc70a18 | 2017-05-09 15:59:24 +0200 | [diff] [blame] | 80 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 81 | |
| 82 | ################################################################ |
| 83 | #### Meta targets |
| 84 | ################################################################ |
| 85 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 86 | all_final: $(all_final) |
| 87 | all: $(all_intermediate) $(all_final) |
| 88 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 89 | .PHONY: default all_final all |
| 90 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 91 | # These files should not be committed to the repository. |
| 92 | list_intermediate: |
| 93 | @printf '%s\n' $(all_intermediate) | sort |
| 94 | # These files should be committed to the repository so that the test data is |
| 95 | # available upon checkout without running a randomized process depending on |
| 96 | # third-party tools. |
| 97 | list_final: |
| 98 | @printf '%s\n' $(all_final) | sort |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 99 | .PHONY: list_intermediate list_final |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 100 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 101 | ## Remove intermediate files |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 102 | clean: |
| 103 | rm -f $(all_intermediate) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 104 | ## Remove all build products, even the ones that are committed |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 105 | neat: clean |
| 106 | rm -f $(all_final) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 107 | .PHONY: clean neat |