[tor-commits] [flashproxy/master] Use get_state_dir in temp_cert.

dcf at torproject.org dcf at torproject.org
Sun Feb 9 11:14:51 UTC 2014


commit c56dfcf8c84f8cde3ceadc24423f3e1a6243bf8d
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Feb 9 03:08:27 2014 -0800

    Use get_state_dir in temp_cert.
    
    Cause the temporary certificate file to be written in
    TOR_PT_STATE_LOCATION. Fixes #10641.
---
 flashproxy-reg-appspot |   14 --------------
 flashproxy-reg-email   |   14 --------------
 flashproxy/keys.py     |   16 +++++++++++++++-
 3 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/flashproxy-reg-appspot b/flashproxy-reg-appspot
index 1f12c26..134e9ff 100755
--- a/flashproxy-reg-appspot
+++ b/flashproxy-reg-appspot
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 """Register with a facilitator through Google App Engine."""
 
-import errno
 import getopt
 import httplib
 import os
@@ -71,19 +70,6 @@ def safe_str(s):
 def safe_format_addr(addr):
     return safe_str(format_addr(addr))
 
-def get_state_dir():
-    """Get a directory where we can put temporary files. Returns None if any
-    suitable temporary directory will do."""
-    pt_dir = os.environ.get("TOR_PT_STATE_LOCATION")
-    if pt_dir is None:
-        return None
-    try:
-        os.makedirs(pt_dir)
-    except OSError, e:
-        if e.errno != errno.EEXIST:
-            raise
-    return pt_dir
-
 def generate_url(addr):
     if getattr(sys, "frozen", False):
         script_dir = os.path.dirname(sys.executable)
diff --git a/flashproxy-reg-email b/flashproxy-reg-email
index de67d43..6309cec 100755
--- a/flashproxy-reg-email
+++ b/flashproxy-reg-email
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 """Register with a facilitator using the email method."""
 
-import errno
 import getopt
 import os
 import re
@@ -96,19 +95,6 @@ def build_reg(addr, transport):
         ("client-transport", transport),
     ))
 
-def get_state_dir():
-    """Get a directory where we can put temporary files. Returns None if any
-    suitable temporary directory will do."""
-    pt_dir = os.environ.get("TOR_PT_STATE_LOCATION")
-    if pt_dir is None:
-        return None
-    try:
-        os.makedirs(pt_dir)
-    except OSError, e:
-        if e.errno != errno.EEXIST:
-            raise
-    return pt_dir
-
 def get_facilitator_pubkey():
     if options.facilitator_pubkey_filename is not None:
         return RSA.load_pub_key(options.facilitator_pubkey_filename)
diff --git a/flashproxy/keys.py b/flashproxy/keys.py
index 7bf4938..08ffc46 100644
--- a/flashproxy/keys.py
+++ b/flashproxy/keys.py
@@ -1,3 +1,4 @@
+import errno
 import os
 import tempfile
 
@@ -71,11 +72,24 @@ def check_certificate_pin(sock, cert_pubkey):
         expected = "(" + ", ".join(x.encode("hex") for x in cert_pubkey) + ")"
         raise ValueError("Public key does not match pin: got %s but expected any of %s" % (found, expected))
 
+def get_state_dir():
+    """Get a directory where we can put temporary files. Returns None if any
+    suitable temporary directory will do."""
+    pt_dir = os.environ.get("TOR_PT_STATE_LOCATION")
+    if pt_dir is None:
+        return None
+    try:
+        os.makedirs(pt_dir)
+    except OSError, e:
+        if e.errno != errno.EEXIST:
+            raise
+    return pt_dir
+
 class temp_cert(object):
     """Implements a with-statement over raw certificate data."""
 
     def __init__(self, certdata):
-        fd, self.path = tempfile.mkstemp(prefix="fp-cert-temp-", suffix=".crt")
+        fd, self.path = tempfile.mkstemp(prefix="fp-cert-temp-", dir=get_state_dir(), suffix=".crt")
         os.write(fd, certdata)
         os.close(fd)
 



More information about the tor-commits mailing list