private int TestBuildChain() { Certificate c = null; CertificateChain cc = null; try { c = CertificateStore.CreateFromPfxFile(@"certs\server.pfx", "test").FindCertificateByUsage(new string[] { "1.3.6.1.5.5.7.3.1" }); } catch { AddWarning("CC-W-TBC1"); return(0); } try { cc = c.GetCertificateChain(); Certificate[] cs = null; try { cs = cc.GetCertificates(); } catch { AddError("CC-TBC2"); } if (cs.Length != 2) { AddError("CC-TBC3"); } if (!cs[0].Equals(c)) { AddError("CC-TBC4"); } } catch { AddError("CC-TBC1"); } return(4); }
/// <summary> /// This method is called when the SecureSocket received the remote /// certificate and when the certificate validation type is set to Manual. /// </summary> /// <param name="socket">The <see cref="SecureSocket"/> that received the certificate to verify.</param> /// <param name="remote">The <see cref="Certificate"/> of the remote party to verify.</param> /// <param name="chain">The <see cref="CertificateChain"/> associated with the remote certificate.</param> /// <param name="e">A <see cref="VerifyEventArgs"/> instance used to (in)validate the certificate.</param> /// <remarks>If an error is thrown by the code in the delegate, the SecureSocket will close the connection.</remarks> protected void OnVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e) { // get all the certificates from the certificate chain .. Certificate[] certs = chain.GetCertificates(); // .. and print them out in the console for (int i = 0; i < certs.Length; i++) { Console.WriteLine(certs[i].ToString(true)); } // print out the result of the chain verification Console.WriteLine(chain.VerifyChain(socket.CommonName, AuthType.Server)); }
// ------------------------ OnVerify ------------------------------------- protected void OnVerify( SecureSocket socket, Certificate remote, CertificateChain InChain, VerifyEventArgs e) { Certificate[] certs = InChain.GetCertificates( ); for (int Ix = 0; Ix < certs.Length; Ix++) { AddMessage(NetworkRole.Client, certs[Ix].ToString(true)); } // print out the result of the chain verification AddMessage( NetworkRole.Client, "Verify certificate: " + InChain.VerifyChain(socket.CommonName, AuthType.Server).ToString( )); }
private void OnCertificateVerify(SecureSocket socket, Certificate remote, CertificateChain chain, VerifyEventArgs e) { Certificate[] certs = chain.GetCertificates(); chain.VerifyChain(socket.CommonName, AuthType.Server); }