blob: 7476bf784f55dd90b0b921b7aaf64152d105356f [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é-Gonnardbc313012017-06-27 12:51:52 +020048test_ca_crt_file_ec = test-ca2.crt
49test_ca_key_file_ec = test-ca2.key
50
51test-int-ca.csr: test-int-ca.key $(test_ca_config_file)
52 $(OPENSSL) req -new -config $(test_ca_config_file) -key test-int-ca.key -subj "/C=NL/O=PolarSSL/CN=PolarSSL Test Intermediate CA" -out $@
53all_intermediate += test-int-ca.csr
54test-int-ca-exp.crt: $(test_ca_key_file_ec) $(test_ca_config_file) test-int-ca.csr
55 $(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 $@
56all_final += test-int-ca-exp.crt
57
Gilles Peskinefd14bca2017-05-11 17:57:22 +020058cli_crt_key_file_rsa = cli-rsa.key
59cli_crt_extensions_file = cli.opensslconf
60
Gilles Peskinef040a172017-05-05 18:56:12 +020061cli-rsa.csr: $(cli_crt_key_file_rsa)
62 $(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 $@
63all_intermediate += cli-rsa.csr
64cli-rsa-sha1.crt: $(cli_crt_key_file_rsa) test-ca-sha1.crt cli-rsa.csr
65 $(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 $@
66all_final += cli-rsa-sha1.crt
67cli-rsa-sha256.crt: $(cli_crt_key_file_rsa) test-ca-sha256.crt cli-rsa.csr
68 $(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 $@
69all_final += cli-rsa-sha256.crt
70
Gilles Peskinebc70a182017-05-09 15:59:24 +020071server2-rsa.csr: server2.key
72 $(OPENSSL) req -new -key server2.key -passin "pass:$(test_ca_pwd_rsa)" -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@
73all_intermediate += server2-rsa.csr
74server2-sha256.crt: server2-rsa.csr
75 $(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 $@
76all_final += server2-sha256.crt
77
Manuel Pégourié-Gonnard29d60fb2017-06-05 10:20:32 +020078test_ca_int_rsa1 = test-int-ca.crt
79
80server7.csr: server7.key
81 $(OPENSSL) req -new -key server7.key -subj "/C=NL/O=PolarSSL/CN=localhost" -out $@
82all_intermediate += server7.csr
83server7-expired.crt: server7.csr $(test_ca_int_rsa1)
84 $(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) > $@
85all_final += server7-expired.crt
86server7-future.crt: server7.csr $(test_ca_int_rsa1)
87 $(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) > $@
88all_final += server7-future.crt
Manuel Pégourié-Gonnard4dfc04a2017-06-05 11:12:13 +020089server7-badsign.crt: server7.crt $(test_ca_int_rsa1)
90 { 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
91all_final += server7-badsign.crt
Manuel Pégourié-Gonnardbc313012017-06-27 12:51:52 +020092server7_int-ca-exp.crt: server7.crt test-int-ca-exp.crt
93 cat server7.crt test-int-ca-exp.crt > $@
94all_final += server7_int-ca-exp.crt
95
96server5-ss-expired.crt: server5.key
97 $(FAKETIME) -f -3653d $(OPENSSL) req -x509 -new -subj "/C=UK/O=mbed TLS/OU=testsuite/CN=localhost" -days 3653 -sha256 -key $< -out $@
98all_final += server5-ss-expired.crt
99
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200100
101################################################################
102#### Meta targets
103################################################################
104
Gilles Peskinef040a172017-05-05 18:56:12 +0200105all_final: $(all_final)
106all: $(all_intermediate) $(all_final)
107
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200108.PHONY: default all_final all
109
Gilles Peskinef040a172017-05-05 18:56:12 +0200110# These files should not be committed to the repository.
111list_intermediate:
112 @printf '%s\n' $(all_intermediate) | sort
113# These files should be committed to the repository so that the test data is
114# available upon checkout without running a randomized process depending on
115# third-party tools.
116list_final:
117 @printf '%s\n' $(all_final) | sort
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200118.PHONY: list_intermediate list_final
Gilles Peskinef040a172017-05-05 18:56:12 +0200119
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200120## Remove intermediate files
Gilles Peskinef040a172017-05-05 18:56:12 +0200121clean:
122 rm -f $(all_intermediate)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200123## Remove all build products, even the ones that are committed
Gilles Peskinef040a172017-05-05 18:56:12 +0200124neat: clean
125 rm -f $(all_final)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200126.PHONY: clean neat