Belgabad
Belgabad

Reputation: 263

Difference between https://<ip> and <ip>:443

I'm currently trying to understand the difference between 2 similar curl commands.

I spun up an AWS EC2 Ubuntu instance, and installed node.js on the instance. I then created a new directory called test-server. From within this directory, I ran npm init, then npm install express. I then wrote a simple web listener called test-server.js, which looks like this:

const express = require('express')
const app = express()

app.get('/', function(req, res){
    console.log('Got a request!')
    res.send('Request received!\n')
})

app.listen(443, function(){
    console.log('Server started')
})

Finally, I started the server with the command sudo node test-server.js, and the server started successfully.

Using aws ec2 authorize-security-group-ingress, I allowed communication from my local IP address to the instance over port 443. I then attempted to test the connection using the following 2 curl commands: curl <ip>:443 and curl https://<ip>. The first command gave the expected output of Request received!. However, I received this error from the second command: curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to <ip>:443.

Now, I'm FAR from a networking expert, but I would have expected both of these commands to function in the same way. Based on this result, I have 2 questions:

  1. What is the difference between these 2 commands?
  2. How can I change the configuration such that the second command works as well as the first?

Upvotes: 1

Views: 593

Answers (2)

Chase
Chase

Reputation: 3105

  1. What is the difference between these 2 commands?

:443 is simply the port configuration, no different than :80. It just tells the server to serve content on that port. 443 is traditionally the port reserved for HTTPS connections, similar to how 80 is traditionally standard HTTP.

  1. How can I change the configuration such that the second command works as well as the first?

You'll need to install a TLS cert. HTTPS indicates that a certificate is being used to secure the connection, and the absence of that certificate will cause the request to fail.

Upvotes: 2

Tomasz Tybulewicz
Tomasz Tybulewicz

Reputation: 8647

Your application is serving regular HTTP on 443 port. In order to use https protocol you need to use encryption keys

var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey  = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

app.get('/', function(req, res){
    console.log('Got a request!')
    res.send('Request received!\n')
})

var httpsServer = https.createServer(credentials, app);

httpsServer.listen(443);

Command curl <ip>:443 is opening http connection to port 443 on givenip,curl https://<ip> is opening https connection to given ip.

If you want your traffic to be encrypted, stick to https:// version (and expanded code for server).

Upvotes: 5

Related Questions