Exemplo n.º 1
0
        public void ProcessLog()
        {
            using (StreamReader file = File.OpenText(OnionLogFilename))
            {
                while (!file.EndOfStream && MatchedCount < MatchMax)
                {
                    string line = file.ReadLine().Trim();
                    if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
                    {
                        continue;
                    }

                    string[] record = line.Split(',');

                    if (record.Length != 2)
                    {
                        Log.Warn("Invalid record does not contain two fields");
                        continue;
                    }

                    string logOnion = record[0];
                    if (OnionPattern.IsMatch(logOnion))
                    {
                        string pkiXml = record[1];

                        try
                        {
                            using (OnionAddress onion = OnionAddress.FromXmlString(pkiXml))
                            {
                                if (OnionPattern.IsMatch(onion.Onion))
                                {
                                    Log.InfoFormat("Found matching onion: {0}", onion.Onion);
                                    if (onion.IsPublicOnly)
                                    {
                                        Log.Warn("Unable to write matched address; record only " +
                                                 "contains public portion of key");
                                    }
                                    string outputDir = PickDirectory(onion);
                                    if (outputDir != null)
                                    {
                                        OnionDirectory.WriteDirectory(onion, outputDir);
                                    }
                                    ++MatchedCount;
                                }
                            }
                        }
                        catch (CryptographicException)
                        {
                            Log.Warn("Unable to parse key");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void GenerateOnionsLoop(object sender, EventArgs e)
        {
            Log.Info("Beginning onion address generation");
            while (!StopRequested && GeneratedCount < GenerateMax && MatchedCount < MatchMax)
            {
                Log.Debug("Generating onion");
                using (OnionAddress onion = OnionAddress.Create())
                {
                    Log.DebugFormat("Onion generated: {0}", onion.Onion);

                    if (StopRequested)
                    {
                        break;
                    }

                    OnionLog.InfoFormat("{0},{1}", onion.Onion, onion.ToXmlString(true));

                    if (StopRequested)
                    {
                        break;
                    }

                    if (OnionPattern != null && OnionPattern.IsMatch(onion.Onion))
                    {
                        Log.InfoFormat("Found matching onion: {0}", onion.Onion);
                        string outputDir = PickDirectory(onion);
                        if (outputDir != null)
                        {
                            OnionDirectory.WriteDirectory(onion, outputDir);
                        }
                        ++MatchedCount;
                    }

                    ++GeneratedCount;
                }
            }
            Log.Info("Stopped onion address generation");
        }