Skip to content

SSL Identity Check Bypass #314

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions documentation/connection-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ JSON object:

|option|description|type|default|
|---:|---|:---:|:---:|
|**servername**| A string with the host name to use with SNI if different to host | *string*|
|**checkServerIdentity**| `function(servername, cert)` to replace SNI default function| *Function*|
|**minDHSize**| Minimum size of the DH parameter in bits to accept a TLS connection | *number*|1024|
|**pfx**| Optional PFX or PKCS12 encoded private key and certificate chain. Encrypted PFX will be decrypted with `passphrase` if provided| *string / string[] / Buffer / Buffer[] / *Object[]*|
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/handshake/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Authentication extends Command {
}
return this.throwNewError('self-signed certificate', true, info, '08000', Errors.ER_SELF_SIGNED);
} else if (info.requireIdentifyCheck) {
const identityError = tls.checkServerIdentity(opts.host, info.tlsCert);
const identityError = tls.checkServerIdentity(typeof opts.ssl === 'object' && opts.ssl.servername ? opts.ssl.servername : opts.host, info.tlsCert);
if (identityError) {
return this.throwNewError(
'certificate identify Error: ' + identityError.message,
Expand Down
5 changes: 2 additions & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,13 @@ class Connection extends EventEmitter {
this.opts.ssl === true ||
this.opts.ssl.rejectUnauthorized === undefined ||
this.opts.ssl.rejectUnauthorized === true;
info.requireIdentifyCheck = this.opts.ssl === true || this.opts.ssl.checkServerIdentity === undefined;
info.requireIdentifyCheck = this.opts.ssl === true || this.opts.ssl.checkServerIdentity !== undefined;
const baseConf = {
servername: this.opts.host,
socket: this.socket,
rejectUnauthorized: false,
checkServerIdentity: () => {}
};
const sslOption = this.opts.ssl === true ? baseConf : Object.assign({}, this.opts.ssl, baseConf);
const sslOption = this.opts.ssl === true ? baseConf : Object.assign({}, baseConf, this.opts.ssl);

try {
const secureSocket = tls.connect(sslOption, callback);
Expand Down