标签: openssl

  • openssl生成CA和EV SSL证书

    #生成CA私钥
    openssl genrsa -out ./private/cakey.pem 2048
    #生成CA证书
    openssl req -config openssl.cnf -x509 -new -nodes -key ./private/cakey.pem -days 3650 -out cacert.pem -extensions v3_ca
    #转换证书格式,用于Windows上导入证书
    openssl x509 -in cacert.pem -outform DER -out cacert.der
    

    以上是生成了一个符合EV SSL要求的CA证书
    命令不复杂,但是配置文件复杂,我把参数都配置到openssl.cnf中了,这个文件是从/etc/ssl/openssl.cnf复制过来,然后根据需要做对应的修改。下面只列出了需要修改的部分

    [ new_oids ]
    # 自定义证书策略oid,EV SSL CA必须,oid的值是自定义的,全球唯一就行。
    ev_policy = 2.16.840.1.113730.1.100
    [req]
    default_bits = 2048
    distinguished_name = dn
    # 禁止提示输入
    prompt             = no
    req_extensions     = v3_req
    x509_extensions    = v3_ca
    [dn]
    # 这部分根据需要修改
    C="CN"
    ST="Shanghai"
    L="Shanghai"
    O="hetao"
    OU="squid"
    emailAddress="tao@hetao.me"
    # 如果域名证书这一项是域名,对于CA证书可以随便填
    CN="Squid CA"
    [ v3_req ]
    
    # Extensions to add to a certificate request
    # 这个区段是签发客户证书用的
    basicConstraints = CA:FALSE
    keyUsage = nonRepudiation, digitalSignature, keyEncipherment
    [ v3_ca ]
    
    # Extensions for a typical CA
    # PKIX recommendation.
    # subjectKeyIdentifier,authorityKeyIdentifier,basicConstraints,keyUsage这几项是任何CA证书都必须的,尤其是basicConstraints,keyUsage。如果没有basicConstraints = critical, CA:true在Firefox上会不认这个CA证书(其它浏览器可以)
    subjectKeyIdentifier = hash
    authorityKeyIdentifier = keyid:always, issuer
    basicConstraints = critical, CA:true
    keyUsage = critical, digitalSignature, cRLSign, keyCertSign, keyEncipherment
    # 这一项Root CA非必须,中间CA需要
    extendedKeyUsage = serverAuth, clientAuth, codeSigning,emailProtection
    #DV SSL证书: CA/B Forum OID:2.23.140.1.2.1
    #IV SSL证书: CA/B Forum OID:2.23.140.1.2.3
    #OV SSL证书: CA/B Forum OID:2.23.140.1.2.2
    #EV SSL证书: CA/B Forum OID:2.23.140.1.1
    #这4个oid是客户域名证书需要的,对于EV SSL CA只需要添加ev_policy这个自定义的oid就行了(非EV SSL CA不需要)。
    certificatePolicies = 2.23.140.1.1,2.23.140.1.2.1,2.23.140.1.2.2,2.23.140.1.2.3,@polsect
    policyConstraints = requireExplicitPolicy:3
    # 证书吊销查询,EV SSL CA必须,非EV SSL CA不需要
    authorityInfoAccess = OCSP;URI:https://ocsp.hetao.me/
    
    [polsect]
    # 经用自定义oid
    policyIdentifier=2.16.840.1.113730.1.100
    CPS.1 = "https://cer.hetao.me"
    CPS.2 = "https://ca.hetao.me"
    userNotice.1 = @notice
    
    [notice]
    explicitText = "UTF8:squid notice"
    organization = "hetao"
    noticeNumbers = 1, 2, 3, 4
    

    以上生成的CA证书我是在squid里面用的,当然用这个CA手动签发域名证书也是可以的。因为squid只需要CA证书就行,关于签发域名证书方法就不赘述了。
    参考:
    https://vircloud.net/operations/sign-ip-crt.html
    https://vircloud.net/exp/openssl-ev.html
    https://blog.csdn.net/sinat_38816924/article/details/124233402

    Views: 18

  • squid配置SSL Bump缓存HTTPS流量

    默认情况下squid是不能解密https流量的,也就不能缓存https流量。但配置SSL Bump功能可以实现对HTTPS流量进行缓存。

    生成证书

    openssl生成CA和EV SSL证书


    参考这篇文章

    配置squid

    http_port 3128 ssl-bump tls-cert=/opt/web/data/squid/ssl/cert1/squid_ca.pem tls-key=/opt/web/data/squid/ssl/cert1/squid_ca.key dynamic_cert_mem_cache_size=128MB generate-host-certificates=on
    sslproxy_cert_error allow all # 即使原始服务器证书错误仍然进行连接
    ssl_bump stare all #所有域名开启解密,默认配置是不解密的
    

    也可以用ssl_bump bump all配置与stare的区别是bump生成的证书除了域名外没有其它扩展字段,比如国家,单位什么的,stare则复制了原始证书中的甩的字段。
    完了以后重启Squid发现系统自带的squid不支持ssl-bump,然后docker中的squid也不支持ssl-bump,然后只能自己编译了。

    squid编译

    • 源码下载

      http://www.squid-cache.org/Versions/v6/

    • 安装依懒包
      apt-get update && apt-get install -y build-essential libssl-dev openssl libxml2-dev libexpat1-dev libsasl2-dev libpam0g-dev libkrb5-dev pkg-config apache2-utils net-tools libecap3-dev libldap2-dev
    • 编译
    ./configure \
    --prefix /usr \
    --enable-arp-acl \
    --enable-linux-netfilter \
    --enable-linux-tproxy \
    --enable-async-io=100 \
    --enable-err-language="Simplify_Chinese" \
    --enable-poll \
    --enable-gnuregex \
    --build=x86_64-linux-gnu \
    --disable-maintainer-mode \
    --disable-dependency-tracking \
    --disable-silent-rules \
    --enable-build-info="Ubuntu linux" \
    --disable-translation \
    --with-filedescriptors=65536 \
    --with-large-files \
    --with-openssl \
    --enable-ssl \
    --enable-ssl-crtd \
    --enable-inline \
    --disable-arch-native \
    --enable-storeio=ufs,aufs,diskd,rock \
    --enable-removal-policies=lru,heap \
    --enable-delay-pools \
    --enable-cache-digests \
    --enable-follow-x-forwarded-for \
    --enable-auth-basic=DB,fake,getpwnam,LDAP,NCSA,PAM,POP3,RADIUS,SASL,SMB \
    --enable-auth-digest=file,LDAP \
    --enable-auth-negotiate=kerberos,wrapper \
    --enable-auth-ntlm=fake,SMB_LM \
    --enable-external-acl-helpers=file_userip,kerberos_ldap_group,LDAP_group,SQL_session,unix_group,wbinfo_group \
    --enable-security-cert-validators=fake \
    --enable-storeid-rewrite-helpers=file \
    --enable-url-rewrite-helpers=fake \
    --enable-eui \
    --enable-esi \
    --enable-icmp \
    --enable-zph-qos \
    --enable-ecap \
    --enable-underscore
    make -j4 && make insstall
    

    启动之前需要执行这条命令初始化证书数据库,squid自己执行的security_file_certgen会报错,初始化后squid就不需要再执行了。
    security_file_certgen -c -s /usr/var/cache/squid/ssl_db -M 128
    或者配置

    “`sslcrtd_program /usr/libexec/security_file_certgen -s /usr/var/cache/squid/ssl_db -M 128MB“`
    在/usr/var/cache/squid/ssl_db/certs/目录下可以看到所有生成的证书
    #添加/usr/libexec到环境变量
    “`export PATH=$PATH:/root/.local/bin:/usr/libexec“`

    参考:

    如何熟悉Squid的SSL碰撞?

    Views: 17

  • Centos7安装Python12

    centos7自带的gcc和openssl版本过低无法成功编译python3.12,所以需要另外安装gcc11和编译openssl1.11。

    yum install centos-release-scl
    yum install -y devtoolset-11-gcc devtoolset-11-gcc-c++
    scl enable devtoolset-11 bash
    echo /opt/rh/devtoolset-11/root/usr/bin/gcc>>~/.bashrc
    yum install -y wget make cmake gcc bzip2-devel libffi-devel zlib-devel
    yum groupinstall -y "Development Tools"
    wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1w.tar.gz
    tar -zxf openssl-1.1.1w.tar.gz
    cd openssl-1.1.1w
    ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
    make && make install_sw
    export PATH=/usr/local/openssl/bin:\PATH
    export LD_LIBRARY_PATH=/usr/local/openssl/lib:\$LD_LIBRARY_PATH
    cd ..
    wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
    tar -zxf Python-3.12.3.tgz
    cd Python-3.12.3
    ./configure --with-openssl=/usr/local/python3 --enable-shared --enable-optimizations
    CFLAGS=-Wno-coverage-mismatch make
    make install
    export PATH=/usr/local/python3/bin:PATH
    export LD_LIBRARY_PATH=/usr/local/python3/lib:$LD_LIBRARY_PATH
    echo /usr/local/python3/lib/ > /etc/ld.so.conf.d/python.conf
    ldconfig
    

    Views: 14