How to fix the "EPROTO" error after updating the Node version?

The following code works in version v10.15.3:

const { post } = require('request');

const { post } = require('request');

post({
  url: 'https://cidadao.sinesp.gov.br/sinesp-cidadao/mobile/consultar-placa/v4',
  body: '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<v:Envelope xmlns:v=\"http://schemas.xmlsoap.org/soap/envelope/\">\n  <v:Header>\n    <b>LGE Nexus 5</b>\n    <c>ANDROID</c>\n    <d>v4</d>\n    <e>4.3.2</e>\n    <f>98.193.54.223</f>\n    <g>514650d8dba4784ed08b5a029583576361a50bc5</g>\n    <h>-3272.3179572637086</h>\n    <i>940.839492700698</i>\n    <j/>\n    <k/>\n    <l>2019-05-24 10:24:35</l>\n    <m>8797e74f0d6eb7b1ff3dc114d4aa12d3</m>\n  </v:Header>\n  <v:Body xmlns:n0=\"http://soap.ws.placa.service.sinesp.serpro.gov.br/\">\n    <n0:getStatus>\n      <a>LSU3J43</a>\n    </n0:getStatus>\n  </v:Body>\n</v:Envelope>',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'User-Agent': 'SinespCidadao / 3.0.2.1 CFNetwork / 758.2.8 Darwin / 15.0.0',
    Host: 'cidadao.sinesp.gov.br'
  },
}, (err, httpResponse, body) => {
  if (err) return console.error(err);
  console.log(JSON.stringify(httpResponse));
});

But after upgrading to v12.2.0 or above I have the following error:

Error: write EPROTO 17432:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1922:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:83:16) {
  errno: 'EPROTO',
  code: 'EPROTO',
  syscall: 'write'
}

How can I fix the problem?

Author: Sorack, 2019-05-27

1 answers

The error indicated is unsupported protocol or protocolo não suportado. Probably the certificate of the address cidadao.sinesp.gov.br is signed with TLSv1.0 and from the version v11.4.0 of the Node.js the minimum supported version of the protocol is TLSv1.2. So for the call to this address to work in later versions it is necessary to start Node.js with the flag --tls-min-v1.0.

 1
Author: Sorack, 2019-06-03 12:32:24