experiment with TLS

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-15 09:11:16 -04:00
parent 873fe3f7d9
commit a2d1b75d66
2 changed files with 30 additions and 3 deletions

View File

@ -1,5 +1,31 @@
context = require "openssl.ssl.context"
cqueues = require "cqueues"
pkey = require "openssl.pkey"
url = require "net.url"
x509 = require "openssl.x509"
make_tls_context = (cert, key) ->
fin, err = io.open cert
if err != nil
return nil, err
cert, err = x509.new fin\read "*a"
if err != nil
return nil, err
fin\close!
fin, err = io.open key
if err != nil
return nil, err
pkey, err = pkey.new fin\read "*a"
if err != nil
return nil, err
fin\close!
ctx = context.new "TLS", true
ctx\setCertificate cert
ctx\setPrivateKey pkey
ctx
class Server
new: (hdlr) =>
@ -30,5 +56,6 @@ class Server
\close!
{
:Server
:Server,
:make_tls_context
}

View File

@ -1,6 +1,6 @@
cqueues = require "cqueues"
socket = require "cqueues.socket"
ln = require "ln"
socket = require "cqueues.socket"
gemini = require "gemini"
@ -16,10 +16,10 @@ class FileServer
fname = "./public" .. ctx.path
ln.log ctx, :fname
fin, err = io.open fname .. "/index.gmi"
ln.err err, ctx
if err != nil
fin, err = io.open fname
if err != nil
ln.err err, ctx
conn\write "51 not found: " .. ctx.path .. "\r\n"
conn\write "20 text/gemini\r\n"