I am trying to implement HTTPS on a development website for a demo. My Front end is a VueJS application and my Back end is a Flask application using Python.
To implement HTTPS on my website I did as following:
Generated self signed certificate:
Private key is a RSA 2048 encrypted key called 'private.key'.
Generate a csr certificate with certificate.txt.
openssl req -new -config certificate.txt -key private.key -out certificate.csr
Generate the final certificate with certificate.csr
openssl x509 -signkey private.key -in certificate.csr -req -days 365 -out certificate.crt
With certificate.txt as following:
[ req ]
prompt = no
distinguished_name = dn
req_extensions = req_ext
[ dn ]
CN = test.domain.en
emailAddress = ssl@exemple.com
O = Company
OU = test
L = UK
ST = UK
C = UK
[ req_ext ]
subjectAltName = DNS: localhost, DNS: test.domain.en, IP: X.X.X.X:XXXX'ip of my vm'
Front end (VueJS configuration):
Adding in vue.config.js the link to the certificate and the private key
const fs = require('fs');
module.exports = {
devServer: {
https: {
key: fs.readFileSync('src/assets/certificate/private.key'),
cert: fs.readFileSync('src/assets/certificate/certificate.crt'),
},
public: 'https://protected.deloitte.lu:8080/',
disableHostCheck: true,
},
};
Adding rejectUnauthorized parameter in an httpsAgent in axios when making a POST request
const httpsAgent = new https.Agent({
rejectUnauthorized: false
});
axios.post(payload, formData, {headers: headers, httpsAgent: httpsAgent})
Back end (Flask configuration in Python)
Adding certificate and key in a ssl context when app is running
if __name__ == '__main__':
context=('./certs/certificate_cloud.crt','./certs/private.key')
app.run(host='0.0.0.0', port=5008, debug=False, ssl_context=context)
- Web browser (Chrome configuration)
Enabled : chrome://flags/#allow-insecure-localhost
Installed certificate.crt in 'Trusted Root Certification Authorities'
Results:
Frontend: https://localhost:8080/
Backend: https://X.X.X.X:5008/
When the back end is hosted and running on localhost, the post request is working well and the protocol is HTTPS as requested.
However, when I migrate the flask application on an AWS virtual machine I get this error:
POST https://XXX.XXX.XXX.XXX:XXXX/path/to/function/ net::ERR_CERT_AUTHORITY_INVALID
What I already tried:
Replace ssl_context=context
with ssl_context='adhoc'
Generate several certificate with different domain name, and config the ip with this domain name.
Additional question:
Is it possible to remove the 'Not secure' icon on Chrome with a self signed certificate generate with openssl?