Skip to content

Commit 7165254

Browse files
bnoordhuisBridgeAR
authored andcommitted
test: more tls hostname verification coverage
Add some additional tests that check the interaction of an IP address as the Common Name and the presence (or lack of presence) of DNS, URI, and IP Address Subject Alternative Names. PR-URL: #27999 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent dfbbfbb commit 7165254

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/parallel/test-tls-check-server-identity.js

+42
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,48 @@ const tests = [
7070
error: 'Host: a.com. is not cert\'s CN: .a.com'
7171
},
7272

73+
// IP address in CN. Technically allowed but so rare that we reject
74+
// it anyway. If we ever do start allowing them, we should take care
75+
// to only allow public (non-internal, non-reserved) IP addresses,
76+
// because that's what the spec mandates.
77+
{
78+
host: '8.8.8.8',
79+
cert: { subject: { CN: '8.8.8.8' } },
80+
error: 'IP: 8.8.8.8 is not in the cert\'s list: '
81+
},
82+
83+
// The spec suggests that a "DNS:" Subject Alternative Name containing an
84+
// IP address is valid but it seems so suspect that we currently reject it.
85+
{
86+
host: '8.8.8.8',
87+
cert: { subject: { CN: '8.8.8.8' }, subjectaltname: 'DNS:8.8.8.8' },
88+
error: 'IP: 8.8.8.8 is not in the cert\'s list: '
89+
},
90+
91+
// Likewise for "URI:" Subject Alternative Names.
92+
// See also https://github.com/nodejs/node/issues/8108.
93+
{
94+
host: '8.8.8.8',
95+
cert: { subject: { CN: '8.8.8.8' }, subjectaltname: 'URI:http://8.8.8.8/' },
96+
error: 'IP: 8.8.8.8 is not in the cert\'s list: '
97+
},
98+
99+
// An "IP Address:" Subject Alternative Name however is acceptable.
100+
{
101+
host: '8.8.8.8',
102+
cert: { subject: { CN: '8.8.8.8' }, subjectaltname: 'IP Address:8.8.8.8' }
103+
},
104+
105+
// But not when it's a CIDR.
106+
{
107+
host: '8.8.8.8',
108+
cert: {
109+
subject: { CN: '8.8.8.8' },
110+
subjectaltname: 'IP Address:8.8.8.0/24'
111+
},
112+
error: 'IP: 8.8.8.8 is not in the cert\'s list: '
113+
},
114+
73115
// Wildcards in CN
74116
{ host: 'b.a.com', cert: { subject: { CN: '*.a.com' } } },
75117
{

0 commit comments

Comments
 (0)