首页 > 解决方案 > 读取 openssl.cnf 文件时出现权限被拒绝错误

问题描述

我正在尝试通过 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:system library:fopen:Input/output error:crypto\bio\bss_file.c:69:fopen( 'C:\Program Files\OpenSSL-Win64\bin\cnf','rb') 9604:error:2006D002:BIO routines:BIO_new_file:system lib:crypto\bio\bss_file.c:78: 9604:error:0E078002:配置文件例程:def_load:system lib:crypto\conf\conf_def.c:170: 9604:error:02001005:system library:fopen:Input/output error:crypto\bio\bss_file.c:69:fopen('C: \Program Files\OpenSSL-Win64\bin\cnf','r') 9604:error:2006D002:BIOroutines:BIO_new_file:system lib:crypto\bio\bss_file.c:78:

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

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

标签: powershellopensslcsr

解决方案


我发现了这个问题。问题是您使用的是公司笔记本电脑还是 VPN。很可能您将面临访问 Program Files 文件夹中文件的权限问题。

我卸载了 OpenSSL 并将其重新安装在 Program Files 文件夹之外。确保它安装在 Program Files 之外。

这对我有用。我能够创建企业社会责任。


推荐阅读