Esempio n. 1
0
        private void CopyCommandLineArgs()
        {
            if (CommandLineParser.CommandLineArgs.TryGetValue("organizationid", out var orgID))
            {
                OrganizationID = orgID;
            }

            if (CommandLineParser.CommandLineArgs.TryGetValue("serverurl", out var serverUrl))
            {
                ServerUrl = serverUrl;
            }

            if (CommandLineParser.CommandLineArgs.TryGetValue("devicegroup", out var deviceGroup))
            {
                DeviceGroup = deviceGroup;
            }

            if (CommandLineParser.CommandLineArgs.TryGetValue("devicealias", out var deviceAlias))
            {
                DeviceAlias = deviceAlias;
            }

            if (CommandLineParser.CommandLineArgs.TryGetValue("deviceuuid", out var deviceUuid))
            {
                DeviceUuid = deviceUuid;
            }

            if (ServerUrl?.EndsWith("/") == true)
            {
                ServerUrl = ServerUrl.Substring(0, ServerUrl.LastIndexOf("/"));
            }
        }
Esempio n. 2
0
        public void PreviousDirectory()
        {
            if (ServerUrl.Substring(ServerUrl.Length - 1) == "/")
            {
                ServerUrl = ServerUrl.Substring(0, ServerUrl.Length - 1);
            }
            var index = ServerUrl.LastIndexOf("/");

            if (index > 0)
            {
                ServerUrl = ServerUrl.Substring(0, index + 1);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Validates the SSL server certificate.
        /// </summary>
        /// <param name="sender">An object that contains state information for this
        /// validation.</param>
        /// <param name="cert">The certificate used to authenticate the remote party.</param>
        /// <param name="chain">The chain of certificate authorities associated with the
        /// remote certificate.</param>
        /// <param name="sslPolicyErrors">One or more errors associated with the remote
        /// certificate.</param>
        /// <returns>Returns a boolean value that determines whether the specified
        /// certificate is accepted for authentication; true to accept or false to
        /// reject.</returns>
        public override bool ValidateServerCertficate(
            object sender,
            X509Certificate cert,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                // Good certificate.
                return(true);
            }

            string msg = string.Format(P4VS.Resources.SSLCertificateHandler_SSLCertificateError, sslPolicyErrors);

            P4VS.P4VsOutputWindow.AppendMessage(msg);
            P4VS.FileLogger.LogMessage(3, "SwarmAPI", msg);

            string certHash = cert.GetCertHashString();

            if (certHash == CertHash)
            {
                // same certificate we looked at before
                if (ExceptionApproved == true)
                {
                    // Already approved
                    return(true);
                }
                if (ExceptionRejected == true)
                {
                    //Already rejected
                    return(false);
                }
            }
            if ((!ExceptionRejected) && ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == 0))
            {
                // likely a self signed certificate.
                string serverName = ServerUrl;
                int    slashIdx   = ServerUrl.LastIndexOf('/');
                if (slashIdx > 0)
                {
                    serverName = ServerUrl.Substring(slashIdx + 1);
                }
                string key = string.Format("SSlCertificateException_{0}", serverName.Replace(':', '_'));
                CertHash = P4VS.Preferences.LocalSettings.GetString(key, null);
                if ((CertHash == null) || (certHash != CertHash))
                {
                    // haven't seen one for this URL or it's a different certificate
                    SSLCertificateErrorDlg dlg = new SSLCertificateErrorDlg();
                    dlg.CertificateText = cert.ToString(true);
                    List <string> certErrors = new List <string>();
                    if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) != 0)
                    {
                        certErrors.Add(Resources.P4ScmProvider_RemoteCertificateNameMismatch);
                    }
                    if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0)
                    {
                        foreach (X509ChainStatus err in chain.ChainStatus)
                        {
                            certErrors.Add(err.StatusInformation);
                        }
                    }
                    dlg.CertificateErrors = certErrors;

                    if (System.Windows.Forms.DialogResult.Yes == dlg.ShowDialog())
                    {
                        // add the exeption
                        P4VS.Preferences.LocalSettings[key] = certHash;
                        ExceptionApproved = true;
                        return(true);
                    }
                    ExceptionRejected = true;
                    return(false);
                }
                ExceptionApproved = true;
                return(true);
            }

            // Return true => allow unauthenticated server,
            //        false => disallow unauthenticated server.
            return(false);
        }