Example #1
0
        // Returns 'true' if the peer trust certificate is installed and
        // can be used.  Precedence based on the current value of this
        // condition is:
        //  blank:    attempt to install certificate and return the result
        //  'true':   attempt to install certificate and return true
        //  'false':  bypass certificate installation and return false
        public static bool Peer_Certificate_Installed()
        {
            // If the condition is unknown, attempt to install and use the
            // results of that install attempt as the value to return.
            bool result = GetConditionValue(nameof(Peer_Certificate_Installed),
                                            ConditionalTestDetectors.IsPeerCertificateInstalled);

            // Regardless whether the value was 'true' on entry or was detected
            // to be true, ensure we have attempted to install and verify the
            // certificate is installed.  This guarantees installation errors
            // are captured and reported in both cases.
            if (result)
            {
                try
                {
                    ServiceUtilHelper.EnsurePeerCertificateInstalled();
                }
                catch
                {
                    // Errors in certificate installation are caught and reported
                    // when an attempt is made to access it.  But for the purposes
                    // of this conditional test, an error does not affect the result.
                }
            }

            return(result);
        }
Example #2
0
 // Detector used by [ConditionalFact(nameof(Peer_Certificate_Installed)].
 // It will attempt to install the server certificate in the certificate store if
 // is not already present, and then it will check whether the install
 // succeeded.  A 'true' return is a guarantee a server certificate is
 // installed in the certificate store.
 public static bool IsPeerCertificateInstalled()
 {
     try
     {
         ServiceUtilHelper.EnsurePeerCertificateInstalled();
         return(true);
     }
     catch
     {
         // Errors installing the certificate are captured and will be
         // reported when an attempt is made to use it.  But for the
         // purposes of this detector, a failure only propagates as
         // a 'false' return.
         return(false);
     }
 }