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

分享下自签名全平台通用的 IP/域名证书的方法

  •  
  •   eBMm8zIi0Zq3 · 2022-12-05 12:49:10 +08:00 · 614 次点击
    这是一个创建于 500 天前的主题,其中的信息可能已经有所发展或是发生改变。
    • 我的初始要求:
    1. 证书有效时间长,少折腾。
    2. 免费
    3. 证书在全平台都可以安装,尤其是 iOS 设备。
    4. 由于国内云的限制,所有带域名的,都无法逃过被拦截,所以可以用 IP+端口+证书的方式访问。
    5. 服务端种类比较多,一张证书能长期解决。

    效果图:
    iOS-1 iOS-2 Android-1 Android-2

    基于以上要求,我试了很多方法,one-self-signed-cert-to-rule-them-all-chrome-android-and-ios可以签出全平台通用的域名证书

    以下部分是关于IP 证书自签的:

    • 首先创建个配置文件 openssl.cnf
    [ req ]
    default_bits        = 2048
    default_keyfile     = ca.key
    default_md          = sha256
    default_days        = 825
    encrypt_key         = no
    distinguished_name  = subject
    req_extensions      = req_ext
    x509_extensions     = x509_ext
    string_mask         = utf8only
    prompt              = no
    
    [ subject ]
    countryName                 = US
    stateOrProvinceName         = Oklahoma
    localityName                = Stillwater
    organizationName            = My Company
    OU                          = Engineering
    
    commonName              = 你的 IP
    emailAddress            = [email protected]
    
    # Section x509_ext is used when generating a self-signed certificate. I.e., openssl req -x509 ...
    
    [ x509_ext ]
    subjectKeyIdentifier      = hash
    authorityKeyIdentifier    = keyid:always,issuer
    
    basicConstraints        = critical, CA:TRUE
    keyUsage            = critical, digitalSignature, keyEncipherment, cRLSign, keyCertSign
    subjectAltName          = IP:你的 IP
    extendedKeyUsage = serverAuth
    
    
    extendedKeyUsage    = TLS Web Server Authentication
    
    [ req_ext ]
    subjectKeyIdentifier        = hash
    basicConstraints        = CA:FALSE
    keyUsage            = digitalSignature, keyEncipherment
    subjectAltName          = IP:你的 IP
    
    nsComment           = "OpenSSL Generated Certificate"
    [alt_names]
    IP.1=你的 IP
    
    
    
    • 然后用命令生成就行:
    openssl req -config openssl.cnf -new -x509 -days 825 -out ca.crt
    openssl x509 -in ca.crt -text -noout
    
    • 关于导入还是挺方便的,网上的普通教程就行。导入.CRT 就行。

    在 Debian / Ubuntu / Alpine 系统中信任证书:

    cp *.crt /usr/local/share/ca-certificates/
    
    update-ca-certificates
    
    • 关于 nginx 配置
    ssl_certificate /home/ssl/xxx/ca.crt;
    
    ssl_certificate_key /home/ssl/xxx/ca.key;
    
    • 关于安全 我在 V2EX 搜索过,关于安全方面,大家说安装证书到设备后只要私钥不泄漏,加密还是能保证的。

    首次在此发言,若有安全隐患或者另有妙招还请多多指教。

    2 条回复    2022-12-05 15:15:28 +08:00
    me221
        1
    me221  
       2022-12-05 13:22:35 +08:00
    tms
        2
    tms  
       2022-12-05 15:15:28 +08:00
    一直用 step-ca
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4622 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:08 · PVG 09:08 · LAX 18:08 · JFK 21:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.