Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'switched': 0.05; 'python': 0.08; 'am,': 0.14; 'wrote:': 0.14; 'fname': 0.16; 'subject:security': 0.16; 'algorithm': 0.16; 'method.': 0.16; 'cc:addr:python-list': 0.17; 'tue,': 0.17; 'meant': 0.18; 'bytes': 0.19; 'guess': 0.19; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'skip:b 20': 0.23; 'values': 0.25; 'junk': 0.26; 'produced': 0.26; 'script': 0.27; 'message-id:@mail.gmail.com': 0.28; 'random': 0.28; 'producing': 0.29; 'originally': 0.29; 'subject:How': 0.30; 'cc:addr:python.org': 0.30; 'get.': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'adds': 0.32; 'file': 0.34; 'using': 0.35; 'probably': 0.36; 'similar': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'subject:: ': 0.38; 'should': 0.39; 'easier': 0.39; "i'd": 0.39; 'received:209': 0.39; 'got': 0.39; 'best': 0.60; 'feeding': 0.67; 'recipients': 0.68; 'safe': 0.69; 'robin': 0.84; 'besides,': 0.91; 'generated.': 0.93; 'subject:good': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=wAucLBD7eyTQ6EgGtEVpylJwIjwLCw9VSGedflfVscc=; b=FlScPK27oIdfMuA2PEnW0sn7PsZEQZwXeBN5QwIFauHETBq5XlxKl2SECOPbM1IAy5 vK4/PJs8PRUGFIpHc/y3sMjGXgOsGczcklmM3vuDvO2UCh2tW67hCOLg41S2BE/28LZv 3jHq/Qk2OAb9bRNPHgKdbJG3CL3WbJOtro/u8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=LVhM6bjZ9CEhh1SDmEPAViL/wEdhbl4irjxxNBe7AEtlvZ6WoKi+4hkENV9rsHVY8T 50USb7WAqnOyrIp+1WcVO0FekjFhOeLr5p9Fc9C5jtDfL3EHm8YtblUGEFTtCAQ8mQNO 0UT/jZEXMGArmnB+ujxrhhQUixjIb7ci9jIRY= MIME-Version: 1.0 In-Reply-To: <4DEDFAEB.4050006@chamonix.reportlab.co.uk> References: <4DEDFAEB.4050006@chamonix.reportlab.co.uk> Date: Tue, 7 Jun 2011 13:02:46 -0700 Subject: Re: How good is security via hashing From: geremy condra To: Robin Becker Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307476970 news.xs4all.nl 49182 [::ffff:82.94.164.166]:52781 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7180 On Tue, Jun 7, 2011 at 3:18 AM, Robin Becker wrote: > A python web process is producing files that are given randomized names of > the form > > hhhhhh-YYYYMMDDhhmmss-rrrrrrrr.pdf > > where rrr.. is a 128bit random number (encoded as base62). The intent of the > random part is to prevent recipients of one file from being able to guess > the names of others. > > The process was originally a cgi script which meant each random number was > produced thusly > > > pid is process id, dur is 4 bytes from /dev/urandom. > > random.seed(long(time.time()*someprimeint)|(pid<<64)|(dur<<32)) > rrr = random.getrandbits(128) > > > is this algorithm safe? Is it safe if the process is switched to fastcgi and > the initialization is only carried out once and then say 50 rrr values are > generated. The advice you got about just using urandom seems to be the best you're likely to get. Given how few values you have to pull out of random.random to reconstruct its state, the progress that's been made in the last few years on similar hidden state problems, and the limited amount of entropy you're feeding it in the first place, I'd probably stay away from this method. And besides, # adds random junk to the filename- should make it hard to guess rrr = os.urandom(16) fname += base64.b64encode(rrr) has to be easier to read and reason about than the process above. Geremy Condra