From: Michael Vrable Date: Mon, 18 Oct 2010 04:40:44 +0000 (-0700) Subject: Support encrypted log items in the cleaner. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=c1f4367b3c65b01562bc6484226dff0135cd4780;p=bluesky.git Support encrypted log items in the cleaner. --- diff --git a/cleaner/cleaner b/cleaner/cleaner index 009ebe8..95bbb08 100755 --- a/cleaner/cleaner +++ b/cleaner/cleaner @@ -15,7 +15,8 @@ from boto.s3.key import Key # The BlueSky 'struct cloudlog_header' data type. HEADER_FORMAT = '<4s48sb16sQIII' HEADER_CRYPTBYTES = 48 -HEADER_MAGIC = 'AgI-' +HEADER_MAGIC1 = 'AgI-' # Unencrypted data +HEADER_MAGIC2 = 'AgI=' # Encrypted data HEADER_SIZE = struct.calcsize(HEADER_FORMAT) class ITEM_TYPE: @@ -131,9 +132,10 @@ class LogItem: def __init__(self): self.cryptkeys = '\0' * HEADER_CRYPTBYTES + self.encrypted = False def __str__(self): - return "" % (self.type, self.location, self.size, base64.b16encode(self.id).lower()[0:8]) + return "" % (self.encrypted and '$' or '', self.type, self.location, self.size, base64.b16encode(self.id).lower()[0:8]) @staticmethod def random_id(): @@ -149,8 +151,12 @@ class LogItem: link_ids = ''.join(link_ids) link_locs = ''.join(link_locs) + if self.encrypted: + magic = HEADER_MAGIC2 + else: + magic = HEADER_MAGIC1 header = struct.pack(HEADER_FORMAT, - HEADER_MAGIC, self.cryptkeys, + magic, self.cryptkeys, ord(self.type), self.id, self.inum, len(self.data), len(link_ids), len(link_locs)) return header + self.data + link_ids + link_locs @@ -232,7 +238,7 @@ def parse_item(data): header = struct.unpack_from(HEADER_FORMAT, data, 0) size = HEADER_SIZE + sum(header[5:8]) - if header[0] != HEADER_MAGIC: + if header[0] not in (HEADER_MAGIC1, HEADER_MAGIC2): print "Bad header magic!" return @@ -241,6 +247,7 @@ def parse_item(data): return item = LogItem() + if header[0] == HEADER_MAGIC2: item.encrypted = True item.cryptkeys = header[1] item.id = header[3] item.inum = header[4] @@ -289,7 +296,7 @@ def parse_log(data, location=None): while len(data) - offset >= HEADER_SIZE: header = struct.unpack_from(HEADER_FORMAT, data, offset) size = HEADER_SIZE + sum(header[5:8]) - if header[0] != HEADER_MAGIC: + if header[0] not in (HEADER_MAGIC1, HEADER_MAGIC2): print "Bad header magic!" break if size + offset > len(data):