~ubuntu-branches/ubuntu/quantal/m2crypto/quantal

« back to all changes in this revision

Viewing changes to demo/x509/proxylib.py

  • Committer: Bazaar Package Importer
  • Author(s): Dima Barsky
  • Date: 2007-05-24 21:14:36 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070524211436-73w3oonappxy8k4a
Tags: 0.17-1
* New upstream release
* Acknowledge NMU (Closes: #380861)
* Changed section to python (Closes: #425875)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
PCI_VALUE_FULL = "critical, language:Inherit all"
32
32
PCI_VALUE_LIMITED = "critical, language:1.3.6.1.4.1.3536.1.1.1.9"
33
33
 
 
34
def create_write_file(fname, perm=0600):
 
35
    """
 
36
    Creates a file to write to while avoiding a possible race condition.
 
37
    This is essential for writing out the proxy file. Need to make sure
 
38
    there is no pre-existing file.
 
39
    """
 
40
    if os.path.exists(fname):
 
41
        os.remove(fname)
 
42
    # Make sure the file doesn't exist. Will throw an exception if
 
43
    # it does. This would only happen if the code is attacked.
 
44
    fd = os.open(fname, os.O_CREAT|os.O_EXCL|os.O_WRONLY, perm)
 
45
    f = os.fdopen(fd, 'w')
 
46
    return f
 
47
 
34
48
 
35
49
class ProxyFactoryException(Exception):
36
50
    """
101
115
        """
102
116
        Writes the proxy information to a file
103
117
        """
104
 
        proxyfile = open(proxypath, "w")
 
118
        proxyfile = create_write_file(proxypath)
105
119
        bio = BIO.File(proxyfile) 
106
120
        bio.write(self._cert.as_pem())
107
121
        self._key.save_key_bio(bio, cipher=None)