【发布时间】:2021-02-17 17:53:53
【问题描述】:
我正在尝试通过 powershell 生成 SSL 证书并为其使用 openssl。 以下是我的代码:
Function new-csr {
[CmdletBinding()]
Param(
$country, #2 please enter char country code
$state, #state
$locality, #city
$org, # organization name
$ou, # orhanization unit name
$cn, # common name hostname
$email, # contact email
$randPath, # path for file
$privateKeyPath, # path to private key
$csrPath # path to certificate signin request (output)
)
# if private key has not been created , create one
if(-not (Test-Path $privateKeyPath)){
openssl genrsa -out $privateKeyPath 2048
}
if(-not(Test-Path $randPath)){
openssl rand -out $randPath
}
$subject = "`"/C=$country/ST=$state/L=$locality/O=$org/OU=$ou/CN=$cn`""
openssl req -new -key $privateKeyPath -rand $randPath -subj $subject -out $csrPath
}
在管理员权限下尝试在 PowerShell 中执行它时。我收到权限被拒绝错误。 我的猜测是这可能是由于 .cnf 文件位于 Program Files 下。那么我应该尝试卸载 PowerShell 并这次在 Program Files 文件夹之外重新安装吗?
无法打开 C:\Program Files\OpenSSL-Win64\bin\cnf 进行读取,权限被拒绝 9604:error:02001005:系统库:fopen:输入/输出错误:crypto\bio\bss_file.c:69:fopen('C:\Program Files\OpenSSL-Win64\bin\cnf','rb') 9604:错误:2006D002:BIO 例程:BIO_new_file:系统库:crypto\bio\bss_file.c:78: 9604:错误:0E078002:配置文件例程:def_load:系统库:crypto\conf\conf_def.c:170: 9604:error:02001005:系统库:fopen:输入/输出错误:crypto\bio\bss_file.c:69:fopen('C:\Program Files\OpenSSL-Win64\bin\cnf','r') 9604:error:2006D002:BIO 例程:BIO_new_file:system lib:crypto\bio\bss_file.c:78:
对于 OpenSSL 配置,我添加了环境变量和用户变量:
EnvironmentVariable:路径为 C:\Program Files\OpenSSL-Win64\bin
用户变量为 OPENSSL_CONF= C:\Program Files\OpenSSL-Win64\bin\cnf
【问题讨论】:
-
你的配置文件本身是
...OpenSSL-Win64\bin\cnf,看起来像一个目录吗?该文件通常是...\openssl.cnf。
标签: powershell openssl csr