Ignore self-signed SSL certificate in fetch - javascript

I'm using fetch in a react-native app, and charles proxy to debug my network requests. In order to use charles with SSL, I need to configure fetch to accept a self-signed certificate generated by charles.
How do I tell fetch to ignore errors from self-signed certificates when using https?

I fixed this by setting up the SSL certificates in the simulator: Help > SSL Proxying > Install Charles Root Certificate in iOS Simulators) in charles and be happy!
Thanks https://stackoverflow.com/a/35047215/82156

Related

React Native Axios allow self signed ssl certificate

I'm writing an app in React Native, and I need to make API requests. The server for that is running on a server with a self-signed SSL certificate, so I need Axios and React Native to make the request and accept the response using a self-signed certificate.
I can't get a certificate from an official certificate authority.
I have already tried using https.Agent, however this doesn't seem
to be possible when using React Native (The https module is part of
the node standard library, which is not included in React Native), so
this is also not a valid solution.
I would prefer to continue using Axios, however I would consider
switching libraries if there are any with similar functionality (I've
already tried a few, none provided functionality to allow self-signed
certs).
Here is some example code from my project (url is the IP of the server):
import axios from 'axios';
const instance = axios.create({ });
instance.get(url)
.then(res => {
this.setState({dataSource: res.data});
})
Btw, when I'm using ngrok everything works fine, so the self-signed certificate is definitely the only problem.
I solved this problem today! I too have a react native app, and i use apisauce, an awesome lib that uses axios under the hood.
My API runs on a LAMP stack locally, and I have a fake development domain in /etc/hosts, and Apache is configured with a self signed certificate.
Instead of disabling the SSL verification, trust your certificate!
The instructions will differ on Android, but for iOS I did the following.
Send the selfsigned.crt to my iPhone via Airdrop
Install the profile in the Settings app
Download and launch Proxyman on my dev machine https://proxyman.io/
Set Proxy in Wifi settings on the iPhone (dev machine IP port 9090)
Open Safari and goto proxy.man/ssl, download the certificate
Install the profile in the Settings app
Enable full trust for both certificates in Settings > General > About > Certificate Trust Settings
Now you should be able to access https://your-dev-domain.whatever without any problems, and apisauce/axios will no longer return Network Error 😎
Just remember to go back into your wifi settings and turn the proxy off again when you are finished developing!

export my localhost server ( node js ) online with a web server like apache

I just made a simple chat-service with Node JS and I want to publish It " Online " ; at the time I used Ngrok and Localtunnel , but they are very limited , therefore I saw Apache web Server but I have not found tutorial on how to use it.
Thanks and hope you can help me.
Ngrok and Localtunnel are services which let you open a connection from inside your network to an external server which then forwards traffic back down the tunnel so clients on the Internet can make requests to your service running inside your LAN.
Apache is HTTP server software. It is nothing like Ngrok and Localtunnel.
While you can set up a reverse proxy using it, for that to use useful in this use case you would have to install it in your router … and most routers don't let you install software on them.
You could possibly run it on a computer inside your LAN and then configure port forwarding on the router … but if you are going to do that then you might as well forget about Apache HTTPD and just forward traffic directly to the service you've written using Node.js.
There are security risks and bandwidth considerations to take into account when running services from your LAN. It's almost always a better idea to just invest in a proper hosting service like Amazon AWS, DigitalOcean Droplets, or Heroku.
By "online" I suppose you mean to host it globally. For that my friend you will be in need of a server (preferably a cloude server) and a static IP address. Both of these are provided by a lot of providers like aws, digitalocean etc as a platform as a service, which we can leverage. So pls do the following:
Register for a cloud service (aws, digitalocean, gcp etc.).
Create a server instance of an operating system of your choice (my pref would be a linux instance).
Attach a public static ip to the server.
Log into the server. (SSH is the most secure way and most providers provide this to log into your server).
Install dependencies (in your case NodeJS etc).
Make sure that the port in which the app is hosted is open publicly. Most providers provide a dashboard in which you can configure port settings.
Use Apache or Nginx for configuring a reverse proxy (this is just for keeping your environment secure)

getting public ssl certificate for node.js server

