private static string PickOutputDirectory(OnionAddress onion) { string onionDir = onion.Onion; string extension = string.Empty; int count = 0; while (true) { using (OnionAddress priorOnion = OnionDirectory.ReadDirectory(onionDir + extension)) { if (priorOnion == null) { break; } if (OnionAddress.AreKeysSame(priorOnion, onion)) { Log.Info("Onion directory already exported, skipping"); return(null); } } Log.WarnFormat("Onion directory collision: {0}", onion.Onion); ++count; extension = "_" + count.ToString(); } return(onionDir + extension); }
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"); } } } } }
private static int CheckOnionDirectory(Settings settings) { Log.DebugFormat("Checking onion directory: {0}", settings.CheckDir); try { OnionDirectory.Validate(settings.CheckDir); } catch (IOException ex) { Console.Error.WriteLine("Validation error (something missing): " + ex.Message); return(1); } catch (PorException ex) { Console.Error.WriteLine("Validation error: " + ex.Message); return(1); } return(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"); }