Mét*_*ule 3 openssl azure azure-webapps azure-linux
在我的 Azure Linux Web 应用程序中,我尝试使用证书对外部提供商执行 API 调用。该调用失败了,但在 Windows 应用服务计划上部署相同的代码时它工作正常。等效的 cURL 命令行是:
curl --cert-type p12 --cert /var/ssl/private/THUMBPRINT.p12 -X POST https://www.example.com
Run Code Online (Sandbox Code Playgroud)
调用失败并出现以下错误:
curl: (58) could not load PKCS12 client certificate, OpenSSL error error:140AB18E:SSL routines:SSL_CTX_use_certificate:ca md too weak
Run Code Online (Sandbox Code Playgroud)
该问题是由 OpenSSL 1.1.1d 引起的,默认情况下要求安全级别为 2,而我的证书是使用 RSA 加密的 SHA1 进行签名的:
openssl pkcs12 -in THUMBPRINT.p12 -nodes | openssl x509 -noout -text | grep 'Signature Algorithm'
Signature Algorithm: sha1WithRSAEncryption
Signature Algorithm: sha1WithRSAEncryption
Run Code Online (Sandbox Code Playgroud)
在普通的 Linux VM 上,我可以编辑/etc/ssl/openssl/cnf
更改
CipherString = DEFAULT@SECLEVEL=2
Run Code Online (Sandbox Code Playgroud)
安全级别为 1,但在 Azure Linux Web 应用程序上,我对该文件所做的更改不会保留。
所以我的问题是:如何更改 Azure Web 应用程序上的 OpenSSL 安全级别?或者有更好的方法来允许使用我的弱证书吗?
注意:我不是证书的颁发者,所以我无法自己重新生成它。我将与发行人核实他们是否可以重新生成它,但与此同时,如果可能的话我想继续:)
Mét*_*ule 15
与 Microsoft 支持人员的通话让我找到了解决方案。每当 Web 应用程序容器启动时都可以运行脚本,这意味着可以openssl.cnf
在启动 dotnet 应用程序之前编辑文件。
为此,请导航到Configuration
Linux Web 应用程序的边栏选项卡,然后General settings
依次选择 、Startup command
:
这Startup command
是容器启动时运行的命令。您可以做您想做的事情,但它必须启动您的应用程序,因为它不再自动完成。
您可以通过 SSH 连接到 Linux Web 应用程序,然后编辑该custom_startup.sh
文件:
#!/usr/sh
# allow weak certificates (certificate signed with SHA1)
# by downgrading OpenSSL security level from 2 to 1
sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf
# run the dotnet website
cd /home/site/wwwroot
dotnet APPLICATION_DLL_NAME.dll
Run Code Online (Sandbox Code Playgroud)
相关文档可以在这里找到:https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq#built-in-images
但请注意,该Startup command
功能不适用于 Azure Functions(截至 2020 年 5 月 19 日撰写本文时)。我在 Github 上打开了一个问题。
为了解决这个问题,我最终创建了自定义 Docker 镜像:
Web 应用程序的 Dockerfile:
FROM mcr.microsoft.com/appsvc/dotnetcore:3.1-latest_20200502.1
# allow weak certificates (certificate signed with SHA1)
# by downgrading OpenSSL security level from 2 to 1
RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf
Run Code Online (Sandbox Code Playgroud)
Azure 函数的 Dockerfile:
FROM mcr.microsoft.com/azure-functions/dotnet:3.0.13614-appservice
# allow weak certificates (certificate signed with SHA1)
# by downgrading OpenSSL security level from 2 to 1
RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11833 次 |
最近记录: |