Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls wild card check supports for port #20875

Closed
wants to merge 1 commit into from
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