读取openssl.cnf文件时出现拒绝权限错误



我正在尝试通过powershell并使用openssl生成SSL证书。以下是我的代码:

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文件在程序文件下。因此,我应该尝试卸载PowerShell并在Program Files文件夹之外再次安装吗?

无法打开C:\Program Files\OpenSSL-Win64\bin\cnf进行读取,权限被拒绝9604:错误:02001005:系统库:fopen:输入/输出错误:crypto\bio\bss_file.c:69:fopen('c:\Program Files\OpenSSL-Win64\bin\cnf','rb'(9604:错误:2006D002:BIO例程:BIO_new_file:system lib:crypto\BIO\bss_file.c:78:9604:错误:0E078002:配置文件例程:def_load:system lib:crypto\conf\conf_def.c:170:9604:错误:02001005:系统库:fopen:输入/输出错误:crypto\bio\bss_file.c:69:fopen('c:\Program Files\OpenSSL-Win64\bin\cnf','r'(9604:错误:2006D002:BIO例程:BIO_new_file:system lib:crypto\BIO\bss_file.c:78:

对于OpenSSL配置,我添加了环境变量和用户变量:

EnvironmentVariable:路径为C: \Program Files\OpenSSL-Win64\bin
UserVariable asOPENSSL_COF=C:\Program Files\OPENSSL-Win64\bin\cnf-

作为Administrator运行cmd对我的有效

我发现了这个问题。问题是,如果你使用的是公司的笔记本电脑或VPN。访问Program files文件夹中的文件很可能会遇到权限问题。

我卸载了OpenSSL,并在Program Files文件夹外重新安装了它。请确保它安装在程序文件之外。

这对我很有效。我能够创建CSR。

最新更新