Codebase list openssl / 9e6a320
Add a test for mismatch between key OID and sig alg Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6732) Matt Caswell 5 years ago
2 changed file(s) with 49 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
5252
5353 #Test 1: Default sig algs should succeed
5454 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
55 plan tests => 21;
55 plan tests => 22;
5656 ok(TLSProxy::Message->success, "Default sigalgs");
5757 my $testtype;
5858
5959 SKIP: {
60 skip "TLSv1.3 disabled", 5 if disabled("tls1_3");
60 skip "TLSv1.3 disabled", 6 if disabled("tls1_3");
6161
6262 $proxy->filter(\&sigalgs_filter);
6363
9393 $testtype = PSS_ONLY_SIG_ALGS;
9494 $proxy->start();
9595 ok(TLSProxy::Message->success, "PSS only sigalgs in TLSv1.3");
96
97 #Test 7: Modify the CertificateVerify sigalg from rsa_pss_rsae_sha256 to
98 # rsa_pss_pss_sha256. This should fail because the public key OID
99 # in the certificate is rsaEncryption and not rsassaPss
100 $proxy->filter(\&modify_cert_verify_sigalg);
101 $proxy->clear();
102 $proxy->start();
103 ok(TLSProxy::Message->fail,
104 "Mismatch between CertVerify sigalg and public key OID");
96105 }
97106
98107 SKIP: {
99108 skip "EC or TLSv1.3 disabled", 1
100109 if disabled("tls1_3") || disabled("ec");
101 #Test 7: Sending a valid sig algs list but not including a sig type that
110 #Test 8: Sending a valid sig algs list but not including a sig type that
102111 # matches the certificate should fail in TLSv1.3.
103112 $proxy->clear();
104113 $proxy->clientflags("-sigalgs ECDSA+SHA256");
111120 skip "EC, TLSv1.3 or TLSv1.2 disabled", 1
112121 if disabled("tls1_2") || disabled("tls1_3") || disabled("ec");
113122
114 #Test 8: Sending a full list of TLSv1.3 sig algs but negotiating TLSv1.2
123 #Test 9: Sending a full list of TLSv1.3 sig algs but negotiating TLSv1.2
115124 # should succeed
116125 $proxy->clear();
117126 $proxy->serverflags("-no_tls1_3");
126135
127136 $proxy->filter(\&sigalgs_filter);
128137
129 #Test 9: Sending no sig algs extension in TLSv1.2 should succeed
138 #Test 10: Sending no sig algs extension in TLSv1.2 should succeed
130139 $proxy->clear();
131140 $testtype = NO_SIG_ALGS_EXT;
132141 $proxy->clientflags("-no_tls1_3");
134143 $proxy->start();
135144 ok(TLSProxy::Message->success, "No TLSv1.2 sigalgs");
136145
137 #Test 10: Sending an empty sig algs extension in TLSv1.2 should fail
146 #Test 11: Sending an empty sig algs extension in TLSv1.2 should fail
138147 $proxy->clear();
139148 $testtype = EMPTY_SIG_ALGS_EXT;
140149 $proxy->clientflags("-no_tls1_3");
142151 $proxy->start();
143152 ok(TLSProxy::Message->fail, "Empty TLSv1.2 sigalgs");
144153
145 #Test 11: Sending a list with no recognised sig algs in TLSv1.2 should fail
154 #Test 12: Sending a list with no recognised sig algs in TLSv1.2 should fail
146155 $proxy->clear();
147156 $testtype = NO_KNOWN_SIG_ALGS;
148157 $proxy->clientflags("-no_tls1_3");
150159 $proxy->start();
151160 ok(TLSProxy::Message->fail, "No known TLSv1.3 sigalgs");
152161
153 #Test 12: Sending a sig algs list without pss for an RSA cert in TLSv1.2
162 #Test 13: Sending a sig algs list without pss for an RSA cert in TLSv1.2
154163 # should succeed
155164 $proxy->clear();
156165 $testtype = NO_PSS_SIG_ALGS;
159168 $proxy->start();
160169 ok(TLSProxy::Message->success, "No PSS TLSv1.2 sigalgs");
161170
162 #Test 13: Sending only TLSv1.3 PSS sig algs in TLSv1.2 should succeed
171 #Test 14: Sending only TLSv1.3 PSS sig algs in TLSv1.2 should succeed
163172 $proxy->clear();
164173 $testtype = PSS_ONLY_SIG_ALGS;
165174 $proxy->serverflags("-no_tls1_3");
167176 $proxy->start();
168177 ok(TLSProxy::Message->success, "PSS only sigalgs in TLSv1.2");
169178
170 #Test 14: Responding with a sig alg we did not send in TLSv1.2 should fail
179 #Test 15: Responding with a sig alg we did not send in TLSv1.2 should fail
171180 # We send rsa_pkcs1_sha256 and respond with rsa_pss_rsae_sha256
172181 # TODO(TLS1.3): Add a similar test to the TLSv1.3 section above
173182 # when we have an API capable of configuring the TLSv1.3 sig algs
178187 $proxy->start();
179188 ok(TLSProxy::Message->fail, "Sigalg we did not send in TLSv1.2");
180189
181 #Test 15: Sending a valid sig algs list but not including a sig type that
190 #Test 16: Sending a valid sig algs list but not including a sig type that
182191 # matches the certificate should fail in TLSv1.2
183192 $proxy->clear();
184193 $proxy->clientflags("-no_tls1_3 -sigalgs ECDSA+SHA256");
188197 ok(TLSProxy::Message->fail, "No matching TLSv1.2 sigalgs");
189198 $proxy->filter(\&sigalgs_filter);
190199
191 #Test 16: No sig algs extension, ECDSA cert, TLSv1.2 should succeed
200 #Test 17: No sig algs extension, ECDSA cert, TLSv1.2 should succeed
192201 $proxy->clear();
193202 $testtype = NO_SIG_ALGS_EXT;
194203 $proxy->clientflags("-no_tls1_3");
204213 my ($dsa_status, $sha1_status, $sha224_status);
205214 SKIP: {
206215 skip "TLSv1.3 disabled", 2 if disabled("tls1_3") || disabled("dsa");
207 #Test 17: signature_algorithms with 1.3-only ClientHello
216 #Test 18: signature_algorithms with 1.3-only ClientHello
208217 $testtype = PURE_SIGALGS;
209218 $dsa_status = $sha1_status = $sha224_status = 0;
210219 $proxy->clear();
214223 ok($dsa_status && $sha1_status && $sha224_status,
215224 "DSA/SHA2 sigalg sent for 1.3-only ClientHello");
216225
217 #Test 18: signature_algorithms with backwards compatible ClientHello
226 #Test 19: signature_algorithms with backwards compatible ClientHello
218227 SKIP: {
219228 skip "TLSv1.2 disabled", 1 if disabled("tls1_2");
220229 $testtype = COMPAT_SIGALGS;
229238
230239 SKIP: {
231240 skip "TLSv1.3 disabled", 3 if disabled("tls1_3");
232 #Test 19: Insert signature_algorithms_cert that match normal sigalgs
241 #Test 20: Insert signature_algorithms_cert that match normal sigalgs
233242 $testtype = SIGALGS_CERT_ALL;
234243 $proxy->clear();
235244 $proxy->filter(\&modify_sigalgs_cert_filter);
236245 $proxy->start();
237246 ok(TLSProxy::Message->success, "sigalgs_cert in TLSv1.3");
238247
239 #Test 19: Insert signature_algorithms_cert that forces PKCS#1 cert
248 #Test 21: Insert signature_algorithms_cert that forces PKCS#1 cert
240249 $testtype = SIGALGS_CERT_PKCS;
241250 $proxy->clear();
242251 $proxy->filter(\&modify_sigalgs_cert_filter);
243252 $proxy->start();
244253 ok(TLSProxy::Message->success, "sigalgs_cert in TLSv1.3 with PKCS#1 cert");
245254
246 #Test 19: Insert signature_algorithms_cert that fails
255 #Test 22: Insert signature_algorithms_cert that fails
247256 $testtype = SIGALGS_CERT_INVALID;
248257 $proxy->clear();
249258 $proxy->filter(\&modify_sigalgs_cert_filter);
379388 }
380389 }
381390 }
391
392 sub modify_cert_verify_sigalg
393 {
394 my $proxy = shift;
395
396 # We're only interested in the CertificateVerify
397 if ($proxy->flight != 1) {
398 return;
399 }
400
401 foreach my $message (@{$proxy->message_list}) {
402 if ($message->mt == TLSProxy::Message::MT_CERTIFICATE_VERIFY) {
403 $message->sigalg(TLSProxy::Message::SIG_ALG_RSA_PSS_PSS_SHA256);
404 $message->repack();
405 }
406 }
407 }
102102 SIG_ALG_ECDSA_SECP256R1_SHA256 => 0x0403,
103103 SIG_ALG_ECDSA_SECP384R1_SHA384 => 0x0503,
104104 SIG_ALG_ECDSA_SECP521R1_SHA512 => 0x0603,
105 SIG_ALG_RSA_PSS_SHA256 => 0x0804,
106 SIG_ALG_RSA_PSS_SHA384 => 0x0805,
107 SIG_ALG_RSA_PSS_SHA512 => 0x0806,
105 SIG_ALG_RSA_PSS_RSAE_SHA256 => 0x0804,
106 SIG_ALG_RSA_PSS_RSAE_SHA384 => 0x0805,
107 SIG_ALG_RSA_PSS_RSAE_SHA512 => 0x0806,
108108 SIG_ALG_ED25519 => 0x0807,
109109 SIG_ALG_ED448 => 0x0808,
110 SIG_ALG_RSA_PSS_PSS_SHA256 => 0x0809,
111 SIG_ALG_RSA_PSS_PSS_SHA384 => 0x080a,
112 SIG_ALG_RSA_PSS_PSS_SHA512 => 0x080b,
110113 SIG_ALG_RSA_PKCS1_SHA1 => 0x0201,
111114 SIG_ALG_ECDSA_SHA1 => 0x0203,
112115 SIG_ALG_DSA_SHA1 => 0x0202,