hunchentoot使用ssl定义易于处理?

jac*_*cal 4 ssl common-lisp hunchentoot

我一直在使用define-easy-handler。我现在有一个刚铸造的ssl证书和相关的pem文件,但无法弄清楚deh的ssl等效项是什么。

例如,我有:

  (hunchentoot:define-easy-handler 
   (login :uri "/login") 
   () 
   (login-html)) 
Run Code Online (Sandbox Code Playgroud)

这只是一个简单的形式,其形式如下:

(hunchentoot:define-easy-handler 
   (dologin :uri "/dologin") 
   (email password) 
   (dologin-html email password)) 
Run Code Online (Sandbox Code Playgroud)

.pem从freecert 获得了所需的文件,因此我认为我拥有以下文件:SSL-CERTIFICATE-FILE和:SSL-PRIVATEKEY-FILE。我已经对上面的各种args进行了尝试,但是似乎无法正常工作。有人可以给我举个例子吗?

预先感谢您的帮助!

cor*_*ump 5

您可以保留方便的处理者,并更改所需的接收器类型。

(defpackage :web (:use :cl :hunchentoot))
(in-package :web)

;; This url can be accessed by all acceptors
(define-easy-handler (no-ssl :uri "/normal") ()
  (setf (content-type*) "text/plain")
  "NORMAL PAGE")

;; This url can be accessed only by an acceptor named SSL
(define-easy-handler (ssl :uri "/secure" :acceptor-names '(ssl)) ()
  (setf (content-type*) "text/plain")
  "SECURED PAGE")
Run Code Online (Sandbox Code Playgroud)

对于测试,如果您还没有自签名证书,则可以执行以下操作:

$ cd /tmp
$ openssl req -new -x509 -nodes -out server.crt -keyout server.key
Run Code Online (Sandbox Code Playgroud)

然后,我们定义两种接收器:

(defvar *no-ssl-acceptor*
  (make-instance 'easy-acceptor :port 8080))

(defvar *ssl-acceptor*
  (make-instance 'easy-ssl-acceptor
                 :name 'ssl
                 :port 7777
                 :ssl-privatekey-file  #P"/tmp/server.key"
                 :ssl-certificate-file #P"/tmp/server.crt"))
Run Code Online (Sandbox Code Playgroud)

启动它们:

(start *ssl-acceptor*)
(start *no-ssl-acceptor*)
Run Code Online (Sandbox Code Playgroud)

您的浏览器在您第一次尝试访问HTTPS页面时应该抱怨(忽略安全异常)。

还要注意,该:acceptor-names参数是可选的(感谢@Simeon Ikudabo),在上面的示例中已明确添加了该参数。您可以只定义一个SSL接受器,并通过安全链接提供所有页面。