Тёмный

Making Minimalist HTTPS Server in C on Linux 

Nir Lichtman
Подписаться 44 тыс.
Просмотров 16 тыс.
50% 1

In this video I will demonstrate how you can make a Simple HTTPS Web Server using the C Programming Language and OpenSSL library on Linux.
You can view the code I wrote in the video over here:
github.com/nir9/welcome/tree/...

Наука

Опубликовано:

 

19 дек 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 60   
@nirlichtman
@nirlichtman 6 месяцев назад
- Notice that if you run the server quickly after running it before, bind might fail since the port may not be cleaned up yet, so I recommend running the server with ltrace/strace so you can actually see what is going on under the hood, my new video about the importance of error handling in c also talks about this specifically
@enesalbay9707
@enesalbay9707 17 дней назад
Add setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) before bind to overcome this problem.
@space9824
@space9824 6 месяцев назад
These videos are so insightful, especially the way you show the man pages where you can find all this information. I literally didn't even know C library functions had man pages until I starting watching your content.
@iamspeed1405
@iamspeed1405 6 месяцев назад
Geez I opened the video and BOOM! it was straight into the action no silly 1 minute long intro. Love it ❤!
@Dysl3xicDog
@Dysl3xicDog 5 месяцев назад
The way you put the documentation digging into the videos is super helpful. The thing that's lost on me at this point is how you discover the functions you need to use before you hit the docs for each item.
@nirlichtman
@nirlichtman 5 месяцев назад
Thanks for the feedback I will try talking more about the discovery as well on future videos, check out my man pages tips video for general tips about finding man pages.
@bromophenol2469
@bromophenol2469 6 месяцев назад
Nir, your distinct no nonsense style is very refreshing
@KimTiger777
@KimTiger777 6 месяцев назад
Wow I guess Christmas came early this year. This opens up many possibilities with all kinds of web services. Only imagination is the limit! Thank you soo much!
@Maagiicc
@Maagiicc 6 месяцев назад
Thanks for the longer video and more complicated program. Do you have any plans on doing anything non-minimalist?
@nirlichtman
@nirlichtman 6 месяцев назад
Yes, I am planning on perhaps fully implementing one of the unix commands :)
@StefanWelebny
@StefanWelebny 6 месяцев назад
Could you show how to handle concurrent requests and concurrent listeners?
@AlTiri-rd7ly
@AlTiri-rd7ly 6 месяцев назад
​​@reapiu8316yeah I would love to see that, although I really loke these semi short videos.
@hermessantos181
@hermessantos181 6 месяцев назад
awesome!@reapiu8316
@spacewad8745
@spacewad8745 6 месяцев назад
Ah you've read my mind! I just started messing around with sockets and was about to try my hand at developing a simple http server.
@sashakuznechkin
@sashakuznechkin 6 месяцев назад
Thanks for video! Happy new year!
@Temon0942
@Temon0942 6 месяцев назад
Hey bro your videos are amazing keep making them
@pavfrang
@pavfrang 6 месяцев назад
WOW - that is original hack stuff. Love it. Carry on!
@Humble_Electronic_Musician
@Humble_Electronic_Musician 6 месяцев назад
This is good stuff! Awesome!
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 месяцев назад
My wish has been heared, thx
@justcurious1940
@justcurious1940 10 дней назад
Great videos bro, Thanks.
@tan4296
@tan4296 6 месяцев назад
I really like your thumbnails
@quezinmark8225
@quezinmark8225 6 месяцев назад
Making short videos are good but giving overview about what you're going to do would make it better I mean explaining flow!
@DrDulos
@DrDulos 4 месяца назад
Thanks, good work
@davidgillies620
@davidgillies620 6 месяцев назад
If you need to implement a production-grade HTTPS server in C++, Vinnie Falco's Beast library is the way to go.
@rogo7330
@rogo7330 6 месяцев назад
I believe it's better to use separate TLS reverse proxies that will do TLS stuff and then pass the connection to next program by just connecting to localhost port or unix socket. It makes programs much simplier and can become a problem only on high load servers, where you don't want too many calls to write and read from programs because it's more user-kernel context switching.
@nirlichtman
@nirlichtman 6 месяцев назад
I agree about this point, for actual production it would be better to separate the HTTP server and the SSL server, or to just use nginx :)
@samjiman
@samjiman 6 месяцев назад
Nice videos. What is the window manager you are using on Windows?
@nirlichtman
@nirlichtman 6 месяцев назад
I am using dwm-win32, more info about the setup in the welcome link in the channel description
@samjiman
@samjiman 6 месяцев назад
@@nirlichtman Thanks, Nir.
@luadicrous
@luadicrous 5 месяцев назад
I found out that if you hold F5 in the browser for a while it can make it 'crash'. It's not a real crash however, it's the SIGPIPE signal that is being fired and it happens when a pipe gets broken. You can capture this event with the 'signal' function if you are on Unix based systems, but no idea what the equivalent on Windows is. Once you've captured this signal, you can just ignore it and the server keeps running.
@ttrss
@ttrss 6 месяцев назад
aw your not writing a c implement of tls in 15 minutes
@erbenton07
@erbenton07 5 месяцев назад
Hi, what editor are you using? I'd like to try it out.
@nirlichtman
@nirlichtman 5 месяцев назад
I am using Vim, many of my older videos are about it if you want more info
@bob-007
@bob-007 6 месяцев назад
great stuff thanks, any chance of something similar but in Python?
@nirlichtman
@nirlichtman 6 месяцев назад
Good idea, noted :)
@kimlehtinen
@kimlehtinen 6 месяцев назад
Interesting! Is this what NGINX does under the hood when configured as reverse proxy with SSL?
@nirlichtman
@nirlichtman 6 месяцев назад
I haven't explored the NGINX source code yet, but I assume it works pretty similar, I am pretty sure it also uses OpenSSL :)
@soniablanche5672
@soniablanche5672 5 месяцев назад
I don't think it's as simple as that. NGINX could be running TLS with http version 2 and it is redirecting the http request to a local web server that is not using TLS and is using http version 1.
@leonss2356
@leonss2356 6 месяцев назад
noice
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 месяцев назад
Hey Nir, i used openssl commandline utility to generate key and cert. i changed "SSL_use_certificate_chain_file(ssl, "fullChain");" to "SSL_use_certificate_file(ssl, "key.pem", SSL_FILETYPE_PEM);" and ajusted file name.I compiled and ran it gave me an "The connection was reset The connection to the server was reset while the page was loading." error. can you help?
@nirlichtman
@nirlichtman 6 месяцев назад
Is that the error you got from the web browser? Reason is probably because the certificate is self-signed, and the browser is rejecting the connection, if you want to try out the server you can use wget with the ignore cert option or try configurating the browser to accept the self-signed cert. If you want it to work out of the box you need to get a certificate signed by a certificate authority, on my setup in the video for example I used my certificate and private generated by let's encrypt which is a service that lets you easily get a certificate for your server
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 месяцев назад
​@@nirlichtman, update, i added an printf debug statement to nearly every function call wich prints its return value, and i found out that `bind()` returns an error (-1) when it doesnt work and success if it works (to download) could the reason be that in the code (because its not "production ready") an "un-bind" is missing?
@Acorn_Anomaly
@Acorn_Anomaly 6 месяцев назад
@@ItsCOMMANDer_ There's no need to "unbind". The binding of the socket is released when the server socket is closed. If bind() is returning -1, then as you said, something is going wrong. When you get a failure, you should add code to print out the value of the errno special variable, to see what the error is. (See the bind(2) man page for more info.)
@aralozkaya
@aralozkaya Месяц назад
Well, wouldn't it be better to send a corresponding HTTP error code (instead of 200 OK each time) when you return a "not found" error?
@honeymak
@honeymak 3 месяца назад
i just wonder how you know the sequence of function calls beforehand
@nirlichtman
@nirlichtman 3 месяца назад
On most cases the man pages/docs are sufficient to help me do the preliminary research, but specifically in the case of OpenSSL, which has quite poor docs in my opinion, I had to also do online research
@dkkogmaw1311
@dkkogmaw1311 Месяц назад
How can you link it static … im stuck at this point
@MarcoLeong
@MarcoLeong 6 месяцев назад
What is that {0} terminator for?
@nirlichtman
@nirlichtman 6 месяцев назад
That is standard C syntax to initialize all array members with 0, as long as you are not using an old/weird C compiler, it works nicely :) devdocs.io/c/language/array_initialization
@rian0xFFF
@rian0xFFF 6 месяцев назад
Do some basic OpenGL stuff or some UI
@nirlichtman
@nirlichtman 6 месяцев назад
I am planning a future UI video about making a minimalist paint app for Windows. OpenGL is a good idea, noted :)
@rian0xFFF
@rian0xFFF 6 месяцев назад
@@nirlichtman 😊
@yargonslavter
@yargonslavter 6 месяцев назад
Narration: Great Content: Great Code Editor: C'mon man, use Visual Code
@nirlichtman
@nirlichtman 6 месяцев назад
My favorite editor is Vim, in some of my older videos I explain why :)
@rajveer_2009
@rajveer_2009 3 месяца назад
upgrade your vim
@rickdearman9992
@rickdearman9992 6 месяцев назад
It annoys me you use void for main. That is very C++ not C. 😂
@benhetland576
@benhetland576 5 месяцев назад
It is not very C++ either.
Далее
Adding Simple System Call in Linux Kernel
7:44
Просмотров 13 тыс.
Making Minimalist Chat Server in C on Linux
14:28
Просмотров 39 тыс.
Kim bo’ldi bu qiz?
00:17
Просмотров 1,6 млн
Coding a Web Server in 25 Lines - Computerphile
17:49
Просмотров 324 тыс.
Making Minimalist Web Server in C on Windows
10:52
Просмотров 8 тыс.
Linux named and unnamed pipes
6:02
Просмотров 156
The Importance of Error Handling in C
8:18
Просмотров 29 тыс.
i wrote my own memory allocator in C to prove a point
5:23
Self-Hosted TRUST with your own Certificate Authority!
26:25
C Programming: TCP Server
21:33
Просмотров 2,4 тыс.
Creating a Web Server from Scratch in C
46:54
Просмотров 54 тыс.
Master Pointers in C:  10X Your C Coding!
14:12
Просмотров 283 тыс.
Making Minimalist Hex Editor in C on Linux
9:35
Просмотров 10 тыс.
Спидран по ПК
0:57
Просмотров 30 тыс.