blob: 521e4a29f6a6e093c5aeba95bf449be22c4384b8 [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
Gilles Peskinefd14bca2017-05-11 17:57:22 +020048cli_crt_key_file_rsa = cli-rsa.key
49cli_crt_extensions_file = cli.opensslconf
50
Gilles Peskinef040a172017-05-05 18:56:12 +020051cli-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 $@
53all_intermediate += cli-rsa.csr
54cli-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 $@
56all_final += cli-rsa-sha1.crt
57cli-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 $@
59all_final += cli-rsa-sha256.crt
60
Gilles Peskinebc70a182017-05-09 15:59:24 +020061server2-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 $@
63all_intermediate += server2-rsa.csr
64server2-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 $@
66all_final += server2-sha256.crt
67
Manuel Pégourié-Gonnard29d60fb2017-06-05 10:20:32 +020068test_ca_int_rsa1 = test-int-ca.crt
69
70server7.csr: server7.key
71 $(OPENSSL) req -new -key server7.key -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@
72all_intermediate += server7.csr
73server7-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) > $@
75all_final += server7-expired.crt
76server7-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) > $@
78all_final += server7-future.crt
79
Gilles Peskinebc70a182017-05-09 15:59:24 +020080
Gilles Peskinefd14bca2017-05-11 17:57:22 +020081
82################################################################
83#### Meta targets
84################################################################
85
Gilles Peskinef040a172017-05-05 18:56:12 +020086all_final: $(all_final)
87all: $(all_intermediate) $(all_final)
88
Gilles Peskinefd14bca2017-05-11 17:57:22 +020089.PHONY: default all_final all
90
Gilles Peskinef040a172017-05-05 18:56:12 +020091# These files should not be committed to the repository.
92list_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.
97list_final:
98 @printf '%s\n' $(all_final) | sort
Gilles Peskinefd14bca2017-05-11 17:57:22 +020099.PHONY: list_intermediate list_final
Gilles Peskinef040a172017-05-05 18:56:12 +0200100
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200101## Remove intermediate files
Gilles Peskinef040a172017-05-05 18:56:12 +0200102clean:
103 rm -f $(all_intermediate)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200104## Remove all build products, even the ones that are committed
Gilles Peskinef040a172017-05-05 18:56:12 +0200105neat: clean
106 rm -f $(all_final)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200107.PHONY: clean neat