AWS S3 .NET SDK

发布于 2024-12-03 03:24:08 字数 1460 浏览 0 评论 0原文

我正在使用 Unity3D,并尝试使用 S3 .NET SDK。但不断出现以下错误:

TlsException: Invalid certificate received from server. Error code: 0xffffffff80092012
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates)
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 ()

我的 javascript 代码:

function Start()
{
    client = Amazon.AWSClientFactory.CreateAmazonS3Client(Conf.AWSAccessKey, Conf.AWSSecretKey);

    var response : ListBucketsResponse = client.ListBuckets();
}

我搜索了一整天,可能找到了原因:

事实证明 Mono 安装时没有根证书,因此默认情况下 Mono 拒绝信任任何受 SSL 保护的 Web 服务。 Mono 安全常见问题解答 对于如何处理该问题有一些建议。”

我有尝试了以下方法:

  1. 参考

    <前><代码>mcs am1.cs 单声道 am1.exe https://www.amazonaws.com

    当我运行编译的 am1.exe 时,它​​给了我很多异常错误

  2. 使用mozroots.exe工具下载并安装所有Mozilla的根证书。

    C:\Program Files (x86)\Mono-2.6.7\lib\mono\1.0>mozroots --import --machine --sync
    

    尽管输出表示证书已成功导入。但在Unity3D中仍然提示“从服务器收到无效证书”

我已经为此工作了一整天,但无法解决它,希望有人能帮助我。

I am using Unity3D, and have try to use S3 .NET SDK. But keep getting below error:

TlsException: Invalid certificate received from server. Error code: 0xffffffff80092012
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates)
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 ()

My javascript code:

function Start()
{
    client = Amazon.AWSClientFactory.CreateAmazonS3Client(Conf.AWSAccessKey, Conf.AWSSecretKey);

    var response : ListBucketsResponse = client.ListBuckets();
}

I have searched a whole day and probably found the reason:

It turns out that Mono installs with no root certs, so by default Mono refuses to trust any SSL-protected web services. The Mono Security FAQ has a couple suggestions for how to handle the issue."

I have tried below methods:

  1. Reference

    mcs am1.cs
    
    mono am1.exe https://www.amazonaws.com
    

    When I run compiled am1.exe, it gives me a lot of exception errors

  2. Use the mozroots.exe tool to download and install all Mozilla's root certificates.

    C:\Program Files (x86)\Mono-2.6.7\lib\mono\1.0>mozroots --import --machine --sync
    

    Although the output said the certs have successfully imported. But in Unity3D it still prompts "Invalid certificate received from server"

I have been working on this the whole day and can't get it solved, hope someone can help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鲜肉鲜肉永远不皱 2024-12-10 03:24:08

当无法验证证书是否已吊销时,会出现0x80092012

从版本 2.8 开始,Mono 将默认为 X509RevitationMode.NoCheck,除非设置了 MONO_X509_REVOCATION_MODE 环境变量(在这种情况下,它将检查证书存储区中的 CRL)。

我不知道你的 Unity3D 版本相对于 Mono 来说有多新。但是,您应该能够使用 ICertificatePolicyServicePointManager.ServerCertificateValidationCallback 来解决此问题。如果0x80092012错误代码来自颁发给亚马逊的证书,则只需忽略它即可。

0x80092012 occurs when the certificate could not be verified for revocation.

Since version 2.8, Mono will default to X509RevocationMode.NoCheck unless the MONO_X509_REVOCATION_MODE environment variable is set (in this case it will check for CRLs inside the certificate stores).

I don't know how recent is your version of Unity3D wrt Mono itself. However you should be able to use ICertificatePolicy or ServicePointManager.ServerCertificateValidationCallback to work around this issue. Simply disregard the 0x80092012 error code if it comes from a certificate issued to Amazon.

心作怪 2024-12-10 03:24:08
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
     public TrustAllCertificatePolicy() {}
     public bool CheckValidationResult(ServicePoint sp, 
         X509Certificate cert,
         WebRequest req, 
         int problem)
     {
        return true;
     }
}

因此,在与远程服务器建立 HTTPS 连接(通过 WebRequest、WebServices 或其他)之前,只需调用:

System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

Enjoy

public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
     public TrustAllCertificatePolicy() {}
     public bool CheckValidationResult(ServicePoint sp, 
         X509Certificate cert,
         WebRequest req, 
         int problem)
     {
        return true;
     }
}

So before establishing HTTPS connection (either via WebRequest, WebServices or other) to remote server just call:

System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

Enjoy

伴我心暖 2024-12-10 03:24:08

如果您在 Mono 中使用 ASP,则需要使用用户 www-data 下载并安装 Mozilla 的根证书

chown www-data /var/www/
sudo -u www-data mozroots --import --sync

If you are using ASP for in mono, you need download and install the Mozilla's root certificates with the user www-data

chown www-data /var/www/
sudo -u www-data mozroots --import --sync
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文