def validChannelCastMsg(channelcast_data): """ Returns true if ChannelCastMsg is valid, format: {'signature':{'publisher_id':, 'publisher_name':, 'infohash':, 'torrenthash':, 'torrent_name':, 'timestamp':, 'signature':}} """ 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,"rvalidChannelCastMsg: a: value not dict" return False if len(ch) !=6: if DEBUG: print >>sys.stderr,"rvalidChannelCastMsg: a: #keys!=6" 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: a: key missing, got",d.keys() return False if not (validPermid(ch['publisher_id']) and (isinstance(ch['publisher_name'],str) or isinstance(ch['publisher_name'], unicode)) and validInfohash(ch['infohash']) and validInfohash(ch['torrenthash']) and (isinstance(ch['torrentname'],str) or isinstance(ch['torrentname'],unicode)) and validTimestamp(ch['time_stamp'])): if DEBUG: print >>sys.stderr,"validChannelCastMsg: something not valid" return False # now, verify signature l = (ch['publisher_id'],ch['infohash'], ch['torrenthash'], ch['time_stamp']) if not verify_data(bencode(l),str2bin(ch['publisher_id']),str2bin(signature)): if DEBUG: print >>sys.stderr, "validChannelCastMsg: verification failed!" return False return True
def validChannelCastMsg(channelcast_data): """ Returns true if ChannelCastMsg is valid, format: {'signature':{'publisher_id':, 'publisher_name':, 'infohash':, 'torrenthash':, 'torrent_name':, 'timestamp':, 'signature':}} """ 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,time.asctime(),'-', "validChannelCastMsg: value not dict" return False # 08-04-2010 We accept both 6 and 7 fields to allow # compatibility with messages from older versions # the rich metadata field length = len(ch) if not 6 <= length <= 7: if DEBUG: print >>sys.stderr,time.asctime(),'-', "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,time.asctime(),'-', "validChannelCastMsg: key missing" return False if length == 7: if 'rich_metadata' not in ch: #enriched Channelcast if DEBUG: print >>sys.stderr,time.asctime(),'-', "validChannelCastMsg: key missing" return False else: if not validMetadataEntry(ch['rich_metadata']): print >> sys.stderr, time.asctime(),'-', "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,time.asctime(),'-', "validChannelCastMsg: something not valid" return False # now, verify signature # Nitin on Feb 5, 2010: Signature is validated using binary forms of permid, infohash, torrenthash fields 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, time.asctime(),'-', "validChannelCastMsg: verification failed!" return False return True
def verifySignature(self): """ Verifies the signature field of this instance. The signature is verified agains the packed version of this instance. See _packData """ assert self.signature is not None toVerify = self._packData() binaryPermId = self.channel return verify_data(toVerify, binaryPermId, self.signature)
def validChannelCastMsg(channelcast_data): """ Returns true if ChannelCastMsg is valid, format: {'signature':{'publisher_id':, 'publisher_name':, 'infohash':, 'torrenthash':, 'torrent_name':, 'timestamp':, 'signature':}} """ 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, "rvalidChannelCastMsg: a: value not dict" return False if len(ch) != 6: if DEBUG: print >> sys.stderr, "rvalidChannelCastMsg: a: #keys!=6" 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: a: key missing, got", d.keys( ) return False if not (validPermid(ch['publisher_id']) and (isinstance(ch['publisher_name'], str) or isinstance(ch['publisher_name'], unicode)) and validInfohash(ch['infohash']) and validInfohash(ch['torrenthash']) and (isinstance(ch['torrentname'], str) or isinstance(ch['torrentname'], unicode)) and validTimestamp(ch['time_stamp'])): if DEBUG: print >> sys.stderr, "validChannelCastMsg: something not valid" return False # now, verify signature l = (ch['publisher_id'], ch['infohash'], ch['torrenthash'], ch['time_stamp']) if not verify_data(bencode(l), str2bin(ch['publisher_id']), str2bin(signature)): if DEBUG: print >> sys.stderr, "validChannelCastMsg: verification failed!" return False return True