blob: 3e20f66411d8f2628193a3d7ee72d025173da13e [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
Ron Eldorb0065182017-10-16 12:40:27 +030067rsa_pkcs1_2048_public.pem: server8.key
Ron Eldor3f2da842017-10-17 15:50:30 +030068 $(OPENSSL) rsa -in $< -outform PEM -RSAPublicKey_out -out $@
69all_final += rsa_pkcs1_2048_public.pem
Gilles Peskinebc70a182017-05-09 15:59:24 +020070
Ron Eldorb0065182017-10-16 12:40:27 +030071rsa_pkcs1_2048_public.der: rsa_pkcs1_2048_public.pem
Ron Eldor3f2da842017-10-17 15:50:30 +030072 $(OPENSSL) rsa -RSAPublicKey_in -in $< -outform DER -RSAPublicKey_out -out $@
73all_final += rsa_pkcs1_2048_public.der
74
75rsa_pkcs8_2048_public.pem: server8.key
76 $(OPENSSL) rsa -in $< -outform PEM -pubout -out $@
77all_final += rsa_pkcs8_2048_public.pem
78
79rsa_pkcs8_2048_public.der: rsa_pkcs8_2048_public.pem
80 $(OPENSSL) rsa -pubin -in $< -outform DER -pubout -out $@
Ron Eldorb0065182017-10-16 12:40:27 +030081all_final += rsa_pkcs8_2048_public.der
Gilles Peskinefd14bca2017-05-11 17:57:22 +020082
83################################################################
84#### Meta targets
85################################################################
86
Gilles Peskinef040a172017-05-05 18:56:12 +020087all_final: $(all_final)
88all: $(all_intermediate) $(all_final)
89
Gilles Peskinefd14bca2017-05-11 17:57:22 +020090.PHONY: default all_final all
91
Gilles Peskinef040a172017-05-05 18:56:12 +020092# These files should not be committed to the repository.
93list_intermediate:
94 @printf '%s\n' $(all_intermediate) | sort
95# These files should be committed to the repository so that the test data is
96# available upon checkout without running a randomized process depending on
97# third-party tools.
98list_final:
99 @printf '%s\n' $(all_final) | sort
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200100.PHONY: list_intermediate list_final
Gilles Peskinef040a172017-05-05 18:56:12 +0200101
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200102## Remove intermediate files
Gilles Peskinef040a172017-05-05 18:56:12 +0200103clean:
104 rm -f $(all_intermediate)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200105## Remove all build products, even the ones that are committed
Gilles Peskinef040a172017-05-05 18:56:12 +0200106neat: clean
107 rm -f $(all_final)
Gilles Peskinefd14bca2017-05-11 17:57:22 +0200108.PHONY: clean neat