Exemple #1
0
        public override bool Fetch()
        {
            if (RemoteUrl.Host.EndsWith(".onion"))
            {
                // Tor has special domain names called ".onion addresses".  They can only be
                // resolved by using a proxy via tor. While the rest of the openssh suite
                // fully supports proxying, ssh-keyscan does not, so we can't use it for .onion
                SparkleLogger.LogInfo("Auth", "using tor .onion address skipping ssh-keyscan");
            }
            else if (!RemoteUrl.Scheme.StartsWith("http"))
            {
                string host_key = FetchHostKey();

                if (string.IsNullOrEmpty(RemoteUrl.Host) || host_key == null)
                {
                    SparkleLogger.LogInfo("Auth", "Could not fetch host key");
                    this.errors.Add("error: Could not fetch host key");

                    return(false);
                }

                bool warn = true;
                if (RequiredFingerprint != null)
                {
                    string host_fingerprint;

                    try {
                        host_fingerprint = DeriveFingerprint(host_key);
                    } catch (InvalidOperationException e) {
                        // "Unapproved cryptographic algorithms" won't work when FIPS is enabled on Windows.
                        // Software like Cisco AnyConnect can demand this feature is on, so we show an error
                        SparkleLogger.LogInfo("Auth", "Unable to derive fingerprint: ", e);
                        this.errors.Add("error: Can't check fingerprint due to FIPS being enabled");

                        return(false);
                    }


                    if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint))
                    {
                        SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match");
                        this.errors.Add("error: Host fingerprint doesn't match");

                        return(false);
                    }

                    warn = false;
                    SparkleLogger.LogInfo("Auth", "Fingerprint matches");
                }
                else
                {
                    SparkleLogger.LogInfo("Auth", "Skipping fingerprint check");
                }

                AcceptHostKey(host_key, warn);
            }

            return(true);
        }
        public override bool Fetch()
        {
            if (RemoteUrl.Host.EndsWith(".onion"))
            {
                // Tor has special domain names called ".onion addresses".  They can only be
                // resolved by using a proxy via tor. While the rest of the openssh suite
                // fully supports proxying, ssh-keyscan does not, so we can't use it for .onion
                SparkleLogger.LogInfo("Auth", "using tor .onion address skipping ssh-keyscan");
            }
            else if (!RemoteUrl.Scheme.StartsWith("http"))
            {
                string host_key = FetchHostKey();

                if (string.IsNullOrEmpty(RemoteUrl.Host) || host_key == null)
                {
                    SparkleLogger.LogInfo("Auth", "Could not fetch host key");
                    this.errors.Add("error: Could not fetch host key");

                    return(false);
                }

                bool warn = true;
                if (RequiredFingerprint != null)
                {
                    string host_fingerprint = DeriveFingerprint(host_key);

                    if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint))
                    {
                        SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match");
                        this.errors.Add("error: Host fingerprint doesn't match");

                        return(false);
                    }

                    warn = false;
                    SparkleLogger.LogInfo("Auth", "Fingerprint matches");
                }
                else
                {
                    SparkleLogger.LogInfo("Auth", "Skipping fingerprint check");
                }

                AcceptHostKey(host_key, warn);
            }

            return(true);
        }
        public void Start()
        {
            IsActive = true;
            Started();

            SparkleLogger.LogInfo("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);

            if (Directory.Exists(TargetFolder))
            {
                Directory.Delete(TargetFolder, true);
            }

            string host_key = "";

            if (!RemoteUrl.Scheme.StartsWith("http"))
            {
                host_key = FetchHostKey();

                if (string.IsNullOrEmpty(RemoteUrl.Host) || host_key == null)
                {
                    SparkleLogger.LogInfo("Auth", "Could not fetch host key");
                    Failed();

                    return;
                }

                bool warn = true;
                if (RequiredFingerprint != null)
                {
                    string host_fingerprint = DeriveFingerprint(host_key);

                    if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint))
                    {
                        SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match");

                        this.errors.Add("error: Host fingerprint doesn't match");
                        Failed();

                        return;
                    }

                    warn = false;
                    SparkleLogger.LogInfo("Auth", "Fingerprint matches");
                }
                else
                {
                    SparkleLogger.LogInfo("Auth", "Skipping fingerprint check");
                }

                AcceptHostKey(host_key, warn);
            }

            this.thread = new Thread(() => {
                if (Fetch())
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Finished");

                    IsActive = false;

                    bool repo_is_encrypted = (RemoteUrl.AbsolutePath.Contains("-crypto") ||
                                              RemoteUrl.Host.Equals("sparkleshare.net"));

                    Finished(repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
                }
                else
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Failed");

                    IsActive = false;
                    Failed();
                }
            });

            this.thread.Start();
        }
Exemple #4
0
        public void Start()
        {
            IsActive = true;
            Started();

            SparkleLogger.LogInfo("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);

            if (Directory.Exists(TargetFolder))
            {
                Directory.Delete(TargetFolder, true);
            }

            string host     = RemoteUrl.Host;
            string host_key = GetHostKey();

            if (string.IsNullOrEmpty(host) || host_key == null)
            {
                Failed();
                return;
            }

            bool warn = true;

            if (RequiredFingerprint != null)
            {
                string host_fingerprint = GetFingerprint(host_key);

                if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint))
                {
                    SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match");

                    this.errors.Add("error: Host fingerprint doesn't match");
                    Failed();

                    return;
                }

                warn = false;
                SparkleLogger.LogInfo("Auth", "Fingerprint matches");
            }
            else
            {
                SparkleLogger.LogInfo("Auth", "Skipping fingerprint check");
            }

            AcceptHostKey(host_key, warn);

            this.thread = new Thread(() => {
                if (Fetch())
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Finished");

                    IsActive = false;

                    // TODO: Find better way to determine if folder should have crypto setup
                    bool repo_is_encrypted = RemoteUrl.ToString().Contains("crypto");
                    Finished(repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
                }
                else
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Failed");

                    IsActive = false;
                    Failed();
                }
            });

            this.thread.Start();
        }