blob: f7826d435977cbc0cfd57a4ab6154081340bf3ec [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
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 Peskinef040a172017-05-05 18:56:12 +020022default: all_final
23
24all_intermediate := # temporary files
25all_final := # files used by tests
26
Gilles Peskinefd14bca2017-05-11 17:57:22 +020027
28
29################################################################
30#### Generate certificates from existing keys
31################################################################
32
33test_ca_key_file_rsa = test-ca.key
34test_ca_pwd_rsa = PolarSSLTest
35test_ca_config_file = test-ca.opensslconf
36
Gilles Peskinef040a172017-05-05 18:56:12 +020037test-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 $@
39all_intermediate += test-ca.csr
40test-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 $@
42all_final += test-ca-sha1.crt
43test-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 $@
45all_final += test-ca-sha256.crt
46
Gilles Peskinefd14bca2017-05-11 17:57:22 +020047cli_crt_key_file_rsa = cli-rsa.key
48cli_crt_extensions_file = cli.opensslconf
49
Gilles Peskinef040a172017-05-05 18:56:12 +020050cli-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 $@
52all_intermediate += cli-rsa.csr
53cli-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 $@
55all_final += cli-rsa-sha1.crt
56cli-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 $@
58all_final += cli-rsa-sha256.crt
59
Gilles Peskinebc70a182017-05-09 15:59:24 +020060server2-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 $@
62all_intermediate += server2-rsa.csr
63server2-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 $@
65all_final += server2-sha256.crt
66
67
Gilles Peskinefd14bca2017-05-11 17:57:22 +020068
69################################################################
70#### Meta targets
71################################################################
72
Gilles Peskinef040a172017-05-05 18:56:12 +020073all_final: $(all_final)
74all: $(all_intermediate) $(all_final)
75
Gilles Peskinefd14bca2017-05-11 17:57:22 +020076.PHONY: default all_final all
77
Gilles Peskinef040a172017-05-05 18:56:12 +020078# These files should not be committed to the repository.
79list_intermediate:
80 @printf '%s\n' $(all_intermediate) | sort
81# These files should be committed to the repository so that the test data is
82# available upon checkout without running a randomized process depending on
83# third-party tools.
84list_final:
85 @printf '%s\n' $(all_final) | sort
Gilles Peskinefd14bca2017-05-11 17:57:22 +020086.PHONY: list_intermediate list_final
Gilles Peskinef040a172017-05-05 18:56:12 +020087
Gilles Peskinefd14bca2017-05-11 17:57:22 +020088## Remove intermediate files
Gilles Peskinef040a172017-05-05 18:56:12 +020089clean:
90 rm -f $(all_intermediate)
Gilles Peskinefd14bca2017-05-11 17:57:22 +020091## Remove all build products, even the ones that are committed
Gilles Peskinef040a172017-05-05 18:56:12 +020092neat: clean
93 rm -f $(all_final)
Gilles Peskinefd14bca2017-05-11 17:57:22 +020094.PHONY: clean neat