|
@ -26,25 +26,29 @@ var tls = require('tls'); |
|
|
|
|
|
|
|
|
var tests = [ |
|
|
var tests = [ |
|
|
// Basic CN handling
|
|
|
// Basic CN handling
|
|
|
{ host: 'a.com', cert: { subject: { CN: 'a.com' } }, result: true }, |
|
|
{ host: 'a.com', cert: { subject: { CN: 'a.com' } } }, |
|
|
{ host: 'a.com', cert: { subject: { CN: 'A.COM' } }, result: true }, |
|
|
{ host: 'a.com', cert: { subject: { CN: 'A.COM' } } }, |
|
|
{ host: 'a.com', cert: { subject: { CN: 'b.com' } }, result: false }, |
|
|
{ |
|
|
{ host: 'a.com', cert: { subject: { CN: 'a.com.' } }, result: true }, |
|
|
host: 'a.com', |
|
|
|
|
|
cert: { subject: { CN: 'b.com' } }, |
|
|
|
|
|
error: 'Host: a.com. is not cert\'s CN: b.com' |
|
|
|
|
|
}, |
|
|
|
|
|
{ host: 'a.com', cert: { subject: { CN: 'a.com.' } } }, |
|
|
|
|
|
|
|
|
// Wildcards in CN
|
|
|
// Wildcards in CN
|
|
|
{ host: 'b.a.com', cert: { subject: { CN: '*.a.com' } }, result: true }, |
|
|
{ host: 'b.a.com', cert: { subject: { CN: '*.a.com' } } }, |
|
|
{ host: 'b.a.com', cert: { |
|
|
{ host: 'b.a.com', cert: { |
|
|
subjectaltname: 'DNS:omg.com', |
|
|
subjectaltname: 'DNS:omg.com', |
|
|
subject: { CN: '*.a.com' } }, |
|
|
subject: { CN: '*.a.com' } }, |
|
|
result: false |
|
|
error: 'Host: b.a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:omg.com' |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// Multiple CN fields
|
|
|
// Multiple CN fields
|
|
|
{ |
|
|
{ |
|
|
host: 'foo.com', cert: { |
|
|
host: 'foo.com', cert: { |
|
|
subject: { CN: ['foo.com', 'bar.com'] } // CN=foo.com; CN=bar.com;
|
|
|
subject: { CN: ['foo.com', 'bar.com'] } // CN=foo.com; CN=bar.com;
|
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// DNS names and CN
|
|
|
// DNS names and CN
|
|
@ -53,49 +57,50 @@ var tests = [ |
|
|
subjectaltname: 'DNS:*', |
|
|
subjectaltname: 'DNS:*', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.com', cert: { |
|
|
host: 'a.com', cert: { |
|
|
subjectaltname: 'DNS:*.com', |
|
|
subjectaltname: 'DNS:*.com', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*.com' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.co.uk', cert: { |
|
|
host: 'a.co.uk', cert: { |
|
|
subjectaltname: 'DNS:*.co.uk', |
|
|
subjectaltname: 'DNS:*.co.uk', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.com', cert: { |
|
|
host: 'a.com', cert: { |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subject: { CN: 'a.com' } |
|
|
subject: { CN: 'a.com' } |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*.a.com' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.com', cert: { |
|
|
host: 'a.com', cert: { |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*.a.com' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.com', cert: { |
|
|
host: 'a.com', cert: { |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.com', cert: { |
|
|
host: 'a.com', cert: { |
|
|
subjectaltname: 'DNS:A.COM', |
|
|
subjectaltname: 'DNS:A.COM', |
|
|
subject: { CN: 'b.com' } |
|
|
subject: { CN: 'b.com' } |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// DNS names
|
|
|
// DNS names
|
|
@ -104,65 +109,64 @@ var tests = [ |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*.a.com' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'b.a.com', cert: { |
|
|
host: 'b.a.com', cert: { |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'c.b.a.com', cert: { |
|
|
host: 'c.b.a.com', cert: { |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subjectaltname: 'DNS:*.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: c.b.a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*.a.com' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'b.a.com', cert: { |
|
|
host: 'b.a.com', cert: { |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a-cb.a.com', cert: { |
|
|
host: 'a-cb.a.com', cert: { |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.b.a.com', cert: { |
|
|
host: 'a.b.a.com', cert: { |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subjectaltname: 'DNS:*b.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:*b.a.com' |
|
|
}, |
|
|
}, |
|
|
// Mutliple DNS names
|
|
|
// Mutliple DNS names
|
|
|
{ |
|
|
{ |
|
|
host: 'a.b.a.com', cert: { |
|
|
host: 'a.b.a.com', cert: { |
|
|
subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com', |
|
|
subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
// URI names
|
|
|
// URI names
|
|
|
{ |
|
|
{ |
|
|
host: 'a.b.a.com', cert: { |
|
|
host: 'a.b.a.com', cert: { |
|
|
subjectaltname: 'URI:http://a.b.a.com/', |
|
|
subjectaltname: 'URI:http://a.b.a.com/', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'a.b.a.com', cert: { |
|
|
host: 'a.b.a.com', cert: { |
|
|
subjectaltname: 'URI:http://*.b.a.com/', |
|
|
subjectaltname: 'URI:http://*.b.a.com/', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'URI:http://*.b.a.com/' |
|
|
}, |
|
|
}, |
|
|
// IP addresses
|
|
|
// IP addresses
|
|
|
{ |
|
|
{ |
|
@ -170,40 +174,44 @@ var tests = [ |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'IP Address:127.0.0.1' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: '127.0.0.1', cert: { |
|
|
host: '127.0.0.1', cert: { |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
} |
|
|
result: true |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: '127.0.0.2', cert: { |
|
|
host: '127.0.0.2', cert: { |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subjectaltname: 'IP Address:127.0.0.1', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'IP: 127.0.0.2 is not in the cert\'s list: ' + |
|
|
|
|
|
'127.0.0.1' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: '127.0.0.1', cert: { |
|
|
host: '127.0.0.1', cert: { |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subject: {} |
|
|
subject: {} |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'IP: 127.0.0.1 is not in the cert\'s list: ' |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
host: 'localhost', cert: { |
|
|
host: 'localhost', cert: { |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subjectaltname: 'DNS:a.com', |
|
|
subject: { CN: 'localhost' } |
|
|
subject: { CN: 'localhost' } |
|
|
}, |
|
|
}, |
|
|
result: false |
|
|
error: 'Host: localhost. is not in the cert\'s altnames: ' + |
|
|
|
|
|
'DNS:a.com' |
|
|
}, |
|
|
}, |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
tests.forEach(function(test, i) { |
|
|
tests.forEach(function(test, i) { |
|
|
assert.equal(tls.checkServerIdentity(test.host, test.cert), |
|
|
var err = tls.checkServerIdentity(test.host, test.cert); |
|
|
test.result, |
|
|
assert.equal(err && err.reason, |
|
|
'Test#' + i + ' failed: ' + util.inspect(test)); |
|
|
test.error, |
|
|
|
|
|
'Test#' + i + ' failed: ' + util.inspect(test) + '\n' + |
|
|
|
|
|
test.error + ' != ' + (err && err.reason)); |
|
|
}); |
|
|
}); |
|
|