0

Goal

Ensure security in my request message.

Environment:

Library: Version

  • node-fetch : 2.6.0

  • https : natively implemented in node, it seems

  • node : 12.15.0

Device : Version

  • Google home nest mini : 2nd generation

Issue

I get a "Failed to fetch" error when I do get request on an api served with https and self certified certificate.

What I tried:

1 - http request: it works fine on google home device and my local machine,

2 - https request: it works on my local machine but not on google home device.

Code I use:

import fetch from 'node-fetch';
import env from './configFile';
import https, { Agent } from 'https';

export default function get(): Promise<any> {
    const url = "https://api.url"; 
    const httpsAgent = new https.Agent({
        rejectUnauthorized: false,
    });

    const option = {
        method: 'get',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
            Authorization: 'Basic ' + btoa(env.login! + ':' + env.password!),
        },
        agent: httpsAgent,
    };

    return fetch(url, option)
        .then(res => {
            return res.json();
        })
        .catch(error => {
            throw new Error(error);
        });
}

Here I disable ssl certification verification. It is something i'll change later because it is not secure, but at least i want to do an https request without error.

My Errors

Go to this link: errors

Reproduce Error

I made a full tutorial, if you want to reproduce the error: https://github.com/killvi/localExecutionHttpsError

In this tuto, i try to make an https request on google to check if I can do it without error. So is not exactly same implementation as mine. But if it works with google, at least i will known that my problem does not come from https implementation in google home device.

Community
  • 1
  • 1
  • It isn't clear from your description how you are running this locally on the Home device, and updating your question with this info may be useful. Additionally, it might be useful to see the details of the "failed to fetch" error (a log of exactly what you get in the `catch` portion above). – Prisoner Mar 02 '20 at 10:02
  • I'll try to share a code that can reproduce the error and a tuto to run the code on a google home. Because, the only error info I get is just "failed to fetch" :/ – Jean Rajaona Mar 05 '20 at 11:58

1 Answers1

0

Google answered my question:

Currently, local execution apps can only use unencrypted HTTP/TCP/UDP to communicate locally to their devices. It has been requested that we enable TLS capabilities over the local channel to enable HTTPS and other standard encrypted transport methods.

Dharman
  • 30,962
  • 25
  • 85
  • 135