当前位置:   article > 正文

unity editor 使用 aws s3 sdk

unity editor 使用 aws s3 sdk

在unity Editor 编码配套工具时使用到aws 的 s3。在.net 平台下充分测试后 将代码转至unity 中发现 无法与服务器连上

环境: unity 5.1.3f

awsDll  :awssdk.core.3.3.17.9 和 awssdk.s3.3.3.11


捕获异常时发现


  1. System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.):
  2. SendFailure
  3. ---> System.IO.IOException: The authentication or decryption has failed.
  4. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server.
  5. Error code: 0xffffffff800b010a at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0
  6. at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0
  7. at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
  8. at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
  9. at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
  10. at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  11. --- End of inner exception stack trace ---
  12. at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  13. --- End of inner exception stack trace ---
  14. at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  15. at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
  16. at Amazon.Runtime.Internal.HttpRequest.GetResponse () [0x00000] in <filename unknown>:0 "
  17. " at Amazon.Runtime.Internal.WebExceptionHandler.HandleException (IExecutionContext executionContext, System.Net.WebException exception) [0x00000] in <filename unknown>:0
  18. at Amazon.Runtime.Internal.ExceptionHandler`1[T].Handle (IExecutionContext executionContext, System.Exception exception) [0x00000] in <filename unknown>:0
  19. at Amazon.Runtime.Internal.ErrorHandler.ProcessException (IExecutionContext executionContext, System.Exception exception) [0x00000] in <filename unknown>:0
  20. at Amazon.Runtime.Internal.ErrorHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  21. at Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  22. at Amazon.Runtime.Internal.CallbackHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  23. at Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  24. at Amazon.Runtime.Internal.Signer.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  25. at Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  26. at Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  27. at Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0
  28. at Amazon.Runtime.Internal.RetryHandler.InvokeSync (IExecutionContext executionContext) [0x00000] in <filename unknown>:0 "


Google 之 使用如下解决方案 

  1. ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback;
  2. protected bool CertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  3. {
  4. bool isOk = true;
  5. // If there are errors in the certificate chain,
  6. // look at each error to determine the cause.
  7. if (sslPolicyErrors != SslPolicyErrors.None)
  8. {
  9. for (int i = 0; i < chain.ChainStatus.Length; i++)
  10. {
  11. if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
  12. {
  13. continue;
  14. }
  15. chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
  16. chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
  17. chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
  18. chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
  19. bool chainIsValid = chain.Build((X509Certificate2)certificate);
  20. if (!chainIsValid)
  21. {
  22. isOk = false;
  23. break;
  24. }
  25. }
  26. }
  27. return isOk;
  28. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/127103
推荐阅读
相关标签
  

闽ICP备14008679号