1
// Copyright Joyent, Inc. and other Node contributors.
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22
var common = require('../common');
23
var assert = require('assert');
24
var util = require('util');
25
var tls = require('tls');
29
{ host: 'a.com', cert: { subject: { CN: 'a.com' } }, result: true },
30
{ host: 'a.com', cert: { subject: { CN: 'A.COM' } }, result: true },
31
{ host: 'a.com', cert: { subject: { CN: 'b.com' } }, result: false },
32
{ host: 'a.com', cert: { subject: { CN: 'a.com.' } }, result: true },
35
{ host: 'b.a.com', cert: { subject: { CN: '*.a.com' } }, result: true },
36
{ host: 'b.a.com', cert: {
37
subjectaltname: 'DNS:omg.com',
38
subject: { CN: '*.a.com' } },
44
host: 'foo.com', cert: {
45
subject: { CN: ['foo.com', 'bar.com'] } // CN=foo.com; CN=bar.com;
52
host: 'a.com', cert: {
53
subjectaltname: 'DNS:*',
54
subject: { CN: 'b.com' }
59
host: 'a.com', cert: {
60
subjectaltname: 'DNS:*.com',
61
subject: { CN: 'b.com' }
66
host: 'a.co.uk', cert: {
67
subjectaltname: 'DNS:*.co.uk',
68
subject: { CN: 'b.com' }
73
host: 'a.com', cert: {
74
subjectaltname: 'DNS:*.a.com',
75
subject: { CN: 'a.com' }
80
host: 'a.com', cert: {
81
subjectaltname: 'DNS:*.a.com',
82
subject: { CN: 'b.com' }
87
host: 'a.com', cert: {
88
subjectaltname: 'DNS:a.com',
89
subject: { CN: 'b.com' }
94
host: 'a.com', cert: {
95
subjectaltname: 'DNS:A.COM',
96
subject: { CN: 'b.com' }
103
host: 'a.com', cert: {
104
subjectaltname: 'DNS:*.a.com',
110
host: 'b.a.com', cert: {
111
subjectaltname: 'DNS:*.a.com',
117
host: 'c.b.a.com', cert: {
118
subjectaltname: 'DNS:*.a.com',
124
host: 'b.a.com', cert: {
125
subjectaltname: 'DNS:*b.a.com',
131
host: 'a-cb.a.com', cert: {
132
subjectaltname: 'DNS:*b.a.com',
138
host: 'a.b.a.com', cert: {
139
subjectaltname: 'DNS:*b.a.com',
144
// Mutliple DNS names
146
host: 'a.b.a.com', cert: {
147
subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com',
154
host: 'a.b.a.com', cert: {
155
subjectaltname: 'URI:http://a.b.a.com/',
161
host: 'a.b.a.com', cert: {
162
subjectaltname: 'URI:http://*.b.a.com/',
169
host: 'a.b.a.com', cert: {
170
subjectaltname: 'IP Address:127.0.0.1',
176
host: '127.0.0.1', cert: {
177
subjectaltname: 'IP Address:127.0.0.1',
183
host: '127.0.0.2', cert: {
184
subjectaltname: 'IP Address:127.0.0.1',
190
host: '127.0.0.1', cert: {
191
subjectaltname: 'DNS:a.com',
197
host: 'localhost', cert: {
198
subjectaltname: 'DNS:a.com',
199
subject: { CN: 'localhost' }
205
tests.forEach(function(test, i) {
206
assert.equal(tls.checkServerIdentity(test.host, test.cert),
208
'Test#' + i + ' failed: ' + util.inspect(test));