Changeset 05022dc in trunk
- Timestamp:
- 2010-07-11T21:37:21Z (15 years ago)
- Branches:
- master
- Children:
- 7528974
- Parents:
- c0e7d84
- Location:
- src/allmydata
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/frontends/ftpd.py ¶
rc0e7d84 r05022dc 1 1 2 import tempfile3 2 from zope.interface import implements 4 3 from twisted.application import service, strports … … 11 10 NoSuchChildError 12 11 from allmydata.immutable.upload import FileHandle 12 from allmydata.util.fileutil import EncryptedTemporaryFile 13 13 14 14 class ReadFile: … … 28 28 # we write the data to a temporary file, since Tahoe can't do 29 29 # streaming upload yet. 30 self.f = tempfile.TemporaryFile()30 self.f = EncryptedTemporaryFile() 31 31 return None 32 32 -
TabularUnified src/allmydata/frontends/sftpd.py ¶
rc0e7d84 r05022dc 1 1 2 import os, tempfile, heapq, binascii, traceback, array, stat, struct2 import heapq, traceback, array, stat, struct 3 3 from types import NoneType 4 4 from stat import S_IFREG, S_IFDIR … … 33 33 from allmydata.immutable.upload import FileHandle 34 34 from allmydata.dirnode import update_metadata 35 36 from pycryptopp.cipher.aes import AES 35 from allmydata.util.fileutil import EncryptedTemporaryFile 37 36 38 37 noisy = True … … 287 286 288 287 return None 289 290 291 class EncryptedTemporaryFile(PrefixingLogMixin):292 # not implemented: next, readline, readlines, xreadlines, writelines293 294 def __init__(self):295 PrefixingLogMixin.__init__(self, facility="tahoe.sftp")296 self.file = tempfile.TemporaryFile()297 self.key = os.urandom(16) # AES-128298 299 def _crypt(self, offset, data):300 # TODO: use random-access AES (pycryptopp ticket #18)301 offset_big = offset // 16302 offset_small = offset % 16303 iv = binascii.unhexlify("%032x" % offset_big)304 cipher = AES(self.key, iv=iv)305 cipher.process("\x00"*offset_small)306 return cipher.process(data)307 308 def close(self):309 self.file.close()310 311 def flush(self):312 self.file.flush()313 314 def seek(self, offset, whence=0): # 0 = SEEK_SET315 if noisy: self.log(".seek(%r, %r)" % (offset, whence), level=NOISY)316 self.file.seek(offset, whence)317 318 def tell(self):319 offset = self.file.tell()320 if noisy: self.log(".tell() = %r" % (offset,), level=NOISY)321 return offset322 323 def read(self, size=-1):324 if noisy: self.log(".read(%r)" % (size,), level=NOISY)325 index = self.file.tell()326 ciphertext = self.file.read(size)327 plaintext = self._crypt(index, ciphertext)328 return plaintext329 330 def write(self, plaintext):331 if noisy: self.log(".write(<data of length %r>)" % (len(plaintext),), level=NOISY)332 index = self.file.tell()333 ciphertext = self._crypt(index, plaintext)334 self.file.write(ciphertext)335 336 def truncate(self, newsize):337 if noisy: self.log(".truncate(%r)" % (newsize,), level=NOISY)338 self.file.truncate(newsize)339 288 340 289 -
TabularUnified src/allmydata/util/fileutil.py ¶
rc0e7d84 r05022dc 3 3 """ 4 4 5 import sys, exceptions, os, stat, tempfile, time 5 import sys, exceptions, os, stat, tempfile, time, binascii 6 6 7 7 from twisted.python import log 8 9 from pycryptopp.cipher.aes import AES 10 8 11 9 12 def rename(src, dst, tries=4, basedelay=0.1): … … 113 116 rm_dir(self.name) 114 117 118 class EncryptedTemporaryFile: 119 # not implemented: next, readline, readlines, xreadlines, writelines 120 121 def __init__(self): 122 self.file = tempfile.TemporaryFile() 123 self.key = os.urandom(16) # AES-128 124 125 def _crypt(self, offset, data): 126 offset_big = offset // 16 127 offset_small = offset % 16 128 iv = binascii.unhexlify("%032x" % offset_big) 129 cipher = AES(self.key, iv=iv) 130 cipher.process("\x00"*offset_small) 131 return cipher.process(data) 132 133 def close(self): 134 self.file.close() 135 136 def flush(self): 137 self.file.flush() 138 139 def seek(self, offset, whence=0): # 0 = SEEK_SET 140 self.file.seek(offset, whence) 141 142 def tell(self): 143 offset = self.file.tell() 144 return offset 145 146 def read(self, size=-1): 147 index = self.file.tell() 148 ciphertext = self.file.read(size) 149 plaintext = self._crypt(index, ciphertext) 150 return plaintext 151 152 def write(self, plaintext): 153 index = self.file.tell() 154 ciphertext = self._crypt(index, plaintext) 155 self.file.write(ciphertext) 156 157 def truncate(self, newsize): 158 self.file.truncate(newsize) 159 160 115 161 def make_dirs(dirname, mode=0777): 116 162 """
Note: See TracChangeset
for help on using the changeset viewer.