Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by mattyway · Sep 17, 2014 at 06:57 AM · monowebrequesthttpssslrest

How to validate SSL certificates when using HttpWebRequest

I am attempting to use the RestSharp library to call a REST API. RestSharp uses HttpWebRequest under the covers. Calling the API works fine when using HTTP, however I need to use the HTTPS protocol when calling the API. The API server has a valid certificate that is trusted in all browsers.

When I attempt to use the HTTPS protocol to call the API, I get a TlsException with the message "Invalid certificate received from server. Error code: 0xffffffff800b010a"

The solutions I have found to solve this problem involve setting a callback on ServicePointManager.ServerCertificateValidationCallback that always returns true. This is unacceptable in production as it introduces a security vulnerability.

I understand that Mono doesn't have any root certificates contained in it's Trust Store by default (http://www.mono-project.com/docs/faq/security). It is possible to import the root certificates used by Mozilla products into the Trust Store by using the mozroots command, however it seems that the implementation of Mono that ships with Unity is missing this tool. Can Unity actually use certificates contained in a Trust Store?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image boinst2 · Oct 26, 2014 at 10:56 AM 0
Share

I have this same problem, and have not found a solution.

avatar image MrG · Jan 29, 2015 at 01:21 PM 0
Share

What a hot mess. Unity apps should always validate against the client computer's CA trust store directly on all platforms. $$anonymous$$eeping that current is the end-user's responsibility, and if it fails, tell the user why and how to update. For self-signed test certs, we create those, and we can deploy them to our test machines and/or to testers's machines. "There can be only one...." CA trust.

avatar image nirvine_bns MrG · Sep 22, 2015 at 10:44 PM 0
Share

Unity's WWW class (does use the OS's CA store)[http://luz.4science.co/unity-android-and-ssl-sslhandshakeexceptioncertpathvalidatorexception/]. Not sure about RestSharp.

2 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by nig · Jan 15, 2015 at 03:57 PM

Yes it can.

Look at http://www.mono-project.com/docs/faq/security/

".. Use the mozroots.exe tool (included in Mono 1.1.10 and later) to download and install all Mozilla’s root certificates (i.e. the ones used in FireFox and other Mozilla’s softwares). It’s easier than finding a specific root but it’s also less granular to make a decision about which one(s) you install or not. .."

There are two reasons why certificate is rejcectd:

  1. X509ChainStatusFlags.UntrustedRoot

  2. X509ChainStatusFlags.RevocationStatusUnknown

Using the mozroots.exe tool to import CA list to Mono/Unity Trust Store fixes first reason.

I found a solution that works for me:

 ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
 
 public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
     bool isOk = true;
     // If there are errors in the certificate chain, look at each error to determine the cause.
     if (sslPolicyErrors != SslPolicyErrors.None) {
         for(int i=0; i<chain.ChainStatus.Length; i++) {
             if(chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown) {
                 chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
                 chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
                 chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
                 chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
                 bool chainIsValid = chain.Build((X509Certificate2)certificate);
                 if(!chainIsValid) {
                     isOk = false;
                 }
             }
         }
     }
     return isOk;
 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Spanky11 · Sep 09, 2017 at 12:27 AM 0
Share

Holy smokes, this just saved me. thanks so much! I've been banging my head for 15 hours trying to get .Net 4.6 working in Unity 2017, and then an Imgur api. The imgur endpoint used https and was failing until I tried the provided $$anonymous$$yRemoteCertificateValidationCallback code.

avatar image Kwi · Jul 05, 2018 at 03:45 PM 0
Share

That code effectively disables SSL certificate verification (e.g. it'll allow https://self-signed.badssl.com/). You might as well simply do return true;.

avatar image
0

Answer by zlSimon · Jun 22, 2016 at 05:09 AM

I have the same issue however when I want to import CA's using the mozroot.exe I always get a null reference exception:

 Downloading from 'http://anduin.linuxfromscratch.org/BLFS/other/certdata.txt'...
 Importing certificates into user store...
 Error: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    bei Mono.Security.X509.X509Certificate.get_Hash()
    bei Mono.Security.X509.X509CertificateCollection.IndexOf(X509Certificate value)
    bei Mono.Tools.MozRoots.Process()
    bei Mono.Tools.MozRoots.Main(String[] args)

When I try to build the X509Chain I also dont get X509ChainStatusFlags.UntrustedRoot instead I get RevocationStatusUnknown and OfflineRevocation.

Is there anyone who managed to get a propper SSL certificate validation including Chain-of-trust verification, hostname verification and CRL verification?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to avoid reestablishing an HTTPS request, use Connection: Keep-Alive or reuse WWW object? 2 Answers

How can I add a certificate to the Mono Trust store? 1 Answer

Unity use of HTTPS 0 Answers

Unsupported hash algorithm 0 Answers

SSL signed by CA validation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges