Skip to content
Examples of using libtls in C. Includes a proof-of-concept for an evented read/write loop.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Lua
LICENSE
Makefile
README
get1.c
get2.c
get3.c

README

  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.
You can’t perform that action at this time.