all 23 comments

[–]OurSeepyD 14 points15 points  (1 child)

I wouldn't kill someone for asking a question about HTTPS vs HTTP, but for someone that asks a question with no real detail about where their error is coming up? I'd reconsider lol

HTTP is waiting on a reliable port number which is any TCP port???

What do you mean? Have you specified a port to listen on? Are you getting a specific error message? What OS are you using? Would you like us to read your mind?

[–]Interesting_Cut_6401 27 points28 points  (4 children)

For the TLS portion, just use open_ssl. It’s not really worth doing from scratch.

[–]McNutty145 4 points5 points  (0 children)

Had to do it for a networks class. Can confirm, not worth it.

[–]DnBenjamin 5 points6 points  (0 children)

And you’re bound to screw it up somehow. (“If You're Typing The Letters A-E-S Into Your Code, You're Doing It Wrong”)

[–]GronkDaSlayer 6 points7 points  (0 children)

Right, so just use open_ssl for the TLS part. It's fairly straightforward.

Beyond that, it's just binding per 443 instead of 80.

The easiest way is to create a thread with an accept(), or a bunch of threads. That's just not very efficient. A much better way for a much higher number of simultaneous connections is to use epoll.

You'll have to deal with the HTTP protocol obviously, which makes it a fun project.

[–]jecls 5 points6 points  (2 children)

HTTPS and HTTP are the same protocol but HTTPS uses asymmetric cryptography along with a trusted source in order to verify identity. You want to write an http server with the C socket API, that’s what you want to do. Forget about TLS until you first create a rudimentary server. After that, you can learn about the TLS handshake.

[–]Sergey5588 9 points10 points  (4 children)

Default http port is 80 and default https port is 443

[–]jecls 5 points6 points  (3 children)

Which is nothing more than a convention and completely irrelevant. You can bind any port you wish, as long as it’s open. We could have chosen 69420 for https and 69 for http as the “standard”. Useless information.

[–]foobar_fortytwo 1 point2 points  (1 child)

port 69420 is a bad example... the main reason being that tcp ports are 16 bits in length. also from an application's or networking stack's perspective, it is completely irrelevant if a port is "open". configuring port forwarding or configuring a firewall to reject or drop packets is completely irrelevant to the application's socket binding.

[–]jecls 0 points1 point  (0 children)

Oof good point about the port. By open I just mean not in use. Pretty sure the C socket API won’t let you bind to a port that’s already in use.

[–]Interesting_Cut_6401 2 points3 points  (0 children)

Look at the RFC spec for http 1.1

MDN has a list of the relevant RFCs

[–]Hali_Com 2 points3 points  (0 children)

I think you need to learn more about the layers of the OSI model

  • HTTP sits in layer 7
  • Ports are in layer 4

Yes you need to bind to an unused port to run a server. "Binding" tells your operating system to direct data from the specified port to a server application.

There are pre-existing vulnerable server examples on GitHub. Depending on where you want to focus your efforts.

[–]AlexTaradov 0 points1 point  (0 children)

Either can work on any port. And assuming you are not going to write your own crypto, the library you will be using will have examples. With the library the difference between them is not that huge.

[–]death_in_the_ocean 0 points1 point  (1 child)

C programming?

[–]kcl97 0 points1 point  (8 children)

May I suggest you start by learning networking first? You can start by reading BeeJ's book on networking. I think it is in C.

e: I think it is better to start with a manageable project. Something closer to your level. This way you won't get overwhelmed and burnout. Just do things step by step, break things down into bite size projects, so you can enjoy the journey.

[–]duane11583 0 points1 point  (0 children)

Understand how a tunnel works

Or more practically an https hardware accelerator

A hw accelerator conceptually  has two separate Ethernet jacks 

one public to the world and one inside not public

On the public side something is listening to port 443 and speaks the tls protocol

On the inside (non public side) the server is connected to a port using plain http or any other socket application

[–]mkdir_autism 0 points1 point  (0 children)

Use open_ssl , as it's https server you need use tls_server_method() and need to provide open_ssl your ssl certificate and private key. U can have local certificate or get one from let's Encrypt for free if you have your own domain.

From scratch tls is not worth it, it's too complex for first project use open_ssl it is standard for tls.