def validChannelCastMsg(channelcast_data): if not isinstance(channelcast_data, dict): return False for signature, ch in channelcast_data.items(): if not isinstance(ch, dict): if DEBUG: print >> sys.stderr, 'validChannelCastMsg: value not dict' return False length = len(ch) if not 6 <= length <= 7: if DEBUG: print >> sys.stderr, 'validChannelCastMsg: #keys!=7' return False if not ('publisher_id' in ch and 'publisher_name' in ch and 'infohash' in ch and 'torrenthash' in ch and 'torrentname' in ch and 'time_stamp' in ch): if DEBUG: print >> sys.stderr, 'validChannelCastMsg: key missing' return False if length == 7: if 'rich_metadata' not in ch: if DEBUG: print >> sys.stderr, 'validChannelCastMsg: key missing' return False if not validMetadataEntry(ch['rich_metadata']): print >> sys.stderr, 'validChannelCastMsg: invalid rich metadata' return False if not (validPermid(ch['publisher_id']) and isinstance(ch['publisher_name'], str) and validInfohash(ch['infohash']) and validInfohash(ch['torrenthash']) and isinstance(ch['torrentname'], str) and validTimestamp(ch['time_stamp'])): if DEBUG: print >> sys.stderr, 'validChannelCastMsg: something not valid' return False l = (ch['publisher_id'], ch['infohash'], ch['torrenthash'], ch['time_stamp']) if not verify_data(bencode(l), ch['publisher_id'], signature): if DEBUG: print >> sys.stderr, 'validChannelCastMsg: verification failed!' return False return True
def verifySignature(self): toVerify = self._packData() binaryPermId = self.channel return verify_data(toVerify, binaryPermId, self.signature)