1
0
Fork 0

- [gemini] added support for proxy.

This commit is contained in:
cage 2024-06-23 20:30:53 +02:00
parent c636fd8edb
commit 1f58010447
4 changed files with 86 additions and 69 deletions

View File

@ -522,7 +522,7 @@ open-message-link-window.input.selected.foreground = #FF00FF
# gemini browser # gemini browser
# the default search engine # absolute address for a search engine used in tinmop (both TUI and GUI)
gemini.search-engine.uri = "gemini://kennedy.gemi.dev/search" gemini.search-engine.uri = "gemini://kennedy.gemi.dev/search"

View File

@ -447,6 +447,8 @@
(client-certificate nil) (client-certificate nil)
(certificate-key nil) (certificate-key nil)
(certificate-key-password nil)) (certificate-key-password nil))
(multiple-value-bind (proxy-host proxy-port)
(swconf:config-gemini-proxy)
(let* ((iri (make-gemini-iri (idn:host-unicode->ascii host) (let* ((iri (make-gemini-iri (idn:host-unicode->ascii host)
(percent-encode-path path) (percent-encode-path path)
:query (percent-encode-query query) :query (percent-encode-query query)
@ -455,13 +457,17 @@
(ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+))) (ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+)))
(cl+ssl:with-global-context (ctx :auto-free-p t) (cl+ssl:with-global-context (ctx :auto-free-p t)
(handler-case (handler-case
(let ((socket (open-tls-socket host port))) (let* ((actual-host (or proxy-host
host))
(actual-port (or proxy-port
port))
(socket (open-tls-socket actual-host actual-port)))
(hooks:run-hooks 'hooks:*after-gemini-socket*) (hooks:run-hooks 'hooks:*after-gemini-socket*)
(let* ((stream (usocket:socket-stream socket)) (let* ((stream (usocket:socket-stream socket))
(ssl-hostname (if (or (iri:ipv4-address-p host) (ssl-hostname (if (or (iri:ipv4-address-p actual-host)
(iri:ipv6-address-p host)) (iri:ipv6-address-p actual-host))
nil nil
host)) actual-host))
(ssl-stream (cl+ssl:make-ssl-client-stream stream (ssl-stream (cl+ssl:make-ssl-client-stream stream
:certificate client-certificate :certificate client-certificate
:key certificate-key :key certificate-key
@ -474,8 +480,8 @@
(request (format nil "~a~a~a" iri #\return #\newline)) (request (format nil "~a~a~a" iri #\return #\newline))
(cert-hash (crypto-shortcuts:sha512 (x509:dump-certificate ssl-stream)))) (cert-hash (crypto-shortcuts:sha512 (x509:dump-certificate ssl-stream))))
(debug-gemini "sending request ~a" request) (debug-gemini "sending request ~a" request)
(if (not (db:tofu-passes-p host cert-hash)) (if (not (db:tofu-passes-p actual-host cert-hash))
(error 'gemini-tofu-error :host host) (error 'gemini-tofu-error :host actual-host)
(progn (progn
(write-sequence (string->octets request) ssl-stream) (write-sequence (string->octets request) ssl-stream)
(force-output ssl-stream) (force-output ssl-stream)
@ -486,7 +492,7 @@
#-sbcl (parse-response ssl-stream) #-sbcl (parse-response ssl-stream)
(values status description meta response socket)))))) (values status description meta response socket))))))
(error (e) (error (e)
(error e)))))) (error e)))))))
(defun missing-dispath-function (status code-description meta response socket iri parsed-iri) (defun missing-dispath-function (status code-description meta response socket iri parsed-iri)
(declare (ignore response socket parsed-iri)) (declare (ignore response socket parsed-iri))

View File

@ -1481,6 +1481,7 @@
:config-default-post-language :config-default-post-language
:config-announcements-separator :config-announcements-separator
:config-announcements-icon :config-announcements-icon
:config-gemini-proxy
:config-gemini-search-engine-iri :config-gemini-search-engine-iri
:link-regex->program-to-use :link-regex->program-to-use
:link-regex->program-to-use-buffer-size :link-regex->program-to-use-buffer-size

View File

@ -597,6 +597,7 @@
gemini gemini
gemlog gemlog
gempub gempub
proxy
library library
sync sync
favicon favicon
@ -1684,6 +1685,15 @@
+key-announcements+ +key-announcements+
+key-icon+) +key-icon+)
(defun config-gemini-proxy ()
(when-let* ((iri (access:accesses *software-configuration*
+key-gemini+
+key-proxy+
+key-uri+))
(parsed-iri (iri:iri-parse iri :null-on-error t)))
(values (uri:host parsed-iri)
(uri:port parsed-iri))))
(defun config-gemini-search-engine-iri () (defun config-gemini-search-engine-iri ()
(let ((iri (access:accesses *software-configuration* (let ((iri (access:accesses *software-configuration*
+key-gemini+ +key-gemini+
@ -1695,8 +1705,7 @@
;;;;;; tests ;;;;;; tests
(defun trivial-configuration-missing-value-check () (defun trivial-configuration-missing-value-check ()
(loop for fn in (list (loop for fn in (list #'gemini-downloading-animation
#'gemini-downloading-animation
#'gemini-default-favicon #'gemini-default-favicon
#'gemini-link-prefix-to-gemini #'gemini-link-prefix-to-gemini
#'gemini-link-prefix-to-other #'gemini-link-prefix-to-other
@ -1727,4 +1736,5 @@
(defun trivial-configuration-checks () (defun trivial-configuration-checks ()
(assert (length= (config-username) (assert (length= (config-username)
(config-server-name)))) (config-server-name)))
(config-gemini-proxy))