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 | |
Manuel Pégourié-Gonnard | 2d825d4 | 2017-07-03 18:06:38 +0200 | [diff] [blame^] | 48 | test_ca_key_file_rsa_alt = test-ca-alt.key |
| 49 | |
| 50 | $(test_ca_key_file_rsa_alt): |
| 51 | $(OPENSSL) genrsa -out $@ 2048 |
| 52 | test-ca-alt.csr: $(test_ca_key_file_rsa_alt) $(test_ca_config_file) |
| 53 | $(OPENSSL) req -new -config $(test_ca_config_file) -key $(test_ca_key_file_rsa_alt) -subj "/C=NL/O=PolarSSL/CN=PolarSSL Test CA" -out $@ |
| 54 | all_intermediate += test-ca-alt.csr |
| 55 | test-ca-alt.crt: $(test_ca_key_file_rsa_alt) $(test_ca_config_file) test-ca-alt.csr |
| 56 | $(OPENSSL) req -x509 -config $(test_ca_config_file) -key $(test_ca_key_file_rsa_alt) -set_serial 0 -days 3653 -sha256 -in test-ca-alt.csr -out $@ |
| 57 | all_final += test-ca-alt.crt |
| 58 | test-ca-alt-good.crt: test-ca-alt.crt test-ca-sha256.crt |
| 59 | cat test-ca-alt.crt test-ca-sha256.crt > $@ |
| 60 | all_final += test-ca-alt-good.crt |
| 61 | test-ca-good-alt.crt: test-ca-alt.crt test-ca-sha256.crt |
| 62 | cat test-ca-sha256.crt test-ca-alt.crt > $@ |
| 63 | all_final += test-ca-good-alt.crt |
| 64 | |
Manuel Pégourié-Gonnard | bc31301 | 2017-06-27 12:51:52 +0200 | [diff] [blame] | 65 | test_ca_crt_file_ec = test-ca2.crt |
| 66 | test_ca_key_file_ec = test-ca2.key |
| 67 | |
| 68 | test-int-ca.csr: test-int-ca.key $(test_ca_config_file) |
| 69 | $(OPENSSL) req -new -config $(test_ca_config_file) -key test-int-ca.key -subj "/C=NL/O=PolarSSL/CN=PolarSSL Test Intermediate CA" -out $@ |
| 70 | all_intermediate += test-int-ca.csr |
| 71 | test-int-ca-exp.crt: $(test_ca_key_file_ec) $(test_ca_config_file) test-int-ca.csr |
| 72 | $(FAKETIME) -f -3653d $(OPENSSL) x509 -req -extfile $(test_ca_config_file) -extensions v3_ca -CA $(test_ca_crt_file_ec) -CAkey $(test_ca_key_file_ec) -set_serial 14 -days 3653 -sha256 -in test-int-ca.csr -out $@ |
| 73 | all_final += test-int-ca-exp.crt |
| 74 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 75 | cli_crt_key_file_rsa = cli-rsa.key |
| 76 | cli_crt_extensions_file = cli.opensslconf |
| 77 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 78 | cli-rsa.csr: $(cli_crt_key_file_rsa) |
| 79 | $(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 $@ |
| 80 | all_intermediate += cli-rsa.csr |
| 81 | cli-rsa-sha1.crt: $(cli_crt_key_file_rsa) test-ca-sha1.crt cli-rsa.csr |
| 82 | $(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 $@ |
| 83 | all_final += cli-rsa-sha1.crt |
| 84 | cli-rsa-sha256.crt: $(cli_crt_key_file_rsa) test-ca-sha256.crt cli-rsa.csr |
| 85 | $(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 $@ |
| 86 | all_final += cli-rsa-sha256.crt |
| 87 | |
Gilles Peskine | bc70a18 | 2017-05-09 15:59:24 +0200 | [diff] [blame] | 88 | server2-rsa.csr: server2.key |
| 89 | $(OPENSSL) req -new -key server2.key -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@ |
| 90 | all_intermediate += server2-rsa.csr |
| 91 | server2-sha256.crt: server2-rsa.csr |
| 92 | $(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 $@ |
| 93 | all_final += server2-sha256.crt |
| 94 | |
Manuel Pégourié-Gonnard | 29d60fb | 2017-06-05 10:20:32 +0200 | [diff] [blame] | 95 | test_ca_int_rsa1 = test-int-ca.crt |
| 96 | |
| 97 | server7.csr: server7.key |
| 98 | $(OPENSSL) req -new -key server7.key -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@ |
| 99 | all_intermediate += server7.csr |
| 100 | server7-expired.crt: server7.csr $(test_ca_int_rsa1) |
| 101 | $(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) > $@ |
| 102 | all_final += server7-expired.crt |
| 103 | server7-future.crt: server7.csr $(test_ca_int_rsa1) |
| 104 | $(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) > $@ |
| 105 | all_final += server7-future.crt |
Manuel Pégourié-Gonnard | 4dfc04a | 2017-06-05 11:12:13 +0200 | [diff] [blame] | 106 | server7-badsign.crt: server7.crt $(test_ca_int_rsa1) |
| 107 | { head -n-2 server7.crt; tail -n-2 server7.crt | sed -e '1s/0\(=*\)$$/_\1/' -e '1s/[^_=]\(=*\)$$/0\1/' -e '1s/_/1/'; cat test-int-ca.crt; } > server7-badsign.crt |
| 108 | all_final += server7-badsign.crt |
Manuel Pégourié-Gonnard | bc31301 | 2017-06-27 12:51:52 +0200 | [diff] [blame] | 109 | server7_int-ca-exp.crt: server7.crt test-int-ca-exp.crt |
| 110 | cat server7.crt test-int-ca-exp.crt > $@ |
| 111 | all_final += server7_int-ca-exp.crt |
| 112 | |
| 113 | server5-ss-expired.crt: server5.key |
| 114 | $(FAKETIME) -f -3653d $(OPENSSL) req -x509 -new -subj "/C=UK/O=mbed TLS/OU=testsuite/CN=localhost" -days 3653 -sha256 -key $< -out $@ |
| 115 | all_final += server5-ss-expired.crt |
| 116 | |
Manuel Pégourié-Gonnard | c10afdb | 2017-06-29 09:48:08 +0200 | [diff] [blame] | 117 | # try to forge a copy of test-int-ca3 with different key |
| 118 | server5-ss-forgeca.crt: server5.key |
| 119 | $(FAKETIME) '2015-09-01 14:08:43' $(OPENSSL) req -x509 -new -subj "/C=UK/O=mbed TLS/CN=mbed TLS Test intermediate CA 3" -set_serial 77 -config $(test_ca_config_file) -extensions noext_ca -days 3650 -sha256 -key $< -out $@ |
| 120 | all_final += server5-ss-forgeca.crt |
| 121 | |
| 122 | |
| 123 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 124 | |
| 125 | ################################################################ |
| 126 | #### Meta targets |
| 127 | ################################################################ |
| 128 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 129 | all_final: $(all_final) |
| 130 | all: $(all_intermediate) $(all_final) |
| 131 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 132 | .PHONY: default all_final all |
| 133 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 134 | # These files should not be committed to the repository. |
| 135 | list_intermediate: |
| 136 | @printf '%s\n' $(all_intermediate) | sort |
| 137 | # These files should be committed to the repository so that the test data is |
| 138 | # available upon checkout without running a randomized process depending on |
| 139 | # third-party tools. |
| 140 | list_final: |
| 141 | @printf '%s\n' $(all_final) | sort |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 142 | .PHONY: list_intermediate list_final |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 143 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 144 | ## Remove intermediate files |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 145 | clean: |
| 146 | rm -f $(all_intermediate) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 147 | ## Remove all build products, even the ones that are committed |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 148 | neat: clean |
| 149 | rm -f $(all_final) |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 150 | .PHONY: clean neat |