tls: show human-readable error messages
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 17 Jan 2014 17:15:36 +0000 (18:15 +0100)
committerFedor Indutny <fedor.indutny@gmail.com>
Fri, 17 Jan 2014 18:51:25 +0000 (18:51 +0000)
commit262a752c2943842df7babdf55a034beca68794cd
tree5f8ed4778efea8686de16ca34a993bd423d82f84
parent24856f04b23eca659ae05e79795b3e9570f9bd52
tls: show human-readable error messages

Before this commit, verification exceptions had err.message set to the
OpenSSL error code (e.g. 'UNABLE_TO_VERIFY_LEAF_SIGNATURE').

This commit moves the error code to err.code and replaces err.message
with a human-readable error.  Example:

    // before
    {
      message: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
    }

    // after
    {
      code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
      message: 'unable to verify the first certificate'
    }

UNABLE_TO_VERIFY_LEAF_SIGNATURE is a good example of why you want this:
the error code suggests that it's the last certificate that fails to
validate while it's actually the first certificate in the chain.

Going by the number of mailing list posts and StackOverflow questions,
it's a source of confusion to many people.
doc/api/tls.markdown
lib/_tls_wrap.js
src/node_crypto.cc
test/simple/test-tls-friendly-error-message.js [new file with mode: 0644]