■ ポイント
* X509Chain.Build() を使用する
X509Chain
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.x509certificates.x509chain.aspxhttps://msdn.microsoft.com/ja-jp/library/system.security.cryptography.x509certificates.x509chain.build.aspx
■ サンプル
using System; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Windows.Forms; namespace SampleDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://yahoo.co.jp"); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { // Do Nothing } var certificate = new X509Certificate2(request.ServicePoint.Certificate); // ★ここから★ var chain = new X509Chain(); int index = 0; if (chain.Build(certificate)) { foreach (var chainElement in chain.ChainElements) { var chainCertificate = chainElement.Certificate; string fileName = "Certificate" + index + ".cer"; File.WriteAllBytes(fileName, chainCertificate.Export(X509ContentType.Cert)); index++; } } } } }