28 lines
843 B
Bash
28 lines
843 B
Bash
#!/bin/bash
|
|
|
|
# 生成自签名证书
|
|
gen_self_tls() {
|
|
local domain="${1:-bing.com}"
|
|
local script_dir="$(dirname "$(realpath "$0")")"
|
|
local key_dir="$script_dir/../tls"
|
|
local config_file="$script_dir/../config/config.json"
|
|
|
|
# 导入utils文件夹中的jq_util.sh脚本
|
|
source "$script_dir/utils/jq_util.sh"
|
|
|
|
# 创建存放证书的目录
|
|
mkdir -p "$key_dir"
|
|
|
|
# 生成自签名证书
|
|
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) \
|
|
-keyout "$key_dir/server.key" \
|
|
-out "$key_dir/server.crt" \
|
|
-subj "/CN=$domain" \
|
|
-days 36500
|
|
|
|
# 更新config.json文件中的域名信息
|
|
modify_json_file "$config_file" "inbounds[0].tls.server_name" "$domain"
|
|
}
|
|
|
|
# 调用函数,传入第一个参数作为域名
|
|
gen_self_tls "${1:-bing.com}" |