V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
testcaoy7
V2EX  ›  程序员

为 Caddy 增加客户端证书认证,做只为自己服务的反代

  •  
  •   testcaoy7 · 2017-10-15 10:55:37 +08:00 · 2904 次点击
    这是一个创建于 2385 天前的主题,其中的信息可能已经有所发展或是发生改变。
    使用 easy-rsa 可以很方便的完成这个任务。
    首先编辑 vars 文件,创建符合自己的模板,然后就是创建证书,命令如下:
    1、init-pki
    2、build-ca nopass
    3、build-client-full <client> nopass
    4、export-p12 <client>

    caddyFile 如下(以反代 rime.im 为例,可以作死的改成某大型搜索引擎):

    https://xxx.xxx {
    gzip
    tls xxx.cer xxx.key {
    clients require /root/EasyRSA-3.0.3/pki/ca.crt
    }
    proxy / http://rime.im/
    }

    http://xxx.xxx {
    redir https://xxx.xxx
    }

    最后是下载<client>.p12 导入到 Firefox 中去,或者装到计算机里去。这样除非装了证书,别人都访问不了反代的小秘密了。
    6 条回复    2019-01-29 08:31:04 +08:00
    abmin521
        1
    abmin521  
       2017-10-16 08:39:33 +08:00
    思路不错 不过手机电脑 都需要一个个导入
    testcaoy7
        2
    testcaoy7  
    OP
       2017-11-03 10:30:34 +08:00
    今天才发现 xxx.xxx 是一个 HSWZ ……
    纯属巧合,不是我故意的
    find456789
        3
    find456789  
       2018-05-13 14:52:55 +08:00
    你好,
    我按照你的步骤最后生成的文件里, 没有 xxx.cer 这样的文件,
    请问是我的步骤不对吗,

    我用的 ubuntu,
    在 github 官方下载的 easy-rsa 3.0.4 版本的
    find456789
        4
    find456789  
       2018-05-13 14:54:11 +08:00
    issued/ 目录下有个 xxx.crt

    private/ 目录下有 ca.key xxx.key xxx.p12
    find456789
        5
    find456789  
       2018-05-13 15:01:18 +08:00
    http://xxx.xxx {
    gzip
    tls xxx.cer xxx.key {
    clients require /root/EasyRSA-3.0.3/pki/ca.crt
    }
    proxy / http://xxx.xx/
    }

    http://xxx.xxx {
    redir https://xxx.xxx
    }


    我是这样的配置, 我猜测有可能是 http://xxx.xxx 我没有改成 https 的,因为我是在本地测试,稍后我放上服务器看看
    testcaoy7
        6
    testcaoy7  
    OP
       2019-01-29 08:31:04 +08:00
    今天更正一下:
    将“ clients require /root/EasyRSA-3.0.3/pki/ca.crt ” 中的“ require ”删去
    有“ require ”表示“ requires a client certificate, but will not verify it.”
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5636 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 03:23 · PVG 11:23 · LAX 20:23 · JFK 23:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.