[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Obscuring contact email addresses



commit 0a0bf4a2cde102bfaef5ea7ad3575156dccf39f9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jul 10 23:35:36 2011 -0700

    Obscuring contact email addresses
    
    Trying to make address scraping a tiny bit harder.
---
 src/cli/wizard.py |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/cli/wizard.py b/src/cli/wizard.py
index e5d6257..0f35247 100644
--- a/src/cli/wizard.py
+++ b/src/cli/wizard.py
@@ -3,8 +3,10 @@ Provides user prompts for setting up a new relay. This autogenerates a torrc
 that's used by arm to run its own tor instance.
 """
 
+import re
 import os
 import sys
+import random
 import shutil
 import functools
 import curses
@@ -79,6 +81,14 @@ MSG_COLOR = "green"
 OPTION_COLOR = "yellow"
 DISABLED_COLOR = "cyan"
 
+# bracketing pairs used in email address obscuring
+BRACKETS = ((' ', ' '),
+            ('<', '>'),
+            ('[', ']'),
+            ('(', ')'),
+            ('{', '}'),
+            ('|', '|'))
+
 # tor's defaults for config options, used to filter unneeded options
 TOR_DEFAULTS = {Options.BANDWIDTH: "5 MB",
                 Options.REUSE: "10 minutes"}
@@ -517,6 +527,9 @@ def getTorrc(relayType, config):
     elif key == Options.NOTICE:
       # notice option is only applied if using low ports
       value &= config[Options.LOWPORTS].getValue()
+    elif key == Options.CONTACT and _isEmailAddress(value):
+      # obscures the email address
+      value = _obscureEmailAddress(value)
     
     templateOptions[key.upper()] = value
   
@@ -702,6 +715,64 @@ def _splitStr(msg, width):
   
   return results
 
+def _isEmailAddress(address):
+  """
+  True if the input is an email address, false otherwise.
+  """
+  
+  # just checks if there's an '@' and '.' in the input w/o whitespace
+  emailMatcher = re.compile("\S*@\S*\.\S*")
+  return emailMatcher.match(address)
+
+def _obscureEmailAddress(address):
+  """
+  Makes some effort to obscure an email address while keeping it readable.
+  
+  Arguments:
+    address - actual email address
+  """
+  
+  address = _obscureChar(address, '@', (_randomCase("at"), ))
+  address = _obscureChar(address, '.', (_randomCase("dot"), ))
+  return address
+
+def _randomCase(word):
+  """
+  Provides a word back with the case of its letters randomized.
+  
+  Arguments:
+    word - word for which to randomize the case
+  """
+  
+  result = []
+  for letter in word:
+    result.append(random.choice((letter.lower(), letter.upper())))
+  
+  return "".join(result)
+
+def _obscureChar(inputText, target, options):
+  """
+  Obscures the given character from the input, replacing it with something
+  from a set of options and bracketing the selection.
+  
+  Arguments:
+    inputText - text to be obscured
+    target    - character to be replaced
+    options   - replacement options for the character
+  """
+  
+  leftSpace = random.randint(0, 3)
+  leftFill = random.choice((' ', '_', '-', '=', '<'))
+  
+  rightSpace = random.randint(0, 3)
+  rightFill = random.choice((' ', '_', '-', '=', '>'))
+  
+  bracketLeft, bracketRight = random.choice(BRACKETS)
+  optSelection = random.choice(options)
+  replacement = "".join((bracketLeft, leftFill * leftSpace, optSelection, rightFill * rightSpace, bracketRight))
+  
+  return inputText.replace(target, replacement)
+
 def _toggleEnabledAction(toggleOptions, option, value):
   """
   Enables or disables custom exit policy options based on our selection.



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits