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.
Type Name Latest commit message Commit time
Failed to load latest commit information.


  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 <> you would do:

	GenericUnixPrompt> ./get1 /

  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


	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.


	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).


	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

	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.


	Same as get1.c, only in Lua.  It uses a currently unpublished
	Lua module I'm working on (as do all the Lua versions).


	Same as get2.c, only in Lua.


	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.


	An implementation that actually works with coroutines in Lua.
You can’t perform that action at this time.