blob: 05d7d23ff56d68bdd25ea546e2a7e51285c028b9 [file] [log] [blame]
Gilles Peskinefd14bca2017-05-11 17:57:22 +02001## 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 Peskinef040a172017-05-05 18:56:12 +02005
Gilles Peskinefd14bca2017-05-11 17:57:22 +02006## Many data files were generated prior to the existence of this
7## makefile, so the method of their generation was not recorded.
Gilles Peskinef040a172017-05-05 18:56:12 +02008
Gilles Peskinefd14bca2017-05-11 17:57:22 +02009## 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
14OPENSSL ?= openssl
Manuel Pégourié-Gonnard29d60fb2017-06-05 10:20:32 +020015FAKETIME ?= faketime
Gilles Peskinefd14bca2017-05-11 17:57:22 +020016
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 Peskinef040a172017-05-05 18:56:12 +020023default: all_final
24
25all_intermediate := # temporary files
26all_final := # files used by tests
27
Gilles Peskinefd14bca2017-05-11 17:57:22 +020028
29
30################################################################
31#### Generate certificates from existing keys
32################################################################
33
34test_ca_key_file_rsa = test-ca.key
35test_ca_pwd_rsa = PolarSSLTest
36test_ca_config_file = test-ca.opensslconf
37
Gilles Peskinef040a172017-05-05 18:56:12 +020038test-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 $@
40all_intermediate += test-ca.csr
41test-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 $@
43all_final += test-ca-sha1.crt
44test-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 $@
46all_final += test-ca-sha256.crt
47
Manuel Pégourié-Gonnard2d825d42017-07-03 18:06:38 +020048test_ca_key_file_rsa_alt = test-ca-alt.key
49
50$(test_ca_key_file_rsa_alt):
51 $(OPENSSL) genrsa -out $@ 2048
52test-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 $@
54all_intermediate += test-ca-alt.csr
55test-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 $@
57all_final += test-ca-alt.crt
58test-ca-alt-good.crt: test-ca-alt.crt test-ca-sha256.crt
59 cat test-ca-alt.crt test-ca-sha256.crt > $@
60all_final += test-ca-alt-good.crt
61test-ca-good-alt.crt: test-ca-alt.crt test-ca-sha256.crt
62 cat test-ca-sha256.crt test-ca-alt.crt > $@
63all_final += test-ca-good-alt.crt
64
Manuel Pégourié-Gonnardbc313012017-06-27 12:51:52 +020065test_ca_crt_file_ec = test-ca2.crt
66test_ca_key_file_ec = test-ca2.key
67
68test-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 $@
70all_intermediate += test-int-ca.csr
Manuel Pégourié-Gonnard7ff243a2017-08-08 18:54:13 +020071test-int-ca-exp.crt: $(test_ca_crt_file_ec) $(test_ca_key_file_ec) $(test_ca_config_file) test-int-ca.csr
Manuel Pégourié-Gonnardbc313012017-06-27 12:51:52 +020072 $(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 $@
73all_final += test-int-ca-exp.crt
74
Gilles Peskinefd14bca2017-05-11 17:57:22 +020075cli_crt_key_file_rsa = cli-rsa.key
76cli_crt_extensions_file = cli.opensslconf
77
Gilles Peskinef040a172017-05-05 18:56:12 +020078cli-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 $@
80all_intermediate += cli-rsa.csr
81cli-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 $@
83all_final += cli-rsa-sha1.crt
84cli-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 $@
86all_final += cli-rsa-sha256.crt
87
Gilles Peskinebc70a182017-05-09 15:59:24 +020088server2-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 $@
90all_intermediate += server2-rsa.csr
91server2-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 $@
93all_final += server2-sha256.crt
94
Manuel Pégourié-Gonnard29d60fb2017-06-05 10:20:32 +020095test_ca_int_rsa1 = test-int-ca.crt
96
97server7.csr: server7.key
98 $(OPENSSL) req -new -key server7.key -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@
99all_intermediate += server7.csr
100server7-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) > $@
102all_final += server7-expired.crt
103server7-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) > $@
105all_final += server7-future.crt
Manuel Pégourié-Gonnard4dfc04a2017-06-05 11:12:13 +0200106server7-badsign.crt: server7.crt $(test_ca_int_rsa1)
Manuel Pégourié-Gonnardd19a41d2017-07-14 11:05:59 +0200107 { head -n-2 $<; tail -n-2 $< | sed -e '1s/0\(=*\)$$/_\1/' -e '1s/[^_=]\(=*\)$$/0\1/' -e '1s/_/1/'; cat $(test_ca_int_rsa1); } > $@
Manuel Pégourié-Gonnard4dfc04a2017-06-05 11:12:13 +0200108all_final += server7-badsign.crt
Manuel Pégourié-Gonnardbc313012017-06-27 12:51:52 +0200109server7_int-ca-exp.crt: server7.crt test-int-ca-exp.crt
110 cat server7.crt test-int-ca-exp.crt > $@
111all_final += server7_int-ca-exp.crt
112
113server5-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 $@
115all_final += server5-ss-expired.crt
116
Manuel Pégourié-Gonnardc10afdb2017-06-29 09:48:08 +0200117# try to forge a copy of test-int-ca3 with different key
118server5-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 $@
120all_final += server5-ss-forgeca.crt
121
Manuel Pégourié-Gonnardd19a41d2017-07-14 11:05:59 +0200122server10-badsign.crt: server10.crt
123 { head -n-2 $<; tail -n-2 $< | sed -e '1s/0\(=*\)$$/_\1/' -e '1s/[^_=]\(=*\)$$/0\1/' -e '1s/_/1/'; } > $@
124all_final += server10-badsign.crt
125server10-bs_int3.pem: server10-badsign.crt test-int-ca3.crt
126 cat server10-badsign.crt test-int-ca3.crt > $@
127all_final += server10-bs_int3.pem
128test-int-ca3-badsign.crt: test-int-ca3.crt
129 { head -n-2 $<; tail -n-2 $< | sed -e '1s/0\(=*\)$$/_\1/' -e '1s/[^_=]\(=*\)$$/0\1/' -e '1s/_/1/'; } > $@
130all_final += test-int-ca3-badsign.crt
131server10_int3-bs.pem: server10.crt test-int-ca3-badsign.crt
132 cat server10.crt test-int-ca3-badsign.crt > $@
133all_final += server10-bs_int3-bs.pem
Manuel Pégourié-Gonnardc10afdb2017-06-29 09:48:08 +0200134
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200135
136################################################################
137#### Meta targets
138################################################################
139
Gilles Peskinef040a172017-05-05 18:56:12 +0200140all_final: $(all_final)
141all: $(all_intermediate) $(all_final)
142
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200143.PHONY: default all_final all
144
Gilles Peskinef040a172017-05-05 18:56:12 +0200145# These files should not be committed to the repository.
146list_intermediate:
147 @printf '%s\n' $(all_intermediate) | sort
148# These files should be committed to the repository so that the test data is
149# available upon checkout without running a randomized process depending on
150# third-party tools.
151list_final:
152 @printf '%s\n' $(all_final) | sort
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200153.PHONY: list_intermediate list_final
Gilles Peskinef040a172017-05-05 18:56:12 +0200154
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200155## Remove intermediate files
Gilles Peskinef040a172017-05-05 18:56:12 +0200156clean:
157 rm -f $(all_intermediate)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200158## Remove all build products, even the ones that are committed
Gilles Peskinef040a172017-05-05 18:56:12 +0200159neat: clean
160 rm -f $(all_final)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200161.PHONY: clean neat