Axios Node Put with authentication does not access

Asked

Viewed 151 times

-2

I made an Node application (v12.14.1) to access a webservice. It has Basic Authentication.

const uname = "xxxxxxxxx";
const pass = "%$7675845353525$%";    
const p_cpf = "97856353424";
const p_senha =  "xxx1111";  
const myurl = "https://defesaagropecuaria.sp.gov.br/api/servicos/login";

const updateUser = async () => {
  try {
      const res = await axios.put(myurl, {
          cpf: p_cpf,
          senha: p_senha,
          auth: {
            username: uname,
            password: pass
          }
      });
      console.log(res.data.token);
  } catch (err) {
      console.log(err);
  }
};

When executing occurs the following error:

Error: write EPROTO 5300:error:1425F102:SSL routines:ssl_choose_client_version:Unsupported Protocol:c: Ws deps openssl openssl ssl statem statem_lib. c:1929:

What could be going on? From what I researched this is related to the minimum version of Node, but I could not figure out how to set this in my code. I would also like to know if it is correct the way I am passing the parameters (it asks Cpf and the user password and the Basic authentication)

  • Try to spin your node with the argument --tls-min-v1.0

2 answers

0

All indicates the server you are trying to access uses a smaller TLS version than supported by your version of Node.js. Since the v11.4.2 the minimum TLS version is TLSv1.2.

To run your code, try to start the Node.js with the argument --tls-min-v1.0.

In case of your second error, just use the line below before the axios.put. But be careful, this amendment is not recommended:

process.env.['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

NODE_TLS_REJECT_UNAUTHORIZED

If value equals '0', Certificate validation is disabled for TLS Connections. This makes TLS, and HTTPS by Extension, insecure. The use of this Environment variable is strongly discouraged.

In free translation:

If the value is equal to '0', the certificate validation will be disabled for TLS connections. This makes TLS and HTTPS by extension unsafe. The use of this environment variable is strongly discouraged.

  • I started my Node like this: Node proxy.js --tls-min-v1 (proxy.js name of my Node file), but the error persists: Error: write EPROTO 5736:error:1425F102:SSL routines:ssl_choose_client_version:Unsupported Protocol:c: Ws deps openssl openssl ssl statem statem_lib. c:1929:

  • He had executed the command in the wrong way. With the correct shape: Node --tls-min-v1.0 proxy.js , now I have the following error: Error: self Signed Certificate

0

Actually, I think it works, but it specifically deals with signed certificates. It doesn’t allow expired or invalid certificates. To allow any certificate, you must add this line at the top of your code;

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

This will allow virtually anything, but it is also dangerous, so use carefully.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.