Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ function check(hostParts, pattern, wildcards) {

// Check host parts from right to left first.
for (var i = hostParts.length - 1; i > 0; i -= 1) {
if (hostParts[i] !== patternParts[i])
if (hostParts[i] !== patternParts[i]) {
if ((i === (hostParts.length - 1)) &&
(patternParts[i].indexOf(':') === -1) &&
(hostParts[i].indexOf(':') > -1)) {
// the last part can contain port from the host, and it is
// legit for the dn and san to not include port to indicate
// all ports for the server is allowed
const justHostPart = hostParts[i].split(':')[0];
if (justHostPart === patternParts[i]) {
continue;
}
}
return false;
}
}

const hostSubdomain = hostParts[0];
Expand Down
37 changes: 37 additions & 0 deletions test/parallel/test-tls-check-server-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,43 @@ const tests = [
subject: { CN: 'b.com' }
}
},
{
host: 'a.co.uk:2443', cert: {
subject: { CN: '*.co.uk' }
}
},
{
host: 'a.co.uk:2443', cert: {
subject: { CN: '*.co.uk:2443' }
}
},
{
host: 'a.co.uk:2443', cert: {
subject: { CN: '*.co.uk:8443' }
},
error: 'Host: a.co.uk:2443. is not ' +
'cert\'s CN: *.co.uk:8443'
},
{
host: 'a.co.uk:2443', cert: {
subjectaltname: 'DNS:*.co.uk',
subject: { CN: 'b.com' }
}
},
{
host: 'a.co.uk:2443', cert: {
subjectaltname: 'DNS:*.co.uk:2443',
subject: { CN: 'b.com' }
}
},
{
host: 'a.co.uk:2443', cert: {
subjectaltname: 'DNS:*.co.uk:8443',
subject: { CN: 'b.com' }
},
error: 'Host: a.co.uk:2443. is not in the cert\'s ' +
'altnames: DNS:*.co.uk:8443'
},
{
host: 'a.com', cert: {
subjectaltname: 'DNS:*.a.com',
Expand Down