-
Notifications
You must be signed in to change notification settings - Fork 0
Examples of using libtls in C. Includes a proof-of-concept for an evented read/write loop.
License
spc476/libtls-examples
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is some code I wrote to get familiar with using libtls, a sane and relatively easy library to use. I'm impressed with it. All the programs have the same command line parameters: the first is the hostname to connect to, and the second is the resource you want to obtain. For instance, to get the main page from <https://www.google.com/> you would do: GenericUnixPrompt> ./get1 www.google.com / All the programs assume port 443 for https:---adding support for port overriding and maybe even parsing a URL is left as an exercise for the reader. get1.c Just a straightforward program to obtain a webpage from a secure website. It uses blocking I/O, and is the minimum you need to obtain a webpage from a secure site. get2.c This program will explicitly create the socket, then call connect() to establish a TCP connection. It then uses said socket to initiate a secure connection via the tls_connect_cbs() function. The custom read and write functions will read data directly from the socket, and dump the contents to some files (input.bin and output.bin for input and output respectively). get3.c This is a proof-of-concept using non-blocking I/O to simulate use in an evented architecture (although it's not fully evented). This also uses tls_connect_cbs() with custom read/write functions which should be enough to show how it would be done in a real evented system. A real evented system would buffer the input from the network to minimize the number of system calls made. I just wanted something simple to prove it would work, and not obscure the details behind a bunch of abstractions---this is a demo after all. Lua/get1.c Same as get1.c, only in Lua. It uses a currently unpublished Lua module I'm working on (as do all the Lua versions). Lua/get2.c Same as get2.c, only in Lua. Lua/get3.c Same as get3.c, only in Lua. Also, misleading, because you cannot call coroutine.yield() in the callback functions as I indicate. I only found this out the hard way. Lua/get4.c An implementation that actually works with coroutines in Lua.
About
Examples of using libtls in C. Includes a proof-of-concept for an evented read/write loop.
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published