0

Using Nan in addon.cc to invoke OpenSSL layer methods for decryption/signing/verification from NodeJS.

When trying to hit the methods again and again in OpenSSL from NodeJS - getting decryption/verification errors - if these errors are hit for several number of times, its causing the server to crash. How can the errors/exception that is crashing the server be caught somehow in addon.cc?

Below is the sample of the exceptions that we saw during the server crash:

Error: 8668943040:error:21070073:PKCS7 routines:PKCS7_dataDecode:no recipient matches certificate:../deps/openssl/openssl/crypto/pkcs7/pk7_doit.c:491:
8668943040:error:21072077:PKCS7 routines:PKCS7_decrypt:decrypt error:../deps/openssl/openssl/crypto/pkcs7/pk7_smime.c:500:

Emitted 'error' event on TLSSocket instance at:
    at TLSSocket._emitTLSError (_tls_wrap.js:893:10)
    at TLSWrap.onerror (_tls_wrap.js:416:11) {
  library: 'PKCS7 routines',
  function: 'PKCS7_dataDecode',
  reason: 'no recipient matches certificate',
  code: 'ERR_SSL_NO_RECIPIENT_MATCHES_CERTIFICATE'
}

We tried to make use of Nan::try_catch but it did not help in catching the exceptions.

1 Answers1

0

This is not an exception that you can catch - it is an error event in a stream handler. It detects a failure and raises an exception and raises an exception in an asynchronous context because you don't have an error handler installed. These exceptions are uncatchable because they don't have an enclosing block.

Register an error handler on the TLSSocket - this error is not coming from your addon.cc.

mmomtchev
  • 2,497
  • 1
  • 8
  • 23