linux下訪問https協議做法

來源:互聯網
上載者:User

一、http://www.mono-project.com/FAQ:_Security

1、inux本身在發行的時候是不帶任何認證的,這和windows平台似乎恰恰相反。不過有工具,允許我們自行安裝認證。

 

                  mozroots --import /               ##匯入認證

 

                    --ask-remove  /       ##僅刪除時確認

 

                    --machine               ##儲存在全域環境

 

              

mozroots --import  --sync

或者手動加入認證

certmgr -ssl https://t.open.com

2是直接在程式中加入代碼預設此https協議是正確的

using System;using System.Security.Cryptography.X509Certificates;namespace SSLtest{        class MainClass    {                // callback used to validate the certificate in an SSL conversation        private static bool ValidateRemoteCertificate(            object sender,            X509Certificate certificate,            X509Chain chain,            System.Net.Security.SslPolicyErrors policyErrors        )        {                        return true;            /*            if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreSslErrors"]))            {                // allow any old dodgy certificate...                return true;            }            else            {                return policyErrors == SslPolicyErrors.None;            }            */        } // End Function ValidateRemoteCertificate                public static void Main (string[] args)        {            //System.Net.ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;            System.Net.ServicePointManager.ServerCertificateValidationCallback += (s,ce,ca,p) => true;                        string strResponse = null;            try             {                System.Net.WebRequest request = System.Net.HttpWebRequest.Create("https://encrypted.google.com/");                System.Net.HttpWebResponse response = (System.Net.HttpWebResponse) request.GetResponse();                System.IO.Stream stream = response.GetResponseStream();                System.IO.StreamReader sr = new System.IO.StreamReader(stream);                strResponse = sr.ReadToEnd();                sr.Close();                sr.Dispose();                stream.Dispose();            }            catch(System.IO.IOException ex)             {                 Console.WriteLine("Failed to connect to URI");                 Console.WriteLine("Reason:");                 Console.WriteLine(ex.Message);                Console.WriteLine(Environment.NewLine);                Console.WriteLine("Stacktrace:");                 Console.WriteLine(ex.StackTrace);             }            catch(System.UriFormatException ex)             {                 Console.WriteLine("Bad URI format");                                 Console.WriteLine("Reason:");                 Console.WriteLine(ex.Message);                 Console.WriteLine(Environment.NewLine);                Console.WriteLine("Stacktrace:");                 Console.WriteLine(ex.StackTrace);             }                    Console.WriteLine ("Read the following stream:");            Console.WriteLine(strResponse);            Console.WriteLine(Environment.NewLine);            Console.WriteLine(" --- Press any key to continue --- ");            Console.ReadKey();        } // End Sub Main                     } // End Class MainClass        } // End Namespace SSLtest

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.