GString *data3 = g_string_new("");
bluesky_serialize_cloudlog(log, data1, data2, data3);
- /* TODO: Right now offset/size are set to the raw data, but we should add
- * header parsing to the code which loads objects back in. */
log->location = state->location;
log->location.offset = state->data->len;
log->data_size = data1->len;
struct cloudlog_header header;
memcpy(header.magic, CLOUDLOG_MAGIC, 4);
+ memset(header.crypt_auth, sizeof(header.crypt_auth), 0);
+ memset(header.crypt_iv, sizeof(header.crypt_iv), 0);
header.type = log->type + '0';
header.size1 = GUINT32_TO_LE(data1->len);
header.size2 = GUINT32_TO_LE(data2->len);
from boto.s3.key import Key
# The BlueSky 'struct cloudlog_header' data type.
-HEADER_FORMAT = '<4sb16sQIII'
+HEADER_FORMAT = '<4s48sb16sQIII'
+HEADER_CRYPTBYTES = 48
HEADER_MAGIC = 'AgI-'
HEADER_SIZE = struct.calcsize(HEADER_FORMAT)
class LogItem:
"""In-memory representation of a single item stored in a log file."""
+ def __init__(self):
+ self.cryptkeys = '\0' * HEADER_CRYPTBYTES
+
def __str__(self):
return "<Item ty=%s location=%s size=%d id=%s...>" % (self.type, self.location, self.size, base64.b16encode(self.id).lower()[0:8])
link_locs = ''.join(link_locs)
header = struct.pack(HEADER_FORMAT,
- HEADER_MAGIC, ord(self.type), self.id, self.inum,
+ HEADER_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
def parse_item(data):
if len(data) < HEADER_SIZE: return
header = struct.unpack_from(HEADER_FORMAT, data, 0)
- size = HEADER_SIZE + sum(header[4:7])
+ size = HEADER_SIZE + sum(header[5:8])
if header[0] != HEADER_MAGIC:
print "Bad header magic!"
return
if len(data) != size:
- print "Item size does not match!"
+ print "Item size does not match: %d != %d" % (size, len(data))
return
item = LogItem()
- item.id = header[2]
- item.inum = header[3]
+ item.cryptkeys = header[1]
+ item.id = header[3]
+ item.inum = header[4]
item.location = None
- item.type = chr(header[1])
+ item.type = chr(header[2])
item.size = size
- item.data = data[HEADER_SIZE : HEADER_SIZE + header[4]]
+ item.data = data[HEADER_SIZE : HEADER_SIZE + header[5]]
links = []
- link_ids = data[HEADER_SIZE + header[4]
- : HEADER_SIZE + header[4] + header[5]]
- link_locs = data[HEADER_SIZE + header[4] + header[5]
- : HEADER_SIZE + sum(header[4:7])]
+ link_ids = data[HEADER_SIZE + header[5]
+ : HEADER_SIZE + header[5] + header[6]]
+ link_locs = data[HEADER_SIZE + header[5] + header[6]
+ : HEADER_SIZE + sum(header[5:8])]
for i in range(len(link_ids) // 16):
id = link_ids[16*i : 16*i + 16]
if id == '\0' * 16:
offset = 0
while len(data) - offset >= HEADER_SIZE:
header = struct.unpack_from(HEADER_FORMAT, data, offset)
- size = HEADER_SIZE + sum(header[4:7])
+ size = HEADER_SIZE + sum(header[5:8])
if header[0] != HEADER_MAGIC:
print "Bad header magic!"
break