aboutsummaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
Diffstat (limited to 'filters')
-rw-r--r--filters/email-gravatar.lua17
-rw-r--r--filters/email-libravatar.lua17
-rw-r--r--filters/file-authentication.lua31
-rw-r--r--filters/gentoo-ldap-authentication.lua31
-rwxr-xr-xfilters/html-converters/md2html17
-rw-r--r--filters/simple-authentication.lua31
6 files changed, 98 insertions, 46 deletions
diff --git a/filters/email-gravatar.lua b/filters/email-gravatar.lua
index 52cf426..c39b490 100644
--- a/filters/email-gravatar.lua
+++ b/filters/email-gravatar.lua
@@ -3,15 +3,24 @@
-- prefix in filters. It is much faster than the corresponding python script.
--
-- Requirements:
--- luacrypto >= 0.3
--- <http://mkottman.github.io/luacrypto/>
+-- luaossl
+-- <http://25thandclement.com/~william/projects/luaossl.html>
--
-local crypto = require("crypto")
+local digest = require("openssl.digest")
+
+function md5_hex(input)
+ local b = digest.new("md5"):final(input)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
function filter_open(email, page)
buffer = ""
- md5 = crypto.digest("md5", email:sub(2, -2):lower())
+ md5 = md5_hex(email:sub(2, -2):lower())
end
function filter_close()
diff --git a/filters/email-libravatar.lua b/filters/email-libravatar.lua
index b0e2447..7336baf 100644
--- a/filters/email-libravatar.lua
+++ b/filters/email-libravatar.lua
@@ -3,15 +3,24 @@
-- prefix in filters.
--
-- Requirements:
--- luacrypto >= 0.3
--- <http://mkottman.github.io/luacrypto/>
+-- luaossl
+-- <http://25thandclement.com/~william/projects/luaossl.html>
--
-local crypto = require("crypto")
+local digest = require("openssl.digest")
+
+function md5_hex(input)
+ local b = digest.new("md5"):final(input)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
function filter_open(email, page)
buffer = ""
- md5 = crypto.digest("md5", email:sub(2, -2):lower())
+ md5 = md5_hex(email:sub(2, -2):lower())
end
function filter_close()
diff --git a/filters/file-authentication.lua b/filters/file-authentication.lua
index 6ee1e19..0248804 100644
--- a/filters/file-authentication.lua
+++ b/filters/file-authentication.lua
@@ -1,15 +1,15 @@
-- This script may be used with the auth-filter.
--
-- Requirements:
--- luacrypto >= 0.3
--- <http://mkottman.github.io/luacrypto/>
+-- luaossl
+-- <http://25thandclement.com/~william/projects/luaossl.html>
-- luaposix
-- <https://github.com/luaposix/luaposix>
--
local sysstat = require("posix.sys.stat")
local unistd = require("posix.unistd")
-local crypto = require("crypto")
-
+local rand = require("openssl.rand")
+local hmac = require("openssl.hmac")
-- This file should contain a series of lines in the form of:
-- username1:hash1
@@ -225,6 +225,13 @@ function get_cookie(cookies, name)
return url_decode(string.match(cookies, ";" .. name .. "=(.-);"))
end
+function tohex(b)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
--
--
@@ -242,12 +249,12 @@ function get_secret()
local secret_file = io.open(secret_filename, "r")
if secret_file == nil then
local old_umask = sysstat.umask(63)
- local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16))
+ local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16))
local temporary_file = io.open(temporary_filename, "w")
if temporary_file == nil then
os.exit(177)
end
- temporary_file:write(crypto.hex(crypto.rand.bytes(32)))
+ temporary_file:write(tohex(rand.bytes(32)))
temporary_file:close()
unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same.
unistd.unlink(temporary_filename)
@@ -272,7 +279,7 @@ function validate_value(expected_field, cookie)
local field = ""
local expiration = 0
local salt = ""
- local hmac = ""
+ local chmac = ""
if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then
return nil
@@ -291,19 +298,19 @@ function validate_value(expected_field, cookie)
elseif i == 3 then
salt = component
elseif i == 4 then
- hmac = component
+ chmac = component
else
break
end
i = i + 1
end
- if hmac == nil or hmac:len() == 0 then
+ if chmac == nil or chmac:len() == 0 then
return nil
end
-- Lua hashes strings, so these comparisons are time invariant.
- if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then
+ if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then
return nil
end
@@ -324,11 +331,11 @@ function secure_value(field, value, expiration)
end
local authstr = ""
- local salt = crypto.hex(crypto.rand.bytes(16))
+ local salt = tohex(rand.bytes(16))
value = url_encode(value)
field = url_encode(field)
authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
- authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret())
+ authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr))
return authstr
end
diff --git a/filters/gentoo-ldap-authentication.lua b/filters/gentoo-ldap-authentication.lua
index b4d98c2..673c88d 100644
--- a/filters/gentoo-ldap-authentication.lua
+++ b/filters/gentoo-ldap-authentication.lua
@@ -1,8 +1,8 @@
-- This script may be used with the auth-filter. Be sure to configure it as you wish.
--
-- Requirements:
--- luacrypto >= 0.3
--- <http://mkottman.github.io/luacrypto/>
+-- luaossl
+-- <http://25thandclement.com/~william/projects/luaossl.html>
-- lualdap >= 1.2
-- <https://git.zx2c4.com/lualdap/about/>
-- luaposix
@@ -10,9 +10,9 @@
--
local sysstat = require("posix.sys.stat")
local unistd = require("posix.unistd")
-local crypto = require("crypto")
local lualdap = require("lualdap")
-
+local rand = require("openssl.rand")
+local hmac = require("openssl.hmac")
--
--
@@ -226,6 +226,13 @@ function get_cookie(cookies, name)
return string.match(cookies, ";" .. name .. "=(.-);")
end
+function tohex(b)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
--
--
@@ -243,12 +250,12 @@ function get_secret()
local secret_file = io.open(secret_filename, "r")
if secret_file == nil then
local old_umask = sysstat.umask(63)
- local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16))
+ local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16))
local temporary_file = io.open(temporary_filename, "w")
if temporary_file == nil then
os.exit(177)
end
- temporary_file:write(crypto.hex(crypto.rand.bytes(32)))
+ temporary_file:write(tohex(rand.bytes(32)))
temporary_file:close()
unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same.
unistd.unlink(temporary_filename)
@@ -273,7 +280,7 @@ function validate_value(expected_field, cookie)
local field = ""
local expiration = 0
local salt = ""
- local hmac = ""
+ local chmac = ""
if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then
return nil
@@ -292,19 +299,19 @@ function validate_value(expected_field, cookie)
elseif i == 3 then
salt = component
elseif i == 4 then
- hmac = component
+ chmac = component
else
break
end
i = i + 1
end
- if hmac == nil or hmac:len() == 0 then
+ if chmac == nil or chmac:len() == 0 then
return nil
end
-- Lua hashes strings, so these comparisons are time invariant.
- if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then
+ if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then
return nil
end
@@ -325,11 +332,11 @@ function secure_value(field, value, expiration)
end
local authstr = ""
- local salt = crypto.hex(crypto.rand.bytes(16))
+ local salt = tohex(rand.bytes(16))
value = url_encode(value)
field = url_encode(field)
authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
- authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret())
+ authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr))
return authstr
end
diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html
index ebf3856..dc20f42 100755
--- a/filters/html-converters/md2html
+++ b/filters/html-converters/md2html
@@ -3,6 +3,7 @@ import markdown
import sys
import io
from pygments.formatters import HtmlFormatter
+from markdown.extensions.toc import TocExtension
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stdout.write('''
@@ -48,10 +49,14 @@ sys.stdout.write('''
line-height: 1;
padding-left: 0;
margin-left: -22px;
- top: 15%}
+ top: 15%;
+}
.markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link {
display: inline-block;
}
+div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink {
+ color: black;
+}
.markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code {
font-size: inherit;
}
@@ -290,5 +295,13 @@ sys.stdout.write('''
sys.stdout.write("<div class='markdown-body'>")
sys.stdout.flush()
# Note: you may want to run this through bleach for sanitization
-markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}})
+markdown.markdownFromFile(
+ output_format="html5",
+ extensions=[
+ "markdown.extensions.fenced_code",
+ "markdown.extensions.codehilite",
+ "markdown.extensions.tables",
+ TocExtension(anchorlink=True)],
+ extension_configs={
+ "markdown.extensions.codehilite":{"css_class":"highlight"}})
sys.stdout.write("</div>")
diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua
index 77d1fd0..23d3457 100644
--- a/filters/simple-authentication.lua
+++ b/filters/simple-authentication.lua
@@ -1,15 +1,15 @@
-- This script may be used with the auth-filter. Be sure to configure it as you wish.
--
-- Requirements:
--- luacrypto >= 0.3
--- <http://mkottman.github.io/luacrypto/>
+-- luaossl
+-- <http://25thandclement.com/~william/projects/luaossl.html>
-- luaposix
-- <https://github.com/luaposix/luaposix>
--
local sysstat = require("posix.sys.stat")
local unistd = require("posix.unistd")
-local crypto = require("crypto")
-
+local rand = require("openssl.rand")
+local hmac = require("openssl.hmac")
--
--
@@ -180,6 +180,13 @@ function get_cookie(cookies, name)
return url_decode(string.match(cookies, ";" .. name .. "=(.-);"))
end
+function tohex(b)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
--
--
@@ -197,12 +204,12 @@ function get_secret()
local secret_file = io.open(secret_filename, "r")
if secret_file == nil then
local old_umask = sysstat.umask(63)
- local temporary_filename = secret_filename .. ".tmp." .. crypto.hex(crypto.rand.bytes(16))
+ local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16))
local temporary_file = io.open(temporary_filename, "w")
if temporary_file == nil then
os.exit(177)
end
- temporary_file:write(crypto.hex(crypto.rand.bytes(32)))
+ temporary_file:write(tohex(rand.bytes(32)))
temporary_file:close()
unistd.link(temporary_filename, secret_filename) -- Intentionally fails in the case that another process is doing the same.
unistd.unlink(temporary_filename)
@@ -227,7 +234,7 @@ function validate_value(expected_field, cookie)
local field = ""
local expiration = 0
local salt = ""
- local hmac = ""
+ local chmac = ""
if cookie == nil or cookie:len() < 3 or cookie:sub(1, 1) == "|" then
return nil
@@ -246,19 +253,19 @@ function validate_value(expected_field, cookie)
elseif i == 3 then
salt = component
elseif i == 4 then
- hmac = component
+ chmac = component
else
break
end
i = i + 1
end
- if hmac == nil or hmac:len() == 0 then
+ if chmac == nil or chmac:len() == 0 then
return nil
end
-- Lua hashes strings, so these comparisons are time invariant.
- if hmac ~= crypto.hmac.digest("sha256", field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt, get_secret()) then
+ if chmac ~= tohex(hmac.new(get_secret(), "sha256"):final(field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt)) then
return nil
end
@@ -279,11 +286,11 @@ function secure_value(field, value, expiration)
end
local authstr = ""
- local salt = crypto.hex(crypto.rand.bytes(16))
+ local salt = tohex(rand.bytes(16))
value = url_encode(value)
field = url_encode(field)
authstr = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
- authstr = authstr .. "|" .. crypto.hmac.digest("sha256", authstr, get_secret())
+ authstr = authstr .. "|" .. tohex(hmac.new(get_secret(), "sha256"):final(authstr))
return authstr
end