diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-10-14 05:10:30 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-10-14 05:10:30 +0000 |
commit | d90990ee3ecd09a2725b8051759a900ebd488b8c (patch) | |
tree | fbe68d0c4b698d45bfdcb6c91a43ea2e60c21329 | |
parent | fb5a6115a6f3ea0216e3ca0645ba1eb31fb02876 (diff) |
Rename glider to thandy, based on discussions on #nottor. Please let me know ASAP if there is another program Thandy, or if it means something rude, or whatever.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17085 55e972cd-5a19-0410-ae62-a4d7a52db4cd
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | lib/thandy/ClientCLI.py (renamed from lib/glider/ClientCLI.py) | 14 | ||||
-rw-r--r-- | lib/thandy/ServerCLI.py (renamed from lib/glider/ServerCLI.py) | 36 | ||||
-rw-r--r-- | lib/thandy/SignerCLI.py (renamed from lib/glider/SignerCLI.py) | 64 | ||||
-rw-r--r-- | lib/thandy/__init__.py (renamed from lib/glider/__init__.py) | 0 | ||||
-rw-r--r-- | lib/thandy/checkJson.py (renamed from lib/glider/checkJson.py) | 38 | ||||
-rw-r--r-- | lib/thandy/download.py (renamed from lib/glider/download.py) | 10 | ||||
-rw-r--r-- | lib/thandy/formats.py (renamed from lib/glider/formats.py) | 30 | ||||
-rw-r--r-- | lib/thandy/keys.py (renamed from lib/glider/keys.py) | 32 | ||||
-rw-r--r-- | lib/thandy/master_keys.py (renamed from lib/glider/master_keys.py) | 0 | ||||
-rw-r--r-- | lib/thandy/repository.py (renamed from lib/glider/repository.py) | 42 | ||||
-rw-r--r-- | lib/thandy/tests.py (renamed from lib/glider/tests.py) | 36 | ||||
-rw-r--r-- | lib/thandy/util.py (renamed from lib/glider/util.py) | 20 | ||||
-rw-r--r-- | specs/thandy-spec.txt (renamed from specs/glider-spec.txt) | 13 |
14 files changed, 170 insertions, 167 deletions
@@ -3,4 +3,4 @@ export PYTHONPATH=./lib test: #python -m sexp.tests - python -m glider.tests + python -m thandy.tests diff --git a/lib/glider/ClientCLI.py b/lib/thandy/ClientCLI.py index c6f13fd..702ebbf 100644 --- a/lib/glider/ClientCLI.py +++ b/lib/thandy/ClientCLI.py @@ -3,12 +3,12 @@ import os import sys import getopt -import glider.util -import glider.repository -import glider.download +import thandy.util +import thandy.repository +import thandy.download def update(args): - repoRoot = glider.util.userFilename("cache") + repoRoot = thandy.util.userFilename("cache") options, args = getopt.getopt(args, "", [ "repo=", "no-download" ]) download = True @@ -18,7 +18,7 @@ def update(args): elif o == "--no-download": download = False - repo = glider.repository.LocalRepository(repoRoot) + repo = thandy.repository.LocalRepository(repoRoot) files = repo.getFilesToUpdate(trackingBundles=args) @@ -27,12 +27,12 @@ def update(args): mirrorlist = repo.getMirrorlistFile().get() - downloader = glider.download.Downloads() + downloader = thandy.download.Downloads() downloader.start() for f in files: # XXXX Use hash. - dj = glider.download.DownloadJob(f, repo.getFilename(f), + dj = thandy.download.DownloadJob(f, repo.getFilename(f), mirrorlist) downloader.addDownloadJob(dj) # XXXX replace file in repository if ok; reload; see what changed. diff --git a/lib/glider/ServerCLI.py b/lib/thandy/ServerCLI.py index c564f5b..47fa912 100644 --- a/lib/glider/ServerCLI.py +++ b/lib/thandy/ServerCLI.py @@ -6,9 +6,9 @@ import time import simplejson -import glider.formats -import glider.util -import glider.keys +import thandy.formats +import thandy.util +import thandy.keys def tstamp(): return time.strftime("%Y%m%d_%H%M%S", time.localtime()) @@ -29,7 +29,7 @@ def snarfObj(fname): def insert(args): repo = os.environ.get("THANDY_MASTER_REPO") - backupDir = glider.util.userFilename("old_files") + backupDir = thandy.util.userFilename("old_files") checkSigs = True options, args = getopt.getopt(args, "", ["repo=", "no-check"]) @@ -50,7 +50,7 @@ def insert(args): os.makedirs(backupDir, 0700) if checkSigs: - keys = glider.util.getKeylist(os.path.join(repo, "meta/keys.txt")) + keys = thandy.util.getKeylist(os.path.join(repo, "meta/keys.txt")) else: keys = None @@ -70,8 +70,8 @@ def insert(args): continue try: - ss, r, path = glider.formats.checkSignedObj(obj, keys) - except glider.FormatException, e: + ss, r, path = thandy.formats.checkSignedObj(obj, keys) + except thandy.FormatException, e: print "Bad format on %s: %s"%(fn, e) continue if checkSigs and not ss.isValid(): @@ -91,14 +91,14 @@ def insert(args): baseFname = "%s_%s" % (tstamp(), os.path.split(path)[1]) backupFname = os.path.join(backupDir, baseFname) print " Copying old file to %s"%backupFname - glider.util.replaceFile(backupFname, oldContents) + thandy.util.replaceFile(backupFname, oldContents) parentDir = os.path.split(targetPath)[0] if not os.path.exists(parentDir): print " Making %s"%parentDir os.makedirs(parentDir, 0755) print " Replacing file..." - glider.util.replaceFile(targetPath, content) + thandy.util.replaceFile(targetPath, content) print " Done." n_ok += 1 if n_ok != len(args): @@ -106,7 +106,7 @@ def insert(args): def timestamp(args): repo = os.environ.get("THANDY_MASTER_REPO") - ts_keyfile = glider.util.userFilename("timestamp_key") + ts_keyfile = thandy.util.userFilename("timestamp_key") options, args = getopt.getopt(args, "", ["repo=", "ts-key="]) for o,v in options: @@ -144,8 +144,8 @@ def timestamp(args): print "(Couldn't read bundle-like %s)"%fn continue try: - _, r, _ = glider.formats.checkSignedObj(bObj) - except glider.FormatException, e: + _, r, _ = thandy.formats.checkSignedObj(bObj) + except thandy.FormatException, e: print "Problem reading object from %s"%fn continue if r != "bundle": @@ -153,19 +153,19 @@ def timestamp(args): continue bundles.append(bObj['signed']) - timestamp = glider.formats.makeTimestampObj( + timestamp = thandy.formats.makeTimestampObj( mObj['signed'], kObj['signed'], bundles) - signable = glider.formats.makeSignable(timestamp) + signable = thandy.formats.makeSignable(timestamp) - keydb = glider.formats.Keylist() + keydb = thandy.formats.Keylist() #XXXX Still a roundabout way to do this. - keylist = glider.formats.makeKeylistObj(ts_keyfile, True) + keylist = thandy.formats.makeKeylistObj(ts_keyfile, True) keydb.addFromKeylist(keylist) for k in keydb.iterkeys(): - glider.formats.sign(signable, k) + thandy.formats.sign(signable, k) content = simplejson.dumps(signable, sort_keys=True) - glider.util.replaceFile(tsFname, content) + thandy.util.replaceFile(tsFname, content) def usage(): print "Known commands:" diff --git a/lib/glider/SignerCLI.py b/lib/thandy/SignerCLI.py index bf5b73a..4facc2e 100644 --- a/lib/glider/SignerCLI.py +++ b/lib/thandy/SignerCLI.py @@ -5,11 +5,11 @@ import sys import logging import simplejson -import glider.keys -import glider.formats +import thandy.keys +import thandy.formats def getKeyStore(): - return glider.keys.KeyStore(glider.util.userFilename("secret_keys")) + return thandy.keys.KeyStore(thandy.util.userFilename("secret_keys")) def dumpKey(key, indent=0): i = " "*indent @@ -58,17 +58,17 @@ def makepackage(args): configFile = args[0] dataFile = args[1] print "Generating package." - package = glider.formats.makePackageObj(configFile, dataFile) + package = thandy.formats.makePackageObj(configFile, dataFile) relpath = package['location'] print "need a key with role matching [package %s]"%relpath ks = getKeyStore() ks.load() key = getKey(ks, keyid=keyid, role='package', path=relpath) - signable = glider.formats.makeSignable(package) - glider.formats.sign(signable, key) + signable = thandy.formats.makeSignable(package) + thandy.formats.sign(signable, key) if 1: - ss, r, p = glider.formats.checkSignedObj(signable, ks) + ss, r, p = thandy.formats.checkSignedObj(signable, ks) assert ss.isValid() location = os.path.split(package['location'])[-1] @@ -94,25 +94,25 @@ def makebundle(args): f = open(pkgFile, 'r') p = simplejson.load(f) f.close() - _, r, _ = glider.formats.checkSignedObj(p) + _, r, _ = thandy.formats.checkSignedObj(p) if r != 'package': print pkgFile, "was not a package" packages[p['signed']['location']] = p def getHash(path): p = packages[path] - return glider.formats.getDigest(p['signed']) + return thandy.formats.getDigest(p['signed']) - bundleObj = glider.formats.makeBundleObj(configFile, getHash) - signable = glider.formats.makeSignable(bundleObj) + bundleObj = thandy.formats.makeBundleObj(configFile, getHash) + signable = thandy.formats.makeSignable(bundleObj) ks = getKeyStore() ks.load() key = getKey(ks, keyid=keyid, role="bundle", path=bundleObj['location']) - glider.formats.sign(signable, key) + thandy.formats.sign(signable, key) if 1: - ss, r, p = glider.formats.checkSignedObj(signable, ks) + ss, r, p = thandy.formats.checkSignedObj(signable, ks) assert ss.isValid() location = os.path.split(bundleObj['location'])[-1] @@ -132,20 +132,20 @@ def makekeylist(args): if len(args) < 1: usage() - keylist = glider.formats.makeKeylistObj(args[0]) - signable = glider.formats.makeSignable(keylist) + keylist = thandy.formats.makeKeylistObj(args[0]) + signable = thandy.formats.makeSignable(keylist) ks = getKeyStore() ks.load() key = getKey(ks, keyid=keyid, role="master", path="/meta/keys.txt") - glider.formats.sign(signable, key) + thandy.formats.sign(signable, key) if 1: - ss, r, p = glider.formats.checkSignedObj(signable, ks) + ss, r, p = thandy.formats.checkSignedObj(signable, ks) assert ss.isValid() print "writing signed keylist to keys.txt" - glider.util.replaceFile("keys.txt", + thandy.util.replaceFile("keys.txt", simplejson.dumps(signable, indent=1, sort_keys=True), textMode=True) @@ -154,17 +154,17 @@ def signkeylist(args): usage() keylist = simplejson.load(open(args[0], 'r')) - glider.formats.SIGNED_SCHEMA.checkMatch(keylist) - glider.formats.KEYLIST_SCHEMA.checkMatch(keylist['signed']) + thandy.formats.SIGNED_SCHEMA.checkMatch(keylist) + thandy.formats.KEYLIST_SCHEMA.checkMatch(keylist['signed']) ks = getKeyStore() ks.load() keys = ks.getKeysByRole("master", "/meta/keys.txt") for k in keys: - glider.formats.sign(keylist, k) + thandy.formats.sign(keylist, k) print "writing signed keylist to keys.txt" - glider.util.replaceFile("keys.txt", + thandy.util.replaceFile("keys.txt", simplejson.dumps(keylist, indent=1, sort_keys=True), textMode=True) @@ -178,20 +178,20 @@ def makemirrorlist(args): if len(args) < 1: usage() - mirrorlist = glider.formats.makeMirrorListObj(args[0]) - signable = glider.formats.makeSignable(mirrorlist) + mirrorlist = thandy.formats.makeMirrorListObj(args[0]) + signable = thandy.formats.makeSignable(mirrorlist) ks = getKeyStore() ks.load() key = getKey(ks, keyid=keyid, role='mirrors', path="/meta/mirrors.txt") - glider.formats.sign(signable, key) + thandy.formats.sign(signable, key) if 1: - ss, r, p = glider.formats.checkSignedObj(signable, ks) + ss, r, p = thandy.formats.checkSignedObj(signable, ks) assert ss.isValid() print "writing signed mirrorlist to mirrors.txt" - glider.util.replaceFile("mirrors.txt", + thandy.util.replaceFile("mirrors.txt", simplejson.dumps(signable, indent=1, sort_keys=True), textMode=True) @@ -201,7 +201,7 @@ def keygen(args): k = getKeyStore() k.load() print "Generating key. This will be slow." - key = glider.keys.RSAKey.generate() + key = thandy.keys.RSAKey.generate() print "Generated new key: %s" % key.getKeyID() k.addKey(key) k.save() @@ -221,9 +221,9 @@ def addrole(args): ks.load() k = getKey(ks, args[0]) r = args[1] - if r not in glider.formats.ALL_ROLES: + if r not in thandy.formats.ALL_ROLES: print "Unrecognized role %r. Known roles are %s"%( - r,", ".join(glider.format.ALL_ROLES)) + r,", ".join(thandy.format.ALL_ROLES)) sys.exit(1) p = args[2] k.addRole(r, p) @@ -236,9 +236,9 @@ def delrole(args): ks.load() k = getKey(ks, args[0]) r = args[1] - if r not in glider.formats.ALL_ROLES: + if r not in thandy.formats.ALL_ROLES: print "Unrecognized role %r. Known roles are %s"%( - r,", ".join(glider.format.ALL_ROLES)) + r,", ".join(thandy.format.ALL_ROLES)) sys.exit(1) p = args[2] diff --git a/lib/glider/__init__.py b/lib/thandy/__init__.py index 87fd983..87fd983 100644 --- a/lib/glider/__init__.py +++ b/lib/thandy/__init__.py diff --git a/lib/glider/checkJson.py b/lib/thandy/checkJson.py index 0c5eed6..e6b6c6e 100644 --- a/lib/glider/checkJson.py +++ b/lib/thandy/checkJson.py @@ -2,13 +2,13 @@ import re import sys -import glider +import thandy class Schema: def matches(self, obj): try: self.checkMatch(obj) - except glider.FormatException: + except thandy.FormatException: return False else: return True @@ -48,7 +48,7 @@ class RE(Schema): self._reName = reName def checkMatch(self, obj): if not isinstance(obj, basestring) or not self._re.match(obj): - raise glider.FormatException("%r did not match %s" + raise thandy.FormatException("%r did not match %s" %(obj,self._reName)) class Str(Schema): @@ -63,7 +63,7 @@ class Str(Schema): self._str = val def checkMatch(self, obj): if self._str != obj: - raise glider.FormatException("Expected %r; got %r"%(self._str, obj)) + raise thandy.FormatException("Expected %r; got %r"%(self._str, obj)) class AnyStr(Schema): """ @@ -85,7 +85,7 @@ class AnyStr(Schema): pass def checkMatch(self, obj): if not isinstance(obj, basestring): - raise glider.FormatException("Expected a string; got %r"%obj) + raise thandy.FormatException("Expected a string; got %r"%obj) class ListOf(Schema): """ @@ -108,16 +108,16 @@ class ListOf(Schema): self._listName = listName def checkMatch(self, obj): if not isinstance(obj, (list, tuple)): - raise glider.FormatException("Expected %s; got %r" + raise thandy.FormatException("Expected %s; got %r" %(self._listName,obj)) for item in obj: try: self._schema.checkMatch(item) - except glider.FormatException, e: - raise glider.FormatException("%s in %s"%(e, self._listName)) + except thandy.FormatException, e: + raise thandy.FormatException("%s in %s"%(e, self._listName)) if not (self._minCount <= len(obj) <= self._maxCount): - raise glider.FormatException("Length of %s out of range" + raise thandy.FormatException("Length of %s out of range" %self._listName) class Struct(Schema): @@ -142,13 +142,13 @@ class Struct(Schema): self._structName = structName def checkMatch(self, obj): if not isinstance(obj, (list, tuple)): - raise glider.FormatException("Expected %s; got %r" + raise thandy.FormatException("Expected %s; got %r" %(self._structName,obj)) elif len(obj) < len(self._subschemas): - raise glider.FormatException( + raise thandy.FormatException( "Too few fields in %s"%self._structName) elif len(obj) > len(self._subschemas) and not self._allowMore: - raise glider.FormatException( + raise thandy.FormatException( "Too many fields in %s"%self._structName) for item, schema in zip(obj, self._subschemas): schema.checkMatch(item) @@ -174,7 +174,7 @@ class DictOf(Schema): try: iter = obj.iteritems() except AttributeError: - raise glider.FormatException("Expected a dict; got %r"%obj) + raise thandy.FormatException("Expected a dict; got %r"%obj) for k,v in iter: self._keySchema.checkMatch(k) @@ -220,14 +220,14 @@ class Obj(Schema): item = obj[k] except KeyError: if not isinstance(schema, Opt): - raise glider.FormatException("Missing key %s in %s" + raise thandy.FormatException("Missing key %s in %s" %(k,self._objname)) else: try: schema.checkMatch(item) - except glider.FormatException, e: - raise glider.FormatException("%s in %s.%s" + except thandy.FormatException, e: + raise thandy.FormatException("%s in %s.%s" %(e,self._objname,k)) @@ -254,9 +254,9 @@ class Int(Schema): if isinstance(obj, bool) or not isinstance(obj, (int, long)): # We need to check for bool as a special case, since bool # is for historical reasons a subtype of int. - raise glider.FormatException("Got %r instead of an integer"%obj) + raise thandy.FormatException("Got %r instead of an integer"%obj) elif not (self._lo <= obj <= self._hi): - raise glider.FormatException("%r not in range [%r,%r]" + raise thandy.FormatException("%r not in range [%r,%r]" %(obj, self._lo, self._hi)) class Bool(Schema): @@ -271,4 +271,4 @@ class Bool(Schema): pass def checkMatch(self, obj): if not isinstance(obj, bool): - raise glider.FormatException("Got %r instead of a boolean"%obj) + raise thandy.FormatException("Got %r instead of a boolean"%obj) diff --git a/lib/glider/download.py b/lib/thandy/download.py index 3135e39..0b22cfa 100644 --- a/lib/glider/download.py +++ b/lib/thandy/download.py @@ -6,7 +6,7 @@ import random import threading, Queue -import glider.util +import thandy.util class Downloads: def __init__(self, n_threads=2): @@ -64,7 +64,7 @@ class DownloadJob: self._mirrorList = mirrorlist self._destPath = destPath - tmppath = glider.util.userFilename("tmp") + tmppath = thandy.util.userFilename("tmp") if relPath.startswith("/"): relPath = relPath[1:] self._tmppath = os.path.join(tmppath, relPath) @@ -89,7 +89,7 @@ class DownloadJob: for c in m['contents']: # CHECK FOR URL SUITABILITY XXXXX - if glider.formats.rolePathMatches(c, self._relPath): + if thandy.formats.rolePathMatches(c, self._relPath): weightSoFar += m['weight'] usable.append( (weightSoFar, m) ) break @@ -119,9 +119,9 @@ class DownloadJob: # XXXXX retry on failure if self._wantHash: - gotHash = glider.formats.getFileDigest(self._tmpPath) + gotHash = thandy.formats.getFileDigest(self._tmpPath) if gotHash != self._wantHash: # XXXX Corrupt file. pass - glider.utils.moveFile(self._tmpPath, self._destPath) + thandy.utils.moveFile(self._tmpPath, self._destPath) diff --git a/lib/glider/formats.py b/lib/thandy/formats.py index 9846c50..42d1086 100644 --- a/lib/glider/formats.py +++ b/lib/thandy/formats.py @@ -5,7 +5,7 @@ import re import binascii import calendar -import glider.checkJson +import thandy.checkJson import Crypto.Hash.SHA256 @@ -134,7 +134,7 @@ def checkSignatures(signed, keyDB, role=None, path=None): try: result = key.checkSignature(method, sig, digest=digest) - except glider.UnknownMethod: + except thandy.UnknownMethod: continue if result == True: @@ -276,7 +276,7 @@ def parseTime(s): try: return calendar.timegm(time.strptime(s, "%Y-%m-%d %H:%M:%S")) except ValueError: - raise glider.FormatError("Malformed time %r", s) + raise thandy.FormatError("Malformed time %r", s) def formatBase64(h): """Return the base64 encoding of h with whitespace and = signs omitted.""" @@ -293,15 +293,15 @@ def parseBase64(s): try: return binascii.a2b_base64(s) except binascii.Error: - raise glider.FormatError("Invalid base64 encoding") + raise thandy.FormatError("Invalid base64 encoding") def parseHash(s): h = parseBase64(s) if len(h) != Crypto.Hash.SHA256.digest_size: - raise glider.FormatError("Bad hash length") + raise thandy.FormatError("Bad hash length") return h -S = glider.checkJson +S = thandy.checkJson # A date, in YYYY-MM-DD HH:MM:SS format. TIME_SCHEMA = S.RE(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}') @@ -425,10 +425,10 @@ class Key: # must match PUBKEY_SCHEMA keytype = obj['_keytype'] if keytype == 'rsa': - return Key(glider.keys.RSAKey.fromJSon(obj)) + return Key(thandy.keys.RSAKey.fromJSon(obj)) if typeattr == 'rsa': - key = glider.keys.RSAKey.fromSExpression(sexpr) + key = thandy.keys.RSAKey.fromSExpression(sexpr) if key is not None: return Key(key) else: @@ -458,8 +458,8 @@ class Keylist(KeyDB): roles = keyitem['roles'] try: - key = glider.keys.RSAKey.fromJSon(key) - except glider.FormatException, e: + key = thandy.keys.RSAKey.fromJSon(key) + except thandy.FormatException, e: print e #LOG skipping key. continue @@ -537,7 +537,7 @@ def readConfigFile(fname, needKeys=(), optKeys=(), preload={}): try: result[k] = parsed[k] except KeyError: - raise glider.FormatError("Missing value for %s in %s"%k,fname) + raise thandy.FormatError("Missing value for %s in %s"%k,fname) for k in optKeys: try: @@ -616,7 +616,7 @@ def makeBundleObj(config_fname, getPackageHash): try: p['hash'] = formatHash(getPackageHash(p['path'])) except KeyError: - raise glider.FormatException("No such package as %s"%p['path']) + raise thandy.FormatException("No such package as %s"%p['path']) BUNDLE_SCHEMA.checkMatch(result) return result @@ -689,7 +689,7 @@ def makeKeylistObj(keylist_fname, includePrivate=False): klist = [] for k in keys: - k = glider.keys.RSAKey.fromJSon(k) + k = thandy.keys.RSAKey.fromJSon(k) klist.append({'key': k.format(private=includePrivate), 'roles' : k.getRoles() }) result = { '_type' : "Keylist", @@ -714,11 +714,11 @@ def checkSignedObj(obj, keydb=None): try: tp = obj['signed']['_type'] except KeyError: - raise glider.FormatException("Untyped object") + raise thandy.FormatException("Untyped object") try: schema = SCHEMAS_BY_TYPE[tp] except KeyError: - raise glider.FormatException("Unrecognized type %r" % tp) + raise thandy.FormatException("Unrecognized type %r" % tp) schema.checkMatch(obj['signed']) if tp == 'Keylist': diff --git a/lib/glider/keys.py b/lib/thandy/keys.py index fefff6c..5b4e072 100644 --- a/lib/glider/keys.py +++ b/lib/thandy/keys.py @@ -13,8 +13,8 @@ import sys import simplejson import getpass -import glider.formats -import glider.util +import thandy.formats +import thandy.util class PublicKey: def __init__(self): @@ -34,13 +34,13 @@ class PublicKey: def getRoles(self): return self._roles def addRole(self, role, path): - assert role in glider.formats.ALL_ROLES + assert role in thandy.formats.ALL_ROLES self._roles.append((role, path)) def clearRoles(self): del self._roles[:] def hasRole(self, role, path): for r, p in self._roles: - if r == role and glider.formats.rolePathMatches(p, path): + if r == role and thandy.formats.rolePathMatches(p, path): return True return False @@ -73,10 +73,10 @@ def binaryToInt(binary): return long(binascii.b2a_hex(binary), 16) def intToBase64(number): - return glider.formats.formatBase64(intToBinary(number)) + return thandy.formats.formatBase64(intToBinary(number)) def base64ToInt(number): - return binaryToInt(glider.formats.parseBase64(number)) + return binaryToInt(thandy.formats.parseBase64(number)) def _pkcs1_padding(m, size): # I'd rather use OAEP+, but apparently PyCrypto barely supports @@ -130,7 +130,7 @@ class RSAKey(PublicKey): def fromJSon(obj): # obj must match RSAKEY_SCHEMA - glider.formats.RSAKEY_SCHEMA.checkMatch(obj) + thandy.formats.RSAKEY_SCHEMA.checkMatch(obj) n = base64ToInt(obj['n']) e = base64ToInt(obj['e']) if obj.has_key('d'): @@ -170,14 +170,14 @@ class RSAKey(PublicKey): def getKeyID(self): if self.keyid == None: d_obj = Crypto.Hash.SHA256.new() - glider.formats.getDigest(self.format(), d_obj) - self.keyid = glider.formats.formatHash(d_obj.digest()) + thandy.formats.getDigest(self.format(), d_obj) + self.keyid = thandy.formats.formatHash(d_obj.digest()) return self.keyid def _digest(self, obj, method=None): if method in (None, "sha256-pkcs1"): d_obj = Crypto.Hash.SHA256.new() - glider.formats.getDigest(obj, d_obj) + thandy.formats.getDigest(obj, d_obj) digest = d_obj.digest() return ("sha256-pkcs1", digest) @@ -292,10 +292,10 @@ def decryptSecret(encrypted, password): Raises BadPassword if the password was not correct. """ if encrypted[:5] != "GKEY1": - raise glider.UnknownFormat() + raise thandy.UnknownFormat() encrypted = encrypted[5:] if len(encrypted) < SALTLEN+1+16: - raise glider.FormatException() + raise thandy.FormatException() salt = encrypted[:SALTLEN+1] iv = encrypted[SALTLEN+1:SALTLEN+1+16] @@ -319,13 +319,13 @@ def decryptSecret(encrypted, password): d.update(salt) if d.digest() != hash: - raise glider.BadPassword() + raise thandy.BadPassword() return secret -class KeyStore(glider.formats.KeyDB): +class KeyStore(thandy.formats.KeyDB): def __init__(self, fname, encrypted=True): - glider.formats.KeyDB.__init__(self) + thandy.formats.KeyDB.__init__(self) self._loaded = None self._fname = fname @@ -392,7 +392,7 @@ class KeyStore(glider.formats.KeyDB): contents = simplejson.dumps(listOfKeys) if self._encrypted: contents = encryptSecret(contents, password) - glider.util.replaceFile(self._fname, contents) + thandy.util.replaceFile(self._fname, contents) self._passwd = password # It worked. logging.info("Done.") diff --git a/lib/glider/master_keys.py b/lib/thandy/master_keys.py index 0d455d1..0d455d1 100644 --- a/lib/glider/master_keys.py +++ b/lib/thandy/master_keys.py diff --git a/lib/glider/repository.py b/lib/thandy/repository.py index b956993..dc13f1b 100644 --- a/lib/glider/repository.py +++ b/lib/thandy/repository.py @@ -1,6 +1,6 @@ -import glider.formats -import glider.util +import thandy.formats +import thandy.util import simplejson import logging @@ -60,7 +60,7 @@ class RepositoryFile: signed_obj,main_obj = self._checkContent(content) fname = self.getPath() - glider.util.replaceFile(fname, contents) + thandy.util.replaceFile(fname, contents) self._signed_obj = signed_obj self._main_obj = main_obj @@ -71,11 +71,11 @@ class RepositoryFile: try: obj = simplejson.loads(content) except ValueError, e: - raise glider.FormatException("Couldn't decode content: %s"%e) + raise thandy.FormatException("Couldn't decode content: %s"%e) if self._signedFormat: # This is supposed to be signed. - glider.formats.SIGNED_SCHEMA.checkMatch(obj) + thandy.formats.SIGNED_SCHEMA.checkMatch(obj) main_obj = obj['signed'] signed_obj = obj @@ -104,7 +104,7 @@ class RepositoryFile: def _checkSignatures(self): self.load() - sigStatus = glider.formats.checkSignatures(self._signed_obj, + sigStatus = thandy.formats.checkSignatures(self._signed_obj, self._repository._keyDB, self._needRole, self._relativePath) self._sigStatus = sigStatus @@ -117,16 +117,16 @@ class RepositoryFile: class LocalRepository: def __init__(self, root): self._root = root - self._keyDB = glider.util.getKeylist(None) + self._keyDB = thandy.util.getKeylist(None) self._keylistFile = RepositoryFile( - self, "/meta/keys.txt", glider.formats.KEYLIST_SCHEMA, + self, "/meta/keys.txt", thandy.formats.KEYLIST_SCHEMA, needRole="master") self._timestampFile = RepositoryFile( - self, "/meta/timestamp.txt", glider.formats.TIMESTAMP_SCHEMA, + self, "/meta/timestamp.txt", thandy.formats.TIMESTAMP_SCHEMA, needRole="timestamp") self._mirrorlistFile = RepositoryFile( - self, "/meta/mirrors.txt", glider.formats.MIRRORLIST_SCHEMA, + self, "/meta/mirrors.txt", thandy.formats.MIRRORLIST_SCHEMA, needRole="mirrors") self._metaFiles = [ self._keylistFile, self._timestampFile, @@ -154,7 +154,7 @@ class LocalRepository: return self._packageFiles[relPath] except KeyError: self._packageFiles[relPath] = pkg = RepositoryFile( - self, relPath, glider.formats.PACKAGE_SCHEMA, + self, relPath, thandy.formats.PACKAGE_SCHEMA, needRole='package') return pkg @@ -163,7 +163,7 @@ class LocalRepository: return self._bundleFiles[relPath] except KeyError: self._bundleFiles[relPath] = pkg = RepositoryFile( - self, relPath, glider.formats.BUNDLE_SCHEMA, + self, relPath, thandy.formats.BUNDLE_SCHEMA, needRole='bundle') return pkg @@ -188,8 +188,8 @@ class LocalRepository: # be good.) ts = self._timestampFile.get() if ts: - age = now - glider.formats.parseTime(ts['at']) - ts = glider.formats.TimestampFile.fromJSon(ts) + age = now - thandy.formats.parseTime(ts['at']) + ts = thandy.formats.TimestampFile.fromJSon(ts) if age > MAX_TIMESTAMP_AGE: need.add(self._timestampFile.getRelativePath()) @@ -217,7 +217,7 @@ class LocalRepository: # FINALLY, we know we have an up-to-date, signed timestamp # file. Check whether the keys and mirrors file are as # authenticated. - h_kf = glider.formats.getDigest(self._keylistFile.get()) + h_kf = thandy.formats.getDigest(self._keylistFile.get()) h_expected = ts.getKeylistInfo().getHash() if h_kf != h_expected: need.add(self._keylistFile.getRelativePath()) @@ -229,7 +229,7 @@ class LocalRepository: if not s.isValid(): need.add(self._mirrorlistFile.getRelativePath()) - h_mf = glider.formats.getDigest(self._mirrorlistFile.get()) + h_mf = thandy.formats.getDigest(self._mirrorlistFile.get()) h_expected = ts.getMirrorlistInfo().getHash() if h_mf != h_expected: need.add(self._mirrorlistFile.getRelativePath()) @@ -255,7 +255,7 @@ class LocalRepository: need.add(rp) continue - h_b = glider.formats.getDigest(bfile.get()) + h_b = thandy.formats.getDigest(bfile.get()) h_expected = binfo.getHash() if h_b != h_expected: need.add(rp) @@ -281,8 +281,8 @@ class LocalRepository: need.add(rp) continue - h_p = glider.formats.getDigest(pfile.get()) - h_expected = glider.formats.parseHash(pkginfo['hash']) + h_p = thandy.formats.getDigest(pfile.get()) + h_expected = thandy.formats.parseHash(pkginfo['hash']) if h_p != h_expected: need.add(rp) continue @@ -299,10 +299,10 @@ class LocalRepository: package = pfile.get() for f in package['files']: rp, h = f[:2] - h_expected = glider.formats.parseHash(h) + h_expected = thandy.formats.parseHash(h) fn = self.getFilename(rp) try: - h_got = glider.formats.getFileDigest(fn) + h_got = thandy.formats.getFileDigest(fn) except OSError: need.add(rp) continue diff --git a/lib/glider/tests.py b/lib/thandy/tests.py index 7aeb4f6..8b967a5 100644 --- a/lib/glider/tests.py +++ b/lib/thandy/tests.py @@ -4,16 +4,16 @@ import doctest import os import tempfile -import glider.keys -import glider.formats -import glider.repository -import glider.checkJson +import thandy.keys +import thandy.formats +import thandy.repository +import thandy.checkJson -import glider.tests +import thandy.tests class CanonicalEncodingTest(unittest.TestCase): def test_encode(self): - enc = glider.formats.encodeCanonical + enc = thandy.formats.encodeCanonical self.assertEquals(enc(''), '""') self.assertEquals(enc('"'), '"\\""') self.assertEquals(enc('\t\\\n"\r'), @@ -23,38 +23,38 @@ class CryptoTests(unittest.TestCase): def test_encrypt(self): s = "The Secret words are marzipan habidashery zeugma." password = "the password is swordfish." - encrypted = glider.keys.encryptSecret(s, password) + encrypted = thandy.keys.encryptSecret(s, password) self.assertNotEquals(encrypted, s) self.assert_(encrypted.startswith("GKEY1")) - self.assertEquals(s, glider.keys.decryptSecret(encrypted, password)) - self.assertRaises(glider.BadPassword, glider.keys.decryptSecret, + self.assertEquals(s, thandy.keys.decryptSecret(encrypted, password)) + self.assertRaises(thandy.BadPassword, thandy.keys.decryptSecret, encrypted, "password") - self.assertRaises(glider.UnknownFormat, glider.keys.decryptSecret, + self.assertRaises(thandy.UnknownFormat, thandy.keys.decryptSecret, "foobar", password) def test_keystore(self): passwd = "umfitty noonah" fname = tempfile.mktemp() - ks = glider.keys.KeyStore(fname) - key1 = glider.keys.RSAKey.generate(512) - key2 = glider.keys.RSAKey.generate(512) + ks = thandy.keys.KeyStore(fname) + key1 = thandy.keys.RSAKey.generate(512) + key2 = thandy.keys.RSAKey.generate(512) ks.addKey(key1) ks.addKey(key2) ks.save(passwd) - ks2 = glider.keys.KeyStore(fname) + ks2 = thandy.keys.KeyStore(fname) ks2.load(passwd) self.assertEquals(key1.key.n, ks2.getKey(key1.getKeyID()).key.n) def suite(): suite = unittest.TestSuite() - suite.addTest(doctest.DocTestSuite(glider.formats)) - suite.addTest(doctest.DocTestSuite(glider.keys)) - suite.addTest(doctest.DocTestSuite(glider.checkJson)) + suite.addTest(doctest.DocTestSuite(thandy.formats)) + suite.addTest(doctest.DocTestSuite(thandy.keys)) + suite.addTest(doctest.DocTestSuite(thandy.checkJson)) loader = unittest.TestLoader() - suite.addTest(loader.loadTestsFromModule(glider.tests)) + suite.addTest(loader.loadTestsFromModule(thandy.tests)) return suite diff --git a/lib/glider/util.py b/lib/thandy/util.py index e2fb57a..e87ed8b 100644 --- a/lib/glider/util.py +++ b/lib/thandy/util.py @@ -5,9 +5,9 @@ import tempfile import simplejson -import glider.formats -import glider.keys -import glider.master_keys +import thandy.formats +import thandy.keys +import thandy.master_keys def moveFile(fromLocation, toLocation): if sys.platform in ('cygwin', 'win32'): @@ -43,17 +43,17 @@ def userFilename(name): return os.path.join(base, name) def getKeylist(keys_fname, checkKeys=True): - import glider.master_keys + import thandy.master_keys - keydb = glider.formats.Keylist() + keydb = thandy.formats.Keylist() - for key in glider.master_keys.MASTER_KEYS: + for key in thandy.master_keys.MASTER_KEYS: keydb.addKey(key) user_keys = userFilename("preload_keys") if os.path.exists(user_keys): #XXXX somewhat roundabout. - keylist = glider.formats.makeKeylistObj(user_keys) + keylist = thandy.formats.makeKeylistObj(user_keys) keydb.addFromKeylist(keylist, allowMasterKeys=True) if keys_fname and os.path.exists(keys_fname): @@ -62,11 +62,11 @@ def getKeylist(keys_fname, checkKeys=True): obj = simplejson.load(f) finally: f.close() - ss, role, path = glider.formats.checkSignedObj(obj, keydb) + ss, role, path = thandy.formats.checkSignedObj(obj, keydb) if role != 'master': - raise glider.FormatException("%s wasn't a keylist."%keys_fname) + raise thandy.FormatException("%s wasn't a keylist."%keys_fname) if checkKeys and not ss.isValid(): - raise glider.FormatException("%s not signed by enough master keys"% + raise thandy.FormatException("%s not signed by enough master keys"% keys_fname) keydb.addFromKeylist(obj['signed'], allowMasterKeys=False) diff --git a/specs/glider-spec.txt b/specs/thandy-spec.txt index b940e49..3c21466 100644 --- a/specs/glider-spec.txt +++ b/specs/thandy-spec.txt @@ -1,5 +1,5 @@ - Glider: Automatic updates for Tor bundles + Thandy: Automatic updates for Tor bundles 0. Preliminaries @@ -10,11 +10,14 @@ 0.1. Proposed code name - Since "auto-update" is so generic, I've been thinking about going with + Since "auto-update" is so generic, I had been thinking about going with "glider", based on the sugar glider you get when you search for "handy - pocket creature". I haven't yet done a search to find out whether - somebody else is using the name, so we shouldn't get too attached to it - before we see if it's taken. + pocket creature". Based on conversations, it seems that "glider" + is taken by a well-known WoW bot, so I'm rechristening this thing + as "Thandy" (which could stand for Tor's Handy pocket creature if + you want it to, or which could also be a person's first name). + + Some of this document still refers to "Glider", and needs to be updated. 0.2. Non-goals |