@@ -229,6 +229,30 @@ sub switch_server_cert
229
229
qr /\Q server certificate for "common-name.pg-ssltest.test" does not match host name "wronghost.test"\E /
230
230
);
231
231
232
+ # Test with an IP address in the Common Name. This is a strange corner case that
233
+ # nevertheless is supported, as long as the address string matches exactly.
234
+ switch_server_cert($node , certfile => ' server-ip-cn-only' );
235
+
236
+ $common_connstr =
237
+ " $default_ssl_connstr user=ssltestuser dbname=trustdb sslrootcert=ssl/root+server_ca.crt hostaddr=$SERVERHOSTADDR sslmode=verify-full" ;
238
+
239
+ $node -> connect_ok(" $common_connstr host=192.0.2.1" ,
240
+ " IP address in the Common Name" );
241
+
242
+ $node -> connect_fails(
243
+ " $common_connstr host=192.000.002.001" ,
244
+ " mismatch between host name and server certificate IP address" ,
245
+ expected_stderr =>
246
+ qr /\Q server certificate for "192.0.2.1" does not match host name "192.000.002.001"\E /
247
+ );
248
+
249
+ # Similarly, we'll also match an IP address in a dNSName SAN. (This is
250
+ # long-standing behavior.)
251
+ switch_server_cert($node , certfile => ' server-ip-in-dnsname' );
252
+
253
+ $node -> connect_ok(" $common_connstr host=192.0.2.1" ,
254
+ " IP address in a dNSName" );
255
+
232
256
# Test Subject Alternative Names.
233
257
switch_server_cert($node , certfile => ' server-multiple-alt-names' );
234
258
@@ -281,7 +305,7 @@ sub switch_server_cert
281
305
qr /\Q server certificate for "single.alt-name.pg-ssltest.test" does not match host name "deep.subdomain.wildcard.pg-ssltest.test"\E /
282
306
);
283
307
284
- # Test server certificate with a CN and SANs. Per RFCs 2818 and 6125, the CN
308
+ # Test server certificate with a CN and DNS SANs. Per RFCs 2818 and 6125, the CN
285
309
# should be ignored when the certificate has both.
286
310
switch_server_cert($node , certfile => ' server-cn-and-alt-names' );
287
311
0 commit comments