I am running a node.js express server on my aws ac2 linux instance. I need to expose it through https to work properly with the react app that pulls data from it. I was able to generate my own ssl certificate but it will not be recognized by other users and the client app will through an error.
Could you please explain how can i get a public ssl certificate just for the node server. The server uses an ip address like xxx.xx.xx.xx:4500/endpoint. Aws seems to offer ssl but only if you pay for its load balancer and I do not want to do that.
Is there a way to verify the certificate that i generated with openssl so i can use it publicly?
Here is my basic setup:
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const moment = require('moment');
var fs = require('fs');
const https = require('https')
const app = express();
xxx
https.createServer({key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')}, app).listen(4500, () => {
console.log('Listening...')
})
Thank you in advance!
OpenSSL itself is a tool to create self-signed certificates. Those certificates are never trusted by the browser.
Instead, you can use Let's Encrypt with this command:
apt install certbot
certbot certonly --standalone -d example.com
Let's Encrypt is a trusted entity, so their certificates are valid.
Your new certificates will be on a path like this:
/etc/letsencrypt/live/example.com
As others suggested, you will need one domain. You can get one free on sites like Freenom.
Your self-signed certificate won't be trusted by the browser.
One solution would be to get yourself a domain and then a free SSL certificate issued by Let's Encrypt. This would remove the error because Let's Encrypt certificates are trusted by all major browsers.
Another solution is to get the free plan of Cloudflare, which includes an SSL certificate. More info here.
There is the possibility to secure your IP with an SSL certificate but there are no free solutions for this.
If you in a region where Amazon Certificate Manager is suported, You can get a SSL certificate for free.
https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html
In order to apply ssl certificate, The easiest way is to use it on a load balancer. Check my answer to this question Apollo Server on Ubuntu 18.04 EC2 instance with HTTPS.
If you want to use the certificate directly on EC2. try the following. I haven't tried this myself.
https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-export-private.html
Also i have seen people using https://letsencrypt.org/ to get certs.

How to solve error with appeal to my rest-api hosted on http from my reactjs-app hosted on https

I have an error with my fetch function in reactjs: when I request data from the rest-api (ASP.NET) hosted on http, my app, which is hosted on Firebase (https) throws an error:
Mixed Content: The page at 'https://[my-domain].firebaseapp.com/' was loaded over HTTPS, but requested an insecure resource
'http://...:*****/filter1/filter2'. This request has been blocked; the content must be served over HTTPS.
Rest hosted on linux by ASP.NET. We already tried make a SSL certificate by .NET CORE option.
fetch(`http://host-ip:port/filter1/filter2`, {
method : 'GET',
mode : 'cors',
credentials : 'same-origin',
}).then(res => res.json())
.then(json => {
this.setState(
{
//some operations
}
)
})
It can be fixed by installing SSL certificate, but we haven't special domain-name (only ip-address). Can it be solved without any cunning operations with domain and certificates? And can we leave it on our ip without transition to domain?
Yeah
You should use your Rest-Api over https. Install valid SSL certificate to your Rest-Api Server and configure is correctly.
You can create a sub-domain for your rest-api using adding DNS A Record and Install SSL for that domain.
I am using
APP : https://myapp.com (https)
API : (my-rest-api-aws-ip) (http)
IN DNS (A Record)
api.myapp.com >>>> (my-rest-api-aws-ip)
Then, I installed free SSL certificate for api.myapp.com using let's encrypt

Site looses javascript and layout after installing HTTPS

I have a site that works fine. Today I tried to install a certificate SSL to pass my site to https.
But once I did it, my site opens (in https now) with no layour or javascript working.
I am using a NGINX server with a GANDI SSL certificate. I donwloaded the certificates in the site and added this in /etc/nginx/sites-available
listen 443;
server_name my.server.fr;
ssl on;
ssl_certificate /etc/nginx/certificates/certificate-99999.crt;
ssl_certificate_key /etc/nginx/certificates/my.server.fr.key;
This is a problem could be related to any configuration of the certificate, or the construction of the pages?
Check your browser console.
There could be errors due to mixed contents... move http resources to https.

Categories

Resources