summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-08 20:49:48 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-15 18:58:09 -0500
commit5074f14e00f00fb0343fadcf7b2ec1c33c8efaaf (patch)
treedc1f34ef94b8cfba539344a8df80251f949971c1
parentecfc5b6d209e305a76c5540e8d7f786571a1d8e8 (diff)
[dynamic] Drop (hashing) for (gcrypt hash)
Since it's a more standard Guile dependency, meaning I don't need to bing out Akku for something as simple as calling a hash function.
-rw-r--r--.gitmodules3
-rw-r--r--dynamic/captcha.scm13
m---------ext-srfi-1970
-rw-r--r--haunt/jakob/utils/comments.scm29
4 files changed, 34 insertions, 11 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..461dfa9
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "ext-srfi-197"]
+ path = ext-srfi-197
+ url = https://github.com/ar-nelson/srfi-197
diff --git a/dynamic/captcha.scm b/dynamic/captcha.scm
index 99aa0cd..b095ebf 100644
--- a/dynamic/captcha.scm
+++ b/dynamic/captcha.scm
@@ -16,7 +16,7 @@
(define-module (captcha)
#:use-module (base64)
- #:use-module (hashing sha-2)
+ #:use-module (gcrypt hash)
#:use-module (gcrypt mac)
#:use-module (gcrypt random)
#:use-module (ice-9 binary-ports)
@@ -155,10 +155,15 @@
(define (check-proof-of-work prefix
challenge challenge-signature
expiry-timestamp timestamp-signature)
+ (define hash-value
+ (chain (list prefix challenge)
+ (string-concatenate _)
+ (string->bytevector _ "utf8")
+ (bytevector-hash _ (lookup-hash-algorithm 'sha256))
+ (bytevector->base16-string _)))
+ (define zero-prefix (string-join (map (lambda (_) "0") (iota %hardness)) ""))
(and (= 32 (string-length prefix))
- (string-prefix?
- (string-join (map (lambda (_) "0") (iota %hardness)) "")
- (sha-256->string (sha-256 (string->bytevector (string-concatenate (list prefix challenge)) "utf8"))))
+ (string-prefix? zero-prefix hash-value)
(valid-base64-signature? %pow-mac-key challenge challenge-signature)
(valid-base64-signature? %pow-mac-key expiry-timestamp timestamp-signature)
(time<=? (current-time)
diff --git a/ext-srfi-197 b/ext-srfi-197
new file mode 160000
+Subproject 78ced23a1af519ee2969939138b3ffff442f339
diff --git a/haunt/jakob/utils/comments.scm b/haunt/jakob/utils/comments.scm
index a1deea7..65befca 100644
--- a/haunt/jakob/utils/comments.scm
+++ b/haunt/jakob/utils/comments.scm
@@ -17,24 +17,39 @@
(define-module (jakob utils comments)
;; #:use-module (dynamic capabilities comments)
#:use-module (dynamic util)
- #:use-module (hashing md5)
+ #:use-module (gcrypt base16)
+ #:use-module (gcrypt hash)
#:use-module (ice-9 receive)
#:use-module (ice-9 iconv)
#:use-module (ice-9 match)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-43)
+ #:use-module (srfi-197)
#:use-module (json)
#:use-module (web client)
#:use-module (web response)
#:export (render-comment-view fetch-comments))
(define (gravatar-url email)
- (format #f "https://www.gravatar.com/avatar/~a" (md5->string (md5 (string->bytevector (string-trim-both (string-downcase email)) "utf8")))))
-;; (chain email
-;; (string-downcase _)
-;; (string-trim-both _)
-;; (string->bytevector _ "utf8")
-;; (md5 _))
+ (chain email
+ (string-downcase _)
+ (string-trim-both _)
+ (string->bytevector _ "utf8")
+ (bytevector-hash _ (lookup-hash-algorithm 'md5))
+ (bytevector->base16-string _)
+ (format #f "https://www.gravatar.com/avatar/~a" _)))
+
+(define (safe-markdown->sxml text)
+ "Convert TEXT to an sxml form filtering out any unsafe entities"
+ (define (sanitize sexp)
+ (cond ((and (list? sexp)
+ (positive? (length sexp))
+ (eqv? 'img (car sexp)))
+ #f)
+ ((list? sexp)
+ (filter identity (map sanitize sexp)))
+ (else sexp)))
+ (sanitize (commonmark->sxml text)))
(define (format-comment comment)
"Format `comment', an alist, as SXML for a comment-type interaction"