/// <summary>
        /// Returns the public key of this server from the certificate file.
        /// </summary>
        /// <returns></returns>
        public static NodePublicKey GetServerPublicKey()
        {
            FieldPublicKey key = new FieldPublicKey(
                GetServerPublicKeyString());

            return(NodePublicKey.BuildWith(key));
        }
 static bool CertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 {
     if (sslPolicyErrors != SslPolicyErrors.None)
     {
         if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors)
         {
             //Make sure the only error is an untrusted root
             //(because we're assuming it's a self-signed certificate and
             // we're going to check it against an internal list of public keys)
             bool failed = false;
             foreach (X509ChainStatus status in chain.ChainStatus)
             {
                 if (status.Status != X509ChainStatusFlags.UntrustedRoot)
                 {
                     failed = true;
                     break;
                 }
             }
             //Pull the public key out of the certificate
             NodePublicKey key = NodePublicKey.BuildWith(new FieldPublicKey(certificate.GetPublicKeyString()));
             if (!failed && PublicKeyRingHasKey(key))
             {
                 return(true);
             }
             else
             {
                 Console.WriteLine("SSL Certificate Validation Error!");
                 Console.WriteLine(sslPolicyErrors.ToString());
                 return(false);
             }
         }
         else
         {
             Console.WriteLine("SSL Certificate Validation Error!");
             Console.WriteLine(sslPolicyErrors.ToString());
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }